/* ============================================================
   Maple House — Smart Home Control Center
   Warm, cozy, residential aesthetic on a dark warm canvas.
   ============================================================ */

:root {
  /* --- Warm dark surfaces --- */
  --bg:          oklch(0.165 0.006 60);
  --bg-glow:     oklch(0.24 0.02 140);
  --surface:     oklch(0.205 0.008 62);
  --surface-2:   oklch(0.245 0.010 64);
  --surface-3:   oklch(0.285 0.012 66);
  --hover:       oklch(0.30 0.014 66);
  --border:      oklch(0.32 0.012 64 / 0.7);
  --border-soft: oklch(0.30 0.010 64 / 0.45);

  /* --- Warm text --- */
  --text:        oklch(0.955 0.010 80);
  --text-2:      oklch(0.78 0.012 75);
  --text-3:      oklch(0.60 0.012 70);
  --text-faint:  oklch(0.48 0.010 68);

  /* --- Accents (shared chroma/lightness, varying hue) --- */
  --green:       oklch(0.80 0.145 150);   /* on / active / eco */
  --green-dim:   oklch(0.80 0.145 150 / 0.16);
  --teal:        oklch(0.80 0.115 200);   /* cooling / water */
  --teal-dim:    oklch(0.80 0.115 200 / 0.16);
  --amber:       oklch(0.82 0.135 70);    /* heat / climate / energy */
  --amber-dim:   oklch(0.82 0.135 70 / 0.16);
  --rose:        oklch(0.74 0.150 25);    /* alerts / security */
  --rose-dim:    oklch(0.74 0.150 25 / 0.16);
  --violet:      oklch(0.76 0.110 300);   /* media / scenes */
  --violet-dim:  oklch(0.76 0.110 300 / 0.16);

  --radius:      22px;
  --radius-sm:   14px;
  --radius-lg:   30px;
  --shadow:      0 1px 2px oklch(0 0 0 / 0.25), 0 8px 24px oklch(0 0 0 / 0.22);
  --shadow-lg:   0 2px 6px oklch(0 0 0 / 0.3), 0 24px 60px oklch(0 0 0 / 0.34);

  --font:    "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --serif:   "Instrument Serif", ui-serif, Georgia, serif;
  --mono:    "Space Mono", ui-monospace, "SF Mono", monospace;

  --sidebar-w: 248px;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

#root { height: 100vh; }

::selection { background: var(--green-dim); color: var(--text); }

/* Inline icon wrapper (Lucide SVG sized via 1em) */
.ms {
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle; flex: none; line-height: 0;
  width: 1em; height: 1em;
}
.ms svg { width: 1em; height: 1em; display: block; }

/* Scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--hover); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   App shell
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  background:
    radial-gradient(1200px 700px at 18% -10%, var(--bg-glow) 0%, transparent 55%),
    var(--bg);
}

/* --- Sidebar --- */
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 26px 18px;
  gap: 6px;
  border-right: 1px solid var(--border-soft);
  background: oklch(0.18 0.007 60 / 0.55);
  backdrop-filter: blur(8px);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 10px 22px;
}
.brand-mark {
  width: 40px; height: 40px; border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--green) 0%, var(--teal) 100%);
  color: oklch(0.18 0.02 150); font-size: 22px;
  box-shadow: 0 6px 18px var(--green-dim);
}
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand-sub  { font-size: 12px; color: var(--text-3); margin-top: 1px; white-space: nowrap; }

.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.13em;
  color: var(--text-faint); font-weight: 700;
  padding: 16px 14px 8px;
}
.nav-item {
  display: flex; align-items: center; gap: 13px;
  padding: 11px 14px; border-radius: 14px;
  color: var(--text-2); font-size: 14.5px; font-weight: 500;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  transition: background .16s, color .16s;
}
.nav-item i { font-size: 21px; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--green-dim); color: var(--green); font-weight: 600; }
.nav-item .badge {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--rose); color: oklch(0.18 0.02 25);
  border-radius: 99px; min-width: 19px; height: 19px; padding: 0 5px;
  display: grid; place-items: center;
}

