:root {
  --navy: #0D1F8C;
  --gold: #F5A800;
  --light-navy: #EEF0FC;
  --light-gold: #FFF8E0;
  --green: #1D9E75;
  --light-green: #E6F9EE;
  --red: #E24B4A;
  --orange: #EF9F27;
  --surface: #F5F7FF;
  --card: #FFFFFF;
  --border: #E0E4F0;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}

/* ── APP SHELL ─────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  position: relative;
  overflow: hidden;
}

/* ── TOP BAR ────────────────────────────────────── */
.topbar {
  background: var(--navy);
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 100;
}
.topbar-left h1 { font-size: 17px; font-weight: 600; color: var(--gold); }
.topbar-left p  { font-size: 11px; color: rgba(255,255,255,0.6); margin-top: 1px; }
.topbar-right   { display: flex; gap: 8px; }
.topbar-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: none; color: var(--gold);
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.topbar-btn:active { background: rgba(255,255,255,0.2); }

/* ── SCREENS ─────────────────────────────────────── */
.screens { flex: 1; overflow: hidden; position: relative; }
.screen  { position: absolute; inset: 0; overflow-y: auto; display: none; -webkit-overflow-scrolling: touch; }
.screen.active { display: block; }

/* ── BOTTOM NAV ──────────────────────────────────── */
.bottom-nav {
  display: flex;
  background: white;
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
  z-index: 100;
}
.nav-btn {
  flex: 1; padding: 10px 4px 8px;
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.nav-btn .ni { font-size: 20px; transition: transform 0.2s; }
.nav-btn .nl { font-size: 10px; color: var(--text-muted); }
.nav-btn.active .nl { color: var(--navy); font-weight: 600; }
.nav-btn.active .ni { transform: scale(1.15); }

/* ── CARDS ───────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--navy); margin-bottom: 6px; }
.card-sub   { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ── PAGE PADDING ────────────────────────────────── */
.page { padding: 14px; }

/* ── SECTION LABEL ───────────────────────────────── */
.sec-lbl {
  font-size: 11px; font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.06em;
  margin-bottom: 8px; margin-top: 14px;
}
.sec-lbl:first-child { margin-top: 0; }

/* ── ACCESS BANNER ───────────────────────────────── */
.access-banner {
  padding: 10px 14px; border-radius: 10px;
  font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.access-free  { background: var(--light-green); color: #0f4d2a; border: 1px solid #9fe1cb; }
.access-trial { background: var(--light-gold);  color: #5a3a00; border: 1px solid var(--gold); }
.access-locked{ background: #fce8e8;            color: #7a1f1f; border: 1px solid #f09595; }

/* ── STAT ROW ────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 12px; }
.stat-box  {
  background: white; border-radius: 10px;
  border: 1px solid var(--border);
  padding: 10px 6px; text-align: center;
}
.stat-val { font-size: 18px; font-weight: 700; color: var(--navy); }
.stat-lbl { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

/* ── PROGRESS BAR ────────────────────────────────── */
.pb-wrap { height: 6px; background: #f0f0f0; border-radius: 3px; overflow: hidden; margin: 4px 0; }
.pb-fill  { height: 100%; border-radius: 3px; transition: width 0.5s ease; }

/* ── CHIPS ───────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip  {
  padding: 6px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  transition: all 0.15s;
}
.chip.sel { background: var(--navy); color: var(--gold); border-color: var(--navy); }

/* ── BUTTONS ─────────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 13px;
  background: var(--navy); color: var(--gold);
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger {
  width: 100%; padding: 11px;
  background: var(--red); color: white;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-ghost {
  width: 100%; padding: 11px;
  background: none; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 13px; cursor: pointer; margin-top: 8px;
}

/* ── INPUTS ──────────────────────────────────────── */
.input-row  { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.input-wrap { margin-bottom: 10px; }
.input-wrap label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.inp {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: white; color: var(--text);
  outline: none; transition: border-color 0.15s;
}
.inp:focus { border-color: var(--navy); }

/* ── ACTIVITY GRID ───────────────────────────────── */
.act-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 14px; }
.act-card {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 6px; cursor: pointer; text-align: center;
  background: white; transition: all 0.15s;
}
.act-card:active { transform: scale(0.97); }
.act-card.sel  { border-color: var(--navy); background: var(--light-navy); }
.act-card.live { border-color: #4ade80; background: #f0fdf4; animation: pulse-border 2s infinite; }
.act-icon { font-size: 26px; margin-bottom: 4px; }
.act-name { font-size: 12px; font-weight: 600; color: var(--navy); }
.act-stat { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
@keyframes pulse-border { 0%,100%{border-color:#4ade80} 50%{border-color:#16a34a} }

/* ── LIVE PANEL ──────────────────────────────────── */
.live-panel {
  background: var(--navy); border-radius: 16px;
  padding: 16px; margin-bottom: 14px;
}
.live-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.live-name { font-size: 16px; font-weight: 600; color: var(--gold); }
.live-rec  { display: flex; align-items: center; gap: 5px; font-size: 11px; color: rgba(255,255,255,0.6); margin-top: 2px; }
.live-dot  { width: 6px; height: 6px; border-radius: 50%; background: #4ade80; animation: blink 1.5s infinite; }
.live-time { font-size: 30px; font-weight: 700; color: white; letter-spacing: 2px; }
.live-stats{ display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; margin-bottom: 14px; }
.ls-val { font-size: 16px; font-weight: 700; color: var(--gold); text-align: center; }
.ls-lbl { font-size: 9px; color: rgba(255,255,255,0.5); text-align: center; margin-top: 1px; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ── TIMELINE ────────────────────────────────────── */
.timeline { }
.tl-row   { display: flex; gap: 10px; align-items: flex-start; }
.tl-left  { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.tl-time  { font-size: 10px; font-weight: 600; color: var(--navy); padding-top: 10px; }
.tl-dot   { width: 10px; height: 10px; border-radius: 50%; margin: 4px 0; flex-shrink: 0; }
.tl-dot.done { background: var(--green); }
.tl-dot.now  { background: var(--gold); box-shadow: 0 0 0 3px var(--light-gold); }
.tl-dot.soon { background: #d1d5db; }
.tl-line  { width: 1px; background: var(--border); flex: 1; min-height: 16px; }
.tl-content{
  flex: 1; padding: 8px 10px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 10px;
  background: white; cursor: pointer; transition: background 0.15s;
}
.tl-content:active { background: var(--light-navy); }
.tl-content.now-item { background: var(--light-navy); border-color: rgba(13,31,140,0.3); }
.tl-label { font-size: 13px; font-weight: 600; color: var(--navy); }
.tl-food  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.tl-voice { font-size: 11px; color: var(--navy); margin-top: 5px; padding: 5px 7px; background: var(--light-navy); border-radius: 6px; font-style: italic; line-height: 1.5; }

/* ── VOICE SCREEN ─────────────────────────────────── */
.voice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.voice-card {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 10px; cursor: pointer; background: white;
  display: flex; align-items: center; gap: 8px; transition: all 0.15s;
}
.voice-card.sel { background: var(--navy); border-color: var(--navy); }
.voice-emoji { font-size: 24px; }
.voice-name { font-size: 13px; font-weight: 600; color: var(--navy); }
.voice-card.sel .voice-name { color: var(--gold); }
.voice-role { font-size: 10px; color: var(--text-muted); }
.voice-card.sel .voice-role { color: rgba(255,255,255,0.5); }

.preview-box {
  background: var(--light-navy); border-radius: 10px;
  padding: 12px 14px; font-size: 12px; color: var(--navy);
  line-height: 1.7; font-style: italic; min-height: 60px; margin-bottom: 10px;
}
.event-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.etab {
  padding: 5px 12px; border-radius: 20px; font-size: 11px;
  border: 1px solid var(--border); background: white;
  color: var(--text-muted); cursor: pointer; transition: all 0.15s;
}
.etab.sel { background: var(--gold); color: var(--navy); border-color: var(--gold); font-weight: 600; }

/* ── SLEEP SCREEN ─────────────────────────────────── */
.sleep-hero {
  background: var(--navy); border-radius: 16px;
  padding: 16px; margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.sleep-dur { font-size: 30px; font-weight: 700; color: white; }
.sleep-sub { font-size: 11px; color: rgba(255,255,255,0.6); margin-top: 2px; }
.sleep-score { font-size: 36px; font-weight: 700; color: var(--gold); text-align: center; }
.sleep-badge { font-size: 10px; background: var(--green); color: white; padding: 3px 10px; border-radius: 10px; text-align: center; margin-top: 4px; }
.stage-bar { height: 10px; border-radius: 5px; overflow: hidden; display: flex; gap: 1px; margin: 8px 0; }
.stage-legend { display: flex; flex-wrap: wrap; gap: 10px; }
.sl-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text); }
.sl-dot  { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.week-bars { display: flex; gap: 4px; align-items: flex-end; height: 60px; }
.wbar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.wbar { width: 100%; border-radius: 3px 3px 0 0; }
.wbar-lbl { font-size: 9px; color: var(--text-muted); }
.zone-row { margin-bottom: 8px; }
.zone-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }

/* ── CHECK-IN ─────────────────────────────────────── */
.q-box { background: var(--light-navy); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.q-text { font-size: 13px; color: var(--navy); font-style: italic; line-height: 1.6; margin-bottom: 10px; }
.q-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.q-opt  {
  padding: 9px 6px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 11px; text-align: center;
  cursor: pointer; background: white; transition: all 0.15s; line-height: 1.3;
}
.q-opt.sel { background: var(--navy); color: var(--gold); border-color: var(--navy); font-weight: 600; }
.result-card { background: var(--light-green); border: 1px solid #9fe1cb; border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.result-title { font-size: 15px; font-weight: 700; color: #0f4d2a; margin-bottom: 6px; }
.result-text  { font-size: 13px; color: #1a5c30; line-height: 1.6; }

/* ── BADGES ──────────────────────────────────────── */
.score-hero { background: var(--navy); border-radius: 16px; padding: 20px; margin-bottom: 14px; text-align: center; }
.score-num  { font-size: 56px; font-weight: 700; color: white; line-height: 1; }
.score-denom{ font-size: 20px; color: rgba(255,255,255,0.5); }
.score-lbl  { font-size: 13px; color: var(--gold); margin-bottom: 10px; }
.badge-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; margin-bottom: 14px; }
.badge-item {
  background: white; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 6px; text-align: center; transition: all 0.15s;
}
.badge-item.earned { background: var(--light-gold); border-color: var(--gold); }
.badge-ico { font-size: 24px; margin-bottom: 4px; }
.badge-name { font-size: 10px; font-weight: 600; color: var(--text); line-height: 1.3; }
.badge-item.earned .badge-name { color: #5a3a00; }
.badge-lock { font-size: 9px; color: var(--text-muted); margin-top: 2px; }

/* ── MEAL PLAN ───────────────────────────────────── */
.meal-card {
  background: white; border-radius: 12px; border: 1px solid var(--border);
  padding: 13px; margin-bottom: 10px; display: flex; gap: 12px; align-items: flex-start;
}
.meal-icon-wrap { width: 40px; height: 40px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.meal-title { font-size: 13px; font-weight: 600; color: var(--navy); }
.meal-detail { font-size: 12px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.meal-time  { font-size: 10px; color: var(--text-muted); margin-top: 3px; }

/* ── HISTORY CARDS ───────────────────────────────── */
.hist-card {
  background: white; border-radius: 12px;
  border-left: 3px solid var(--navy);
  padding: 12px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
}
.hist-icon { font-size: 24px; }
.hist-name { font-size: 13px; font-weight: 600; color: var(--navy); }
.hist-sub  { font-size: 11px; color: var(--text-muted); }
.hist-right{ margin-left: auto; text-align: right; }
.hist-dur  { font-size: 13px; font-weight: 600; color: var(--navy); }
.hist-cal  { font-size: 11px; color: var(--green); }

/* ── SMART ALARM ─────────────────────────────────── */
.toggle-wrap { display: flex; justify-content: space-between; align-items: center; }
.toggle {
  width: 44px; height: 24px; border-radius: 12px;
  background: var(--navy); position: relative; cursor: pointer;
  transition: background 0.2s;
}
.toggle.off { background: #d1d5db; }
.toggle-knob {
  width: 18px; height: 18px; border-radius: 50%; background: var(--gold);
  position: absolute; top: 3px; right: 3px;
  transition: right 0.2s, background 0.2s;
}
.toggle.off .toggle-knob { right: 23px; background: white; }

/* ── INSTALL PROMPT ──────────────────────────────── */
.install-bar {
  background: var(--gold); color: var(--navy);
  padding: 10px 14px; font-size: 12px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0; cursor: pointer;
}
.install-bar.hidden { display: none; }

/* ── DEVICE ROWS ─────────────────────────────────── */
.dev-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 7px; cursor: pointer;
  background: white; transition: background 0.15s;
}
.dev-row:active { background: var(--surface); }
.dev-ico { width: 36px; height: 36px; border-radius: 8px; background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.dev-name { font-size: 12px; font-weight: 600; color: var(--navy); }
.dev-meta { font-size: 10px; color: var(--text-muted); }
.dev-status { margin-left: auto; font-size: 10px; padding: 3px 9px; border-radius: 10px; font-weight: 600; }
.ds-conn { background: var(--light-green); color: #0f4d2a; }
.ds-disc { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }

/* ── UTILITIES ───────────────────────────────────── */
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.text-navy    { color: var(--navy); }
.text-gold    { color: var(--gold); }
.text-green   { color: var(--green); }
.text-muted   { color: var(--text-muted); }
.fw6          { font-weight: 600; }
.fs12         { font-size: 12px; }
.fs11         { font-size: 11px; }
.mb8          { margin-bottom: 8px; }
.mb12         { margin-bottom: 12px; }
.mt10         { margin-top: 10px; }
.gap8         { gap: 8px; }

/* ── SCROLLBAR HIDE ──────────────────────────────── */
.screen::-webkit-scrollbar { display: none; }
.screen { scrollbar-width: none; }

/* ── LOADING SPINNER ─────────────────────────────── */
.spinner {
  width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: var(--gold); border-radius: 50%;
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOAST ───────────────────────────────────────── */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: #1a1a2e; color: white; padding: 10px 20px;
  border-radius: 20px; font-size: 13px; z-index: 9999;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
  max-width: 320px; text-align: center;
}
@keyframes toastIn  { from { opacity:0; transform: translateX(-50%) translateY(10px); } to { opacity:1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { to   { opacity:0; transform: translateX(-50%) translateY(10px); } }
