/* ==========================================================================
   Mellow Health — shared theme  ("Cloud" redesign)
   Dark, mobile-first, touch-first. Loaded by every page (/style.css).
   Page-specific rules stay inline in each page.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  /* surfaces */
  --bg:       #07090c;
  --bg-grad:  radial-gradient(115% 70% at 50% 0%, #0b1014 0%, #07090c 52%, #050608 100%);
  --card:     #10151d;                                  /* metric cards            */
  --card2:    #141a20;                                  /* panel top (gradient)    */
  --card3:    #0b0f13;                                  /* panel bottom (gradient) */
  --panel:    linear-gradient(180deg, #141a20, #0b0f13);
  --nav-bg:   #0a0e12;
  --active:   #1b2630;
  --grid:     rgba(255,255,255,.06);

  /* borders */
  --border:   rgba(255,255,255,.12);
  --border2:  rgba(255,255,255,.08);
  --border3:  rgba(255,255,255,.07);

  /* text */
  --text:     #e8ebef;
  --text2:    #eef1f4;
  --ink:      #eaedf1;
  --muted:    #8b93a1;
  --muted2:   #7c8593;
  --muted3:   #5a6271;

  /* unified accent (primary actions, spinners) */
  --accent:   #46dd9c;
  --accent-ink:#06120c;

  /* status */
  --good:     #46dd9c;
  --watch:    #f2c44d;
  --concern:  #f5706e;

  /* metric palette (per-chart colours, shared across pages + canvas charts) */
  --red:      #f5706e;
  --green:    #46dd9c;
  --blue:     #6aa9ff;
  --orange:   #f2a65a;
  --purple:   #b08cf0;
  --teal:     #46c8dd;
  --yellow:   #f2c44d;

  /* domain colours */
  --body:     #46dd9c;
  --sleep:    #8c9af0;
  --deep:     #3a6df0;
  --rem:      #46dd9c;
  --light:    #3ba3dd;
  --core:     #3ba3dd;
  --awake:    rgba(255,255,255,.30);
  --run:      #46dd9c;
  --walk:     #6aa9ff;
  --cycle:    #f2a65a;
  --train:    #b08cf0;
  --cal:      #f2a65a;
  --prot:     #f08a7a;
  --carb:     #f2a65a;
  --fat:      #8c9af0;
  --fiber:    #46dd9c;

  --maxw:     1180px;
  --mono:     'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
  --display:  'Space Grotesk', var(--mono);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.10); border-radius: 5px; }
html { background: var(--bg); }
body {
  background: var(--bg-grad); background-attachment: fixed; color: var(--text);
  font-family: var(--mono);
  font-size: 14px; -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px 48px; }
@media (min-width: 700px) { .wrap { padding: 0 24px 56px; } }
a { color: inherit; text-decoration: none; }
.num { font-family: var(--display); letter-spacing: -.01em; }

/* ── top nav header (rendered by /nav.js) ───────────────────────── */
.app-header {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  max-width: var(--maxw); margin: 0 auto; padding: 18px 16px 14px;
}
@media (min-width: 700px) { .app-header { padding: 22px 24px 16px; } }
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-logo {
  width: 32px; height: 32px; flex: none;
  object-fit: contain;
  image-rendering: pixelated;
}
.brand-name { font-family: var(--display); font-weight: 600; font-size: 14.5px; color: var(--text2); }
.tabs {
  display: flex; gap: 3px; background: var(--nav-bg);
  border: 1px solid var(--border2); border-radius: 12px; padding: 4px;
  order: 3; width: 100%; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
@media (min-width: 640px) { .tabs { order: 0; width: auto; margin: 0 auto; } }
.tab {
  padding: 8px 16px; border-radius: 9px; border: none; cursor: pointer;
  font-family: inherit; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: transparent; color: var(--muted); flex: 1; text-align: center;
}
.tab.active { background: var(--active); color: var(--text2); box-shadow: inset 0 0 0 1px rgba(255,255,255,.09); }
.gear {
  width: 34px; height: 34px; border-radius: 8px; flex: none; margin-left: auto;
  border: 1px solid var(--border); background: var(--nav-bg); color: var(--muted);
  font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.gear.active { color: var(--text2); border-color: rgba(255,255,255,.22); }
@media (min-width: 640px) { .gear { margin-left: 0; } }

/* active-profile chip → links back to the profile picker */
.profile-chip {
  display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto;
  height: 34px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--nav-bg);
  color: var(--muted); font-size: 12px; font-weight: 600; max-width: 160px;
}
.profile-chip:hover { color: var(--text2); border-color: rgba(255,255,255,.22); }
.profile-chip .profile-dot { width: 16px; height: 16px; border-radius: 5px; flex: none; }
.profile-chip .profile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .gear { margin-left: 8px; }
@media (min-width: 640px) { .app-header .gear { margin-left: 8px; } }

/* ── page heading ───────────────────────────────────────────────── */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin: 6px 0 18px;
}
.eyebrow {
  font-size: 10.5px; letter-spacing: .15em; text-transform: uppercase;
  color: var(--muted3); font-weight: 600; margin-bottom: 7px;
}
.page-title { font-family: var(--display); font-size: 23px; font-weight: 600; letter-spacing: -.01em; color: var(--text2); }
.legend { display: flex; gap: 15px; align-items: center; font-size: 10.5px; color: var(--muted); flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* ── group label (Body sections) ────────────────────────────────── */
.group-label {
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted3); font-weight: 600; margin-bottom: 12px;
  display: flex; align-items: center; gap: 10px;
}
.group-label::after { content: ''; flex: 1; height: 1px; background: var(--border3); }

/* ── grids ──────────────────────────────────────────────────────── */
.grid { display: grid; gap: 12px; }
.g-home  { grid-template-columns: repeat(auto-fill, minmax(min(100%, 224px), 1fr)); }
.g-body  { grid-template-columns: repeat(auto-fill, minmax(min(100%, 232px), 1fr)); }
.g-kpi   { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }

/* ── cards ──────────────────────────────────────────────────────── */
.kpi-card {
  background: var(--panel); border: 1px solid var(--border2); border-radius: 13px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px; min-height: 118px;
}
.metric-card {
  background: var(--card); border: 1px solid var(--border3); border-radius: 16px;
  padding: 17px 17px 14px; display: flex; flex-direction: column; gap: 10px;
  min-height: 168px; cursor: pointer; transition: border-color .15s;
}
.metric-card:hover { border-color: rgba(255,255,255,.16); }
.metric-card:active { border-color: rgba(255,255,255,.22); }
.tile {                                   /* home tinted tile */
  position: relative; border-radius: 12px; padding: 16px 15px 14px; overflow: hidden;
  display: flex; flex-direction: column; gap: 12px; min-height: 160px; cursor: pointer;
}
.panel {
  background: var(--panel); border: 1px solid var(--border2);
  border-radius: 14px; padding: 18px; min-width: 0;
}
.panel-label {
  font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 14px;
}
.card-lbl { font-size: 12px; font-weight: 500; color: #aab1bd; line-height: 1.3; }
.card-val { display: flex; align-items: baseline; gap: 5px; }
.card-val b { font-family: var(--display); font-size: 33px; font-weight: 600; letter-spacing: -.015em; color: var(--ink); line-height: 1; }
.card-val s { font-size: 12px; color: var(--muted2); text-decoration: none; }
.card-sub { font-size: 11px; color: var(--muted2); }
.card-foot { display: flex; justify-content: space-between; align-items: center; }
.card-foot .upd { font-size: 10px; color: #586070; }
.card-foot .view { font-size: 10px; color: var(--muted); }

/* ── status pill ────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 999px; font-size: 10px; font-weight: 600; white-space: nowrap;
}
.pill i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.pill.lg { padding: 5px 12px; font-size: 11px; gap: 6px; }
.pill.lg i { width: 7px; height: 7px; }

/* ── rings (SVG donut helper container) ─────────────────────────── */
.ring { position: relative; flex: none; }
.ring-c { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* ── detail view header ─────────────────────────────────────────── */
.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.back-btn {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--nav-bg); color: var(--text);
  font-family: inherit; font-size: 12px; cursor: pointer;
}
.back-btn:hover { border-color: rgba(255,255,255,.24); }

/* ── range strip ────────────────────────────────────────────────── */
.range-strip { display: flex; gap: 4px; background: var(--nav-bg); border: 1px solid var(--border2); border-radius: 11px; padding: 4px; }
.rbtn {
  flex: 1; height: 30px; border: none; background: transparent; color: var(--muted);
  border-radius: 8px; font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s; touch-action: manipulation;
}
.rbtn.active { background: var(--active); color: var(--text2); box-shadow: inset 0 0 0 1px rgba(255,255,255,.09); }
.rbtn:active { opacity: .7; }

/* ── sub-nav (Overview / Sleep toggle) ──────────────────────────── */
.subnav { display: flex; gap: 3px; background: var(--nav-bg); border: 1px solid var(--border2); border-radius: 11px; padding: 4px; }
.subnav-btn {
  flex: 1; text-align: center; padding: 8px 0; border: none; border-radius: 8px;
  background: transparent; color: var(--muted); text-decoration: none;
  font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s; touch-action: manipulation;
}
.subnav-btn.active { background: var(--active); color: var(--text2); box-shadow: inset 0 0 0 1px rgba(255,255,255,.09); }
.subnav-btn:active { opacity: .8; }

/* ── filter chips ───────────────────────────────────────────────── */
.chip-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  height: 34px; padding: 0 15px; border-radius: 999px;
  font-family: inherit; font-size: 12.5px; font-weight: 500; white-space: nowrap; flex-shrink: 0;
  border: 1px solid var(--border2); color: var(--muted); background: var(--nav-bg);
  cursor: pointer; touch-action: manipulation;
}
.chip:active { opacity: .7; }
.chip.active { color: var(--text2); background: var(--active); border-color: rgba(255,255,255,.18); }

/* ── chart card (canvas charts, reskinned) ──────────────────────── */
.chart-box {
  background: var(--panel); border: 1px solid var(--border2);
  border-radius: 14px; overflow: hidden; position: relative;
}
.chart-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.chart-title { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.chart-badge { font-size: 11px; color: var(--muted2); }
.chart-canvas-wrap { position: relative; height: 200px; touch-action: none; cursor: crosshair; }
.chart-canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.chart-footer { padding: 12px 18px 16px; display: flex; gap: 22px; flex-wrap: wrap; }
.cf-stat { display: flex; flex-direction: column; }
.cf-val { font-family: var(--display); font-size: 18px; font-weight: 600; color: var(--ink); }
.cf-lbl { font-size: 10px; color: var(--muted2); margin-top: 2px; letter-spacing: .04em; text-transform: uppercase; }

/* ── stat row ───────────────────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 11px; }
.stat {
  background: var(--panel); border: 1px solid var(--border2); border-radius: 13px;
  padding: 15px 16px; display: flex; flex-direction: column; gap: 8px;
}
.st-lbl { font-size: 10px; color: var(--muted2); letter-spacing: .06em; text-transform: uppercase; }
.st-val { font-family: var(--display); font-size: 24px; font-weight: 600; line-height: 1; color: var(--ink); }
.st-sub { font-size: 10px; color: var(--muted3); }

/* ── list cards (workouts / nutrition / sleep log) ──────────────── */
.list { padding: 0; }
.day-header {
  padding: 16px 2px 8px; font-size: 10.5px; font-weight: 600;
  color: var(--muted3); text-transform: uppercase; letter-spacing: .08em;
}
.card {
  margin: 0 0 9px; background: var(--panel); border: 1px solid var(--border2);
  border-radius: 14px; overflow: hidden; cursor: pointer; transition: border-color .12s;
}
.card:hover { border-color: rgba(255,255,255,.16); }
.card.expanded { border-color: rgba(255,255,255,.18); }
.card-compact { display: flex; align-items: center; padding: 14px 16px; gap: 14px; }
.icon-badge {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 600;
}
.card-main { flex: 1; min-width: 0; }
.card-name { font-family: var(--display); font-size: 14px; font-weight: 500; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-time { font-size: 10.5px; color: var(--muted2); margin-top: 3px; }
.card-metrics { display: flex; gap: 16px; flex-shrink: 0; text-align: right; }
.metric { display: flex; flex-direction: column; align-items: flex-end; }
.metric-val { font-family: var(--display); font-size: 15px; font-weight: 600; color: var(--ink); }
.metric-lbl { font-size: 10px; color: var(--muted3); margin-top: 1px; }
.chevron { color: var(--muted3); font-size: 12px; margin-left: 4px; flex-shrink: 0; transition: transform .2s; }
.card.expanded .chevron { transform: rotate(180deg); }
.card-detail { display: none; border-top: 1px solid var(--border2); }
.card.expanded .card-detail { display: block; }
.detail-section { padding: 16px; border-top: 1px solid var(--border2); }
.detail-section:first-child { border-top: none; }
.section-title {
  font-size: 10px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px;
}

/* ── load more ──────────────────────────────────────────────────── */
.load-more {
  display: none; margin: 12px 0 8px; padding: 13px;
  background: var(--nav-bg); border: 1px solid var(--border2);
  border-radius: 12px; color: var(--muted); font-family: inherit; font-size: 13px;
  cursor: pointer; width: 100%; text-align: center; touch-action: manipulation;
}
.load-more:active { background: var(--active); }

/* ── empty state ────────────────────────────────────────────────── */
.empty { padding: 64px 30px; text-align: center; color: var(--muted); }
.empty .e-icon { font-size: 40px; margin-bottom: 14px; }
.empty .e-title { font-family: var(--display); font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty .e-sub { font-size: 13px; line-height: 1.6; }
.empty a { color: var(--accent); }

/* ── tooltip ────────────────────────────────────────────────────── */
.tip {
  position: absolute; background: rgba(16,21,29,.97); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; font-size: 12px;
  pointer-events: none; display: none; z-index: 20; min-width: 140px;
  box-shadow: 0 4px 20px rgba(0,0,0,.6);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.tip-time { color: var(--muted); margin-bottom: 4px; font-size: 11px; }
.tip-val { font-family: var(--display); font-size: 20px; font-weight: 600; }
.tip-sub { font-size: 11px; font-weight: 400; color: var(--muted); }
@media (hover: none) {
  .tip { left: 50%!important; transform: translateX(-50%)!important; top: 10px!important; min-width: 160px; font-size: 13px; }
}

/* ── primary / secondary buttons ────────────────────────────────── */
.btn {
  display: block; width: 100%; padding: 14px;
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 11px;
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer; touch-action: manipulation;
  transition: opacity .15s, transform .1s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:not(:disabled):active { opacity: .85; transform: scale(.99); }
.btn-secondary {
  display: block; width: 100%; padding: 12px;
  background: var(--nav-bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 11px; font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.btn-secondary:active { opacity: .8; }

/* ── loading overlay ────────────────────────────────────────────── */
.loading {
  position: fixed; inset: 0; background: rgba(7,9,12,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; font-size: 13px; color: var(--muted); z-index: 200;
}
.spinner {
  width: 24px; height: 24px; border: 2px solid var(--border2);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
