/* Sprout — the refined look, layered over every page (loads last). Same colours; softer depth, pill controls,
   a calm greeting header and a floating tab bar on phones. Motion lives in js/motion-ui.js. Light and dark both. */

:root {
  /* DESIGN.md: 4 px base, 8-point rhythm; radii 8 / 12 / 16 / 24 / full */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --r-card: 24px;
  --r-pill: 999px;
  /* Depth: one soft contact shadow plus one wide ambient one, so cards float without outlines */
  --shadow-1: 0 1px 2px rgba(20, 30, 24, .04), 0 6px 18px -6px rgba(20, 30, 24, .08);
  --shadow-2: 0 2px 6px rgba(20, 30, 24, .05), 0 22px 44px -18px rgba(20, 30, 24, .18);
  --glass: color-mix(in srgb, var(--surface) 78%, transparent);
  --glass-edge: rgba(255, 255, 255, .55);
}
[data-theme="dark"] {
  /* In the dark a shadow alone disappears; a hairline catches the light instead */
  --shadow-1: 0 0 0 1px rgba(255, 255, 255, .045), 0 8px 22px -10px rgba(0, 0, 0, .55);
  --shadow-2: 0 0 0 1px rgba(255, 255, 255, .06), 0 24px 48px -18px rgba(0, 0, 0, .7);
  --glass: color-mix(in srgb, var(--surface) 72%, transparent);
  --glass-edge: rgba(255, 255, 255, .08);
}

/* ---------- Type: tighter as it grows, calm at body size ---------- */
.page-head h1, .listen-q, .fit-hero h2 { font-optical-sizing: auto; text-wrap: balance; }
.card-head h3, .card > h3, .fit-section-title { letter-spacing: -.015em; }
.kpi-value { letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

/* ---------- Surfaces ---------- */
.card, .fit-cat, .fm-card, .fm-list, .fm-tip, .fm-note, .ai-offer { box-shadow: var(--shadow-1); }
.card { border-radius: var(--r-card); }
.modal-card { box-shadow: var(--shadow-2); }

/* Things you can open lift a little under a mouse (never on touch, where hover fires on tap) */
@media (hover: hover) and (pointer: fine) {
  a.card, a.fit-cat, .fm-tip, .fm-note, .lchip {
    transition: transform var(--dur-3) var(--ease-out), box-shadow var(--dur-3) var(--ease-out);
  }
  a.card:hover, a.fit-cat:hover, .fm-tip:hover, .fm-note:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
}

/* ---------- Controls: pills, pressed on touch-down ---------- */
.btn, .seg, .fin-tabs a, .seg button { border-radius: var(--r-pill); }
.btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.btn-primary { box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--accent) 70%, transparent); }

/* Segmented tabs: one scrolling row, no scrollbar, a soft fade where it runs off */
.fin-tabs { position: relative; scrollbar-width: none; -webkit-overflow-scrolling: touch; box-shadow: var(--shadow-1); }
.fin-tabs::-webkit-scrollbar { display: none; }
.fin-tabs a { position: relative; z-index: 1; white-space: nowrap; }
/* With the sliding pill (js/motion-ui.js) the current tab lets the pill show through */
.fin-tabs.has-ind a[aria-current="page"] { background: none; }
.seg-ind { position: absolute; z-index: 0; top: 4px; bottom: 4px; left: 0; border-radius: var(--r-pill); background: var(--hero); pointer-events: none; will-change: transform; }

/* ---------- Motion hand-off: Motion runs the entrances, so the CSS ones step aside ---------- */
html.has-motion .view.entering { animation: none; }

/* The greeting line shows only in the phone header */
.me-hello { display: none; }

/* ---------- Phones: the reference layout ---------- */
@media (max-width: 760px) {
  body { background: var(--panel); }
  .app { padding: 0; gap: 0; }

  /* Greeting header: you on the left, search and alerts on the right */
  .topbar { position: sticky; top: 0; z-index: 20; gap: 8px; padding: max(12px, env(safe-area-inset-top)) 16px 12px; border-radius: 0;
    background: color-mix(in srgb, var(--panel) 82%, transparent); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4); }
  .topbar .menu-btn, #themeBtn, .search kbd { display: none; }
  .topbar .me { order: -1; margin: 0 auto 0 0; gap: 12px; min-width: 0; }
  .topbar .top-actions { display: contents; }
  .topbar .avatar-lg { width: 44px; height: 44px; font-size: 16px; box-shadow: var(--shadow-1); }
  .me-text { display: flex; min-width: 0; }
  .me-text .me-hello { display: block; font-size: 13px; }
  .me-text strong { font-size: 16px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .me-text #meMail { display: none; }
  .icon-btn { width: 44px; height: 44px; background: var(--surface); box-shadow: var(--shadow-1); }
  .icon-btn.has-dot::after { top: 10px; right: 10px; }
  /* Search folds into a round button and opens across the bar when tapped */
  .search { flex: 0 0 44px; height: 44px; padding: 0; justify-content: center; box-shadow: var(--shadow-1); order: 1;
    transition: flex-basis var(--dur-4) var(--ease-out); }
  .search input { width: 0; flex: 0; padding: 0; transition: flex var(--dur-4) var(--ease-out); }
  .search:focus-within { position: absolute; left: 16px; right: 16px; z-index: 2; flex-basis: auto; padding: 0 16px; justify-content: flex-start; }
  .search:focus-within input { flex: 1; width: auto; }
  .topbar .top-actions #bellBtn { display: grid; order: 2; } /* beats the older phone rule that hid it */

  /* The page sits on the background; cards float on it */
  .view { background: transparent; border-radius: 0; padding: 8px 16px calc(var(--tabbar-h) + 32px); }
  .page-head { margin-bottom: var(--sp-4); }
  .page-head h1 { font-size: 34px; letter-spacing: -.035em; }
  .page-head p { font-size: 14px; margin-top: 4px; }
  .card { padding: var(--sp-4); }
  /* One rhythm on phones: 16 between cards and columns, 24 before a section title */
  .td-grid, .fit-grid, .fin-grid, .fit-kpis, .fit-cats, .fin-m { gap: var(--sp-4); }
  .td-hero, .fit-coach, .fin-m, .fit-kpis, .fit-top, .fit-weekstrip { margin-bottom: var(--sp-4); }
  .fin-tabs { margin: 0 0 var(--sp-4); }
  .fit-section-title { margin: var(--sp-6) 0 var(--sp-3); }

  /* Floating pill tab bar */
  .tabbar { left: 50%; right: auto; width: min(calc(100% - 32px), 380px); transform: translateX(-50%); height: 66px; padding: 8px;
    border-radius: var(--r-pill); border: 1px solid var(--glass-edge); background: var(--glass); box-shadow: var(--shadow-2);
    backdrop-filter: blur(22px) saturate(1.6); -webkit-backdrop-filter: blur(22px) saturate(1.6); }
  .tabbar a, .tabbar button { position: relative; z-index: 1; border-radius: var(--r-pill); transition: color var(--dur-2) ease; }
  .tabbar [aria-current="page"] { color: var(--text); }
  [data-theme="dark"] .tabbar [aria-current="page"] { color: var(--text); }
  .tabbar .tab-capture { width: 50px; height: 50px; transform: none; box-shadow: 0 8px 18px -6px color-mix(in srgb, var(--accent) 60%, transparent); }
  .tabbar .tab-capture:active { transform: none; }
  .tab-ind { position: absolute; z-index: 0; top: 8px; bottom: 8px; left: 0; border-radius: var(--r-pill); background: var(--surface-2); pointer-events: none; will-change: transform; }
  [data-theme="dark"] .tab-ind { background: color-mix(in srgb, var(--text) 10%, transparent); }

  /* Today: the progress card reads like the reference — words left, rings right */
  .td-hero { grid-template-columns: 1fr auto; grid-template-areas: "level rings" "legend legend"; justify-items: stretch; text-align: left; gap: 16px 12px; }
  .td-hero .td-ring-wrap { grid-area: rings; align-self: start; }
  .td-hero .td-ring-wrap .td-rings { width: 112px; height: 112px; }
  .td-hero .td-level { grid-area: level; }
  .td-hero .td-legend { grid-area: legend; padding-top: 16px; border-top: 1px solid var(--line); }

  /* Capture: the header already greets, so the page leads with the question */
  .listen-greet { display: none; }
  .listen-box textarea { font-size: 16px; }

  /* Fitness */
  .fit-hero { box-shadow: var(--shadow-2); }
}

/* ---------- Capture: chips under the box when the page is empty ---------- */
.listen-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 16px auto 0; max-width: 640px; }
.listen:not(.is-empty) .listen-chips { display: none; }
.listen-chips button { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border: 0; border-radius: var(--r-pill); cursor: pointer;
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; box-shadow: var(--shadow-1); -webkit-tap-highlight-color: transparent; }
.listen-chips button svg { width: 15px; height: 15px; color: var(--muted); }
@media (hover: hover) and (pointer: fine) { .listen-chips button:hover { background: var(--surface-2); } }
@media (max-width: 760px) {
  .listen-chips { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; margin: 12px -16px 0; padding: 2px 16px 8px; }
  .listen-chips::-webkit-scrollbar { display: none; }
  .listen-chips button { flex: none; }
}

/* ---------- Comfort settings ---------- */
@media (prefers-reduced-transparency: reduce) {
  .tabbar, .topbar { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .card, .fit-cat, .tabbar, .listen-chips button { box-shadow: none; border: 1px solid var(--text); }
}
@media (prefers-reduced-motion: reduce) {
  .search, .search input, a.card, a.fit-cat { transition: none; }
}

/* ---------- Touch targets: small icon buttons keep their look but get a 44 px hit area ---------- */
.tx-del, .fm-eye, .icon-btn.sm, .td-remind-toggle { position: relative; }
.tx-del::after, .fm-eye::after { content: ""; position: absolute; inset: 50% auto auto 50%; width: 44px; height: 44px; transform: translate(-50%, -50%); }

/* ---------- Phone menu (drawer): the whole menu scrolls, the logo stays pinned on a solid strip, and the end
   (Logout, Add to Home Screen) clears the browser's bottom bar and the home indicator ---------- */
@media (max-width: 900px) {
  .sidebar { height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--sp-5) calc(env(safe-area-inset-bottom) + var(--sp-6)); scrollbar-width: none; }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar .brand { position: sticky; top: 0; z-index: 2; flex: none; margin: 0 calc(-1 * var(--sp-5)); padding: max(var(--sp-6), env(safe-area-inset-top)) calc(var(--sp-5) + var(--sp-3)) var(--sp-3);
    background: var(--panel); box-shadow: 0 8px 12px -12px rgba(0, 0, 0, .35); }
  .sidebar-scroll { flex: none; overflow: visible; margin: 0; padding: 0 0 var(--sp-2); -webkit-mask-image: none !important; mask-image: none !important; }
  .sidebar .app-card { flex: none; margin-top: var(--sp-4); }
}

/* ---------- "Add Sprout to your Home Screen" guide ---------- */
.install-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-3); counter-reset: step; }
.install-steps li { display: grid; grid-template-columns: 28px 1fr; gap: var(--sp-3); align-items: start; line-height: 1.45; counter-increment: step; }
.install-steps li::before { content: counter(step); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--accent-soft); color: var(--accent); }
.install-steps svg { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; margin: 0 2px; }

/* ---------- Phones: no surprise zoom ----------
   iOS Safari zooms the whole page when you tap a field with text under 16 px, and the page stays zoomed after.
   Every field is 16 px on touch screens, so tapping search or a form never moves the layout. */
@media (max-width: 900px), (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea { font-size: 16px !important; }
}
/* The search icon keeps its shape whether the search is folded into a circle or open across the bar */
.search > [data-icon] { flex: none; width: 20px; height: 20px; }
.search > [data-icon] svg { width: 20px; height: 20px; }
@media (max-width: 760px) {
  .search:focus-within { gap: var(--sp-3); }
  .search input { line-height: 1.25; }
}

/* ---------- Forms never run past their card ----------
   A select with a long option ("Mostly sitting (Desk job, little walking)") or a fieldset sizes itself to its
   content by default, which pushed the whole page wider than the phone. Fields fill their column and can shrink. */
.form-grid > *, .form-grid label { min-width: 0; }
.form-grid select, .form-grid input:not([type="checkbox"]):not([type="radio"]), .form-grid textarea { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }
.form-grid select { text-overflow: ellipsis; }
fieldset { min-width: 0; }
