:root {
  --primary: #82cfff;
  --on-primary: #003549;
  --primary-container: #004d68;
  --on-primary-container: #c6e7ff;
  --secondary: #b4cada;
  --on-secondary: #1e333f;
  --secondary-container: #354a56;
  --on-secondary-container: #cfe6f6;
  --tertiary: #8dcfa0;
  --on-tertiary: #003920;
  --tertiary-container: #005230;
  --on-tertiary-container: #a8ecba;
  --error: #ffb4ab;
  --on-error: #690005;
  --error-container: #93000a;
  --on-error-container: #ffdad6;
  --surface: #0d0d0d;
  --on-surface: #e2e2e6;
  --surface-dim: #0d0d0d;
  --surface-bright: #353535;
  --surface-lowest: #050505;
  --surface-low: #1a1a1a;
  --surface-container: #252525;
  --surface-high: #303030;
  --surface-highest: #3b3b3b;
  --on-surface-variant: #c4c6d0;
  --outline: #8e9099;
  --outline-variant: #44474f;
  --scrim: #000;
  --elevation-0: none;
  --elevation-1: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.15);
  --elevation-2: 0 1px 2px rgba(0,0,0,0.3), 0 2px 6px rgba(0,0,0,0.2);
  --elevation-3: 0 2px 4px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
  --elevation-4: 0 2px 4px rgba(0,0,0,0.3), 0 8px 16px rgba(0,0,0,0.2);
  --elevation-5: 0 4px 8px rgba(0,0,0,0.3), 0 12px 24px rgba(0,0,0,0.2);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 20px;
  background: var(--surface);
  color: var(--on-surface);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
body {
  max-width: 480px;
  margin: 0 auto;
}

.app-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  height: 56px;
  background: var(--surface-low);
  box-shadow: var(--elevation-2);
  box-sizing: border-box;
}
.app-header button {
  background: none;
  border: none;
  color: var(--on-surface-variant);
  font-size: 22px;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}
.app-header button:first-child { left: 12px; }
.app-header button:last-child { right: 12px; }
.app-header button:hover { background: rgba(226,226,230,0.04); }
.app-header button:active { background: rgba(226,226,230,0.10); }

.header-logo {
  height: 22px;
  object-fit: contain;
}
body.in-app .header-logo { display: none; }

.app-content {
  padding-top: 56px;
  padding-bottom: 12px;
}

.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
}

.panel {
  position: fixed;
  top: 10px;
  width: 63.75%;
  max-width: 320px;
  max-height: calc(100vh - 10px);
  background: var(--surface-container);
  z-index: 300;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: var(--elevation-1);
  padding: 16px 0;
}
.panel-left { left: 0; border-radius: 0 16px 16px 0; }
.panel-right { right: 0; border-radius: 16px 0 0 16px; }
.panel-header {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--on-surface-variant);
  cursor: default;
}

.panel-link {
  color: inherit;
  text-decoration: none;
}

.menu-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-right: 12px;
  vertical-align: middle;
  background-color: currentColor;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}
.menu-icon-back {
  --url: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20z'/></svg>");
  -webkit-mask-image: var(--url);
  mask-image: var(--url);
}
.menu-icon-website {
  --url: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 1a11 11 0 1 0 0 22 11 11 0 0 0 0-22m0 2c.05.03.15.09.32.26q.47.45 1.01 1.72c.61 1.5 1.05 3.6 1.15 6.02H9.52c.1-2.42.54-4.53 1.15-6.02q.54-1.26 1.02-1.73.24-.23.31-.24m-2.83.46C8.24 5.28 7.62 7.96 7.51 11H3.06a9 9 0 0 1 6.1-7.54m5.66 0A9 9 0 0 1 20.94 11h-4.46c-.11-3.04-.73-5.72-1.65-7.54M9.52 13h4.96c-.1 2.42-.54 4.53-1.15 6.02a6 6 0 0 1-1.02 1.73q-.24.22-.31.24a1 1 0 0 1-.31-.24 6 6 0 0 1-1.02-1.73c-.61-1.5-1.05-3.6-1.15-6.02m-6.46 0h4.46c.11 3.04.73 5.72 1.65 7.54A9 9 0 0 1 3.05 13m13.42 0h4.46a9 9 0 0 1-6.1 7.54c.91-1.82 1.53-4.5 1.64-7.54'/></svg>");
  -webkit-mask-image: var(--url);
  mask-image: var(--url);
}
.menu-icon-logout {
  --url: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M19 2a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H9a1 1 0 0 1 0-2h10V4H9a1 1 0 0 1 0-2zM9.3 7.3a1 1 0 0 0 0 1.4l2.29 2.3H4a1 1 0 0 0 0 2h7.59l-2.3 2.3a1 1 0 1 0 1.42 1.4l4.7-4.7-4.7-4.7a1 1 0 0 0-1.42 0'/></svg>");
  -webkit-mask-image: var(--url);
  mask-image: var(--url);
}

.menu-list {
  list-style: none;
}
.menu-list li {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.menu-list li:hover {
  background: rgba(226,226,230,0.04);
}
.menu-list li:active {
  background: rgba(226,226,230,0.10);
}

.device-list { list-style: none; }
.device-list li {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.device-list li:hover { background: rgba(226,226,230,0.04); }
.device-list li:active { background: rgba(226,226,230,0.10); }
.device-list li.active { background: rgba(130,207,255,0.08); }
.device-list li img {
  width: 48px;
  height: auto;
  object-fit: contain;
  border-radius: 0;
  margin-right: 12px;
}
.device-list li .device-info { flex: 1; min-width: 0; }
.device-list li .device-name {
  font-size: 16px;
  font-weight: 500;
  line-height: 24px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-list li .device-meta {
  font-size: 12px;
  line-height: 16px;
  color: var(--on-surface-variant);
  margin-top: 2px;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  line-height: 16px;
  border-radius: 4px;
}
.status-online {
  background: var(--tertiary-container);
  color: var(--on-tertiary-container);
}
.status-offline {
  background: var(--error-container);
  color: var(--on-error-container);
}
.perm-icon {
  font-size: 14px;
  opacity: 0.45;
  margin-left: 4px;
  line-height: 1;
  display: inline-block;
  vertical-align: middle;
}
.device-header .perm-icon img,
.device-meta .perm-icon img {
  height: 20px;
  width: 20px;
  object-fit: contain;
  object-position: left center;
  border-radius: 0;
  filter: invert(0.7);
}

.device-category {
  margin: 10px 12px;
  background: var(--surface-low);
  border-radius: 16px;
  overflow: hidden;
}
.device-category h2 {
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  letter-spacing: 0.25px;
  color: var(--primary);
  padding: 12px 16px 8px;
  text-transform: none;
}

.param-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: default;
  position: relative;
}
.param-row.param-editable { cursor: pointer; }
.param-row.param-editable:hover {
  background: rgba(226,226,230,0.04);
}
.param-row.param-editable:active {
  background: rgba(226,226,230,0.10);
}
.param-row + .param-row {
  border-top: 1px solid var(--outline-variant);
}
.param-row.param-editable {
  border-right: 3px solid var(--primary);
}
.param-label {
  font-size: 14px;
  line-height: 20px;
  color: var(--on-surface);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.param-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
  transition: background 0.3s;
}
.dot-saving {
  background: #d9534f;
  animation: pulse-dot 1s ease-in-out infinite;
}
.dot-sent {
  background: #f0ad4e;
  animation: pulse-dot 1s ease-in-out infinite;
}
.dot-done {
  background: #5cb85c;
  animation: fade-out-dot 0.5s ease-out 2.5s forwards;
}
.dot-fail {
  background: #d9534f;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
@keyframes fade-out-dot {
  to { opacity: 0; transform: scale(0); }
}
.param-value {
  font-size: 14px;
  line-height: 20px;
  color: var(--primary);
  font-weight: 600;
  margin-left: 10px;
  white-space: nowrap;
}

.device-header {
  display: flex;
  align-items: center;
  padding: 16px;
  background: var(--surface-low);
  margin: 10px 12px;
  border-radius: 16px;
  box-shadow: var(--elevation-1);
}
.device-header img {
  width: 56px;
  height: auto;
  object-fit: contain;
  margin-right: 16px;
}
.device-header .device-title { font-size: 18px; font-weight: 500; line-height: 24px; }
.device-header .device-online { margin-top: 4px; }

.alarms-section {
  margin: 10px 12px;
  border-radius: 16px;
  overflow: hidden;
}
.alarms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--error-container);
  color: var(--on-error-container);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  transition: background 0.15s;
}
.alarms-header:hover { background: rgba(147,0,10,0.9); }
.alarms-header .alarms-count {
  background: rgba(255,218,214,0.2);
  padding: 1px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.alarm-item {
  padding: 8px 16px;
  background: var(--surface-low);
  font-size: 13px;
  line-height: 20px;
  border-bottom: 1px solid var(--outline-variant);
}
.alarm-item:last-of-type { border-bottom: none; }

.popup-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
}
.popup {
  background: var(--surface-container);
  border-radius: 16px;
  min-width: 280px;
  max-width: 90%;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--elevation-3);
}
.popup-header {
  padding: 16px 16px 0;
  font-weight: 500;
  font-size: 16px;
  line-height: 24px;
}
.popup-body {
  padding: 16px;
}
.popup-body .current-value {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
}
.popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 16px 16px;
}
.popup-actions button {
  padding: 8px 20px;
  border: none;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.popup-actions .btn-save {
  background: var(--primary);
  color: var(--on-primary);
}
.popup-actions .btn-save:hover { background: rgba(130,207,255,0.85); }
.popup-actions .btn-cancel {
  background: var(--surface-high);
  border: 1px solid var(--outline-variant);
  color: var(--on-surface-variant);
}
.popup-actions .btn-cancel:hover { background: rgba(196,198,208,0.08); }

.popup-body input[type="range"] {
  width: 100%;
  margin: 10px 0;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--outline-variant);
  outline: none;
  position: relative;
}
.popup-body input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: var(--elevation-1);
}

.slider-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.step-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--outline);
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface);
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  user-select: none;
  -webkit-user-select: none;
}
.step-btn:hover { background: rgba(226,226,230,0.04); }
.step-btn:active { background: rgba(226,226,230,0.10); }
.step-btn.btn-pressed {
  background: rgba(226, 226, 230, 0.15);
}

.popup-option-list { list-style: none; }
.popup-option-list li {
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
  font-size: 15px;
  line-height: 20px;
  border-radius: 8px;
  margin-bottom: 2px;
}
.popup-option-list li:hover { background: rgba(226,226,230,0.04); }
.popup-option-list li.selected {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--outline-variant);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface-low);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--elevation-1);
}
.login-box h1 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 22px;
  font-weight: 500;
  line-height: 28px;
  color: var(--primary);
}
.login-box h1 b { font-weight: 500; }
.login-box .error-msg {
  display: none;
  padding: 10px 12px;
  background: var(--error-container);
  color: var(--on-error-container);
  border-radius: 8px;
  margin-bottom: 12px;
  text-align: center;
  font-size: 13px;
  line-height: 20px;
}
.login-box .error-msg.visible { display: block; }

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  color: var(--on-surface-variant);
}
.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: transparent;
  color: var(--on-surface);
  font-size: 15px;
  line-height: 20px;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus {
  border-color: var(--primary);
  border-width: 2px;
  padding: 11px 13px;
}

.btn-primary {
  width: 100%;
  padding: 10px 20px;
  border: none;
  border-radius: 16px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 15px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 4px;
}
.btn-primary:hover { background: rgba(130,207,255,0.85); }
.btn-primary:disabled { background: rgba(130,207,255,0.3); color: rgba(0,53,73,0.5); cursor: not-allowed; }

.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes fadeInLeft { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
.animated { animation-duration: 0.3s; animation-fill-mode: both; }
.fadeIn { animation-name: fadeIn; }
.fadeOut { animation-name: fadeOut; }
.fadeInLeft { animation-name: fadeInLeft; }
.fadeInRight { animation-name: fadeInRight; }

.lang-btn {
  flex:1; padding:10px 6px; min-width:44px;
  border:1px solid var(--outline); border-radius:16px;
  background:transparent; color:var(--on-surface-variant);
  font-size:14px; font-weight:500; line-height:20px;
  cursor:pointer; text-align:center; transition:all .15s;
}
.lang-btn:hover { background: rgba(226,226,230,0.04); }
.lang-btn.active {
  background:var(--primary-container); border-color:var(--primary-container);
  color:var(--on-primary-container);
}

.confirm-body {
  text-align:center; font-size:15px; line-height:22px;
  color:var(--on-surface); padding:12px 0;
}
.btn-danger {
  background:var(--error); color:var(--on-error);
}
.btn-danger:hover { background: rgba(255,180,171,0.85); }

