/* ============================================================================
   Rested — calm night theme. Mobile-first, big tap targets, buildless.
   ========================================================================== */
:root {
  --bg-0: #0b0f22;
  --bg-1: #10152e;
  --bg-2: #161d3d;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text: #eef0fb;
  --muted: #9aa2c8;
  --faint: #6b7299;

  --accent: #8b9cff;     /* periwinkle */
  --accent-2: #b9a3ff;   /* soft violet */
  --mint: #6ee7c7;       /* good / positive */
  --amber: #ffcf7a;      /* attention */
  --coral: #ff9d8a;      /* warning */
  --pink: #ff8fb1;

  --good: var(--mint);
  --warn: var(--amber);
  --bad: var(--coral);

  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, #1c2450 0%, rgba(28,36,80,0) 60%),
    radial-gradient(900px 500px at -10% 10%, #241b48 0%, rgba(36,27,72,0) 55%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); }

/* ---- Layout ---------------------------------------------------------------*/
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; position: relative; }

#topbar {
  position: sticky; top: 0; z-index: 30;
  padding-top: var(--safe-t);
  background: linear-gradient(180deg, rgba(11,15,34,0.92) 0%, rgba(11,15,34,0.6) 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }
.brand-moon {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 68% 34%, #0b0f22 0 46%, transparent 47%),
              linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 0 14px rgba(139,156,255,0.55);
}
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }

#view {
  padding: 18px 16px calc(var(--nav-h) + var(--safe-b) + 28px);
  animation: fade .28s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- Bottom nav + FAB -----------------------------------------------------*/
#bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 560px; margin: 0 auto;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: linear-gradient(180deg, rgba(16,21,46,0.85) 0%, rgba(11,15,34,0.98) 100%);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.nav-item {
  border: 0; background: transparent; color: var(--faint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  transition: color .18s;
}
.nav-item.active { color: var(--accent); }
.nav-item.active svg { filter: drop-shadow(0 0 8px rgba(139,156,255,0.5)); }
.nav-item:active { color: var(--text); }

.fab {
  position: fixed; z-index: 31;
  right: max(18px, calc(50% - 280px + 18px));
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 58px; height: 58px; border-radius: 50%;
  border: 0; color: #0b0f22;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 8px 24px rgba(139,156,255,0.45);
  display: grid; place-items: center;
}
.fab:active { transform: scale(0.94); }

/* ---- Cards ----------------------------------------------------------------*/
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 14px; }
.card h2, .card h3 { margin: 0 0 4px; }
.card-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); margin-bottom: 12px;
}
.card-title .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

.section-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 4px 2px 14px; }
.subtle { color: var(--muted); }
.faint { color: var(--faint); }
.hint { font-size: 12.5px; color: var(--faint); line-height: 1.5; }

/* ---- Hero (Today) ---------------------------------------------------------*/
.hero { text-align: center; padding: 22px 18px 20px; }
.hero .greeting { color: var(--muted); font-size: 14px; font-weight: 600; }
.ring-wrap { position: relative; width: 200px; height: 200px; margin: 8px auto 6px; }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.ring-value { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.ring-label { color: var(--muted); font-size: 13px; margin-top: 4px; font-weight: 600; }
.ring-sub { color: var(--faint); font-size: 12px; margin-top: 2px; }

/* ---- Stat grid ------------------------------------------------------------*/
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px;
}
.stat .k { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .v { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin-top: 6px; }
.stat .v small { font-size: 14px; font-weight: 600; color: var(--muted); }
.stat .trend { font-size: 12px; margin-top: 3px; font-weight: 600; }
.trend.up { color: var(--mint); } .trend.down { color: var(--coral); } .trend.flat { color: var(--faint); }
.ico { width: 15px; height: 15px; color: var(--accent); }

/* ---- Pills / chips --------------------------------------------------------*/
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.pill.good { color: var(--mint); border-color: rgba(110,231,199,.3); background: rgba(110,231,199,.08); }
.pill.warn { color: var(--amber); border-color: rgba(255,207,122,.3); background: rgba(255,207,122,.08); }
.pill.bad  { color: var(--coral); border-color: rgba(255,157,138,.3); background: rgba(255,157,138,.08); }

.tag-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 14px; border-radius: 12px; font-size: 14px; font-weight: 600;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border);
  user-select: none;
}
.tag-toggle.on { background: rgba(139,156,255,.14); color: var(--text); border-color: var(--accent); }

/* ---- Buttons --------------------------------------------------------------*/
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 18px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 700; font-size: 15px;
  width: 100%;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%); color: #0b0f22; border: 0; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 9px 13px; font-size: 13px; width: auto; border-radius: 11px; }
.btn.danger { color: var(--coral); border-color: rgba(255,157,138,.3); }
.btn-row { display: flex; gap: 10px; }

/* ---- Forms ----------------------------------------------------------------*/
label.field { display: block; margin-bottom: 16px; }
label.field > .lab { display: block; font-size: 13.5px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
input, select, textarea {
  width: 100%; padding: 13px 14px; font-size: 16px; /* 16px stops iOS zoom */
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; outline: none; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: var(--surface-2); }
input[type=time] { -webkit-appearance: none; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }

/* stepper / segmented rating */
.rating { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.rating button {
  padding: 12px 0; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-weight: 700; font-size: 18px;
}
.rating button.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color:#0b0f22; border:0; }

/* ---- Modal / bottom sheet -------------------------------------------------*/
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(4,6,16,.6);
  backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border-strong);
  border-radius: 24px 24px 0 0; padding: 8px 18px calc(28px + var(--safe-b));
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
  animation: slideup .28s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 640px) { .sheet { border-radius: 24px; margin: 0 16px; } }
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--border-strong); margin: 8px auto 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h2 { font-size: 20px; font-weight: 800; margin: 0; }

/* ---- Insights / findings --------------------------------------------------*/
.finding {
  display: flex; gap: 12px; padding: 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); margin-bottom: 10px;
}
.finding .badge {
  flex: none; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  font-size: 20px;
}
.finding .badge.bad  { background: rgba(255,157,138,.13); }
.finding .badge.good { background: rgba(110,231,199,.13); }
.finding .body { flex: 1; min-width: 0; }
.finding .body .t { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.finding .body .d { color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.finding .body .meta { color: var(--faint); font-size: 12px; margin-top: 5px; }

/* ---- Coach chat -----------------------------------------------------------*/
.chat-wrap { display: flex; flex-direction: column; gap: 12px; }
.bubble { max-width: 84%; padding: 12px 15px; border-radius: 18px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; }
.bubble.me { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0b0f22; border-bottom-right-radius: 6px; font-weight: 500; }
.bubble.ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.bubble.ai.thinking { color: var(--muted); }
.chat-input-bar {
  position: sticky; bottom: 0; display: flex; gap: 8px; padding-top: 10px;
  background: linear-gradient(180deg, transparent, var(--bg-0) 40%);
}
.chat-input-bar input { border-radius: 999px; }
.chat-send { flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; color: #0b0f22;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; }
.suggest-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.suggest { font-size: 13px; padding: 8px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); }

/* ---- Toast ----------------------------------------------------------------*/
#toast-host { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 20px); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--bg-2); border: 1px solid var(--border-strong); color: var(--text);
  padding: 12px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); animation: fade .2s ease;
}
.toast.good { border-color: rgba(110,231,199,.4); }
.toast.bad { border-color: rgba(255,157,138,.4); }

/* ---- Misc -----------------------------------------------------------------*/
.empty { text-align: center; padding: 30px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }
.center { text-align: center; }
.mt8{margin-top:8px}.mt12{margin-top:12px}.mt16{margin-top:16px}.mb0{margin-bottom:0}
.flex { display: flex; } .between { justify-content: space-between; } .items-center { align-items: center; }
.gap8 { gap: 8px; } .gap12 { gap: 12px; } .wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
details summary { list-style: none; } details summary::-webkit-details-marker { display: none; }
details > summary::before { content: '▸ '; color: var(--accent); }
details[open] > summary::before { content: '▾ '; }
.spin { animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }
