/* ── Vitaritmo — visual system (TASK-013J) ──────────────────────────────────
 * Light theme by default, dark theme via prefers-color-scheme or the
 * data-theme attribute on <html> (toggle stored in localStorage).
 * Legacy token names (--bg, --bg2, --bg3, --text-sub, --accent, …) are kept
 * because scripts and inline styles reference them.
 */

/* Inter (variable), vendored locally — the dashboard loads no external assets.
 * SIL Open Font License 1.1, see /static/vendor/fonts/Inter-OFL.txt. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("/static/vendor/fonts/inter-cyrillic-wght-normal.woff2") format("woff2-variations"),
       url("/static/vendor/fonts/inter-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("/static/vendor/fonts/inter-latin-wght-normal.woff2") format("woff2-variations"),
       url("/static/vendor/fonts/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Base & tokens ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #f4f5f8;            /* page */
  --bg2: #ffffff;           /* cards */
  --bg3: #f1f3f7;           /* inset fields, chips */
  --bg4: #e6e9f0;
  --surface-hover: #eef1f6;
  --surface-raised: #ffffff;
  --border: #e3e6ed;
  --border-strong: #cfd5e0;
  --border-focus: #3b5bdb;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.16);

  /* Typography */
  --text: #111827;
  --text-sub: #4b5263;      /* 7.9:1 on cards, 7.2:1 on the page */
  --text-muted: #646c7e;    /* WCAG AA: 5.3:1 on cards, 4.8:1 on the page */
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;

  /* Accent & semantic colors */
  --accent: #3b5bdb;
  --accent-hover: #3249c0;
  --accent-soft: rgba(59, 91, 219, 0.10);
  --accent-contrast: #ffffff;
  --green: #0c9f72;
  --red: #e03131;
  --yellow: #e67700;
  --orange: #e8590c;
  --purple: #7048e8;
  --cyan: #1098ad;

  --ok-bg: rgba(12, 159, 114, 0.12);
  --warn-bg: rgba(230, 119, 0, 0.12);
  --err-bg: rgba(224, 49, 49, 0.10);
  --neutral-bg: rgba(91, 100, 116, 0.10);

  /* Metric palette — shared by cards, legends and charts */
  --c-glucose: #0c9f72;
  --c-glucose-low: #e03131;
  --c-glucose-high: #f08c00;
  --c-target-band: rgba(12, 159, 114, 0.08);
  --c-sleep: #7048e8;
  --c-hrv: #1098ad;
  --c-battery: #228be6;
  --c-steps: #fd7e14;
  --c-heart: #e64980;
  --c-stress: #fab005;
  --c-spo2: #4dabf7;
  --c-meals: #be4bdb;
  --c-workouts: #f76707;
  --chart-grid: rgba(17, 24, 39, 0.06);
  --chart-axis: #687082;

  /* Baseline comparison chips (neutral descriptive) */
  --range-low: #1c7ed6;
  --range-in: #0c9f72;
  --range-high: #e67700;

  /* Layout, radius & spacing scale */
  --card-radius: 16px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --sidebar-w: 248px;

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgba(59, 91, 219, 0.35);
}

/* Dark theme: explicit choice … */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --bg2: #161b24;
  --bg3: #1e2430;
  --bg4: #283040;
  --surface-hover: #212836;
  --surface-raised: #1b212c;
  --border: #262d3a;
  --border-strong: #353e4f;
  --border-focus: #8ea2ff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
  --text: #e9ecf2;
  --text-sub: #b4bccb;
  --text-muted: #9099aa;   /* WCAG AA: 6.0:1 on cards, 6.6:1 on the page */
  --accent: #8ea2ff;
  --accent-hover: #a5b5ff;
  --accent-soft: rgba(142, 162, 255, 0.14);
  --accent-contrast: #0d1117;
  --green: #38d9a9;
  --red: #ff6b6b;
  --yellow: #ffc246;
  --orange: #ff922b;
  --purple: #b197fc;
  --cyan: #3bc9db;
  --ok-bg: rgba(56, 217, 169, 0.14);
  --warn-bg: rgba(255, 194, 70, 0.14);
  --err-bg: rgba(255, 107, 107, 0.14);
  --neutral-bg: rgba(163, 171, 186, 0.12);
  --c-glucose: #38d9a9;
  --c-glucose-low: #ff6b6b;
  --c-glucose-high: #ffc246;
  --c-target-band: rgba(56, 217, 169, 0.09);
  --c-sleep: #9775fa;
  --c-hrv: #3bc9db;
  --c-battery: #4dabf7;
  --c-steps: #ffa94d;
  --c-heart: #f783ac;
  --c-stress: #ffd43b;
  --c-spo2: #74c0fc;
  --c-meals: #da77f2;
  --c-workouts: #ff922b;
  --chart-grid: rgba(233, 236, 242, 0.07);
  --chart-axis: #8f98a9;
  --range-low: #74c0fc;
  --range-in: #38d9a9;
  --range-high: #ffc246;
  --focus-ring: 0 0 0 3px rgba(142, 162, 255, 0.4);
}

/* … or the system preference when the person has not chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1117;
    --bg2: #161b24;
    --bg3: #1e2430;
    --bg4: #283040;
    --surface-hover: #212836;
    --surface-raised: #1b212c;
    --border: #262d3a;
    --border-strong: #353e4f;
    --border-focus: #8ea2ff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
    --text: #e9ecf2;
    --text-sub: #b4bccb;
    --text-muted: #9099aa;   /* WCAG AA: 6.0:1 on cards, 6.6:1 on the page */
    --accent: #8ea2ff;
    --accent-hover: #a5b5ff;
    --accent-soft: rgba(142, 162, 255, 0.14);
    --accent-contrast: #0d1117;
    --green: #38d9a9;
    --red: #ff6b6b;
    --yellow: #ffc246;
    --orange: #ff922b;
    --purple: #b197fc;
    --cyan: #3bc9db;
    --ok-bg: rgba(56, 217, 169, 0.14);
    --warn-bg: rgba(255, 194, 70, 0.14);
    --err-bg: rgba(255, 107, 107, 0.14);
    --neutral-bg: rgba(163, 171, 186, 0.12);
    --c-glucose: #38d9a9;
    --c-glucose-low: #ff6b6b;
    --c-glucose-high: #ffc246;
    --c-target-band: rgba(56, 217, 169, 0.09);
    --c-sleep: #9775fa;
    --c-hrv: #3bc9db;
    --c-battery: #4dabf7;
    --c-steps: #ffa94d;
    --c-heart: #f783ac;
    --c-stress: #ffd43b;
    --c-spo2: #74c0fc;
    --c-meals: #da77f2;
    --c-workouts: #ff922b;
    --chart-grid: rgba(233, 236, 242, 0.07);
    --chart-axis: #8f98a9;
    --range-low: #74c0fc;
    --range-in: #38d9a9;
    --range-high: #ffc246;
    --focus-ring: 0 0 0 3px rgba(142, 162, 255, 0.4);
  }
}

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 6px;
}
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
svg.icon { width: 20px; height: 20px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px 16px;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 20px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.logo-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #3b5bdb 0%, #0c9f72 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 91, 219, 0.25);
}
.logo-icon svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.logo-text small { display: block; font-size: 11px; font-weight: 500; color: var(--text-muted); letter-spacing: 0; }

.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 12px 6px;
}
.nav-menu, .nav-aux { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  cursor: pointer;
  border-radius: 10px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-sub);
  transition: background 0.15s, color 0.15s;
  outline: none;
  user-select: none;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item:focus-visible { box-shadow: var(--focus-ring); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-icon { display: inline-flex; width: 20px; height: 20px; }
.nav-icon svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-badge {
  margin-left: auto;
  min-width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted); opacity: 0.5;
}
.nav-badge.ok { background: var(--green); opacity: 1; }

.sidebar-footer { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
}
.status-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500;
  color: var(--text-sub);
  background: var(--bg3);
  border-radius: var(--radius-pill);
  padding: 3px 10px 3px 8px;
  cursor: default;
}
.status-dot::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted); opacity: 0.6;
}
.status-dot.active::before { background: var(--green); opacity: 1; }
.status-dot.error::before { background: var(--text-muted); }

.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-sub);
  border-radius: 10px; padding: 7px 10px;
  font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ── Mobile top bar & bottom tab bar ─────────────────────────────────────── */
.topbar { display: none; }
.tabbar { display: none; }
.scrim { display: none; }

/* ── Main Content ────────────────────────────────────────────────────────── */
.content {
  margin-left: var(--sidebar-w);
  padding: 32px 40px 64px;
  max-width: calc(1240px + var(--sidebar-w));
}
.section { display: none; }
.section.active { display: block; animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}
.section-header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; }
.section-sub { font-size: 14px; color: var(--text-sub); margin-top: 4px; max-width: 640px; }
.refresh-paused { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; font-size: 14px; color: var(--text-sub); background: var(--bg2); border: 1px solid var(--border); }
.refresh-paused[hidden] { display: none; }
.header-sub { display: block; font-size: 14px; font-weight: 500; color: var(--text-sub); letter-spacing: 0; margin-top: 4px; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 0; }
.stack > * + * { margin-top: 16px; }

.card-label { font-size: 13px; font-weight: 600; color: var(--text-sub); margin-bottom: 8px; letter-spacing: 0; }
.card-title { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.card-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.card-value.large { font-size: 48px; }
.card-value .unit { font-size: 15px; font-weight: 500; color: var(--text-sub); margin-left: 4px; letter-spacing: 0; }
.card-sub { font-size: 13px; color: var(--text-sub); }
.card-badge { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: var(--radius-pill); }
.card-badge:empty { display: none; }
.card-badge.normal { background: var(--ok-bg); color: var(--green); }
.card-badge.high { background: var(--warn-bg); color: var(--yellow); }
.card-badge.low { background: var(--err-bg); color: var(--red); }
.card-footer { margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-header h3 { font-size: 16px; font-weight: 650; }
.card-body { display: flex; flex-direction: column; gap: 12px; }

.big-card { grid-column: span 1; min-height: 180px; }

/* ── Today: hero metrics ─────────────────────────────────────────────────── */
.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(0, 1fr));
  grid-template-rows: auto auto;
  gap: 16px;
  margin-bottom: 20px;
}
.metric-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 150px;
  padding: 18px 20px;
}
.metric-tile .tile-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.metric-tile .tile-icon {
  width: 32px; height: 32px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--tile-color, var(--accent)) 14%, transparent);
  color: var(--tile-color, var(--accent));
}
.metric-tile .tile-icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.metric-tile .card-label { margin-bottom: 0; color: var(--text); font-size: 14px; }
.metric-tile .metric-source-tag {
  margin-left: auto; font-size: 11px; color: var(--text-muted);
  background: var(--bg3); border-radius: var(--radius-pill); padding: 2px 8px;
}
.metric-tile .metric-source-tag:empty { display: none; }
.metric-tile .card-value { font-size: 30px; margin-top: 2px; }
.metric-tile .card-sub { margin-top: 2px; }
.metric-tile .usual {
  margin-top: auto; padding-top: 10px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--text-muted);
}
.metric-tile .usual:empty { display: none; }
.usual-chip { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-pill); font-size: 12px; }
.usual-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.usual-chip.typical { color: var(--range-in); background: color-mix(in srgb, var(--range-in) 13%, transparent); }
.usual-chip.above { color: var(--range-high); background: color-mix(in srgb, var(--range-high) 14%, transparent); }
.usual-chip.below { color: var(--range-low); background: color-mix(in srgb, var(--range-low) 14%, transparent); }

.metric-tile.is-empty .card-value { color: var(--text-muted); font-weight: 600; }
.metric-tile.is-empty .card-sub { color: var(--text-muted); }

.card-glucose { --tile-color: var(--c-glucose); }
.card-sleep   { --tile-color: var(--c-sleep); }
.card-hrv     { --tile-color: var(--c-hrv); }
.card-battery { --tile-color: var(--c-battery); }
.card-steps   { --tile-color: var(--c-steps); }
.card-recovery { --tile-color: var(--c-heart); }

.hero-glucose {
  grid-row: span 2;
  min-height: 316px;
  background:
    radial-gradient(120% 90% at 100% 0%, color-mix(in srgb, var(--glu-state, var(--c-glucose)) 10%, transparent) 0%, transparent 60%),
    var(--bg2);
}
.hero-glucose .glucose-main { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.hero-glucose .card-value { font-size: 56px; letter-spacing: -0.035em; font-weight: 700; margin: 0; }
.hero-glucose .card-value .unit { font-size: 16px; }
.trend-arrow {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--glu-state, var(--c-glucose)) 14%, transparent);
  color: var(--glu-state, var(--c-glucose));
  transition: transform 0.3s ease;
}
.trend-arrow svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.trend-arrow[hidden] { display: none; }
.hero-glucose[data-state="in"]   { --glu-state: var(--c-glucose); }
.hero-glucose[data-state="low"]  { --glu-state: var(--c-glucose-low); }
.hero-glucose[data-state="high"] { --glu-state: var(--c-glucose-high); }
.hero-glucose[data-state="in"] .card-value,
.hero-glucose[data-state="low"] .card-value,
.hero-glucose[data-state="high"] .card-value { color: var(--glu-state); }
.range-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600;
  padding: 4px 10px; border-radius: var(--radius-pill);
  color: var(--glu-state, var(--text-sub));
  background: color-mix(in srgb, var(--glu-state, var(--text-sub)) 13%, transparent);
  width: fit-content;
  margin-top: 12px;
}
.range-chip:empty { display: none; }
.glucose-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: auto; padding-top: 18px; border-top: 1px solid var(--border); }
.glucose-facts .fact-label { font-size: 12px; color: var(--text-muted); }
.glucose-facts .fact-value { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.glucose-sparkline { margin-top: 16px; display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; min-height: 96px; }
.glucose-sparkline .spark-label { font-size: 12px; color: var(--text-muted); }
.glucose-sparkline .spark-canvas { position: relative; flex: 1 1 auto; min-height: 84px; max-height: 150px; }
.glucose-sparkline[hidden] { display: none; }

/* ── Error banner ────────────────────────────────────────────────────────── */
.error-banner {
  background: var(--err-bg);
  border: 1px solid color-mix(in srgb, var(--red) 30%, transparent);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--red);
  white-space: pre-wrap;
}
.alert-banner {
  background: var(--accent-soft); color: var(--text);
  border-radius: var(--radius-md); padding: 12px 16px; font-size: 14px;
}
.info-banner {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13.5px; color: var(--text-sub); line-height: 1.55;
}
.info-banner strong { color: var(--text); }
.info-banner svg { color: var(--accent); margin-top: 1px; }

/* ── Charts ──────────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px 20px 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.chart-title { font-size: 16px; font-weight: 650; color: var(--text); letter-spacing: -0.01em; margin-bottom: 2px; }
.chart-sub { font-size: 13px; color: var(--text-muted); }
.chart-wrap { position: relative; height: 200px; }
.chart-wrap-tall { height: 340px; }
.no-data { text-align: center; padding: 40px; color: var(--text-sub); font-size: 14px; }

.timeline-presets { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.preset-status { font-size: 12px; color: var(--text-muted); }

.timeline-legend { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; font-size: 12.5px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px 5px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, opacity 0.15s, border-color 0.15s;
}
.legend-item:hover { background: var(--surface-hover); }
.legend-item:not(.active) { color: var(--text-muted); border-style: dashed; }
.legend-item:not(.active) .swatch { opacity: 0.35; }
.legend-item .metric-source-tag { font-size: 11px; color: var(--text-muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--sw, var(--accent)); flex-shrink: 0; }
.swatch.line { width: 14px; height: 3px; border-radius: 2px; }
.swatch.band { width: 14px; height: 10px; border-radius: 3px; background: color-mix(in srgb, var(--sw) 30%, transparent); border: 1px solid var(--sw); }
.swatch.bar { width: 8px; height: 11px; border-radius: 2px; }
.sw-glucose { --sw: var(--c-glucose); }
.sw-battery { --sw: var(--c-battery); }
.sw-steps { --sw: var(--c-steps); }
.sw-meals { --sw: var(--c-meals); }
.sw-stress { --sw: var(--c-stress); }
.sw-heart { --sw: var(--c-heart); }
.sw-hrv { --sw: var(--c-hrv); }
.sw-spo2 { --sw: var(--c-spo2); }
.sw-sleep { --sw: var(--c-sleep); }
.sw-workouts { --sw: var(--c-workouts); }

/* Segmented controls (period / preset selectors) */
.btn-group {
  display: inline-flex; flex-wrap: wrap; gap: 2px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  max-width: 100%;
}
.btn.btn-period {
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 550;
  border: none;
  background: transparent;
  color: var(--text-sub);
  border-radius: 8px;
  box-shadow: none;
}
.btn.btn-period:hover { color: var(--text); opacity: 1; background: transparent; }
.btn.btn-period.active { background: var(--bg2); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }

/* ── Empty states ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 10px;
  padding: 40px 24px;
  color: var(--text-sub);
}
.empty-state .empty-icon {
  width: 56px; height: 56px; border-radius: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  margin-bottom: 4px;
}
.empty-state .empty-icon svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.empty-state h3 { font-size: 18px; font-weight: 650; color: var(--text); letter-spacing: -0.01em; }
.empty-state p { font-size: 14px; max-width: 440px; line-height: 1.55; }
.empty-state .btn { margin-top: 6px; }
.empty-state.compact { padding: 28px 16px; }
.empty-hero { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--card-radius); box-shadow: var(--shadow-sm); margin-bottom: 20px; padding: 48px 24px; }
.empty-sources { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.empty-sources span { font-size: 12.5px; font-weight: 500; padding: 4px 10px; border-radius: var(--radius-pill); background: var(--bg3); color: var(--text-sub); }

/* ── TIR ─────────────────────────────────────────────────────────────────── */
.tir-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.tir-title { font-size: 16px; font-weight: 650; color: var(--text); margin-bottom: 2px; }
.tir-stack {
  display: flex; height: 14px; border-radius: var(--radius-pill); overflow: hidden;
  background: var(--bg3); margin: 16px 0 14px; gap: 2px;
}
.tir-stack .tir-bar { height: 100%; transition: width 0.6s ease; min-width: 0; }
.tir-stack .tir-bar:first-child { border-radius: var(--radius-pill) 0 0 var(--radius-pill); }
.tir-stack .tir-bar:last-child { border-radius: 0 var(--radius-pill) var(--radius-pill) 0; }
.tir-normal { background: var(--c-glucose); }
.tir-low    { background: var(--c-glucose-low); }
.tir-high   { background: var(--c-glucose-high); }
.tir-rows { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tir-row { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: var(--radius-md); background: var(--bg3); }
.tir-label { font-size: 12.5px; color: var(--text-sub); display: flex; align-items: center; gap: 6px; }
.tir-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot); flex-shrink: 0; }
.tir-row.r-normal { --dot: var(--c-glucose); }
.tir-row.r-low { --dot: var(--c-glucose-low); }
.tir-row.r-high { --dot: var(--c-glucose-high); }
.tir-pct { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tir-meta { margin-top: 12px; font-size: 12.5px; color: var(--text-muted); }

.dash-grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; margin-bottom: 20px; align-items: stretch; }

/* Coach teaser */
.coach-teaser { display: flex; flex-direction: column; gap: 10px; }
.coach-teaser .teaser-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, #7048e8, #3b5bdb);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
}
.coach-teaser .teaser-icon svg { width: 22px; height: 22px; stroke: #fff; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.coach-teaser p { font-size: 13.5px; color: var(--text-sub); }
.coach-teaser .btn { align-self: flex-start; margin-top: auto; }

/* Insights list */
.insight-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--bg3);
}
.insight-item .insight-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; background: var(--accent); flex-shrink: 0; }
.insight-item.attention .insight-dot { background: var(--yellow); }
.insight-item .insight-cat { font-size: 12px; font-weight: 600; color: var(--text-sub); }
.insight-item .insight-text { font-size: 14px; color: var(--text); }

/* Collapsible “data sources” */
details.sources-details {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--card-radius);
  box-shadow: var(--shadow-sm); margin-bottom: 20px;
}
details.sources-details > summary {
  list-style: none; cursor: pointer; padding: 14px 20px;
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 600; color: var(--text-sub);
}
details.sources-details > summary::-webkit-details-marker { display: none; }
details.sources-details > summary::after {
  content: ""; margin-left: auto; width: 8px; height: 8px;
  border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg); transition: transform 0.2s;
}
details.sources-details[open] > summary::after { transform: rotate(-135deg); }
details.sources-details .details-body { padding: 0 20px 18px; font-size: 13px; color: var(--text-sub); }

/* ── Stat table ─────────────────────────────────────────────────────────── */
.stat-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.stat-table td { padding: 8px 4px; border-bottom: 1px solid var(--border); }
.stat-table td:first-child { color: var(--text-sub); }
.stat-table td:last-child { font-weight: 600; text-align: right; }
.stat-table th { font-weight: 600; font-size: 12px; color: var(--text-muted); }
.table-wrap { overflow-x: auto; margin-top: 10px; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.data-table th { text-align: left; padding: 8px 8px; font-size: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th.r, .data-table td.r { text-align: right; }
.data-table th.c { text-align: center; }
.data-table td { padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tbody tr:hover { background: var(--bg3); }

/* ── Workouts ────────────────────────────────────────────────────────────── */
.workouts-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.workout-item { background: var(--bg3); border-radius: 12px; padding: 14px 16px; display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.workout-type { font-size: 22px; }
.workout-info .wname { font-size: 14px; font-weight: 600; }
.workout-info .wdetail { font-size: 12px; color: var(--text-sub); }
.workout-stats { font-size: 13px; font-weight: 700; color: var(--accent); text-align: right; }

/* ── AI coach ────────────────────────────────────────────────────────────── */
.coach-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.coach-card { display: flex; flex-direction: column; }
.coach-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.coach-card-head .teaser-icon {
  width: 38px; height: 38px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #7048e8, #3b5bdb); flex-shrink: 0;
}
.coach-card-head .teaser-icon.sun { background: linear-gradient(135deg, #f59f00, #f76707); }
.coach-card-head .teaser-icon svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.coach-card-head .card-title { margin: 0; }
.coach-label { font-size: 12.5px; color: var(--text-muted); }
.coach-card-head .btn { margin-left: auto; }

.briefing-text {
  font-size: 15px;
  line-height: 1.65;
  min-height: 80px;
  color: var(--text);
}
.briefing-placeholder { color: var(--text-sub); font-size: 14px; }

/* Safe formatted text rendered from LLM output (headings, lists, bold) */
.rich-text > * + * { margin-top: 10px; }
.rich-text h3 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; margin-top: 18px; }
.rich-text h4 { font-size: 14.5px; font-weight: 700; margin-top: 14px; }
.rich-text h3:first-child, .rich-text h4:first-child { margin-top: 0; }
.rich-text ul, .rich-text ol { padding-left: 22px; display: flex; flex-direction: column; gap: 5px; }
.rich-text li::marker { color: var(--text-muted); }
.rich-text strong { font-weight: 650; }
.rich-text code { font-size: 0.88em; }
.rich-text pre { white-space: pre-wrap; word-break: break-word; background: var(--bg3); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; color: var(--text-sub); }
.rich-text hr { border: none; border-top: 1px solid var(--border); }
.rich-text blockquote { border-left: 3px solid var(--border-strong); padding-left: 12px; color: var(--text-sub); }

.coach-state {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--radius-md);
  font-size: 14px; line-height: 1.55;
}
.coach-state svg { flex-shrink: 0; margin-top: 1px; }
.coach-state.warn { background: var(--warn-bg); color: var(--text); }
.coach-state.warn svg { color: var(--yellow); }
.coach-state.err { background: var(--err-bg); color: var(--text); }
.coach-state.err svg { color: var(--red); }
.coach-state .state-title { font-weight: 650; margin-bottom: 2px; }
.coach-state .state-text { color: var(--text-sub); font-size: 13.5px; }

.typing { display: inline-flex; align-items: center; gap: 10px; color: var(--text-sub); font-size: 14px; }
.typing .dots { display: inline-flex; gap: 4px; }
.typing .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: blink 1.2s infinite ease-in-out; }
.typing .dots i:nth-child(2) { animation-delay: 0.15s; }
.typing .dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
.skeleton-lines { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.skeleton-lines span { height: 10px; border-radius: 6px; background: linear-gradient(90deg, var(--bg3), var(--bg4), var(--bg3)); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
.skeleton-lines span:nth-child(2) { width: 85%; }
.skeleton-lines span:nth-child(3) { width: 65%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.spinner { font-size: 14px; color: var(--text-sub); margin-top: 10px; }

.chat-history {
  min-height: 160px;
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
  padding: 4px 2px;
}
.chat-empty { color: var(--text-muted); font-size: 13.5px; text-align: center; padding: 24px 8px; }
.chat-bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.6;
  max-width: 88%;
  word-break: break-word;
}
.chat-bubble.user { background: var(--accent); color: var(--accent-contrast); align-self: flex-end; border-bottom-right-radius: 6px; white-space: pre-wrap; }
.chat-bubble.ai   { background: var(--bg3); color: var(--text); align-self: flex-start; border-bottom-left-radius: 6px; }
.chat-bubble.ai.err { background: var(--err-bg); }
.chat-suggestions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip-btn {
  border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  border-radius: var(--radius-pill); padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip-btn:hover { background: var(--surface-hover); }
.chip-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.chat-input-row { display: flex; gap: 8px; align-items: center; background: var(--bg3); border: 1px solid var(--border); border-radius: 14px; padding: 5px 5px 5px 14px; }
.chat-input-row:focus-within { border-color: var(--border-focus); box-shadow: var(--focus-ring); }
.chat-input {
  flex: 1; min-width: 0;
  background: transparent;
  border: none;
  padding: 8px 0;
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  outline: none;
}
.chat-input:focus-visible { box-shadow: none; }
.coach-disclaimer { margin-top: 10px; font-size: 12px; color: var(--text-muted); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="datetime-local"], select, textarea {
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--bg2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--text-muted); }
input:focus, select:focus, textarea:focus { border-color: var(--border-focus); box-shadow: var(--focus-ring); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
textarea { width: 100%; resize: vertical; }
::placeholder { color: var(--text-muted); opacity: 1; }

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label, .field-label { font-size: 13px; font-weight: 550; color: var(--text-sub); }
.form-row input { width: 100%; max-width: 520px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .form-row input { max-width: none; }
.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.save-actions { margin-top: 8px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.checkbox-group { flex-direction: row; align-items: center; gap: 10px; font-size: 14px; }
.form-group label { font-size: 13px; color: var(--text-sub); }
.form-group.checkbox-group label { font-size: 14px; color: var(--text); }

.test-result { font-size: 13.5px; color: var(--text-sub); white-space: pre-wrap; }
.test-result.ok { color: var(--green); }
.test-result.err { color: var(--red); }

.mfa-block { margin-top: 14px; background: var(--bg3); border-radius: 12px; padding: 14px; }
.mfa-block p { margin-bottom: 10px; font-size: 14px; }
.mfa-block .form-row { flex-direction: row; align-items: center; margin-bottom: 0; }
.mfa-block input { max-width: 160px; }

.text-muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transition: background 0.15s, box-shadow 0.15s, border-color 0.15s, color 0.15s;
  outline: none;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg2); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--text-sub); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(1.05); }
.btn-icon { padding: 8px; width: 38px; height: 38px; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 9px; }

/* ── Connections ─────────────────────────────────────────────────────────── */
.conn-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.conn-card { display: flex; flex-direction: column; gap: 12px; }
.conn-head { display: flex; align-items: flex-start; gap: 14px; }
.conn-logo {
  width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 15px; letter-spacing: -0.02em;
}
.conn-logo svg { width: 26px; height: 26px; stroke: #fff; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.logo-libre { background: linear-gradient(135deg, #f59f00, #e8590c); }
.logo-garmin { background: linear-gradient(135deg, #1c7ed6, #1864ab); }
.logo-samsung { background: linear-gradient(135deg, #1428a0, #3b5bdb); }
.logo-trackers { background: linear-gradient(135deg, #0ca678, #1098ad); }
.logo-phone { background: linear-gradient(135deg, #7048e8, #3b5bdb); }
.logo-telegram { background: linear-gradient(135deg, #339af0, #1c7ed6); }
.conn-title { font-size: 17px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.3; }
.conn-desc { font-size: 13.5px; color: var(--text-sub); line-height: 1.5; margin-top: 2px; }
.conn-status-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.conn-sync { font-size: 12.5px; color: var(--text-muted); }

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600;
  padding: 3px 10px; border-radius: var(--radius-pill);
  background: var(--neutral-bg); color: var(--text-sub);
  white-space: nowrap;
}
.status-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-badge.ok { background: var(--ok-bg); color: var(--green); }
.status-badge.warn { background: var(--warn-bg); color: var(--yellow); }
.status-badge.err { background: var(--err-bg); color: var(--red); }

.conn-body { border-top: 1px solid var(--border); padding-top: 14px; }
.conn-note { font-size: 13px; color: var(--text-sub); line-height: 1.55; background: var(--bg3); border-radius: 10px; padding: 10px 12px; }
.conn-note strong { color: var(--text); }
.conn-ways { display: grid; gap: 10px; }
.conn-way { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.conn-way.recommended { border-color: color-mix(in srgb, var(--green) 45%, transparent); background: color-mix(in srgb, var(--green) 5%, transparent); }
.conn-way-title { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14px; }
.conn-way p { font-size: 13px; color: var(--text-sub); margin-top: 4px; line-height: 1.5; }
.tag { display: inline-flex; align-items: center; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: var(--radius-pill); letter-spacing: 0.01em; }
.tag.green { background: var(--ok-bg); color: var(--green); }
.tag.gray { background: var(--neutral-bg); color: var(--text-sub); }

details.conn-more > summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--accent); list-style: none; display: inline-flex; align-items: center; gap: 6px; }
details.conn-more > summary::-webkit-details-marker { display: none; }
details.conn-more > summary::after { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-top: -3px; transition: transform 0.2s; }
details.conn-more[open] > summary::after { transform: rotate(-135deg); margin-top: 3px; }
details.conn-more .conn-more-body { margin-top: 12px; }
.hint-list { font-size: 13px; color: var(--text-sub); padding-left: 18px; line-height: 1.6; }

.region-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

.data-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.data-chips span { font-size: 12.5px; font-weight: 500; padding: 3px 10px; border-radius: var(--radius-pill); background: var(--bg3); color: var(--text-sub); border: 1px solid var(--border); }

/* Phone setup — one shared step-by-step block */
.phone-setup { margin-bottom: 16px; }
.phone-setup-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px; }
.steps { list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 14px; }
.steps > li { counter-increment: step; position: relative; padding-left: 42px; font-size: 14px; color: var(--text); line-height: 1.5; }
.steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: -2px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 13.5px;
  display: inline-flex; align-items: center; justify-content: center;
}
.steps > li .step-title { font-weight: 650; }
.steps > li .step-text { font-size: 13.5px; color: var(--text-sub); margin-top: 2px; }
.steps > li .step-action { margin-top: 8px; }
.app-path { font-size: 13px; color: var(--text-sub); }
.app-path b { color: var(--text); font-weight: 600; }

.devices-steps { margin: 4px 0 12px 20px; color: var(--text-sub); font-size: 13.5px; line-height: 1.6; }
.devices-steps a { color: var(--accent); }
.devices-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.devices-form label { width: 100%; font-size: 13px; font-weight: 550; color: var(--text-sub); }
.devices-form input { flex: 1 1 180px; }
.devices-new { background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.devices-new p { font-size: 13px; color: var(--yellow); font-weight: 600; margin-bottom: 8px; }
.devices-new p.meta { color: var(--text-sub); font-weight: 400; }
.devices-new label { font-size: 12px; color: var(--text-sub); }
.devices-copy { display: flex; gap: 8px; align-items: center; margin: 4px 0 8px; }
.devices-copy code { flex: 1; overflow-wrap: anywhere; font-size: 13px; color: var(--text); background: var(--bg2); padding: 8px 10px; }
.devices-list { list-style: none; }
.devices-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 0; border-top: 1px solid var(--border); font-size: 14px; color: var(--text);
}
.devices-list .meta { color: var(--text-muted); font-size: 12px; }
.panel-label { font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings-card { margin-bottom: 16px; }
.settings-group-title { font-size: 16px; font-weight: 650; margin-bottom: 6px; display: flex; align-items: center; gap: 10px; }
.settings-hint { font-size: 13.5px; color: var(--text-sub); margin-bottom: 16px; line-height: 1.6; }
.settings-hint code { font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.theme-choice { display: inline-flex; }

/* ── Journal Workspace (M7 TASK-007B) ────────────────────────────────────── */
.journal-entry-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease;
}
.journal-entry-card:hover { border-color: var(--border-strong); }
.journal-card-header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-sm); }
.journal-category-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600; border: 1px solid transparent;
}
.journal-cat-general   { background: var(--accent-soft); color: var(--accent); }
.journal-cat-nutrition { background: color-mix(in srgb, var(--c-glucose) 13%, transparent); color: var(--c-glucose); }
.journal-cat-sleep     { background: color-mix(in srgb, var(--c-sleep) 13%, transparent); color: var(--c-sleep); }
.journal-cat-recovery  { background: color-mix(in srgb, var(--c-hrv) 13%, transparent); color: var(--c-hrv); }
.journal-cat-training  { background: color-mix(in srgb, var(--c-workouts) 13%, transparent); color: var(--c-workouts); }
.journal-cat-stress    { background: var(--err-bg); color: var(--red); }
.journal-cat-other     { background: var(--bg3); color: var(--text-sub); }
.journal-entry-time { font-size: 12px; color: var(--text-sub); }
.journal-card-body { margin: var(--space-xs) 0; }
.journal-note-text { margin: 0; font-size: 14.5px; line-height: 1.6; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.journal-card-footer { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: var(--space-sm); margin-top: var(--space-xs); }
.journal-source-tag { font-size: 11px; color: var(--text-sub); }
.journal-card-actions { display: flex; gap: 8px; align-items: center; }
.journal-form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: 12px; margin-bottom: 12px; }

/* Form input focus states */
input:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
}

/* ── Metric & Source Chips (M6) ─────────────────────────────────────────── */
.metric-chip {
  display: inline-flex; align-items: center; gap: var(--space-xs);
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 500;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
}
.metric-chip.source { font-size: 12px; color: var(--text-sub); }
.metric-chip.low { border-color: transparent; color: var(--range-low); background: color-mix(in srgb, var(--range-low) 12%, transparent); }
.metric-chip.in-range { border-color: transparent; color: var(--range-in); background: color-mix(in srgb, var(--range-in) 12%, transparent); }
.metric-chip.high { border-color: transparent; color: var(--range-high); background: color-mix(in srgb, var(--range-high) 12%, transparent); }

/* ── Empty / Error / Loading States (M6) ─────────────────────────────────── */
.state-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: var(--space-xl) var(--space-md);
  color: var(--text-sub); font-size: 14px;
  background: var(--bg2); border: 1px dashed var(--border-strong); border-radius: var(--card-radius);
}
.state-container .state-icon { font-size: 28px; margin-bottom: var(--space-sm); }
.state-container.error { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }

/* ── Workspace sub-navigation & tabs (M6) ───────────────────────────────── */
.workspace-tabs { display: flex; gap: var(--space-sm); margin-bottom: var(--space-md); border-bottom: 1px solid var(--border); padding-bottom: var(--space-xs); }
.workspace-tab-btn { background: transparent; border: none; color: var(--text-sub); padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer; border-radius: var(--radius-sm); outline: none; }
.workspace-tab-btn:hover { color: var(--text); background: var(--bg3); }
.workspace-tab-btn:focus-visible { box-shadow: var(--focus-ring); }
.workspace-tab-btn.active { color: var(--accent); background: var(--accent-soft); }

/* Toolbar card for range selectors */
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.toolbar .hint { font-size: 12.5px; color: var(--text-muted); }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid var(--bg); }

/* ── Habits Workspace (M7 TASK-007D) ─────────────────────────────────────── */
.habit-card {
  padding: 16px 20px; border-radius: var(--radius-lg);
  background: var(--bg2); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 12px;
}
.habit-card.habit-archived { opacity: 0.75; border-style: dashed; }
.habit-header-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.habit-title-group { display: flex; align-items: center; gap: 10px; }
.habit-name { font-size: 16px; font-weight: 600; color: var(--text); }
.habit-badge-archived { font-size: 11px; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--neutral-bg); color: var(--text-sub); }
.habit-actions-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.habit-checkin-controls {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 10px 14px; background: var(--bg3); border-radius: var(--radius-md);
}
.habit-status-label-group { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.habit-status-title { color: var(--text-sub); }
.habit-current-status-val { font-weight: 600; }
.habit-current-status-val.status-done { color: var(--green); }
.habit-current-status-val.status-not-done { color: var(--red); }
.habit-current-status-val.status-missing { color: var(--text-sub); }
.habit-btn-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.btn-habit-done { background: var(--ok-bg); color: var(--green); border: 1px solid transparent; }
.btn-habit-done:hover, .btn-habit-done.active { background: var(--green); color: #fff; }
.btn-habit-not-done { background: var(--err-bg); color: var(--red); border: 1px solid transparent; }
.btn-habit-not-done:hover, .btn-habit-not-done.active { background: var(--red); color: #fff; }
.btn-habit-clear { background: transparent; color: var(--text-sub); border: 1px solid var(--border-strong); }
.btn-habit-clear:hover:not(:disabled) { color: var(--text); background: var(--bg2); }
.habit-history-section { padding-top: 6px; border-top: 1px solid var(--border); }
.habit-history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; }
.habit-history-title { color: var(--text-sub); font-weight: 500; }
.habit-history-summary-text { color: var(--accent); font-weight: 600; }
.habit-history-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.habit-day-cell { display: flex; flex-direction: column; align-items: center; padding: 6px 4px; border-radius: var(--radius-sm); background: var(--bg3); border: 1px solid transparent; text-align: center; }
.habit-day-cell.selected-day { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.habit-day-label { font-size: 10px; color: var(--text-sub); margin-bottom: 4px; }
.habit-day-indicator { font-size: 13px; font-weight: 700; line-height: 1; }
.habit-day-indicator.indicator-done { color: var(--green); }
.habit-day-indicator.indicator-not-done { color: var(--red); }
.habit-day-indicator.indicator-missing { color: var(--text-sub); font-weight: 400; }
.habit-day-indicator.indicator-error { color: var(--orange); }

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(10, 14, 22, 0.5);
  backdrop-filter: blur(3px);
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-content.card { max-width: 460px; width: 100%; padding: 24px; box-shadow: var(--shadow-lg); border-radius: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-sub); cursor: pointer; width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-close svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-content select, .modal-content input { width: 100%; }

/* ── Sign-in overlay (Milestone 13 hosted beta) ─────────────────────────── */
.auth-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(60% 50% at 20% 10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    radial-gradient(50% 50% at 90% 90%, color-mix(in srgb, var(--green) 12%, transparent), transparent 70%),
    var(--bg);
  padding: 16px;
}
.auth-overlay[hidden] { display: none; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 20px; padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-card h2 { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.auth-card form { display: flex; flex-direction: column; gap: 8px; }
.auth-card label { font-size: 13px; font-weight: 550; color: var(--text-sub); margin-top: 4px; }
.auth-card input { width: 100%; padding: 11px 12px; }
.auth-card .btn { margin-top: 12px; padding: 11px 16px; }
.auth-link { margin-top: 14px; background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13.5px; }
.auth-status { min-height: 1.2em; margin-top: 12px; font-size: 13px; color: var(--text-sub); }
.auth-note { margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.auth-signout { width: 100%; }
.auth-signout[hidden] { display: none; }
.settings-card.server-only[hidden] { display: none; }
.settings-card.hosted-only[hidden], .devices-new[hidden] { display: none; }

/* ── Proactive card (privacy section) ───────────────────────────────────── */
#proactive-notifications-card .card-body input[type="text"] { max-width: 160px; }
.proactive-delivery-details { background: var(--bg3); border-radius: var(--radius-md); padding: 12px 14px; font-size: 13px; color: var(--text-sub); }
.proactive-delivery-details h4 { font-size: 13px; color: var(--text); margin-bottom: 6px; }
.proactive-delivery-details strong { color: var(--text); font-weight: 600; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .hero-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-glucose { grid-column: span 2; grid-row: auto; min-height: 0; }
  .content { padding: 28px 28px 64px; }
}

@media (max-width: 960px) {
  .conn-grid, .settings-grid, .coach-layout, .dash-grid-2, .phone-setup-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  :root { --sidebar-w: 0px; }
  body { padding-top: 56px; padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .topbar {
    display: flex; align-items: center; gap: 10px;
    position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 90;
    padding: 0 12px 0 16px;
    background: color-mix(in srgb, var(--bg2) 88%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .topbar .logo { padding: 0; font-size: 16px; }
  .topbar .logo-icon { width: 30px; height: 30px; border-radius: 9px; }
  .topbar .spacer { flex: 1; }
  .topbar .btn-icon { width: 40px; height: 40px; background: transparent; border: none; color: var(--text); }

  .sidebar {
    width: 284px; max-width: 86vw;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; background: rgba(10, 14, 22, 0.45); z-index: 150; }

  .tabbar {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
    background: color-mix(in srgb, var(--bg2) 92%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tab-btn {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font: inherit; font-size: 11px; font-weight: 600;
    padding: 4px 2px; border-radius: 10px; min-width: 0;
  }
  .tab-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .tab-btn svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tab-btn.active { color: var(--accent); }
  .tab-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

  .content { margin-left: 0; padding: 18px 16px 32px; max-width: 100%; }
  .section-header { margin-bottom: 18px; align-items: flex-start; }
  .section-header h1 { font-size: 24px; }
  .cards-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .card { padding: 16px; }
  .chart-card { padding: 16px 12px 12px; }
  .chart-wrap-tall { height: 280px; }
  .hero-grid { gap: 12px; }
  .metric-tile { min-height: 132px; padding: 14px 14px; }
  .metric-tile .card-value { font-size: 24px; }
  .metric-tile .tile-head { margin-bottom: 6px; }
  .metric-tile .metric-source-tag { display: none; }
  .hero-glucose .card-value { font-size: 46px; }
  .tir-rows { gap: 8px; }
  .tir-pct { font-size: 18px; }
  .tir-row { padding: 8px 10px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .journal-form-grid { grid-template-columns: minmax(0, 1fr); }
  .chat-bubble { max-width: 94%; }
}

@media (max-width: 420px) {
  .cards-row { grid-template-columns: minmax(0, 1fr); }
  .hero-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .glucose-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .glucose-facts .fact-value { font-size: 14px; }
  .btn-group .btn.btn-period { padding: 5px 9px; font-size: 12.5px; }
  .tir-rows { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tir-label { font-size: 11.5px; }
}

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

/* ── Timeline workspace: co-occurring events ───────────────────────────── */
#ws-timeline-events-list { display: flex; flex-direction: column; gap: 8px; }
.ws-event-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm, 10px); flex-wrap: wrap;
}
.ws-event-main { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.ws-event-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex: none; }
.ws-event-dot.ev-meal { background: var(--c-meals); }
.ws-event-dot.ev-workout { background: var(--c-workouts); border-radius: 3px; }
.ws-event-dot.ev-sleep { background: var(--c-sleep); }
.ws-event-title { font-weight: 600; }
.ws-event-detail { font-size: 12.5px; color: var(--text-sub); }
.ws-event-meta { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-sub); font-variant-numeric: tabular-nums; }
.test-result.pending { color: var(--text-sub); }

/* ── Phone refinements: chips scroll sideways instead of stacking ───────── */
@media (max-width: 640px) {
  .chart-head { flex-wrap: nowrap; }
  .timeline-presets .btn-group,
  .timeline-legend {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .timeline-presets .btn-group::-webkit-scrollbar,
  .timeline-legend::-webkit-scrollbar { display: none; }
  .timeline-presets .btn-period,
  .legend-item { flex: none; white-space: nowrap; }
  .timeline-legend { margin-left: -2px; padding-bottom: 2px; }
  .glucose-sparkline .spark-canvas { max-height: 96px; }
  .tir-rows .tir-label { font-size: 11.5px; white-space: nowrap; }
  .tir-rows { gap: 6px; }
}
.chat-bubble.state { background: transparent; border: 0; padding: 0; box-shadow: none; max-width: 92%; }
.chat-bubble.state .coach-state { margin: 0; }

/* Android app: the app's own navigation replaces the site's tab bar. */
html.in-app .tabbar { display: none !important; }
html.in-app body { padding-bottom: env(safe-area-inset-bottom); }

/* ── Data sources and priority (TASK-013V) ─────────────────────────────────── */
.sources-card { margin-bottom: 16px; }
.sources-list { display: grid; gap: 12px; margin-top: 14px; }
.source-group { background: var(--bg3); border-radius: 10px; padding: 12px 14px; }
.source-group-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.source-group-title { font-weight: 700; font-size: 14.5px; }
.source-group-used { font-size: 13px; color: var(--text-sub); margin-top: 2px; }
.source-group select { max-width: 100%; min-width: 0; }
.source-rows { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.source-rows li { font-size: 13px; color: var(--text-sub); line-height: 1.45; overflow-wrap: anywhere; }
.source-rows .src-name { color: var(--text); font-weight: 600; }
.source-rows .src-used { color: var(--green); }
.source-rows .src-unused { color: var(--text-muted); }
.source-note { font-size: 12.5px; color: var(--yellow); margin-top: 6px; }

/* ── Timeline charts: zoom bar + scrub readout above the plot ───────────── */
.chart-zoom-bar {
  position: relative;
  display: flex; align-items: flex-start; gap: 10px;
  margin: 0 0 8px; padding: 8px 8px 8px 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-md);
  transition: border-color 0.15s;
}
.chart-zoom-bar[hidden] { display: none; }
.chart-zoom-bar.is-scrubbing { border-color: var(--border-strong); }
.chart-readout { flex: 1; min-width: 0; align-self: center; }
.chart-readout-line { font-size: 13px; color: var(--text-sub); font-variant-numeric: tabular-nums; line-height: 1.35; }
.ro-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; min-height: 24px; }
.ro-extra {
  min-height: 18px; margin-top: 2px; font-size: 12px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ro-time { display: inline-flex; align-items: baseline; gap: 6px; }
.ro-time-label { font-size: 11.5px; color: var(--text-muted); }
.ro-time-value { font-size: 17px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.ro-item { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.ro-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; align-self: center; flex: none; }
.ro-dot-event { border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.ro-event { font-weight: 500; }
.ro-event + .ro-event { margin-left: 14px; }
.ro-label { color: var(--text-sub); }
.ro-value { font-size: 15px; font-weight: 700; color: var(--text); }
.ro-missing { color: var(--text-muted); font-weight: 500; }
.ro-unit { font-size: 12px; color: var(--text-muted); }
.ro-note { font-size: 12px; font-weight: 600; color: var(--text-sub); }
.ro-hint { color: var(--text-muted); }
.chart-zoom-tools { display: flex; gap: 2px; flex: none; }
.chart-zoom-btn { width: 34px; height: 34px; padding: 7px; }
.chart-zoom-btn:disabled { opacity: 0.35; }
canvas.hx-interactive {
  touch-action: pan-y;               /* vertical page scroll stays; horizontal drags scrub */
  cursor: crosshair;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
canvas.hx-interactive.is-zoomed { cursor: grab; }
canvas.hx-interactive.is-panning { cursor: grabbing; }
canvas.hx-interactive:focus-visible { box-shadow: var(--focus-ring); border-radius: 8px; }
@media (max-width: 640px) {
  /* Time gets its own row next to the buttons; values use the full width below. */
  .chart-zoom-bar { display: block; padding: 6px 8px 6px 10px; }
  .chart-zoom-tools { position: absolute; top: 3px; right: 4px; }
  .ro-time { flex-basis: 100%; min-height: 30px; align-items: center; padding-right: 108px; }
  .ro-main { gap: 1px 12px; min-height: 52px; align-content: flex-start; }
  .chart-readout-line { font-size: 12.5px; }
  .ro-time-value { font-size: 16px; }
  .ro-value { font-size: 14px; }
  .chart-zoom-btn { width: 34px; height: 34px; padding: 7px; }
}

/* Quick windows on the 24 h charts: "3 ч · 6 ч · 12 ч · 24 ч" (TASK-014B) */
.chart-quick { flex: none; align-self: center; flex-wrap: nowrap; }
.chart-quick[hidden] { display: none; }
.chart-quick .btn.btn-period { padding: 4px 10px; font-size: 12.5px; min-height: 28px; }
@media (max-width: 640px) {
  .chart-quick { display: inline-flex; margin-top: 6px; }
}

/* ── Clickable "Сегодня" cards and the metric page (TASK-014B) ───────────── */
[data-home-link] { cursor: pointer; border-radius: var(--radius-md); }
[data-home-link]:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.metric-tile.is-link { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.metric-tile.is-link:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.metric-tile.is-link:active { transform: scale(0.995); }
.metric-tile.is-link:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.metric-tile .tile-chevron {
  width: 18px; height: 18px; flex: none; margin-left: auto;
  stroke: var(--text-muted); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transition: transform 0.15s, stroke 0.15s;
}
.metric-tile .metric-source-tag:not(:empty) + .tile-chevron { margin-left: 2px; }
.metric-tile.is-link:hover .tile-chevron { stroke: var(--text-sub); transform: translateX(2px); }

.metric-topline { margin: -6px 0 6px -8px; }
.metric-back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.metric-heading { display: flex; align-items: center; gap: 12px; }
.metric-title-icon {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.metric-title-icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#metric-title:focus { outline: none; }
.metric-switch {
  display: flex; gap: 6px; margin: 0 0 14px; overflow-x: auto; scrollbar-width: none;
  padding-bottom: 2px;
}
.metric-switch::-webkit-scrollbar { display: none; }
.metric-chip {
  flex: none; font: inherit; font-size: 13px; font-weight: 550; cursor: pointer;
  padding: 6px 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--bg2); color: var(--text-sub);
}
.metric-chip:hover { color: var(--text); border-color: var(--border-strong); }
.metric-chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.metric-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.metric-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.metric-nav { display: flex; gap: 2px; flex: none; }
.metric-nav .btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.metric-nav .btn[hidden] { display: none; }
.metric-status { font-size: 13px; color: var(--text-sub); margin: -6px 0 12px; }
.metric-status[hidden] { display: none; }
.metric-summary { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.metric-stat { padding: 14px 16px; }
.metric-stat .card-label { font-size: 13px; color: var(--text-sub); }
.metric-stat .card-value { font-size: 24px; }
.metric-stat .card-value.is-missing { color: var(--text-muted); }
.metric-stat .card-sub { font-size: 12.5px; color: var(--text-sub); }
.metric-chart-card .chart-head { margin-bottom: 8px; }
.metric-chart-wrap[hidden], #metric-chart-wrap[hidden] { display: none; }
.metric-source { font-size: 13px; color: var(--text-sub); margin: 0 0 24px; line-height: 1.5; }
.metric-source:empty { display: none; }
@media (max-width: 640px) {
  .metric-controls { flex-direction: column; align-items: stretch; }
  .metric-periods { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .metric-periods::-webkit-scrollbar { display: none; }
  .metric-periods .btn.btn-period { flex: none; }
  .metric-nav { justify-content: flex-end; margin-top: -4px; }
  .metric-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-stat .card-value { font-size: 21px; }
}
.ro-time-value { white-space: nowrap; }
@media (max-width: 640px) { .ro-time { flex-wrap: wrap; column-gap: 6px; row-gap: 0; } }
.metric-switch, .metric-periods { position: relative; }
