/* meds — app.css
   Calm clinical design: soft paper surfaces, one teal accent, per-med colour
   via --med (set through the CSSOM, never a style="" attribute). Every colour
   is a token; the dark theme redefines the tokens and nothing else. */

:root {
  color-scheme: light;
  --bg: #F3F6F6;
  --surface: #FFFFFF;
  --surface-2: #EDF2F2;
  --surface-3: #E1E9E9;
  --line: #E2E9E9;
  --line-strong: #C9D5D4;
  --text: #132020;
  --text-2: #4F605F;
  --text-3: #849392;
  --accent: #1F8A8A;
  --accent-strong: #166E6E;
  --accent-soft: rgba(31, 138, 138, 0.11);
  --on-accent: #FFFFFF;
  --good: #23885A;
  --good-soft: rgba(46, 158, 107, 0.13);
  --warn: #B26A12;
  --warn-soft: rgba(217, 138, 43, 0.15);
  --bad: #C8433A;
  --bad-soft: rgba(210, 84, 75, 0.11);
  --on-bad: #FFFFFF;
  --serum: #7A4FE0;
  --avg: #C7892B;
  --seg-on: #FFFFFF;
  --tip-bg: #132020;
  --tip-fg: #F3F6F6;
  --focus: rgba(31, 138, 138, 0.45);
  --scrim: rgba(10, 22, 20, 0.42);
  --shadow-1: 0 1px 2px rgba(19, 40, 38, 0.05), 0 1px 1px rgba(19, 40, 38, 0.03);
  --shadow-2: 0 10px 30px rgba(19, 40, 38, 0.12), 0 2px 6px rgba(19, 40, 38, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
  --med: var(--accent);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0D1312;
    --surface: #151E1D;
    --surface-2: #1C2726;
    --surface-3: #263331;
    --line: #22302E;
    --line-strong: #344541;
    --text: #E4ECEB;
    --text-2: #A3B1AF;
    --text-3: #6E7F7D;
    --accent: #3BC3C3;
    --accent-strong: #62D6D6;
    --accent-soft: rgba(59, 195, 195, 0.14);
    --on-accent: #052020;
    --good: #52C78F;
    --good-soft: rgba(82, 199, 143, 0.15);
    --warn: #E8AE52;
    --warn-soft: rgba(232, 174, 82, 0.15);
    --bad: #F0776C;
    --bad-soft: rgba(240, 119, 108, 0.14);
    --on-bad: #1A0807;
    --serum: #B49BFF;
    --avg: #E4B65A;
    --seg-on: #2E3D3B;
    --tip-bg: #E4ECEB;
    --tip-fg: #0D1312;
    --focus: rgba(59, 195, 195, 0.5);
    --scrim: rgba(0, 0, 0, 0.6);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 12px 36px rgba(0, 0, 0, 0.5);
  }
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { background: var(--bg); color: var(--text); }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, input[type=number], .metric-value, .hist-time { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.view:focus { outline: none; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico-xs { width: 14px; height: 14px; stroke-width: 2.6; }
.ico-chev { width: 18px; height: 18px; color: var(--text-3); }
.logo { width: 30px; height: 30px; flex: none; }
.logo-lg { width: 52px; height: 52px; }
.logo-bg { fill: var(--accent); }
.logo-fg { stroke: var(--on-accent); stroke-width: 2.6; stroke-linecap: round; fill: none; }
.logo-dot { fill: var(--on-accent); }
.noscript { padding: 24px; text-align: center; }

/* ── App chrome ───────────────────────────────────────────────────────────── */
.view { display: block; padding: calc(12px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
.page { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page-detail { max-width: 1080px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.5) blur(16px); -webkit-backdrop-filter: saturate(1.5) blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-brand { display: none; }
.nav-links { display: grid; grid-template-columns: repeat(3, 1fr); height: var(--nav-h); max-width: 520px; margin: 0 auto; }
.nav-link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em; min-height: 44px;
}
.nav-link .nav-ico { width: 24px; height: 24px; }
.nav-link.is-active { color: var(--accent); }
.nav-link:active { opacity: 0.7; }

@media (min-width: 721px) {
  .app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
  .nav {
    position: sticky; top: 0; bottom: auto; height: 100dvh; padding: 22px 14px;
    border-top: 0; border-right: 1px solid var(--line); background: var(--surface);
    display: flex; flex-direction: column; gap: 26px; backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .nav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px; font-weight: 700; font-size: 19px; letter-spacing: -0.01em; }
  .nav-links { display: flex; flex-direction: column; gap: 4px; height: auto; max-width: none; margin: 0; }
  .nav-link { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 12px; height: 44px; border-radius: 12px; font-size: 15px; color: var(--text-2); }
  .nav-link .nav-ico { width: 20px; height: 20px; }
  .nav-link:hover { background: var(--surface-2); color: var(--text); }
  .nav-link.is-active { background: var(--accent-soft); color: var(--accent); }
  .view { padding: 36px 40px 64px; }
}

/* ── Page headers ─────────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: center; gap: 12px; padding: 6px 0 2px; }
.page-head-text { flex: 1; min-width: 0; }
.page-eyebrow { color: var(--text-2); font-size: 13.5px; font-weight: 600; }
.page-title { font-size: 28px; line-height: 1.15; font-weight: 750; letter-spacing: -0.02em; }
.page-head-today .page-title { font-size: 26px; }
.page-sub { color: var(--text-2); font-size: 14px; margin-top: 3px; }
.med-title { display: flex; align-items: center; gap: 10px; font-size: 24px; }
.med-title .med-dot { width: 18px; height: 18px; }
.page-head-detail { align-items: flex-start; }
.page-head-detail .back-btn { margin-left: -8px; }
@media (min-width: 721px) { .page-title { font-size: 30px; } .med-title { font-size: 28px; } }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 15px; font-weight: 650; line-height: 1; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, transform .08s, box-shadow .15s;
  user-select: none; -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn .ico { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-quiet { background: var(--surface-2); color: var(--text); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-3); }
.btn-danger { background: var(--bad); color: var(--on-bad); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.06); }
.btn-danger-quiet { background: var(--bad-soft); color: var(--bad); }
.btn-danger-quiet:hover:not(:disabled) { background: color-mix(in srgb, var(--bad) 18%, transparent); }
.btn-block { width: 100%; }
.btn-grow { flex: 1; }
.btn-lg { min-height: 52px; font-size: 16px; padding: 0 22px; border-radius: 14px; }
.btn-compact { padding: 0 14px; }
.btn-icon { width: 44px; padding: 0; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid currentColor; border-color: var(--text-3); border-top-color: transparent;
  animation: spin .7s linear infinite;
}
.btn-primary.is-busy::after { border-color: var(--on-accent); border-top-color: transparent; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: inline-grid; place-items: center; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2); cursor: pointer;
  transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-quiet { border-color: transparent; background: transparent; color: var(--text-3); }
.icon-btn-quiet:hover { background: var(--bad-soft); color: var(--bad); }
.chip-toggle {
  min-height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 650; cursor: pointer;
}
.chip-toggle.is-on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* ── Segmented control ────────────────────────────────────────────────────── */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 13px; background: var(--surface-2); }
.seg-btn {
  min-height: 38px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent;
  color: var(--text-2); font-size: 14px; font-weight: 650; cursor: pointer; flex: 1; white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-on { background: var(--seg-on); color: var(--text); box-shadow: var(--shadow-1); }
.seg-filter { display: flex; width: 100%; }
.seg-sm .seg-btn { min-height: 32px; padding: 0 9px; font-size: 12.5px; }

/* ── Cards, states ────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head-wrap { flex-wrap: wrap; }
.card-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.form-card > .card-title { margin-bottom: 14px; }
.card-count { font-size: 12.5px; font-weight: 650; color: var(--text-2); background: var(--surface-2); border-radius: 999px; padding: 2px 8px; }
.card-intro { color: var(--text-2); font-size: 14px; margin: -6px 0 14px; }
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 40px 16px; text-align: center; color: var(--text-2); }
.state-loading { flex-direction: row; font-size: 14px; }
.state-title { font-weight: 700; color: var(--text); font-size: 16px; }
.state-text { font-size: 14px; max-width: 360px; }
.state .btn { margin-top: 8px; }
.state-error .state-title { color: var(--bad); }
.card .state { padding: 22px 8px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line-strong); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.note-chip { font-size: 13.5px; color: var(--text-2); background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin-top: 12px; }
.banner { display: flex; align-items: center; gap: 10px; border-radius: 12px; padding: 10px 12px; font-size: 14px; font-weight: 600; margin-top: 12px; }
.banner .ico { width: 18px; height: 18px; }
.banner-bad { background: var(--bad-soft); color: var(--bad); }
.disclaimer { font-size: 12.5px; color: var(--text-3); text-align: center; padding: 4px 12px 8px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }

/* ── Today ────────────────────────────────────────────────────────────────── */
.today-body { display: flex; flex-direction: column; gap: 18px; }
.today-summary { display: flex; align-items: center; gap: 12px; border-radius: var(--radius); padding: 12px 14px; }
.today-summary-icon { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.today-summary-text { display: flex; flex-direction: column; font-size: 13.5px; color: var(--text-2); }
.today-summary-text strong { font-size: 15.5px; color: var(--text); }
.today-summary.is-alert { background: var(--bad-soft); }
.today-summary.is-alert .today-summary-icon { background: var(--bad); color: var(--on-bad); }
.today-summary.is-pending { background: var(--accent-soft); }
.today-summary.is-pending .today-summary-icon { background: var(--accent); color: var(--on-accent); }
.today-summary.is-clear { background: var(--good-soft); }
.today-summary.is-clear .today-summary-icon { background: var(--good); color: var(--surface); }

.group { display: flex; flex-direction: column; gap: 8px; }
.group-title { font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.06em; display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.group-count { font-size: 12px; letter-spacing: 0; color: var(--text-3); }
.group-attention .group-title { color: var(--bad); }
.med-list { list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); overflow: hidden; }
.med-row { display: flex; align-items: center; gap: 8px; padding-right: 12px; position: relative; }
.med-row + .med-row { border-top: 1px solid var(--line); }
.med-row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 14px 4px 14px 14px; min-height: 68px; border-radius: 0; }
.med-row-main:hover .med-name { text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.med-row-main:focus-visible { outline-offset: -3px; border-radius: var(--radius); }
.med-dot { width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 50%; }
.med-dot::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--med); box-shadow: 0 0 0 4px color-mix(in srgb, var(--med) 20%, transparent); }
.med-dot.is-done { background: var(--good-soft); color: var(--good); }
.med-dot.is-done::before { display: none; }
.med-text { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.med-name { font-weight: 650; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; overflow-wrap: anywhere; }
.med-status { font-size: 13.5px; color: var(--text-2); }
.med-when { font-size: 13px; color: var(--text-3); }
.tone-bad .med-status { color: var(--bad); font-weight: 600; }
.tone-warn .med-status { color: var(--warn); font-weight: 600; }
.tone-good .med-status { color: var(--good); }
.is-done .med-name, .med-row.is-done .med-name { color: var(--text-2); }
.med-row-act { flex: none; }
.act-btn { min-width: 88px; }
.who-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.who-tag { font-size: 11.5px; font-weight: 650; color: var(--text-2); background: var(--surface-2); border-radius: 6px; padding: 1px 7px; }

/* ── Meds list ────────────────────────────────────────────────────────────── */
.meds-body { display: flex; flex-direction: column; gap: 16px; }
.list-card { padding: 0; overflow: hidden; }
.list { list-style: none; }
.list li + li { border-top: 1px solid var(--line); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 16px; min-height: 68px; }
.list-row:hover { background: var(--surface-2); }
.list-row:focus-visible { outline-offset: -3px; }
.list-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-row-title { font-weight: 650; font-size: 16px; }
.list-row-sub { font-size: 13.5px; color: var(--text-2); }
.status-pill { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 9px; flex: none; }
.st-red { background: var(--bad-soft); color: var(--bad); }
.st-yellow { background: var(--warn-soft); color: var(--warn); }
.archived > .list { border-top: 1px solid var(--line); }
.archived-sum { display: flex; align-items: center; gap: 10px; padding: 0 16px; min-height: 56px; cursor: pointer; font-weight: 650; color: var(--text-2); list-style: none; }
.archived-sum::-webkit-details-marker { display: none; }
.archived-sum::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(45deg); transition: transform .15s; }
.archived[open] .archived-sum::after { transform: rotate(-135deg); }

/* ── Detail ───────────────────────────────────────────────────────────────── */
.detail-body { display: block; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 1100px) {
  .detail-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .detail-grid > .page-head, .detail-grid > .hero-card, .detail-grid > .chart-card, .detail-grid > .disclaimer, .detail-grid > .labs-card { grid-column: 1 / -1; }
}
.hero-top { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.hero-status { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--text-2); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; }
.hero-status.tone-bad { color: var(--bad); } .hero-status.tone-bad .status-dot { background: var(--bad); }
.hero-status.tone-warn { color: var(--warn); } .hero-status.tone-warn .status-dot { background: var(--warn); }
.hero-status.tone-good { color: var(--good); } .hero-status.tone-good .status-dot { background: var(--good); }
.hero-action .btn { width: 100%; }
@media (min-width: 721px) {
  .hero-top { flex-direction: row; align-items: center; justify-content: space-between; }
  .hero-action .btn { width: auto; min-width: 200px; }
}
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 721px) { .metrics.n-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .metrics.n-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.metric { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.metric-label { font-size: 12px; font-weight: 650; color: var(--text-2); }
.metric-value { font-size: 24px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.metric-unit { font-size: 13px; font-weight: 650; color: var(--text-2); letter-spacing: 0; }
.metric-sub { font-size: 12.5px; color: var(--text-3); overflow-wrap: anywhere; }
.metric.tone-accent .metric-value { color: var(--accent); }
.metric.tone-bad .metric-value { color: var(--bad); }
.metric.tone-warn .metric-value { color: var(--warn); }
.metric.tone-good .metric-value { color: var(--good); }

.chart-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chart-wrap { height: 260px; margin: 4px -4px 0; }
@media (min-width: 721px) { .chart-wrap { height: 340px; } }
.chart { display: block; width: 100%; height: 100%; touch-action: pan-y; cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 12.5px; color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.lg-sw { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.sw-med { background: var(--med); }
.sw-avg { background: var(--avg); }
.sw-serum { background: var(--serum); }
.sw-lab { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
.sw-target { background: repeating-linear-gradient(90deg, var(--text-2) 0 5px, transparent 5px 8px); }
.sw-trough { background: repeating-linear-gradient(90deg, var(--bad) 0 2px, transparent 2px 5px); }
.sw-proj { background: repeating-linear-gradient(90deg, var(--med) 0 4px, transparent 4px 7px); }

.range-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.range-head { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; color: var(--text-2); }
.range-val { color: var(--text); font-weight: 700; }
.range { width: 100%; height: 32px; accent-color: var(--accent); cursor: pointer; }
.plan-results { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 4px 0 14px; }
.plan-result { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.plan-result .metric-value { font-size: 20px; }
.plan-result:first-child .metric-value { color: var(--accent); }

.adh-strip { list-style: none; display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; }
.adh-day { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.adh-bar { position: relative; width: 100%; height: 46px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.adh-fill { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--frac, 0) * 100%); background: var(--med); opacity: .9; }
.adh-day.is-part .adh-fill { opacity: .5; }
.adh-day.is-today .adh-bar { box-shadow: inset 0 0 0 2px var(--accent); }
.adh-letter { font-size: 11px; font-weight: 650; color: var(--text-3); }
.adh-day.is-today .adh-letter { color: var(--accent); }
.adh-stats { display: flex; gap: 20px; margin-top: 14px; color: var(--text-2); font-size: 14px; flex-wrap: wrap; }
.adh-stats strong { color: var(--text); font-size: 20px; font-weight: 750; margin-right: 2px; }

.history { display: flex; flex-direction: column; gap: 12px; }
.hist-date { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 700; color: var(--text-2); padding: 0 4px 4px; }
.hist-count { color: var(--text-3); }
.hist-rows { list-style: none; border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.hist-rows li + li { border-top: 1px solid var(--line); }
.hist-row {
  width: 100%; display: grid; grid-template-columns: 70px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  min-height: 48px; padding: 8px 10px 8px 12px; border: 0; background: transparent; text-align: left; cursor: pointer;
}
.hist-row:hover { background: var(--surface-3); }
.hist-row:focus-visible { outline-offset: -3px; }
.hist-time { color: var(--text-2); font-size: 14px; }
.hist-main { display: flex; flex-direction: column; min-width: 0; }
.hist-amt { font-weight: 650; }
.hist-meta { font-size: 12.5px; color: var(--text-3); overflow-wrap: anywhere; }
.history-card > .btn-block { margin-top: 12px; }
.lab-rows { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.lab-row { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 12px; padding: 6px 6px 6px 14px; }
.lab-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lab-val { font-weight: 650; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label { font-size: 13.5px; font-weight: 650; color: var(--text-2); }
.field-hint { font-size: 12.5px; color: var(--text-3); }
.input {
  width: 100%; min-height: 46px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font-size: 16px; transition: border-color .15s, box-shadow .15s;
}
select.input { appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.input::placeholder { color: var(--text-3); }
.input:disabled { opacity: .55; }
.input-unit { position: relative; display: block; }
.input-unit .input { padding-right: 58px; }
.input-unit .unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 14px; font-weight: 600; pointer-events: none; }
.amount-field .input { font-size: 22px; font-weight: 700; min-height: 54px; }
.form-error { color: var(--bad); font-size: 14px; font-weight: 600; background: var(--bad-soft); border-radius: 10px; padding: 10px 12px; margin: 6px 0 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.disclosure { margin-bottom: 14px; }
.disclosure > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; min-height: 36px; display: flex; align-items: center; }
.disclosure[open] > summary { margin-bottom: 8px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 0; min-height: 52px; cursor: pointer; }
.switch-text { display: flex; flex-direction: column; min-width: 0; }
.switch-label { font-weight: 650; font-size: 15.5px; }
.switch-hint { font-size: 13px; color: var(--text-3); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch-input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch-track { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); transition: background-color .18s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .18s; }
.switch-input:checked + .switch-track { background: var(--accent); }
.switch-input:checked + .switch-track::after { transform: translateX(20px); }
.switch-input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch-input:disabled { cursor: default; }
.switch-input:disabled + .switch-track { opacity: .5; }

/* editor */
.editor { display: flex; flex-direction: column; gap: 16px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; position: relative;
  background: var(--sw); display: grid; place-items: center; transition: transform .1s;
}
.swatch::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2.5px solid transparent; }
.swatch.is-on::after { border-color: var(--text); }
.swatch:active { transform: scale(0.94); }
.swatch-custom-wrap { background: conic-gradient(from 0deg, #d2544b, #d9822b, #b8901a, #2e9e6b, #1f8a8a, #3b6fd8, #7a4fe0, #c2479a, #d2544b); color: #fff; overflow: visible; }
.swatch-custom-wrap .ico { filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.swatch-custom { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; }
.swatch-custom-wrap:focus-within::after { border-color: var(--focus); }
.check-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.check-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-weight: 650; position: relative;
}
.check-chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.check-chip .ico { display: none; }
.check-chip.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.check-chip.is-on .ico { display: block; }
.check-chip:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.chip-note { font-size: 12px; font-weight: 500; color: var(--text-3); }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 14px;
  border: 1.5px solid var(--line-strong); background: var(--surface); cursor: pointer; position: relative;
  transition: border-color .15s, background-color .15s;
}
.choice-list.compact .choice { padding: 12px 14px; }
.choice:hover { border-color: var(--text-3); }
.choice.is-on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.choice-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice-mark { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong); flex: none; margin-top: 1px; display: grid; place-items: center; }
.choice.is-on .choice-mark { border-color: var(--accent); }
.choice.is-on .choice-mark::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.choice-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.choice-title { font-weight: 650; }
.choice-sub { font-size: 13.5px; color: var(--text-2); }
.choice-extra { display: block; margin-top: 10px; }
.choice:not(.is-on) .choice-extra { display: none; }
.choice-extra .field { margin-bottom: 0; max-width: 240px; }
.sub-block { margin-top: 12px; }
.inline-fields { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-fields .input { width: auto; min-width: 0; }
.inline-fields select.input { width: 110px; }
.inline-fields input[type=time] { width: 128px; }
.inline-fields.big .inline-label { font-size: 16px; font-weight: 650; color: var(--text); }
.inline-label { font-size: 14px; color: var(--text-2); }
.w-num { width: 84px; display: inline-block; }
.w-num .input { width: 100%; text-align: center; }
.cp-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.cp-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--surface-2); border-radius: 12px; padding: 8px 8px 8px 12px; }
.cp-row input[type=time] { width: 128px; }
.cp-row .btn-icon { margin-left: auto; }
.rem-block { margin-top: 4px; }
.audience { font-size: 14px; color: var(--text-2); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.audience:empty { display: none; }
.audience.is-warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.form-card > .btn { margin-top: 4px; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 30%, var(--line)); }
.danger-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.save-bar {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  display: flex; gap: 10px; padding: 10px; border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line);
  box-shadow: var(--shadow-2); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.save-bar .btn-secondary { min-width: 110px; }
@media (min-width: 721px) { .save-bar { bottom: 16px; } }

/* settings */
.chan { border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px; margin-bottom: 10px; transition: opacity .15s; }
.chan.is-off .chan-body { opacity: .5; }
.chan-body { padding: 4px 0 12px; }
.ch-master { background: var(--surface-2); border-color: transparent; }
.gate { font-size: 13.5px; color: var(--text-2); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.devices { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.device { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 12px; padding: 6px 6px 6px 12px; }
.device-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.device-name { font-weight: 650; font-size: 14.5px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.device-sub { font-size: 12.5px; color: var(--text-3); }
.tag { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 1px 6px; background: var(--accent-soft); color: var(--accent); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.time-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.time-chip { display: inline-flex; align-items: center; gap: 2px; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.time-chip .input { width: 124px; border-color: transparent; background: var(--surface); }
.time-chip .btn-icon { background: transparent; }
.field > .btn-quiet { align-self: flex-start; margin-top: 4px; }
.account-line { display: flex; align-items: center; gap: 6px; color: var(--text-2); margin-bottom: 12px; }
.account-line .ico { color: var(--good); }
.about-card .card-intro { margin: 6px 0 0; }

/* ── Sheets ───────────────────────────────────────────────────────────────── */
dialog.sheet {
  border: 0; padding: 0; background: transparent; color: var(--text);
  width: 100%; max-width: 100%; max-height: 100%; margin: auto 0 0 0; inset: 0; overflow: visible;
}
dialog.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(2px); animation: fade .2s ease; }
.sheet-inner {
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; max-height: 92dvh; animation: sheet-up .24s cubic-bezier(.2,.8,.2,1);
}
.sheet.is-closing .sheet-inner { animation: sheet-down .16s ease-in forwards; }
.sheet.is-closing::backdrop { opacity: 0; transition: opacity .16s; }
.sheet-grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 6px 12px 4px 20px; }
.sheet-title { flex: 1; font-size: 19px; font-weight: 750; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.sheet-close { border-color: transparent; background: var(--surface-2); border-radius: 50%; width: 40px; height: 40px; }
.sheet-body { padding: 10px 20px 8px; overflow-y: auto; overscroll-behavior: contain; }
.sheet-actions { display: flex; gap: 10px; align-items: center; padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-actions .btn-secondary { min-width: 100px; }
.sheet-actions .spacer { flex: 1; }
.sheet-msg { color: var(--text-2); margin-bottom: 14px; }
.sheet-confirm .sheet-actions .btn { flex: 1; }
@media (min-width: 721px) {
  dialog.sheet { width: min(520px, calc(100% - 32px)); margin: auto; }
  .sheet-inner { border-radius: 22px; max-height: min(86dvh, 760px); animation: pop .2s cubic-bezier(.2,.8,.2,1); }
  .sheet.is-closing .sheet-inner { animation: pop-out .14s ease-in forwards; }
  .sheet-grab { display: none; }
  .sheet-head { padding-top: 16px; }
  .sheet-actions { padding-bottom: 18px; }
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-down { to { transform: translateY(100%); } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop-out { to { transform: scale(.97); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ── Toasts ───────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed; left: 0; right: 0; z-index: 100; pointer-events: none;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 520px; width: max-content;
  background: var(--tip-bg); color: var(--tip-fg); border-radius: 14px; padding: 6px 6px 6px 16px; min-height: 48px;
  box-shadow: var(--shadow-2); font-size: 14.5px; font-weight: 600; animation: toast-in .2s ease;
}
.toast:not(:has(.toast-action)) { padding-right: 16px; }
.toast-msg { flex: 1; }
.toast-error { background: var(--bad); color: var(--on-bad); }
.toast-action {
  min-height: 36px; padding: 0 14px; border-radius: 10px; border: 0; cursor: pointer; font-weight: 750;
  background: color-mix(in srgb, var(--tip-fg) 16%, transparent); color: var(--tip-fg);
}
.toast-action:hover { background: color-mix(in srgb, var(--tip-fg) 26%, transparent); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 721px) { .toasts { bottom: 24px; padding-left: 232px; } }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(120% 70% at 50% 0%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-2); padding: 28px 22px 22px; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-brand h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.login-brand p { color: var(--text-2); font-size: 14px; }
.login-card .btn { margin-top: 6px; }
.login-foot { text-align: center; font-size: 12.5px; color: var(--text-3); margin-top: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
.sheet-body .note-chip { margin: -4px 0 14px; }
.settings-body, .editor-body { display: flex; flex-direction: column; gap: 16px; }
.time-chip .input { width: 148px; }
.inline-fields input[type=time], .cp-row input[type=time] { width: 144px; }