.sidebar-foot { margin-top: auto; }
.user-chip {
  display: flex; align-items: center; gap: 11px;
  padding: 10px; border-radius: 16px; cursor: pointer;
  border: 1px solid var(--border-soft);
  transition: background .16s;
}
.user-chip:hover { background: var(--surface); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  color: oklch(0.2 0.02 150); flex: none;
}
.user-chip .nm { font-size: 13.5px; font-weight: 600; }
.user-chip .rl { font-size: 11.5px; color: var(--text-3); }

/* --- Main scroll area --- */
.main { overflow-y: auto; overflow-x: hidden; min-width: 0; }
.main-inner { padding: 34px 40px 64px; max-width: 1320px; margin: 0 auto; }

/* --- Top bar --- */
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 30px;
}
.greeting { font-family: var(--serif); font-size: 42px; line-height: 1.05; letter-spacing: -0.01em; white-space: nowrap; }
.greeting .accent { color: var(--green); }
.sub-greeting { color: var(--text-3); font-size: 14.5px; margin-top: 9px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border-soft);
  color: var(--text-2); font-size: 21px; position: relative;
  transition: background .16s, color .16s, transform .1s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn .dot {
  position: absolute; top: 9px; right: 10px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--rose);
  border: 2px solid var(--surface);
}

.status-pill {
  display: flex; align-items: center; gap: 9px;
  padding: 0 16px 0 14px; height: 44px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border-soft);
  font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--text);
  transition: background .16s;
}
.status-pill:hover { background: var(--hover); }
.status-pill .ring {
  width: 9px; height: 9px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 4px var(--green-dim);
}
.status-pill.away .ring { background: var(--amber); box-shadow: 0 0 0 4px var(--amber-dim); }

/* ============================================================
   Cards & primitives
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 22px; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 34px 2px 16px;
}
.section-head:first-child { margin-top: 8px; }
.section-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.section-title .count { color: var(--text-faint); font-weight: 600; margin-left: 8px; }
.link-btn {
  font-size: 13.5px; color: var(--text-3); font-weight: 600; cursor: pointer;
  background: none; border: none; display: flex; align-items: center; gap: 5px;
}
.link-btn:hover { color: var(--text); }

.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* --- Device card --- */
.device {
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: var(--surface); box-shadow: var(--shadow);
  padding: 18px;
  cursor: pointer;
}
.device > * + * { margin-top: 14px; }
.device:hover { border-color: var(--border); background: var(--surface-2); }
.device.on { background: var(--surface-2); }
.device-top { display: grid; grid-template-columns: 1fr auto; align-items: flex-start; gap: 10px; }
.device-ico {
  width: 46px; height: 46px; border-radius: 13px; flex: none;
  display: grid; place-items: center; font-size: 24px;
  background: var(--surface-3); color: var(--text-2);
  transition: background .18s, color .18s;
}
.device.on .device-ico { background: var(--accent-dim); color: var(--accent); }
.device-name { font-size: 15px; font-weight: 600; line-height: 1.2; }
.device-meta { font-size: 12.5px; color: var(--text-3); margin-top: 3px; }
.device.on .device-meta { color: var(--accent); }
.device-foot { margin-top: 14px; }

/* --- Toggle --- */
.toggle {
  width: 46px; height: 28px; border-radius: 99px; flex: none;
  background: var(--surface-3); border: none; cursor: pointer;
  padding: 3px; transition: background .2s; position: relative;
}
.toggle .knob {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--text-2); transition: margin-left .2s, background .2s;
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.4); margin-left: 0;
}
.toggle.on { background: var(--accent); }
.toggle.on .knob { margin-left: 18px; background: oklch(0.18 0.01 150); }

/* --- Range slider --- */
.range { width: 100%; }
.range-track {
  height: 8px; border-radius: 99px; background: var(--surface-3);
  position: relative; cursor: pointer;
}
.range-fill { height: 100%; border-radius: 99px; background: var(--accent); }
.range-thumb {
  position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%;
  background: var(--text); margin-left: -9px; margin-top: -9px;
  box-shadow: 0 2px 6px oklch(0 0 0 / 0.4); pointer-events: none;
}

/* --- Pill / chip --- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--text-2);
}
.chip.green { background: var(--green-dim); color: var(--green); }
.chip.amber { background: var(--amber-dim); color: var(--amber); }
.chip.teal  { background: var(--teal-dim);  color: var(--teal); }
.chip.rose  { background: var(--rose-dim);  color: var(--rose); }
.chip.violet{ background: var(--violet-dim);color: var(--violet); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 18px; height: 42px; border-radius: 13px; cursor: pointer;
  font-family: var(--font); font-size: 14px; font-weight: 600;
  border: 1px solid var(--border-soft); background: var(--surface-2); color: var(--text);
  transition: background .16s, transform .1s, border-color .16s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--green); color: oklch(0.18 0.02 150); border-color: transparent; }
.btn.primary:hover { background: oklch(0.84 0.145 150); }
.btn.danger { background: var(--rose-dim); color: var(--rose); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { height: 36px; padding: 0 14px; font-size: 13px; border-radius: 11px; }

/* ============================================================
   Scenes
   ============================================================ */
.scene {
  border-radius: var(--radius); padding: 20px; cursor: pointer;
  border: 1px solid var(--border-soft); background: var(--surface); box-shadow: var(--shadow);
}
.scene .scene-ico { margin-bottom: 16px; }
.scene:hover { border-color: var(--border); background: var(--surface-2); }
.scene-ico {
  width: 50px; height: 50px; border-radius: 15px; display: grid; place-items: center;
  font-size: 26px; background: var(--accent-dim); color: var(--accent);
}
.scene-name { font-size: 16px; font-weight: 700; }
.scene-meta { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.scene-glow {
  position: absolute; inset: auto -40% -70% auto; width: 200px; height: 200px;
  border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, var(--accent-dim) 0%, transparent 70%);
}

/* ============================================================
   Misc helpers
   ============================================================ */
.stat-big { font-family: var(--serif); font-size: 54px; line-height: 0.95; letter-spacing: -0.01em; }
.stat-unit { font-family: var(--font); font-size: 18px; color: var(--text-3); font-weight: 600; }
.muted { color: var(--text-3); }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.col { display: flex; flex-direction: column; }
.spacer { flex: 1; }
.mono { font-family: var(--mono); }

/* Placeholder (camera/image slots) */
.placeholder {
  border-radius: var(--radius-sm); overflow: hidden; position: relative;
  background:
    repeating-linear-gradient(45deg,
      oklch(0.24 0.01 64) 0 10px,
      oklch(0.21 0.01 64) 10px 20px);
  display: grid; place-items: center; color: var(--text-faint);
  font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.02em;
}
.placeholder .ph-label {
  background: oklch(0.15 0.01 60 / 0.7); padding: 4px 10px; border-radius: 7px;
}

/* Live dot */
.live {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px;
  font-weight: 700; color: var(--rose); text-transform: uppercase; letter-spacing: 0.06em;
}
.live::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--rose);
  animation: pulse 1.8s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Toast */
.toast-wrap {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.toast {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface-3); border: 1px solid var(--border);
  padding: 13px 20px 13px 16px; border-radius: 15px; box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 500; color: var(--text);
  animation: toast-in .32s cubic-bezier(.2,.9,.3,1.3);
}
.toast i { font-size: 20px; color: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }

/* Entrance for screens — disabled: a transform/animation on this wrapper
   prevents the layer from compositing into screenshot captures. */
.screen-enter { }

/* Sparkline / bars */
.bars { display: flex; align-items: flex-end; gap: 5px; height: 64px; }
.bars .bar { flex: 1; border-radius: 5px 5px 3px 3px; background: var(--accent-dim); min-height: 4px; transition: height .4s; }
.bars .bar.hl { background: var(--accent); }

/* Drawer (notifications) */
.drawer-scrim {
  position: fixed; inset: 0; background: oklch(0 0 0 / 0.5); z-index: 80;
  animation: fade .2s; backdrop-filter: blur(2px);
}
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 392px; z-index: 81;
  background: var(--bg); border-left: 1px solid var(--border);
  padding: 26px; overflow-y: auto;
  animation: slide-in .3s cubic-bezier(.2,.8,.3,1);
  box-shadow: var(--shadow-lg);
}
@keyframes slide-in { from { transform: translateX(100%); } }

/* Modal */
.modal-scrim {
  position: fixed; inset: 0; background: oklch(0 0 0 / 0.55); z-index: 90;
  display: grid; place-items: center; animation: fade .2s; backdrop-filter: blur(3px);
}
.modal {
  width: min(560px, 92vw); max-height: 88vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 30px; box-shadow: var(--shadow-lg);
  animation: modal-in .3s cubic-bezier(.2,.8,.3,1);
}
@keyframes modal-in { from { opacity: 0; transform: scale(.95) translateY(10px); } }

/* small responsive guard */
@media (max-width: 1100px) {
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .cols-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   Mobile — sidebar becomes a bottom tab bar, columns stack.
   Desktop (>760px) is unaffected.
   ============================================================ */
@media (max-width: 760px) {
  body { overflow: auto; }
  .app {
    grid-template-columns: 1fr;
    height: auto; min-height: 100vh; min-height: 100dvh;
  }

  /* sidebar -> bottom nav */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    flex-direction: row; height: auto; gap: 2px;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--border);
    background: oklch(0.17 0.007 60 / 0.94); backdrop-filter: blur(16px);
    z-index: 60; justify-content: space-around;
  }
  .brand, .nav-label, .sidebar-foot { display: none; }
  .nav-item {
    flex-direction: column; gap: 4px; flex: 1; min-width: 0;
    padding: 7px 2px; border-radius: 13px; text-align: center;
    font-size: 9.5px; font-weight: 600; position: relative; line-height: 1.1;
  }
  .nav-item .ms { font-size: 22px; }
  .nav-item .badge {
    position: absolute; top: 4px; left: 50%; margin-left: 5px;
    transform: none; min-width: 16px; height: 16px; font-size: 10px;
  }

  /* main */
  .main { overflow: visible; }
  .main-inner { padding: 22px 16px 104px; max-width: none; }

  /* topbar stacks */
  .topbar { flex-direction: column; align-items: stretch; gap: 16px; }
  .greeting { font-size: clamp(25px, 7.5vw, 34px); white-space: nowrap; }
  .topbar-actions { justify-content: flex-start; }

  /* grids collapse */
  .cols-2 { grid-template-columns: 1fr; }
  .grid.respond2 { grid-template-columns: 1fr !important; }

  /* room header stacks */
  .room-header { grid-template-columns: 1fr !important; gap: 16px !important; }
  .room-header > div:last-child { justify-content: space-between; }

  /* room tabs scroll horizontally */
  .room-tabs { flex-wrap: nowrap !important; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
  .room-tabs::-webkit-scrollbar { display: none; }
  .room-tabs .btn { flex: none; white-space: nowrap; }

  /* overlays full width */
  .drawer { width: 100%; }
  .modal { width: 94vw; padding: 24px; }
  .toast-wrap { bottom: 104px; width: max-content; max-width: 90vw; }

  .section-head { margin-top: 26px; }
}

@media (max-width: 480px) {
  .main-inner { padding: 18px 13px 104px; }
  .card-pad { padding: 18px; }
  .cols-3 { grid-template-columns: 1fr; }
  .stat-big { font-size: clamp(34px, 12vw, 46px) !important; }
  .greeting { font-size: clamp(23px, 8vw, 30px); }
  .device, .scene { padding: 16px; }
}

/* On phones, device cards go full-width so controls (steppers, sliders)
   stay comfortable and meet 44px touch targets. Stat cards stay 2-up. */
@media (max-width: 540px) {
  .grid:has(.device) { grid-template-columns: 1fr !important; }
}
