*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
:root {
  --radius: 16px;
}
[data-theme="dark"] {
  --bg: #0a0b10;
  --surface: rgba(255,255,255,.04);
  --surface2: rgba(255,255,255,.06);
  --border: rgba(255,255,255,.06);
  --border-active: rgba(255,255,255,.12);
  --text: #f0f2f8;
  --text-dim: rgba(255,255,255,.35);
  --text-muted: rgba(255,255,255,.5);
  --accent: #7c6df0;
  --accent-glow: rgba(124,109,240,.25);
  --green: #34d399;
  --orange: #fb923c;
  --blue: #60a5fa;
  --red: #f87171;
  --sched-bg: #14151e;
}
[data-theme="light"] {
  --bg: #f4f5f9;
  --surface: rgba(0,0,0,.03);
  --surface2: rgba(0,0,0,.05);
  --border: rgba(0,0,0,.08);
  --border-active: rgba(0,0,0,.14);
  --text: #1a1a2e;
  --text-dim: rgba(0,0,0,.35);
  --text-muted: rgba(0,0,0,.45);
  --accent: #6d5ee0;
  --accent-glow: rgba(109,94,224,.2);
  --green: #16a34a;
  --orange: #d97706;
  --blue: #2563eb;
  --red: #dc2626;
  --sched-bg: #ffffff;
}
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: -apple-system, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none;
}

/* Header */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px; flex-shrink: 0;
}
header h1 { font-size: 20px; font-weight: 700; letter-spacing: -.3px; white-space: nowrap; }
header h1 span { color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); font-weight: 500; flex-wrap: wrap; justify-content: flex-end; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); }

/* Sensor display in header */
.sensor-display {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12px; font-weight: 600;
}
.sensor-icon { font-size: 14px; }
.sensor-temp { color: var(--blue); }
.sensor-hum { color: var(--green); }
.admin-link {
  font-size: 16px; cursor: pointer; opacity: .4;
  transition: opacity .2s; text-decoration: none; color: var(--text-muted);
}
.admin-link:hover { opacity: .8; }
.search-toggle {
  font-size: 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); padding: 4px 8px;
  border-radius: 8px; transition: all .2s; font-family: inherit;
}
.search-toggle:hover { background: var(--surface2); color: var(--text); }
.theme-btn {
  font-size: 13px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); padding: 4px 10px;
  border-radius: 20px; line-height: 1; font-weight: 600;
  transition: all .2s; font-family: inherit;
  display: flex; align-items: center; gap: 4px;
}
.theme-btn:hover { background: var(--surface2); color: var(--text); }
.logout-btn { gap: 5px; }
.logout-btn:hover { background: rgba(248,113,113,.12); border-color: rgba(248,113,113,.25); color: var(--red); }
.refresh-btn {
  font-size: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); padding: 5px 14px;
  border-radius: 8px; line-height: 1; font-weight: 600;
  transition: all .2s; font-family: inherit;
}
.refresh-btn:hover { background: var(--surface2); color: var(--text); }
.rficon { display: inline-block; width: 12px; height: 12px; vertical-align: middle; }
.rficon::after { content: '↻'; font-size: 13px; line-height: 1; }
.refresh-btn.spin .rficon::after { content: ''; }
.refresh-btn.spin .rficon {
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Groups bar */
.groups-bar {
  display: flex; gap: 8px; padding: 4px 16px 8px;
  overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none; -ms-overflow-style: none;
}
.groups-bar::-webkit-scrollbar { display: none; }
.group-btn {
  flex-shrink: 0;
  padding: 8px 18px; border-radius: 12px;
  font-size: 13px; font-weight: 700;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  transition: all .25s; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
  border-left: 3px solid transparent;
  touch-action: manipulation;
  position: relative;
}
.group-btn:active { transform: scale(.95); }
.group-btn.on {
  background: var(--accent); border-color: var(--accent);
  color: #fff; box-shadow: 0 4px 16px var(--accent-glow);
}
.group-btn .grp-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.group-btn .grp-count {
  font-size: 10px; opacity: .5; font-weight: 500;
}
.group-btn.has-sched::after {
  content: ''; position: absolute; top: 4px; right: 4px;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); opacity: .8;
}

/* Scenes bar */
.scenes-bar {
  display: flex; gap: 8px; padding: 0 16px 8px;
  overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none; -ms-overflow-style: none;
}
.scenes-bar::-webkit-scrollbar { display: none; }
.scenes-bar:empty { display: none; }
.scene-btn {
  flex-shrink: 0;
  padding: 8px 16px; border-radius: 12px;
  font-size: 12px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  transition: all .25s; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
  touch-action: manipulation;
}
.scene-btn:active { transform: scale(.95); }
.scene-btn .scene-icon { font-size: 14px; }
.scene-btn.on {
  background: var(--accent); border-color: var(--accent);
  color: #fff; box-shadow: 0 4px 16px var(--accent-glow);
}
.scene-btn:hover {
  background: rgba(124,109,240,.1); border-color: var(--accent);
  color: var(--accent);
}
.scene-btn.has-sched {
  border-color: var(--accent);
}
.scene-btn.has-sched::after {
  content: ''; position: absolute; top: 4px; right: 4px;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); opacity: .8;
}
.scene-btn { position: relative; }

/* Room tabs */
.room-tabs {
  display: flex; gap: 6px; padding: 8px 16px 4px;
  overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none; -ms-overflow-style: none;
  touch-action: manipulation;
}
.room-tabs::-webkit-scrollbar { display: none; }
.room-tab {
  flex-shrink: 0;
  padding: 6px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  transition: all .25s; white-space: nowrap;
  letter-spacing: .2px;
}
.room-tab:active { transform: scale(.95); }
.room-tab.active {
  background: var(--accent); border-color: var(--accent);
  color: #fff; box-shadow: 0 4px 16px var(--accent-glow);
}
.room-tab .count {
  display: inline-block; margin-left: 4px;
  font-size: 10px; opacity: .5;
}
.room-tab.active .count { opacity: .6; }

/* Cards container (scrollable) */
.cards-area {
  flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 12px;
  scroll-behavior: smooth; -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.room-group {
  margin-top: 10px;
}
.room-group.hidden { display: none; }
.room-group:first-child { margin-top: 0; }
.room-group .group-label {
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  padding: 10px 0 6px;
}
.device-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 6px 10px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-align: center;
  transition: all .3s cubic-bezier(.4,0,.2,1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden; min-width: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sched-badge {
  position: absolute; top: 6px; right: 6px;
  width: 18px; height: 18px;
  display: none; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(124,109,240,.15);
  color: var(--accent);
  pointer-events: none;
}
.sched-badge svg { width: 10px; height: 10px; display: block; }
.sched-badge.has-sched { display: flex; }

.card::before {
  content: ''; position: absolute; inset: 0;
  border-radius: var(--radius);
  opacity: 0;
  transition: opacity .4s;
  pointer-events: none;
}
.card:active { transform: scale(.94); }
.card.busy { transform: scale(.93); opacity: .7; transition: all .15s; }
.cards-area.busy { pointer-events: none; }
.cards-area.busy .card { opacity: .45; transition: opacity .15s; }
.cards-area.busy .card.busy { opacity: .35; }
.card.on {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 32px rgba(124,109,240,.08);
}
.card.on::before {
  opacity: 1;
  background: linear-gradient(135deg, rgba(124,109,240,.06), transparent 60%);
}

/* Device icon container */
.icon-wrap {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  border-radius: 50%;
  background: rgba(255,255,255,.03);
  transition: all .4s;
}
.card.on .icon-wrap {
  background: rgba(124,109,240,.08);
}
.icon-wrap svg { width: 24px; height: 24px; pointer-events: none; }
.icon-wrap svg * { pointer-events: none; }

/* Bulb */
.bulb-off { fill: #3a3a4a; transition: fill .4s; }
.card.on .bulb-off { fill: #fbbf24; }
.bulb-glow { opacity: 0; transition: opacity .6s; }
.card.on .bulb-glow { opacity: 1; animation: bulb-pulse 2.5s ease-in-out infinite; }
@keyframes bulb-pulse {
  0%, 100% { opacity: .15; }
  50% { opacity: .35; }
}

/* Fan */
.fan-center { fill: #3a3a4a; transition: fill .4s; }
.card.on .fan-center { fill: var(--blue); }
.fan-blade { fill: #3a3a4a; transition: fill .4s; transform-origin: 16px 16px; }
.card.on .fan-blade { fill: var(--blue); animation: fan-spin 1s linear infinite; }
.card.off .fan-blade { animation: none; }
@keyframes fan-spin { to { transform: rotate(360deg); } }

/* AC */
.ac-body { stroke: #3a3a4a; fill: #1a1a2a; transition: all .4s; }
.card.on .ac-body { stroke: var(--green); fill: rgba(52,211,153,.05); }
.ac-line { stroke: #3a3a4a; transition: stroke .4s; }
.card.on .ac-line { stroke: var(--green); }

/* TV */
.tv-body { stroke: #3a3a4a; fill: #1a1a2a; transition: all .4s; }
.card.on .tv-body { stroke: var(--blue); }
.tv-screen { fill: #1a1d27; transition: fill .6s; }
.card.on .tv-screen { fill: #1a3a5a; }

/* Lock */
.lock-body { stroke: #3a3a4a; fill: #1a1a2a; transition: all .4s; }
.lock-shackle { stroke: #3a3a4a; transition: stroke .4s; }
.card.on .lock-body { stroke: var(--green); fill: rgba(52,211,153,.05); }
.card.on .lock-shackle { stroke: var(--green); }

/* Plug */
.plug-body { stroke: #3a3a4a; fill: #1a1a2a; transition: all .4s; }
.card.on .plug-body { stroke: var(--orange); fill: rgba(251,146,60,.05); }
.plug-dot { fill: #3a3a4a; transition: fill .4s; }
.card.on .plug-dot { fill: var(--green); }

.card-label {
  font-size: 10px; font-weight: 500; line-height: 1.2;
  letter-spacing: -.1px;
  overflow-wrap: break-word; word-break: break-word; max-width: 100%;
  pointer-events: none;
}
.card-status {
  font-size: 8px; font-weight: 600; letter-spacing: .5px;
  text-transform: uppercase;
  pointer-events: none;
}
.card.off .card-status { color: var(--text-dim); }
.card.on .card-status { color: var(--green); }

.card.sync-error {
  border-color: var(--orange) !important;
  box-shadow: 0 0 12px rgba(251,146,60,.25);
}
.card.sync-error .card-status { color: var(--orange) !important; }
.card.sync-error::after {
  content: '⚠';
  position: absolute; top: 6px; left: 8px;
  font-size: 14px; line-height: 1;
  animation: pulse-warn 1.5s ease-in-out infinite;
}
@keyframes pulse-warn {
  0%, 100% { opacity: .6; }
  50% { opacity: 1; }
}

/* Status bar */
.status-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 12px;
  font-size: 11px; color: var(--text-muted); flex-shrink: 0;
  font-weight: 500;
}
.status-bar .stats { display: flex; gap: 12px; }
.status-bar .stats .num { color: var(--text); font-weight: 600; }
.status-bar .stats .num.on { color: var(--green); }
#msg { font-size: 10px; color: var(--text-dim); transition: opacity .3s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }

/* WiFi status */
.wifi-status {
  display: flex; gap: 8px; align-items: center;
  font-size: 10px; color: var(--text-dim); font-weight: 500;
}
.wifi-dot {
  width: 5px; height: 5px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}
.wifi-dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.wifi-dot.offline { background: var(--red); box-shadow: 0 0 8px var(--red); }
.wifi-bars { display: flex; align-items: flex-end; gap: 1px; height: 10px; }
.wifi-bar {
  width: 3px; border-radius: 1px; background: var(--text-dim);
  transition: background .3s;
}
.wifi-bar.s1 { height: 3px; }
.wifi-bar.s2 { height: 5px; }
.wifi-bar.s3 { height: 7px; }
.wifi-bar.s4 { height: 10px; }
.wifi-bars.good .wifi-bar { background: var(--green); }
.wifi-bars.fair .wifi-bar { background: var(--orange); }
.wifi-bars.poor .wifi-bar { background: var(--red); }
.wifi-bars.good .wifi-bar.s1,
.wifi-bars.fair .wifi-bar.s1,
.wifi-bars.poor .wifi-bar.s1 { background: var(--text-dim); }

/* Offline banner */
.offline-banner {
  display: none; position: fixed; top: 0; left: 0; right: 0;
  background: var(--red); color: #fff; text-align: center;
  padding: 6px; font-size: 11px; font-weight: 600; z-index: 9999;
  letter-spacing: .5px;
}
.offline-banner.show { display: block; }

/* ESP32 offline banner — persistent bottom bar */
.esp-offline-banner {
  display: none; position: fixed; bottom: 44px; left: 0; right: 0;
  width: 100vw; margin: 0;
  background: linear-gradient(135deg, #f59e0b, #d97706); color: #000; text-align: center;
  padding: 8px 16px; font-size: 12px; font-weight: 600; z-index: 9998;
  letter-spacing: .3px; box-shadow: 0 -2px 8px rgba(245,158,11,.3);
  box-sizing: border-box;
}
.esp-offline-banner.show { display: block; }

/* Empty state */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--text-dim); font-size: 13px;
}

/* Screensaver */
.screensaver {
  position: fixed; inset: 0; z-index: 99999;
  background: #000;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  color: #fff; font-family: -apple-system, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
  cursor: none; user-select: none;
}
.screensaver.show {
  display: flex;
  animation: ss-fade .8s ease;
}
@keyframes ss-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.ss-time {
  font-size: 20vw; font-weight: 700; letter-spacing: -2px;
  line-height: 1; color: #fff;
  font-variant-numeric: tabular-nums;
}
.ss-ampm {
  font-size: 7vw; font-weight: 400; color: rgba(255,255,255,.6);
  margin-left: 1.5vw; vertical-align: super;
}
.ss-date {
  font-size: 5vw; font-weight: 400; color: rgba(255,255,255,.5);
  letter-spacing: 5px; text-transform: uppercase;
  margin-top: 2vw;
}
.ss-sensor {
  display: flex; gap: 20px; margin-top: 3vw;
  font-size: 4vw; font-weight: 500;
}
.ss-temp { color: rgba(96,165,250,.8); }
.ss-hum { color: rgba(52,211,153,.8); }
.ss-hint {
  position: fixed; bottom: 6vh; font-size: 3.5vw;
  color: rgba(255,255,255,.25); letter-spacing: 3px;
  text-transform: uppercase;
  animation: ss-blink 3s ease-in-out infinite;
}
@keyframes ss-blink {
  0%, 100% { opacity: .25; }
  50% { opacity: .7; }
}

/* Onboarding */
.onboarding-overlay {
  display: none; position: fixed; inset: 0; z-index: 100000;
  background: rgba(0,0,0,.85); backdrop-filter: blur(8px);
  align-items: center; justify-content: center; padding: 20px;
}
.onboarding-overlay.show { display: flex; }
.onboarding-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; width: 100%; max-width: 340px;
  text-align: center;
}
.onboarding-card h2 {
  font-size: 20px; font-weight: 700; margin-bottom: 20px;
}
.onboarding-steps { min-height: 160px; }
.onboarding-step { display: none; }
.onboarding-step.active { display: block; }
.step-icon { font-size: 48px; margin-bottom: 12px; }
.onboarding-step h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.onboarding-step p { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.onboarding-dots { display: flex; justify-content: center; gap: 8px; margin: 16px 0; }
.onboarding-dots .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim); transition: all .2s;
}
.onboarding-dots .dot.active { background: var(--accent); transform: scale(1.2); }
.onboarding-actions { display: flex; gap: 10px; justify-content: center; }
.onboarding-actions .btn { padding: 10px 24px; font-size: 13px; }

/* Search bar */
.search-bar {
  display: none; padding: 8px 16px; gap: 8px; flex-shrink: 0;
}
.search-bar.show { display: flex; }
.search-bar input {
  flex: 1; padding: 10px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; outline: none;
  transition: border-color .2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: var(--text-dim); }
.search-clear {
  padding: 8px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 14px; cursor: pointer;
  transition: all .2s; font-family: inherit;
}
.search-clear:hover { background: var(--surface2); color: var(--text); }

/* Card hint for long-press */
.card-hint {
  position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
  font-size: 8px; color: var(--text-dim); white-space: nowrap;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
@media (hover: none) {
  .card-hint { opacity: .5; }
}
@media (hover: hover) {
  .card:hover .card-hint { opacity: .6; }
}
@media (max-width: 480px) {
  header { padding: 10px 12px 6px; flex-wrap: wrap; gap: 6px; }
  header h1 { font-size: 17px; }
  .header-right { gap: 6px; }
  .header-right .theme-btn span:not(#themeIcon) { display: none; }
  .header-right .logout-btn svg { display: none; }
  .header-right .logout-btn { font-size: 11px; padding: 4px 8px; }
  .sensor-display { font-size: 11px; padding: 3px 8px; }
}

/* Schedule modal */
.schedule-overlay {
  display: none; position: fixed; inset: 0;
  background: var(--bg);
  z-index: 10000; align-items: stretch; justify-content: center;
  padding: 0;
}
.schedule-overlay.show { display: flex; }
.schedule-modal {
  background: var(--sched-bg);
  border: none;
  border-radius: 0;
  padding: 16px; width: 100%; max-width: 100%;
  max-height: 100vh; height: 100vh; overflow: hidden;
  display: flex; flex-direction: column;
}
.schedule-modal h3 {
  font-size: 18px; font-weight: 600; margin-bottom: 4px;
  flex-shrink: 0;
}
.schedule-modal .sub {
  font-size: 12px; color: var(--text-dim); margin-bottom: 12px;
  flex-shrink: 0;
}
.schedule-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.schedule-item {
  padding: 12px 14px; border-radius: 12px;
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 14px; flex-shrink: 0;
}
.sched-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.sched-btns {
  display: flex; align-items: center; gap: 8px; margin-left: auto;
}
.schedule-item .sched-time {
  font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--text); min-width: 50px; white-space: nowrap;
  font-size: 15px;
}
.sched-tz { font-size: 11px; color: var(--text-dim); font-weight: 500; }
.schedule-item .sched-action {
  font-weight: 600; padding: 4px 12px; border-radius: 8px; font-size: 12px;
}
.schedule-item .sched-action.on { background: rgba(124,109,240,.2); color: var(--accent); }
.schedule-item .sched-action.off { background: rgba(248,113,113,.15); color: var(--red); }
.schedule-item .sched-days {
  flex: 1; font-size: 12px; color: var(--text-dim); min-width: 0;
}
.schedule-item .sched-toggle {
  cursor: pointer; font-size: 12px; font-weight: 700;
  padding: 8px 16px; border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim);
  transition: all .2s; letter-spacing: .5px;
  min-height: 36px; min-width: 48px;
}
.schedule-item .sched-toggle.on {
  background: rgba(124,109,240,.15); border-color: var(--accent);
  color: var(--accent);
}
.schedule-item .sched-toggle:hover { opacity: .8; }
.schedule-item .sched-del {
  cursor: pointer; font-size: 16px; opacity: .4;
  background: none; border: none; color: var(--text);
  padding: 8px 10px; transition: opacity .2s; line-height: 1;
  min-height: 36px; min-width: 36px;
  display: flex; align-items: center; justify-content: center;
}
.schedule-item .sched-del:hover { opacity: 1; color: var(--red); }
.schedule-add {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding: 14px 0 8px; border-top: 1px solid var(--border);
  flex-shrink: 0; position: relative; z-index: 1;
}
.schedule-add input[type="time"] {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px;
  color: var(--text); font-size: 16px; outline: none;
  flex: 1; min-width: 100px; min-height: 44px;
  position: relative; z-index: 2;
}
.schedule-add input[type="time"]:focus { border-color: var(--accent); }
.schedule-add select {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px;
  color: var(--text); font-size: 14px; outline: none;
  min-height: 44px; min-width: 100px;
  -webkit-appearance: none;
}
.schedule-add select:focus { border-color: var(--accent); }
.schedule-add .btn {
  padding: 12px 24px; border-radius: 12px;
  border: none; font-size: 14px; font-weight: 600;
  cursor: pointer; background: var(--accent); color: #fff;
  flex-shrink: 0; align-self: flex-end;
  min-height: 44px; min-width: 70px;
}
.schedule-add .btn:active { transform: scale(.96); }
.sched-form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 100px; }
.sched-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .3px; }

/* Day picker */
.sched-days-group { flex-basis: 100%; min-width: 0; }
.day-picker {
  display: flex; gap: 6px;
}
.day-btn {
  flex: 1; padding: 10px 0; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text-dim); font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all .2s; font-family: inherit;
  min-height: 40px; display: flex; align-items: center; justify-content: center;
}
.day-btn.active {
  background: var(--accent); border-color: var(--accent);
  color: #fff; box-shadow: 0 2px 8px var(--accent-glow);
}
.day-btn:active { transform: scale(.92); }
.day-quick {
  display: flex; gap: 6px; margin-top: 6px;
}
.day-quick-btn {
  flex: 1; padding: 6px 0; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); font-size: 11px; font-weight: 600;
  cursor: pointer; transition: all .2s; font-family: inherit;
}
.day-quick-btn:hover { background: var(--surface2); color: var(--text); }
.day-quick-btn.active {
  background: rgba(124,109,240,.1); border-color: var(--accent);
  color: var(--accent);
}
.schedule-empty {
  font-size: 14px; color: var(--text-dim);
  text-align: center; padding: 20px 0;
}
.schedule-modal .close-btn {
  margin-top: 10px; width: 100%; padding: 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: transparent; color: var(--text-muted);
  font-size: 15px; font-weight: 600; cursor: pointer;
  min-height: 48px; flex-shrink: 0;
}
.schedule-modal .close-btn:hover { background: var(--surface2); }

/* Sensor chart overlay */
.chart-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(6px);
  z-index: 10001; align-items: center; justify-content: center;
  padding: 16px;
}
.chart-overlay.show { display: flex; }
.chart-panel {
  background: var(--bg); width: 100%; max-width: 700px;
  max-height: 85vh; border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  animation: chart-fade .2s ease;
}
@keyframes chart-fade {
  from { opacity: 0; transform: scale(.95); }
  to { opacity: 1; transform: scale(1); }
}
.chart-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; flex-shrink: 0; flex-wrap: wrap;
}
.chart-header h3 { font-size: 16px; font-weight: 700; margin-right: auto; }
.chart-range-btns {
  display: flex; gap: 4px;
}
.range-btn {
  padding: 5px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); font-size: 11px; font-weight: 600;
  cursor: pointer; transition: all .2s; font-family: inherit;
}
.range-btn.active {
  background: var(--accent); border-color: var(--accent);
  color: #fff;
}
.range-btn:hover { background: var(--surface2); color: var(--text); }
.chart-header .close-btn {
  padding: 6px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-muted); font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.chart-header .close-btn:hover { background: var(--surface2); }
.chart-body {
  flex: 1; padding: 0 16px 16px; min-height: 0;
  overflow: hidden; position: relative;
}
.chart-body canvas { width: 100% !important; height: 100% !important; }
.chart-empty {
  font-size: 14px; color: var(--text-dim);
  text-align: center; padding: 40px 20px;
  display: none;
}
