/* ── RESET & ROOT ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg:       #111111;
  --card:     #1C1C1E;
  --card2:    #2C2C2E;
  --card3:    #3A3A3C;
  --accent:   #30D158;
  --text:     #FFFFFF;
  --text2:    #8E8E93;
  --sep:      #2C2C2E;
  --red:      #FF453A;
  --tab-h:    80px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── PAGES ── */
.page {
  display: none;
  position: fixed;
  inset: 0;
  bottom: var(--tab-h);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page.active { display: block; }

/* ── HEADER ── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(var(--safe-top) + 20px) 20px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-sub {
  font-size: 12px;
  color: var(--text2);
  margin-top: 3px;
}

/* ── STATUS BADGE ── */
.status-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(48,209,88,0.1);
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
  margin-top: 4px;
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 2.5s ease-in-out infinite;
}

.status-badge.offline {
  background: rgba(255,69,58,0.1);
  color: var(--red);
}

.status-badge.offline .status-dot {
  background: var(--red);
  animation: none;
}

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── CONTENT ── */
.content {
  padding: 4px 16px calc(var(--safe-bot) + 24px);
}

/* ── SECTION LABEL ── */
.sec-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text2);
  margin: 16px 4px 8px;
}

/* ── SENSOR GRID ── */
.sensor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sensor-card {
  background: var(--card);
  border-radius: 18px;
  padding: 16px 15px;
}

.sc-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}

.sc-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
}

.sc-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
}

.sc-range {
  font-size: 11px;
  color: var(--text2);
  margin-top: 7px;
  min-height: 14px;
}

/* ── DEVICE LIST ── */
.device-list {
  background: var(--card);
  border-radius: 18px;
  overflow: hidden;
}

.device-row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
  border-bottom: 1px solid var(--sep);
}

.device-row:last-child { border-bottom: none; }

.device-info { flex: 1; }

.device-name {
  font-size: 15px;
  font-weight: 500;
}

.device-status {
  font-size: 12px;
  color: var(--text2);
  margin-top: 2px;
}

.device-status.on { color: var(--accent); }

/* ── TOGGLE ── */
.tog {
  position: relative;
  width: 48px; height: 28px;
  flex-shrink: 0;
  cursor: pointer;
}

.tog input { display: none; }

.tog-track {
  position: absolute;
  inset: 0;
  border-radius: 100px;
  background: var(--card2);
  transition: background .25s;
}

.tog input:checked + .tog-track { background: var(--accent); }

.tog-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 24px; height: 24px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  transition: transform .25s cubic-bezier(.34,1.4,.64,1);
  pointer-events: none;
}

.tog input:checked ~ .tog-thumb { transform: translateX(20px); }

/* ── THRESH CARD ── */
.thresh-card {
  background: var(--card);
  border-radius: 18px;
  padding: 16px 16px 18px;
  margin-bottom: 10px;
}

.thresh-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.thresh-title {
  font-size: 15px;
  font-weight: 600;
}

.thresh-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(48,209,88,0.1);
  padding: 3px 10px;
  border-radius: 20px;
}

.thresh-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.thresh-field label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.thresh-field input[type=number] {
  width: 100%;
  background: var(--card2);
  border: none;
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  font-family: inherit;
  -moz-appearance: textfield;
  transition: background .2s;
}

.thresh-field input[type=number]::-webkit-outer-spin-button,
.thresh-field input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }

.thresh-field input[type=number]:focus { background: var(--card3); }

.thresh-unit {
  font-size: 11px;
  color: var(--text2);
  text-align: right;
  margin-top: 5px;
}

/* ── SAVE BUTTON ── */
.save-btn {
  width: 100%;
  margin-top: 20px;
  padding: 15px;
  background: var(--accent);
  color: #000;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .2s, transform .1s;
}

.save-btn:active { opacity: 0.85; transform: scale(0.98); }

/* ── COMING SOON ── */
.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 60px 24px;
  gap: 12px;
}

.cs-icon {
  width: 64px; height: 64px;
  background: var(--card);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.cs-icon svg {
  width: 32px; height: 32px;
  color: var(--text2);
}

.coming-soon h3 {
  font-size: 20px;
  font-weight: 700;
}

.coming-soon p {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.55;
  max-width: 280px;
}

.cs-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}

.cs-chip {
  background: var(--card);
  border-radius: 20px;
  padding: 6px 13px;
  font-size: 12px;
  color: var(--text2);
}

/* ── TAB BAR ── */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tab-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  background: rgba(18,18,18,0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--sep);
  display: flex;
  align-items: flex-start;
  padding-top: 10px;
  z-index: 100;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  transition: color .2s;
  padding: 0;
}

.tab-item svg {
  width: 24px; height: 24px;
  transition: transform .2s;
}

.tab-item span {
  font-size: 10px;
  font-weight: 500;
  font-family: inherit;
}

.tab-item.active { color: var(--accent); }
.tab-item.active svg { transform: scale(1.08); }

/* ── SKELETON LOADER ── */
.skeleton {
  background: linear-gradient(90deg, var(--card) 25%, var(--card2) 50%, var(--card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
  color: transparent;
  user-select: none;
}

@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }
