/* ============================================================================
   Cup — daily health tracker.
   Tokens come from the shared design system (theme.css, --ds-*). This file
   only aliases them to Cup's local names + holds app-specific extras.
   Change the look in theme.css and every app follows.
   ========================================================================== */
:root {
  /* brand + category accents (theme-independent, from the design system) */
  --accent: var(--ds-accent);
  --accent-strong: var(--ds-lavender-strong);
  --accent-interactive: var(--ds-interactive);
  --accent-tint: var(--ds-lavender-tint);
  --cat-lime: var(--ds-cat-lime);
  --cat-sage: var(--ds-cat-sage);
  --cat-coral: var(--ds-cat-coral);
  --cat-sky: var(--ds-cat-sky);
  --cat-periwinkle: var(--ds-cat-periwinkle);

  /* shape + type tokens */
  --radius-pill: var(--ds-radius-pill);
  --radius-card: var(--ds-radius-card);
  --radius-sm: var(--ds-radius-sm);
  --font-ui: var(--ds-font-ui);
  --font-display: var(--ds-font-display);

  /* surfaces & text follow the active theme via the system */
  --bg: var(--ds-bg);
  --surface: var(--ds-surface);
  --surface-2: var(--ds-surface-2);
  --surface-3: var(--ds-surface-3);
  --card: var(--ds-surface-2);
  --text: var(--ds-text);
  --text-2: var(--ds-text-2);
  --text-muted: var(--ds-text-muted);
  --border: var(--ds-border);

  /* app-specific */
  --tabbar-h: 64px;
}

/* the few per-theme values the system doesn't dictate */
html[data-theme="dark"] {
  --card-hover: var(--ds-surface-3);
  --accent-text: #C9B4FF;      /* lavender pops on dark */
  --on-accent: #FFFFFF;        /* white on accent buttons, both themes */
  /* ambient glow colours — edit these (or set to transparent for a flat look) */
  --glow: rgba(159, 133, 255, 0.30);   /* top-right lavender */
  --glow-2: rgba(175, 141, 255, 0.16); /* bottom-left lavender */
}
html[data-theme="light"] {
  --card-hover: var(--ds-surface);
  --accent-text: var(--ds-interactive);
  --on-accent: #FFFFFF;
  /* darker/stronger so the glow reads on the light surface */
  --glow: rgba(159, 133, 255, 0.50);   /* top-right lavender */
  --glow-2: rgba(175, 141, 255, 0.30); /* bottom-left lavender */
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.4 var(--font-ui);
  transition: background .25s, color .25s;
}
button { font-family: inherit; cursor: pointer; }
img { display: block; }
.muted { color: var(--text-muted); }
.mobile-only { display: none; }

/* Tiimo-style fine grain over everything (real noise texture) */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 9999;
  opacity: .11; mix-blend-mode: overlay;
  background-image: url("/noise.avif"); background-size: 320px; background-repeat: repeat;
}
html[data-theme="dark"] body::after { opacity: .16; }

/* ---- app shell: sidebar + content panel ---- */
#app {
  display: grid;
  grid-template-columns: 232px 1fr;
  gap: 8px;
  padding: 8px;
  height: 100vh;
}

/* ---- sidebar ---- */
#sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px 8px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.brand { font-family: var(--font-display); font-size: 22px; font-weight: 600; padding: 6px 14px 18px; display: flex; align-items: center; gap: 9px; }
.brand-logo { width: 30px; height: 30px; flex: 0 0 auto; }
.nav-primary { list-style: none; margin: 0 0 16px; padding: 0; }
.nav-primary li {
  padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text-2);
  font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 12px;
  transition: background .15s, color .15s;
}
.nav-primary li:hover { color: var(--text); background: var(--surface-2); }
.nav-primary li.active { color: var(--text); background: var(--surface-2); }
/* Streamline SVG icons */
.nav-ico  { width: 20px; height: 20px; object-fit: contain; flex: 0 0 auto; filter: var(--icon-filter, none); }
.chrome-ico { width: 18px; height: 18px; object-fit: contain; filter: var(--icon-filter, none); }
.card-ico { width: 22px; height: 22px; object-fit: contain; filter: var(--icon-filter, none); }
.sidebar-fill { flex: 1; }
.sidebar-links { padding: 12px 14px; font-size: 12px; color: var(--text-muted); line-height: 1.6; }

/* ---- micro-interactions (skipped for reduced-motion folks) ---- */
.icon-btn, #theme-toggle, .stepper button, .mood-btn, .cupline button, .med-row, .ds-btn {
  transition: transform .12s ease, opacity .15s, background .15s, color .15s, border-color .15s;
}
.icon-btn:active, #theme-toggle:active, .stepper button:active, .mood-btn:active, .cupline button:active { transform: scale(.88); }
@media (prefers-reduced-motion: no-preference) {
  #theme-toggle:hover { transform: translateY(-1.5px); }
  .nav-ico { transition: transform .18s ease; }
  .nav-primary li:hover .nav-ico { transform: rotate(-8deg) scale(1.12); }
  .brand-logo { transition: transform .25s ease; }
  .brand:hover .brand-logo { transform: rotate(-10deg) scale(1.1); }
}

/* ---- content panel + ambient gradient glow (Tiimo-style) ---- */
#content {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card); overflow-y: auto; position: relative;
  background-image:
    radial-gradient(115% 90% at 100% 0%, var(--glow) 0%, transparent 72%),
    radial-gradient(85% 70% at 0% 100%, var(--glow-2) 0%, transparent 68%);
}
#topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
#topbar .brand { padding: 0; font-size: 19px; }
#topbar .brand-logo { width: 26px; height: 26px; }
.topbar-spacer { flex: 1; }
#theme-toggle { font-size: 18px; width: 38px; height: 38px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface-2); display: grid; place-items: center; }
#view { padding: 8px 24px 40px; max-width: 860px; }
.view-title { font-family: var(--font-display); font-size: 32px; font-weight: 600; margin: 16px 0 2px; }
.view-sub { color: var(--text-muted); margin: 0 0 18px; }
.section-title { font-family: var(--font-display); font-size: 22px; font-weight: 500; margin: 26px 0 12px; }

/* ---- tracker cards (Today) ---- */
.tracker-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.tracker-grid .wide { grid-column: 1 / -1; }
.tcard {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 18px;
  transition: background .2s;
}
.tcard-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 700; font-size: 15px; }
.tcard-head .spacer { flex: 1; }
.tcard-head .stat { color: var(--text-muted); font-weight: 600; font-size: 13px; }
.tcard-head .stat b { color: var(--accent-text); font-size: 15px; }
.tcard-head .stat.met b { color: inherit; }
.goal-tick { font-size: 13px; }

/* water: a row of tappable cups */
.cupline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cupline button {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-3);
  display: grid; place-items: center; padding: 0;
}
.cupline button img { width: 28px; height: 28px; filter: grayscale(1) opacity(.35); transition: filter .15s, transform .15s; }
.cupline button.full { background: var(--accent-tint); border-color: var(--accent); }
.cupline button.full img { filter: none; }
html[data-theme="dark"] .cupline button.full { background: rgba(175,141,255,.16); }
@media (prefers-reduced-motion: no-preference) {
  .cupline button:hover img { transform: scale(1.15); }
  .cupline button.full.just img { animation: cup-pop .35s ease; }
  @keyframes cup-pop { 0% { transform: scale(1); } 45% { transform: scale(1.45) rotate(-8deg); } 100% { transform: scale(1); } }
}

/* steppers (sleep hours, movement minutes) */
.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button {
  width: 38px; height: 38px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface-3);
  color: var(--text); font-size: 18px; font-weight: 700;
}
.stepper button:hover { border-color: var(--accent); }
.stepper .val { font-family: var(--font-display); font-size: 30px; font-weight: 600; min-width: 86px; text-align: center; }
.stepper .val small { font-family: var(--font-ui); font-size: 13px; color: var(--text-muted); font-weight: 600; margin-left: 4px; }

/* mood: five faces */
.moodline { display: flex; gap: 8px; flex-wrap: wrap; }
.mood-btn {
  width: 48px; height: 48px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface-3);
  font-size: 24px; line-height: 1; display: grid; place-items: center;
  filter: grayscale(1) opacity(.6);
}
.mood-btn:hover { filter: grayscale(.4); }
.mood-btn.on { background: var(--accent-tint); border-color: var(--accent); filter: none; transform: scale(1.06); }
html[data-theme="dark"] .mood-btn.on { background: rgba(175,141,255,.16); }

/* meds checklist */
.med-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; margin-bottom: 8px;
  color: var(--text); font: inherit; font-weight: 600;
}
.med-row:hover { border-color: var(--accent); }
.med-row .ring {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid var(--text-muted); display: grid; place-items: center;
  color: var(--on-accent); font-size: 13px; transition: background .15s, border-color .15s;
}
.med-row.done .ring { background: var(--accent); border-color: var(--accent); }
.med-row.done span.name { color: var(--text-muted); text-decoration: line-through; }

/* notes */
.note-box {
  width: 100%; min-height: 74px; resize: vertical;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font: 14px/1.5 var(--font-ui); outline: none;
}
.note-box:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-tint); }

/* ---- history rows ---- */
.day-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 14px 16px; margin-bottom: 10px;
}
.day-row .d-date { min-width: 108px; }
.day-row .d-date b { display: block; font-size: 15px; }
.day-row .d-date span { color: var(--text-muted); font-size: 12px; }
.day-row .d-mood { font-size: 24px; }
.day-row .d-note { flex-basis: 100%; color: var(--text-2); font-size: 13px; border-top: 1px dashed var(--border); padding-top: 8px; }
.day-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--radius-pill); padding: 5px 12px;
  font-size: 12px; font-weight: 700; color: #161213; background: var(--surface-3);
}
.day-pill.water { background: var(--cat-sky); }
.day-pill.sleep { background: var(--cat-periwinkle); }
.day-pill.move  { background: var(--cat-lime); }
.day-pill.meds  { background: var(--cat-sage); }
.day-pill.empty { background: var(--surface-3); color: var(--text-muted); }

/* ---- trends ---- */
.streak-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-card { margin-bottom: 16px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; margin-top: 8px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 5px; text-align: center; }
.bars .b i {
  display: block; border-radius: 6px 6px 3px 3px; min-height: 3px;
  background: var(--surface-3); transition: height .3s ease;
}
.bars .b.met i { background: var(--accent); }
.bars .b.some i { background: color-mix(in srgb, var(--accent) 45%, var(--surface-3)); }
.bars .b span { font-size: 10px; color: var(--text-muted); font-weight: 600; }
.bars .b.today span { color: var(--accent-text); }
.goal-line { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.moodtrail { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.moodtrail .m { width: 40px; text-align: center; }
.moodtrail .m i { font-style: normal; font-size: 22px; display: block; }
.moodtrail .m i.none { filter: grayscale(1) opacity(.25); }
.moodtrail .m span { font-size: 10px; color: var(--text-muted); font-weight: 600; }

/* ---- settings ---- */
.set-card { margin-bottom: 16px; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; flex-wrap: wrap; }
.set-row label { flex: 1; min-width: 160px; font-weight: 600; }
.set-row label small { display: block; color: var(--text-muted); font-weight: 500; }
.num-input {
  width: 86px; background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 10px 14px; font: 600 15px var(--font-ui); outline: none; text-align: center;
}
.num-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-tint); }
.text-input {
  flex: 1; min-width: 160px; background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 10px 16px; font: 14px var(--font-ui); outline: none;
}
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-tint); }
.med-manage { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.med-manage span { flex: 1; font-weight: 600; }
.med-del { background: none; border: none; color: var(--text-muted); font-size: 15px; padding: 4px 8px; }
.med-del:hover { color: var(--cat-coral); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.danger { color: var(--cat-coral) !important; border-color: var(--cat-coral) !important; }

/* welcome hero: shown on Today until something is logged */
.welcome { text-align: center; padding: 40px 20px 12px; }
.welcome img { width: 96px; height: 96px; margin: 0 auto; }
.welcome h2 { font-family: var(--font-display); font-size: 30px; margin: 14px 0 8px; }
.welcome p { color: var(--text-2); margin: 0 0 4px; }

/* toast: little confirmation blurbs ("Saved") */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(8px);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 9px 16px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }

/* ---- phones: hide the sidebar, show a bottom tab bar ---- */
#tabbar { display: none; }
@media (max-width: 760px) {
  .mobile-only { display: flex; }
  #sidebar { display: none; }
  #app { grid-template-columns: 1fr; padding: 8px 8px 0; height: calc(100vh - var(--tabbar-h)); height: calc(100dvh - var(--tabbar-h)); }
  #view { padding: 4px 16px 32px; }
  #tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar-h);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px); border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 4px; z-index: 50;
  }
  #tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: none; border-radius: var(--radius-sm);
    color: var(--text-muted); font: 600 11px var(--font-ui); padding: 6px 0;
  }
  #tabbar button .nav-ico { width: 22px; height: 22px; }
  #tabbar button.active { color: var(--text); background: var(--surface); }
  #toast { bottom: calc(var(--tabbar-h) + 14px); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
