/* =========================================================
   Naledi monitoring platform: app shell (dashboard, events)
   Builds on the tokens, buttons and status pills in site.css
   ========================================================= */

body.app { background: var(--bg-soft); font-size: 15.5px; overflow-x: hidden; }
.app-shell { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--navy-950); color: #b6c3d6; padding: 22px 16px 18px; z-index: 40;
}
.side .brand { padding: 4px 8px 22px; }
.side .brand-mark { width: 40px; height: 40px; }
.side .brand-word { font-size: 1.4rem; background: linear-gradient(100deg, #fff 0%, #cfe6ea 60%, var(--cyan-400) 100%); -webkit-background-clip: text; background-clip: text; }
.side .brand-sub { color: #8396b2; font-size: .48rem; }
.side-label { font: 700 .68rem var(--display); letter-spacing: .16em; text-transform: uppercase; color: #6c80a0; padding: 18px 12px 8px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a, .side-nav span {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px;
  color: #c4d0e2; font-weight: 600; font-size: .94rem; transition: background .2s, color .2s;
}
.side-nav a svg, .side-nav span svg { width: 19px; height: 19px; flex: none; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.active { background: linear-gradient(100deg, rgba(42,155,168,.22), rgba(42,155,168,.06)); color: #fff; box-shadow: inset 3px 0 0 var(--gold-500); }
.side-nav span.soon { color: #6c80a0; cursor: default; }
.side-nav .chip { margin-left: auto; font-size: .62rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 3px 7px; border-radius: 999px; background: rgba(255,255,255,.06); color: #8396b2; }
.side-nav .count { margin-left: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: #d64545; color: #fff; font-size: .72rem; font-weight: 800; display: none; align-items: center; justify-content: center; }
.side-nav .count.show { display: inline-flex; }
.side-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 12px; padding: 8px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font: 800 .9rem var(--display); color: var(--navy-950); background: var(--grad-gold); flex: none; }
.user-chip b { display: block; color: #fff; font-size: .9rem; line-height: 1.2; }
.user-chip small { color: #8396b2; font-size: .78rem; text-transform: capitalize; }
.side-foot .btn { width: 100%; margin-top: 10px; background: rgba(255,255,255,.06); color: #c4d0e2; border-color: rgba(255,255,255,.1); }
.side-foot .btn:hover { background: rgba(255,255,255,.12); color: #fff; transform: none; }
.side-tag { margin: 14px 8px 0; font: 600 .62rem var(--display); letter-spacing: .16em; text-transform: uppercase; color: var(--gold-500); }

/* ---------- Main area ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 32px; background: rgba(245,248,251,.85); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.02em; }
.topbar .sub { color: var(--muted); font-size: .88rem; margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: .84rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(16,145,107,.5); animation: pulse 2s infinite; }
.live.err { color: #b42318; }
.live.err i { background: #d64545; animation: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: #fff; display: inline-grid; place-items: center; cursor: pointer; color: var(--navy-800); transition: border-color .2s, transform .2s; }
.icon-btn:hover { border-color: var(--navy-700); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
.side-toggle { display: none; }
.content { padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 24px; max-width: 1440px; width: 100%; }

/* ---------- Banners ---------- */
.conn-banner { display: none; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 14px; background: #fdecec; color: #b42318; font-weight: 600; font-size: .92rem; }
.conn-banner.show { display: flex; }
.conn-banner svg { width: 18px; height: 18px; flex: none; }

/* ---------- Alerts ---------- */
.alerts { display: flex; flex-direction: column; gap: 14px; }
.alert-card {
  position: relative; display: grid; grid-template-columns: 56px 1fr auto; gap: 18px; align-items: center;
  padding: 20px 22px; border-radius: 20px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.alert-card .a-ico { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; }
.alert-card .a-ico svg { width: 26px; height: 26px; }
.alert-card h3 { font-size: 1.1rem; margin: 0 0 4px; }
.alert-card .a-meta { color: var(--body); font-size: .9rem; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.alert-card .a-meta span { display: inline-flex; align-items: center; gap: 6px; }
.alert-card .a-meta svg { width: 15px; height: 15px; }
.alert-card .a-quote { margin-top: 8px; font-size: .9rem; color: var(--ink); font-style: italic; }
.alert-card .a-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.alert-card .a-tag { font: 800 .7rem var(--display); letter-spacing: .1em; text-transform: uppercase; padding: 6px 10px; border-radius: 999px; white-space: nowrap; }
.alert-card.critical { border: 2px solid #d64545; background: linear-gradient(90deg, #fff1f1, #fff 60%); box-shadow: 0 14px 30px -18px rgba(214,69,69,.6); }
.alert-card.critical .a-ico { background: #d64545; color: #fff; animation: alarm 1.6s ease-in-out infinite; }
.alert-card.critical .a-tag { background: #d64545; color: #fff; }
.alert-card.warning { border: 2px solid #e0a43a; background: linear-gradient(90deg, #fff7e8, #fff 60%); }
.alert-card.warning .a-ico { background: #e0a43a; color: #fff; }
.alert-card.warning .a-tag { background: #fbecd0; color: #8a5a10; }
.alert-card.info { border-color: rgba(31,134,149,.35); background: linear-gradient(90deg, var(--teal-50), #fff 60%); }
.alert-card.info .a-ico { background: var(--teal-600); color: #fff; }
.alert-card.info .a-tag { background: var(--cyan-100); color: var(--teal-700); }
@keyframes alarm { 0%,100% { box-shadow: 0 0 0 0 rgba(214,69,69,.5); } 50% { box-shadow: 0 0 0 10px rgba(214,69,69,0); } }
.all-clear { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-radius: 18px; background: var(--ok-bg); color: var(--ok); font-weight: 700; border: 1px solid rgba(16,145,107,.18); }
.all-clear svg { width: 22px; height: 22px; }
.all-clear small { display: block; color: #3f7a66; font-weight: 500; font-size: .85rem; }
.alerts-note { font-size: .8rem; color: var(--muted); margin: -4px 0 0 4px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; gap: 6px; text-align: left; font: inherit; color: inherit; }
button.kpi { cursor: pointer; transition: border-color .2s, box-shadow .2s, transform .2s; }
button.kpi:hover { border-color: transparent; box-shadow: var(--shadow); transform: translateY(-2px); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.kpi-label { font: 700 .74rem var(--display); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.kpi .icon-tile { width: 40px; height: 40px; border-radius: 12px; }
.kpi .icon-tile svg { width: 19px; height: 19px; }
.kpi-value { font: 800 1.9rem/1.1 var(--display); color: var(--ink); letter-spacing: -.02em; text-transform: capitalize; overflow-wrap: anywhere; }
.kpi-foot { font-size: .84rem; color: var(--muted); }

/* ---------- Panels ---------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 22px 22px 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { font-size: 1.08rem; margin: 0; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
.panel-head h2 svg { width: 19px; height: 19px; color: var(--teal-600); }
.panel-head .hint { font-size: .8rem; color: var(--muted); }
.empty { padding: 22px 8px; text-align: center; color: var(--muted); font-size: .92rem; }
.empty svg { width: 26px; height: 26px; margin: 0 auto 8px; color: #b8c4d4; }
.skeleton { height: 14px; border-radius: 8px; background: linear-gradient(90deg, #eef2f7, #f7f9fc, #eef2f7); background-size: 200% 100%; animation: shimmer 1.4s infinite; margin: 10px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Hour chart */
.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 4px; align-items: end; height: 120px; padding-top: 8px; }
.hours .bar { position: relative; border-radius: 6px 6px 3px 3px; background: linear-gradient(180deg, var(--teal-500), var(--teal-600)); min-height: 3px; opacity: .9; transition: height .5s cubic-bezier(.2,.8,.2,1); }
.hours .bar.zero { background: var(--line-soft); }
.hours .bar.now { background: linear-gradient(180deg, #e3c47e, var(--gold-500)); }
.hours .bar:hover { opacity: 1; }
.hours-axis { display: grid; grid-template-columns: repeat(24, 1fr); gap: 4px; margin-top: 6px; font-size: .68rem; color: var(--muted); text-align: center; }
.hours-axis span:not(:nth-child(6n+1)) { visibility: hidden; }

/* Timeline */
.day-label { font: 700 .72rem var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 14px 4px 6px; }
.day-label:first-child { padding-top: 0; }
.tl { display: flex; flex-direction: column; }
.tl-row {
  display: grid; grid-template-columns: 58px 38px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 8px; border-radius: 12px; cursor: pointer; border: 0; background: none; text-align: left; font: inherit; color: inherit; width: 100%;
  transition: background .15s;
}
.tl-row:hover, .tl-row:focus-visible { background: var(--bg-soft); }
.tl-time { font: 600 .82rem var(--mono); color: var(--muted); }
.tl-ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--bg-soft); color: var(--navy-700); }
.tl-ico svg { width: 18px; height: 18px; }
.tl-main { min-width: 0; }
.tl-title, .tl-sub { display: block; }
.tl-title { font-weight: 700; color: var(--ink); font-size: .94rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-sub { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-chip { font-size: .74rem; font-weight: 700; color: var(--navy-700); background: var(--bg-soft); border: 1px solid var(--line-soft); padding: 4px 9px; border-radius: 999px; text-transform: capitalize; white-space: nowrap; }
.tone-alert .tl-ico, .tl-ico.tone-alert { background: #fdecec; color: #c03535; }
.tone-warn .tl-ico, .tl-ico.tone-warn { background: #fbf1de; color: #a46b12; }
.tone-ok .tl-ico, .tl-ico.tone-ok { background: var(--ok-bg); color: var(--ok); }
.tone-teal .tl-ico, .tl-ico.tone-teal { background: var(--teal-50); color: var(--teal-700); }
.panel-foot { display: flex; justify-content: center; padding-top: 12px; margin-top: 8px; border-top: 1px solid var(--line-soft); }

/* Rooms */
.rooms-list { display: flex; flex-direction: column; gap: 8px; }
.room-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; border: 1px solid var(--line-soft); background: var(--bg-soft); }
.room-row .dot { width: 10px; height: 10px; border-radius: 50%; background: #c3ccd8; flex: none; }
.room-row.on { background: var(--teal-50); border-color: rgba(31,134,149,.3); }
.room-row.on .dot { background: var(--teal-500); box-shadow: 0 0 0 4px rgba(31,134,149,.15); }
.room-row b { color: var(--ink); text-transform: capitalize; font-size: .92rem; }
.room-row small { display: block; color: var(--muted); font-size: .78rem; }
.room-row .state { margin-left: auto; font-size: .78rem; font-weight: 700; color: var(--muted); }
.room-row.on .state { color: var(--teal-700); }

/* Medication */
.med-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.med { padding: 14px 10px; border-radius: 14px; text-align: center; background: var(--bg-soft); }
.med b { display: block; font: 800 1.5rem var(--display); color: var(--ink); }
.med small { font-size: .76rem; font-weight: 700; color: var(--muted); }
.med.ok { background: var(--ok-bg); } .med.ok b { color: var(--ok); }
.med.warn { background: #fbf1de; } .med.warn b { color: #a46b12; }

/* System */
.sys-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.sys-list li { display: flex; justify-content: space-between; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line-soft); font-size: .9rem; }
.sys-list li:last-child { border-bottom: 0; }
.sys-list span { color: var(--muted); }
.sys-list b { color: var(--ink); text-align: right; }
.sys-list b.good { color: var(--ok); }
.sys-list b.bad { color: #b42318; }

/* ---------- Events page ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font: 600 .86rem var(--font); color: var(--navy-800); cursor: pointer; transition: .2s; }
.chip-btn svg { width: 16px; height: 16px; }
.chip-btn .n { font-size: .74rem; font-weight: 800; padding: 1px 7px; border-radius: 999px; background: var(--bg-soft); color: var(--muted); }
.chip-btn:hover { border-color: var(--navy-700); }
.chip-btn.active { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }
.chip-btn.active .n { background: rgba(255,255,255,.15); color: #fff; }
.search { position: relative; margin-left: auto; min-width: 240px; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); }
.search input { padding-left: 40px; background: #fff; }
.toolbar select { width: auto; min-width: 150px; background: #fff; padding: 12px 14px; }
.ev-table .tl-row { grid-template-columns: 120px 38px minmax(0, 1fr) 120px 90px; }
.ev-table .conf { font: 600 .8rem var(--mono); color: var(--muted); text-align: right; }
.result-note { font-size: .84rem; color: var(--muted); }

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(12,26,51,.45); backdrop-filter: blur(3px); opacity: 0; visibility: hidden; transition: .25s; z-index: 80; }
.scrim.open { opacity: 1; visibility: visible; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: #fff; z-index: 90;
  transform: translateX(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1); display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 14px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 1.2rem; margin: 0; }
.drawer-head .code { font: 600 .76rem var(--mono); color: var(--muted); }
.drawer-head .icon-btn { margin-left: auto; }
.drawer-body { padding: 22px 24px 32px; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 20px; }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.meta-grid div { background: var(--bg-soft); border-radius: 12px; padding: 12px 14px; }
.meta-grid small { display: block; font: 700 .68rem var(--display); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.meta-grid b { color: var(--ink); font-size: .92rem; text-transform: capitalize; overflow-wrap: anywhere; }
.drawer h3 { font-size: .95rem; margin: 0 0 10px; }
.raw { background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 12px; padding: 14px; font: 500 .82rem/1.6 var(--mono); color: var(--navy-800); white-space: pre-wrap; overflow-wrap: anywhere; }
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: .92rem; line-height: 1.45; }
.bubble small { display: block; font: 700 .66rem var(--display); letter-spacing: .1em; text-transform: uppercase; opacity: .7; margin-bottom: 3px; }
.bubble.naledi { background: var(--navy-900); color: #fff; border-bottom-left-radius: 4px; align-self: flex-start; }
.bubble.resident { background: var(--gold-100); color: var(--ink); border-bottom-right-radius: 4px; align-self: flex-end; }
.chat-note { font-size: .78rem; color: var(--muted); }
.list-rows { display: flex; flex-direction: column; gap: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 85; transform: translateX(-100%); transition: transform .3s cubic-bezier(.2,.8,.2,1); }
  .side.open { transform: none; box-shadow: var(--shadow-lg); }
  .side-toggle { display: inline-grid; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 1.15rem; }
  .topbar .sub, .live span { display: none; }
  .content { padding: 18px 16px 40px; gap: 18px; }
  .search { margin-left: 0; flex: 1 1 100%; min-width: 0; }
  .toolbar select { flex: 1; }
  .ev-table .tl-row { grid-template-columns: 52px 38px minmax(0, 1fr) auto; }
  .ev-table .tl-row .conf { display: none; }
  .ev-table .tl-time .d { display: none; }
}
@media (max-width: 600px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 1.35rem; }
  .kpi .icon-tile { display: none; }
  .alert-card { grid-template-columns: 44px 1fr; padding: 16px; gap: 14px; }
  .alert-card .a-ico { width: 44px; height: 44px; border-radius: 13px; }
  .alert-card .a-side { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .tl-row { grid-template-columns: 48px 34px minmax(0, 1fr); }
  .tl-row .room-chip { display: none; }
  .tl-ico { width: 34px; height: 34px; }
  .meta-grid { grid-template-columns: 1fr; }
  .panel { padding: 18px 14px 14px; }
}

[hidden] { display: none !important; }

/* ---------- Sleep page (bedroom radar) ---------- */
.sleep-note { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 16px; background: var(--teal-50); border: 1px solid rgba(31,134,149,.2); color: var(--body); font-size: .9rem; }
.sleep-note svg { width: 18px; height: 18px; color: var(--teal-600); flex: none; margin-top: 2px; }
.kpi-of { font-size: .9rem; color: var(--muted); font-weight: 700; }
.sg-deep { background: var(--navy-800); }
.sg-light { background: var(--teal-500); }
.sg-awake { background: var(--gold-500); }
.sg-none { background: #dfe5ee; }
.sg-up { background: #d64545; }
.night-top { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.ring { position: relative; width: 128px; height: 128px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring .ring-bg { stroke: var(--line-soft); }
.ring .ring-fg { stroke: var(--teal-500); stroke-linecap: round; transition: stroke-dasharray .6s; }
.ring.q-fair .ring-fg { stroke: var(--gold-500); }
.ring.q-poor .ring-fg { stroke: #d64545; }
.ring-txt { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-txt b { font: 800 2.1rem/1 var(--display); color: var(--ink); }
.ring-txt small { font-size: .78rem; font-weight: 700; color: var(--muted); margin-top: 2px; }
.night-split { flex: 1; min-width: 220px; }
.night-hours { font-size: .95rem; color: var(--muted); margin-bottom: 10px; }
.night-hours b { font: 800 1.5rem var(--display); color: var(--ink); margin-right: 4px; }
.stage-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--line-soft); }
.stage-bar span { height: 100%; }
.stage-bar.mini { height: 8px; width: 130px; margin-bottom: 4px; }
.stage-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: .82rem; color: var(--muted); }
.stage-legend span { display: inline-flex; align-items: center; gap: 6px; }
.stage-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.stage-legend b { color: var(--ink); }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 20px; }
.metric { padding: 14px; border-radius: 14px; background: var(--bg-soft); display: flex; flex-direction: column; gap: 2px; }
.metric svg { width: 18px; height: 18px; color: var(--teal-600); margin-bottom: 4px; }
.metric small { font-size: .74rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.metric b { font: 800 1.4rem var(--display); color: var(--ink); }
.metric span { font-size: .78rem; color: var(--muted); }
.night-nav { display: flex; align-items: center; gap: 8px; font-size: .86rem; font-weight: 700; color: var(--ink); }
.night-nav .icon-btn { width: 32px; height: 32px; border-radius: 10px; }
.night-nav .icon-btn:disabled { opacity: .35; cursor: default; }
.night-track { position: relative; height: 54px; border-radius: 12px; background: var(--bg-soft); overflow: hidden; border: 1px solid var(--line-soft); }
.tl-seg { position: absolute; top: 0; bottom: 0; }
.tl-seg.sg-deep { top: 4px; }
.tl-seg.sg-light { top: 16px; }
.tl-seg.sg-awake { top: 30px; }
.tl-seg.sg-none { top: 44px; }
.tl-up { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1px; background: #d64545; border-radius: 2px; }
.tl-now { position: absolute; top: 0; bottom: 0; border-left: 2px dashed var(--muted); }
.night-axis { position: relative; height: 20px; margin-top: 6px; font-size: .72rem; color: var(--muted); }
.night-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.night-axis span:first-child { transform: none; }
.night-axis span:last-child { transform: translateX(-100%); }
.getup-row, .review-row { display: flex; gap: 14px; align-items: baseline; padding: 9px 4px; border-bottom: 1px solid var(--line-soft); font-size: .9rem; color: var(--body); }
.getup-row:last-child, .review-row:last-child { border-bottom: 0; }
.review-row .tl-time, .getup-row .tl-time { flex: none; min-width: 52px; }
.review-row .tl-time { min-width: 96px; }
.table-scroll { overflow-x: auto; }
table.nights { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 780px; }
table.nights th { text-align: left; font: 700 .7rem var(--display); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.nights td { padding: 12px 10px; border-bottom: 1px solid var(--line-soft); color: var(--body); white-space: nowrap; }
table.nights td small { color: var(--muted); font-size: .75rem; }
table.nights tr:last-child td { border-bottom: 0; }
.q-pill { display: inline-block; min-width: 38px; text-align: center; padding: 3px 8px; border-radius: 999px; font-weight: 800; font-size: .82rem; background: var(--ok-bg); color: var(--ok); }
.q-pill.q-fair { background: #fbf1de; color: #a46b12; }
.q-pill.q-poor { background: #fde8e8; color: #b42318; }
.sys-list b.bad { color: #b42318; }
@media (max-width: 560px) { .night-top { justify-content: center; } .night-nav span { font-size: .78rem; } }
.panel-head:has(.night-nav) { flex-wrap: wrap; }
body[data-page="sleep"] .kpi-value { text-transform: none; }

/* ---------- Heart rate & breathing charts ---------- */
.vital + .vital { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.vital-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 8px; }
.vital-head > b { font: 700 .95rem var(--display); color: var(--ink); }
.vital-sum { font-size: .84rem; color: var(--muted); }
.vital-sum b { color: var(--ink); }
.v-plot { position: relative; }
.v-plot svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.v-grid { stroke: var(--line-soft); stroke-width: 1; }
.v-ylab { font-size: 10.5px; fill: var(--muted); text-anchor: end; }
.v-xlab { font-size: 10.5px; fill: var(--muted); }
.v-line { fill: none; stroke: var(--teal-600); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.v-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.v-dot { fill: var(--teal-600); stroke: #fff; stroke-width: 2; }
.v-hit { fill: transparent; cursor: crosshair; }
.v-tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--navy-900); color: #fff; padding: 6px 10px; border-radius: 10px; font-size: .8rem; white-space: nowrap; pointer-events: none; box-shadow: var(--shadow); }
.v-tip b { font-size: .95rem; }
.v-tip small { display: block; color: #b6c3d6; font-size: .72rem; }

/* ---------- "Today" dashboard: headline, four facts, day story ---------- */
.hero-status { display: flex; align-items: center; gap: 18px; padding: 22px 24px; border-radius: 22px; background: #fff; border: 1px solid var(--line); }
.hero-status h2 { margin: 0; font-size: clamp(1.3rem, 2.6vw, 1.8rem); letter-spacing: -.02em; line-height: 1.2; }
.hero-status p { margin: 6px 0 0; color: var(--body); font-size: .98rem; }
.hero-status p a { font-weight: 700; }
.hero-ico { width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; flex: none; background: var(--bg-soft); color: var(--muted); }
.hero-ico svg { width: 30px; height: 30px; }
.hero-status.tone-ok { background: var(--ok-bg); border-color: rgba(16,145,107,.25); }
.hero-status.tone-ok .hero-ico { background: #fff; color: var(--ok); }
.hero-status.tone-warn { background: #fbf1de; border-color: rgba(183,121,31,.35); }
.hero-status.tone-warn .hero-ico { background: #fff; color: #a46b12; }
.hero-status.tone-alert { background: #fdecec; border: 2px solid #d64545; }
.hero-status.tone-alert .hero-ico { background: #d64545; color: #fff; }
.hero-status.tone-alert h2 { color: #8f1d1d; }
.hero-status.tone-load .hero-ico svg { animation: spin 1.2s linear infinite; }
.alerts[hidden] { display: none; }

.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.fact { display: flex; flex-direction: column; gap: 4px; padding: 18px; border-radius: 20px; background: #fff; border: 1px solid var(--line); text-align: left; font: inherit; color: inherit; cursor: pointer; transition: border-color .2s, transform .2s; min-width: 0; }
.fact:hover { border-color: var(--teal-500); transform: translateY(-1px); }
.fact-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--bg-soft); color: var(--muted); margin-bottom: 8px; }
.fact-ico svg { width: 20px; height: 20px; }
.fact-label { font: 700 .72rem var(--display); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.fact-title { font: 800 1.25rem/1.25 var(--display); color: var(--ink); letter-spacing: -.01em; }
.fact-sub { font-size: .86rem; color: var(--muted); }
.fact.tone-ok .fact-ico { background: var(--ok-bg); color: var(--ok); }
.fact.tone-warn { border-color: rgba(183,121,31,.45); }
.fact.tone-warn .fact-ico { background: #fbf1de; color: #a46b12; }

.story-group + .story-group { margin-top: 14px; }
.story-period { font: 700 .74rem var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 4px 4px 8px; }
.story-row { display: grid; grid-template-columns: 92px 34px minmax(0, 1fr); align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line-soft); }
.story-group .story-row:last-child { border-bottom: 0; }
.story-time { font-size: .85rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.story-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--bg-soft); color: var(--navy-700); }
.story-ico svg { width: 17px; height: 17px; }
.story-text { font-size: 1rem; color: var(--ink); }
.story-row.tone-ok .story-ico { background: var(--ok-bg); color: var(--ok); }
.story-row.tone-warn .story-ico { background: #fbf1de; color: #a46b12; }
.story-row.tone-alert .story-ico { background: #fdecec; color: #b42318; }
.story-row.tone-alert .story-text { color: #8f1d1d; font-weight: 700; }
.dash-note { margin: 0; text-align: center; color: var(--muted); font-size: .86rem; }

@media (max-width: 1100px) { .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .hero-status { padding: 18px; gap: 14px; align-items: flex-start; }
  .hero-ico { width: 46px; height: 46px; border-radius: 14px; }
  .facts { gap: 10px; }
  .fact { padding: 14px; }
  .fact-title { font-size: 1.05rem; }
  .story-row { grid-template-columns: 64px 30px minmax(0, 1fr); gap: 8px; }
  .story-ico { width: 30px; height: 30px; }
  .story-text { font-size: .94rem; }
}
