/* Migraine Ledger — "clinical journal": warm paper, deep ink, a single warm
   pain ramp (amber → coral → crimson) and a muted categorical set for treatments. */
:root {
  --paper: #F6F1E9;
  --surface: #FBF8F2;
  --surface-2: #F1EADF;
  --ink: #1E1A17;
  --ink-2: #4E4640;
  --muted: #8A8178;
  --line: #E3DACC;
  --line-2: #D4C8B6;
  --p1: #F2B65E;
  --p2: #E0663F;
  --p3: #A3142F;
  --p1-soft: #FBE7C4;
  --p2-soft: #F7CDBB;
  --good: #2F7D4F;
  --bad: #A3142F;
  --focus: #2E7BD6;
  --radius: 18px;
  --shadow: 0 1px 0 rgba(30, 26, 23, .04), 0 18px 40px -22px rgba(60, 40, 20, .25);
  --display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --body: 'Instrument Sans', ui-sans-serif, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--body); color: var(--ink); background: var(--paper); min-height: 100vh;
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 600px at 85% -10%, rgba(224, 102, 63, .09), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(242, 182, 94, .12), transparent 60%);
  background-attachment: fixed;
}
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: .35; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.3 0 0 0 0 0.25 0 0 0 0 0.2 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
em { font-style: normal; }
b { font-weight: 650; }

/* ── Brand ─────────────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-size: 20px; font-weight: 500; letter-spacing: -.01em; white-space: nowrap; }
.brand em { font-style: italic; color: var(--p3); font-weight: 400; }
.brand-mark { width: 30px; height: 30px; }
.brand-lg { font-size: 22px; justify-content: center; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 999px; font-weight: 600; font-size: 14px; transition: background .15s, transform .15s, box-shadow .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: var(--surface); box-shadow: 0 6px 16px -8px rgba(30, 26, 23, .6); }
.btn-primary:hover { background: #000; }
.btn-ghost { border: 1px solid var(--line-2); background: var(--surface); }
.btn-ghost:hover { background: #fff; border-color: var(--ink-2); }
.btn-danger { background: var(--p3); color: #fff; }
.btn-sm { height: 34px; padding: 0 13px; font-size: 13px; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); transition: background .15s, border-color .15s; }
.icon-btn:hover { background: #fff; border-color: var(--ink-2); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.link-btn { color: var(--ink); font-weight: 600; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 4px; }
.link-btn:hover { text-decoration-color: var(--ink); }

/* ── Lock screen ───────────────────────────────────────────────────── */
.lock { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.lock-card { width: min(380px, 100%); text-align: center; animation: rise .7s cubic-bezier(.2, .8, .2, 1) both; }
.lock-title { font-family: var(--display); font-weight: 400; font-size: 40px; letter-spacing: -.02em; margin: 34px 0 6px; line-height: 1.05; }
.lock-sub { color: var(--muted); }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 30px 0 8px; min-height: 16px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--ink-2); transition: background .15s, transform .15s; }
.pin-dots i.on { background: var(--p3); border-color: var(--p3); transform: scale(1.1); }
.pin-dots.shake { animation: shake .4s; }
.lock-error { color: var(--p3); min-height: 22px; font-size: 14px; font-weight: 500; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); justify-content: center; gap: 14px 22px; margin: 16px 0 22px; }
.keypad button { width: 76px; height: 76px; border-radius: 50%; font-family: var(--display); font-size: 30px; font-weight: 350; border: 1px solid var(--line); background: var(--surface); transition: background .12s, transform .12s; display: grid; place-items: center; }
.keypad button:hover { background: #fff; }
.keypad button:active { transform: scale(.94); background: var(--p1-soft); }
.keypad svg { width: 24px; height: 24px; }

/* ── Top bar ───────────────────────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px clamp(16px, 4vw, 40px); background: rgba(246, 241, 233, .82); backdrop-filter: blur(14px) saturate(1.2); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.tabs button { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--ink-2); transition: background .2s, color .2s; }
.tabs button svg { width: 16px; height: 16px; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--surface); box-shadow: 0 6px 14px -8px rgba(0, 0, 0, .6); }
.top-actions { display: flex; gap: 10px; align-items: center; }

/* ── Views & cards ─────────────────────────────────────────────────── */
.views { max-width: 1280px; margin: 0 auto; padding: clamp(18px, 3vw, 36px) clamp(14px, 4vw, 40px) 80px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; position: relative; }
.eyebrow { font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; font-weight: 650; color: var(--muted); }
.display { font-family: var(--display); font-weight: 350; font-size: clamp(28px, 3.6vw, 44px); letter-spacing: -.025em; line-height: 1.05; margin-top: 6px; }
.display em { font-style: italic; color: var(--p3); }
.display .dash { color: var(--line-2); }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.reveal { animation: rise .7s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--d, 0) * 70ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ── Calendar ──────────────────────────────────────────────────────── */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 24px; align-items: start; }
.cal-main { padding: 28px 28px 22px; }
.cal-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.cal-title h2 { font-family: var(--display); font-weight: 350; font-size: clamp(36px, 5vw, 60px); letter-spacing: -.035em; line-height: .95; }
.cal-title .y { font-style: italic; color: var(--muted); font-weight: 300; }
.cal-nav { display: flex; gap: 8px; align-items: center; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-bottom: 8px; }
.weekdays span { font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; font-weight: 650; color: var(--muted); padding-left: 10px; }
.weekdays .we { color: var(--line-2); }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cell {
  position: relative; aspect-ratio: 1 / .88; border-radius: 14px; text-align: left; padding: 9px 10px;
  background: #fff; border: 1px solid var(--line); overflow: hidden;
  transition: transform .18s cubic-bezier(.2, .8, .2, 1), box-shadow .18s, background .25s, border-color .2s;
  animation: cellIn .5s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i) * 9ms);
}
@keyframes cellIn { from { opacity: 0; transform: scale(.94); } }
.cell.pad { background: transparent; border: 1px dashed transparent; animation: none; }
.cell:not(.pad):not(.future):hover { transform: translateY(-2px); box-shadow: 0 12px 22px -14px rgba(60, 30, 10, .45); border-color: var(--line-2); }
.cell .num { font-family: var(--display); font-size: 17px; font-weight: 450; line-height: 1; font-variant-numeric: lining-nums; }
.cell .lvl-num { position: absolute; right: 9px; bottom: 4px; font-family: var(--display); font-style: italic; font-weight: 300; font-size: clamp(26px, 3.4vw, 44px); line-height: 1; opacity: .9; }
.cell .dots { position: absolute; left: 10px; bottom: 11px; display: flex; gap: 3px; }
.cell .dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .75; }
.cell.lvl-1 { background: var(--p1-soft); border-color: #F1D29C; }
.cell.lvl-1 .lvl-num { color: #B4751A; }
.cell.lvl-2 { background: var(--p2-soft); border-color: #EDB29B; }
.cell.lvl-2 .lvl-num { color: #B4421F; }
.cell.lvl-3 { background: var(--p3); border-color: var(--p3); color: #FCEDE8; }
.cell.lvl-3 .lvl-num { color: #fff; }
.cell.lvl-3 { background-image: linear-gradient(150deg, #B51D39, #8A0F26); }
.cell.today { box-shadow: inset 0 0 0 2px var(--ink); }
.cell.today .num::after { content: 'today'; font-family: var(--body); font-size: 9.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; margin-left: 6px; vertical-align: 3px; opacity: .7; }
.cell.future { background: transparent; border-style: dashed; color: var(--line-2); cursor: default; }
.cell.sel { outline: 2px solid var(--ink); outline-offset: 2px; }
.cell.pop { animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { 40% { transform: scale(1.08); } }
.cell .note-dot { position: absolute; top: 10px; right: 10px; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); opacity: .55; }
.cell.lvl-3 .note-dot { background: #fff; }
.cell .pill-start { position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; box-shadow: 0 0 0 2px #fff; }
.cell .pill-start svg { width: 11px; height: 11px; stroke-width: 2.2; }
.cell .note-dot + .pill-start, .cell .pill-start ~ .note-dot { top: 30px; }
.cell .ribbons { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; gap: 1px; }
.cell .ribbons i { height: 3px; display: block; opacity: .9; }
.cell.future .ribbons { opacity: .25; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 20px; align-items: center; font-size: 13px; color: var(--ink-2); }
.lg { display: inline-flex; align-items: center; gap: 7px; }
.lg i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line-2); background: #fff; }
.lg.lvl-1 i { background: var(--p1); border-color: var(--p1); }
.lg.lvl-2 i { background: var(--p2); border-color: var(--p2); }
.lg.lvl-3 i { background: var(--p3); border-color: var(--p3); }
.lg.med u { width: 16px; height: 4px; border-radius: 2px; background: var(--c); }
.lg-hint { margin-left: auto; color: var(--muted); font-size: 12.5px; }

/* day popover */
.day-pop { position: absolute; z-index: 10; width: 320px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 18px; padding: 16px; box-shadow: 0 30px 60px -20px rgba(40, 20, 10, .45); animation: popIn .22s cubic-bezier(.2, .8, .2, 1); }
.day-pop.above { transform: translateY(-100%); animation: none; }
@keyframes popIn { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
.day-pop.sheet { position: fixed; left: 0; right: 0; bottom: 0; top: auto !important; width: auto; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); z-index: 40; animation: sheetIn .3s cubic-bezier(.2, .8, .2, 1); }
@keyframes sheetIn { from { transform: translateY(100%); } }
.pop-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.pop-head h4 { font-family: var(--display); font-weight: 450; font-size: 19px; letter-spacing: -.01em; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.sg { border: 1px solid var(--line); border-radius: 12px; padding: 9px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; background: #fff; transition: transform .12s, background .15s, border-color .15s; }
.sg b { font-family: var(--display); font-size: 24px; font-weight: 400; line-height: 1; }
.sg span { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.sg:hover { border-color: var(--ink-2); }
.sg:active { transform: scale(.96); }
.sg.on.lvl-0 { background: var(--ink); color: #fff; border-color: var(--ink); }
.sg.on.lvl-1 { background: var(--p1); border-color: var(--p1); }
.sg.on.lvl-2 { background: var(--p2); border-color: var(--p2); color: #fff; }
.sg.on.lvl-3 { background: var(--p3); border-color: var(--p3); color: #fff; }
.sg.on span { color: inherit; }
.pop-meds { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); }
.tag i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.pop-foot { display: flex; justify-content: flex-end; margin-top: 12px; }

/* side cards */
.cal-side { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 90px; }
.today-card h3 { font-family: var(--display); font-weight: 400; font-size: 26px; letter-spacing: -.02em; line-height: 1.1; margin: 6px 0 16px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.q { aspect-ratio: 1 / 1.15; border-radius: 14px; border: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; transition: transform .15s cubic-bezier(.3, 1.6, .5, 1), background .2s, border-color .2s, color .2s; }
.q:hover { transform: translateY(-3px); border-color: var(--ink-2); }
.q-n { font-family: var(--display); font-size: 32px; font-weight: 350; line-height: 1; }
.q-l { font-size: 11.5px; font-weight: 650; letter-spacing: .02em; color: var(--ink-2); }
.q.lvl-1 .q-n { color: #C8861F; } .q.lvl-2 .q-n { color: var(--p2); } .q.lvl-3 .q-n { color: var(--p3); }
.q.on { transform: translateY(-2px); }
.q.on.lvl-0 { background: var(--ink); border-color: var(--ink); }
.q.on.lvl-1 { background: var(--p1); border-color: var(--p1); }
.q.on.lvl-2 { background: var(--p2); border-color: var(--p2); }
.q.on.lvl-3 { background: var(--p3); border-color: var(--p3); }
.q.on .q-n, .q.on .q-l { color: #fff; }
.q.on.lvl-1 .q-n, .q.on.lvl-1 .q-l { color: var(--ink); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 14px; }
.stat { display: flex; flex-direction: column; }
.stat .big { font-family: var(--display); font-size: 36px; font-weight: 350; letter-spacing: -.03em; line-height: 1; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 5px; }
.mini-bar { display: flex; gap: 2px; height: 8px; border-radius: 99px; overflow: hidden; margin-bottom: 12px; background: var(--surface-2); }
.mini-bar i.lvl-1 { background: var(--p1); } .mini-bar i.lvl-2 { background: var(--p2); } .mini-bar i.lvl-3 { background: var(--p3); } .mini-bar i.lvl-0 { background: var(--surface-2); }
.med-chip { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; }
.med-chip > i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-top: 6px; box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 18%, transparent); }
.meds-card p.small { margin-top: 10px; }

/* ── Year ──────────────────────────────────────────────────────────── */
.year-card { padding: 28px; }
.year-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; padding: 4px 0 22px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.ygrid { overflow-x: auto; }
.yrow { display: grid; grid-template-columns: 44px minmax(560px, 1fr) 40px; align-items: center; gap: 10px; margin-bottom: 4px; animation: rise .5s both; animation-delay: calc(var(--i) * 35ms); }
.yrow.yhead { animation: none; }
.ym { font-family: var(--display); font-weight: 450; font-size: 14px; }
.ycells { display: grid; grid-template-columns: repeat(31, 1fr); gap: 3px; }
.yhead .ycells span { font-size: 10px; color: var(--muted); text-align: center; }
.ycount { font-family: var(--display); font-size: 15px; text-align: right; color: var(--ink-2); }
.yhead .ycount { font-family: var(--body); font-size: 10px; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }
.yc { position: relative; aspect-ratio: 1; border-radius: 5px; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; cursor: pointer; transition: transform .12s; }
.yc:hover { transform: scale(1.25); z-index: 2; }
.yc b { font-size: 10px; font-weight: 700; line-height: 1; }
.yc.lvl-1 { background: var(--p1); border-color: var(--p1); }
.yc.lvl-2 { background: var(--p2); border-color: var(--p2); color: #fff; }
.yc.lvl-3 { background: var(--p3); border-color: var(--p3); color: #fff; }
.yc.void { visibility: hidden; }
.yc.future { background: transparent; border-style: dashed; cursor: default; }
.yc.today { box-shadow: 0 0 0 2px var(--ink); }
.yc u { position: absolute; left: -1px; right: -1px; bottom: -4px; height: 2px; background: var(--c); border-radius: 2px; }
.yc em { position: absolute; top: -4px; left: 50%; width: 7px; height: 7px; border-radius: 50%; background: var(--c); transform: translateX(-50%); box-shadow: 0 0 0 1.5px #fff; }

/* ── Insights ──────────────────────────────────────────────────────── */
.ins-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.filters { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.seg-pills { display: inline-flex; gap: 2px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.seg-pills button, .seg-pills label span { display: block; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg-pills button.on, .seg-pills input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg-pills input { position: absolute; opacity: 0; pointer-events: none; }
.seg-pills.wrap { flex-wrap: wrap; border-radius: 18px; }
.range { display: none; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.range.show { display: flex; }
input[type=date], .field input, .field textarea { border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 10px; background: #fff; font-size: 14px; width: 100%; }
.range input[type=date] { width: auto; }
input:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }

.tiles { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 16px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.tile .lbl { font-size: 12px; font-weight: 650; color: var(--muted); letter-spacing: .04em; }
.tile .big { font-family: var(--display); font-size: 44px; font-weight: 330; letter-spacing: -.04em; line-height: 1; margin: 10px 0 6px; }
.tile .sub { font-size: 12.5px; color: var(--muted); }
.tile.hero { background: var(--ink); color: var(--surface); border-color: var(--ink); background-image: radial-gradient(400px 200px at 110% 0%, rgba(224, 102, 63, .45), transparent 70%); }
.tile.hero .lbl, .tile.hero .sub { color: #CFC5B8; }
.tile.hero .big { font-size: 62px; }
.chart-card { margin-bottom: 18px; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.chart-head h3, .card > h3 { font-family: var(--display); font-weight: 450; font-size: 21px; letter-spacing: -.015em; }
.chart-legend { margin: 6px 0 4px; }
.chart-box { width: 100%; }
.ins-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; }

svg.chart { display: block; width: 100%; height: auto; fill: initial; stroke: none; stroke-width: 1; overflow: visible; font-family: var(--body); }
.chart .axis text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .baseline { stroke: var(--line-2); stroke-width: 1; }
.chart .x-label { font-size: 11px; fill: var(--muted); }
.chart .bar-val { font-size: 11px; font-weight: 650; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart .med-label { font-size: 11px; font-weight: 650; fill: var(--ink-2); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.chart .bar { transition: opacity .15s; }
.chart:has(.bar.hover) .bar:not(.hover) { opacity: .45; }
.chart .hit { cursor: crosshair; }
.chart .cross-line { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .trend-line { stroke-dasharray: 3000; stroke-dashoffset: 3000; animation: draw 1.4s .2s cubic-bezier(.4, 0, .2, 1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.mix { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.mix-row { display: grid; grid-template-columns: 96px 1fr 64px; align-items: center; gap: 10px; font-size: 13px; }
.mix-l { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.mix-l i { width: 10px; height: 10px; border-radius: 3px; }
.mix-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.mix-track span { display: block; height: 100%; border-radius: 99px; }
.mix-v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.mix-v em { color: var(--muted); font-weight: 500; margin-left: 4px; }

.table-wrap { overflow-x: auto; margin-top: 10px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
table.data th { text-align: left; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line-2); }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); }

/* before/after cards */
.cmp-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-top: 6px; }
.cmp { border: 1px solid var(--line); border-radius: 14px; padding: 16px; background: #fff; position: relative; overflow: hidden; }
.cmp::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); }
.cmp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cmp-head > i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.delta { margin-left: auto; font-weight: 700; font-size: 13px; padding: 3px 10px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.delta.better { background: #DDEFE3; color: var(--good); }
.delta.worse { background: #F7DADF; color: var(--bad); }
.delta.flat { background: var(--surface-2); color: var(--ink-2); }
.cmp-grid { display: grid; grid-template-columns: 1fr 28px 1fr; gap: 10px; align-items: center; }
.cmp-grid > div:not(.arrow) { display: flex; flex-direction: column; gap: 2px; }
.cmp-grid .lbl { font-size: 11.5px; font-weight: 650; color: var(--muted); letter-spacing: .03em; }
.cmp-grid .big { font-family: var(--display); font-size: 34px; font-weight: 350; letter-spacing: -.03em; line-height: 1.05; }
.cmp-grid .unit { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.cmp-grid .arrow { color: var(--line-2); display: grid; place-items: center; }
.cmp-bar { display: flex; gap: 1.5px; height: 6px; border-radius: 99px; overflow: hidden; margin-bottom: 6px; }
.cmp-bar .rest { background: var(--surface-2); }
.verdict { margin-top: 12px; font-size: 13.5px; font-weight: 600; display: flex; gap: 6px; flex-wrap: wrap; }
.verdict.better { color: var(--good); } .verdict.worse { color: var(--bad); } .verdict.flat { color: var(--ink-2); }
.verdict .muted { font-weight: 400; }

/* ── Treatments ────────────────────────────────────────────────────── */
.sec-title { font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 650; margin: 26px 0 12px; }
.med-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(460px, 100%), 1fr)); gap: 18px; }
.med-card { border-top: 4px solid var(--c); }
.med-top { display: flex; justify-content: space-between; gap: 12px; }
.med-id { display: flex; gap: 12px; align-items: center; }
.med-swatch { width: 40px; height: 40px; border-radius: 12px; background: var(--c); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .35); flex: none; }
.med-id h3 { font-family: var(--display); font-weight: 450; font-size: 23px; letter-spacing: -.02em; line-height: 1.1; }
.med-actions { display: flex; gap: 6px; align-items: flex-start; }
.med-dates { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--ink-2); margin: 14px 0 10px; }
.med-notes { font-size: 13.5px; color: var(--ink-2); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.med-card .cmp { background: var(--surface); }
.med-card .cmp::before { display: none; }
.cmp-title { display: none; font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.med-card .cmp-head > i, .med-card .cmp-head > b, .med-card .cmp-head > .muted { display: none; }
.med-card .cmp-head .cmp-title { display: inline; }
.med-actions .btn { white-space: nowrap; }
.empty { text-align: center; padding: 56px 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty p { max-width: 520px; }
.empty-ico { width: 44px; height: 44px; color: var(--p2); stroke-width: 1.4; }
.empty h3 { font-family: var(--display); font-weight: 400; font-size: 28px; }

/* ── Dialog, forms, toast, tooltip ─────────────────────────────────── */
.dialog { margin: auto; border: 0; border-radius: 22px; background: var(--surface); color: var(--ink); width: min(520px, calc(100% - 24px)); box-shadow: 0 40px 80px -30px rgba(40, 20, 10, .5); }
.dialog::backdrop { background: rgba(30, 22, 16, .38); backdrop-filter: blur(4px); }
.dialog[open] { animation: rise .3s cubic-bezier(.2, .8, .2, 1); }
.dlg { padding: 26px; display: flex; flex-direction: column; gap: 14px; }
.dlg h3 { font-family: var(--display); font-weight: 400; font-size: 28px; letter-spacing: -.02em; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.dlg-foot.spread { justify-content: space-between; }
.dlg-foot span { display: flex; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.field > span em { font-weight: 400; }
.field textarea { resize: vertical; min-height: 60px; font-size: 14px; font-weight: 400; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.custom-range { display: none; }
.custom-range.show { display: grid; }
.swatches { display: flex; gap: 10px; }
.swatches input { position: absolute; opacity: 0; }
.swatches i { display: block; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; transition: transform .15s; }
.swatches input:checked + i { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--ink); }
.swatches input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 4px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-weight: 500; }
.checks label { display: flex; gap: 8px; align-items: center; }
.checks input { accent-color: var(--p3); width: 16px; height: 16px; }
.form-err { color: var(--p3); font-size: 13px; min-height: 0; }
.form-err:empty { display: none; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--ink); color: var(--surface); padding: 11px 18px; border-radius: 99px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s cubic-bezier(.2, .8, .2, 1); z-index: 60; box-shadow: 0 16px 30px -12px rgba(0, 0, 0, .5); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--p3); }
.tooltip { position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none; background: var(--ink); color: var(--surface); padding: 10px 12px; border-radius: 12px; font-size: 12.5px; min-width: 150px; max-width: 260px; opacity: 0; transition: opacity .12s; box-shadow: 0 14px 30px -12px rgba(0, 0, 0, .55); }
.tooltip.on { opacity: 1; }
.tooltip b { font-weight: 600; color: #CFC5B8; font-size: 12px; }
.tooltip .tt-big { font-family: var(--display); font-size: 18px; margin: 2px 0 6px; }
.tooltip .tt-note { font-style: italic; color: #E6DDD0; margin-bottom: 6px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; margin-top: 3px; }
.tooltip .tt-row i { width: 9px; height: 9px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .25); }
.tooltip .tt-row span { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 650; }

.report { display: none; }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  #print-btn span { display: none; }
  #print-btn { width: 38px; padding: 0; justify-content: center; }
  .topbar { gap: 12px; }
  .cal-layout { grid-template-columns: 1fr; }
  .cal-side { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tile.hero { grid-column: span 3; }
  .ins-row { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { font-size: 14.5px; }
  /* no backdrop-filter here: it would become the containing block of the fixed bottom tab bar */
  .topbar { padding: 10px 14px; backdrop-filter: none; background: rgba(246, 241, 233, .97); }
  .brand { font-size: 18px; }
  .tabs { position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 30; justify-content: space-between; background: rgba(30, 26, 23, .92); backdrop-filter: blur(10px); border: 0; box-shadow: 0 14px 30px -10px rgba(0, 0, 0, .5); }
  .tabs button { flex: 1; flex-direction: column; gap: 3px; padding: 8px 4px; font-size: 11px; color: #BDB2A4; justify-content: center; }
  .tabs button svg { width: 19px; height: 19px; }
  .tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); }
  #print-btn span { display: none; }
  #print-btn { width: 38px; padding: 0; justify-content: center; }
  .views { padding-bottom: 110px; }
  .card { padding: 18px; border-radius: 16px; }
  .cal-main { padding: 18px 12px 16px; }
  .cal-head { flex-direction: column; align-items: flex-start; }
  .grid, .weekdays { gap: 4px; }
  .weekdays span { padding-left: 4px; font-size: 10px; letter-spacing: .06em; }
  .cell { border-radius: 10px; padding: 5px 6px; aspect-ratio: 1 / 1.08; }
  .cell .num { font-size: 14px; }
  .cell.today .num::after { display: none; }
  .cell .dots { left: 6px; bottom: 7px; }
  .cell .dots i { width: 4px; height: 4px; }
  .cell .lvl-num { right: 5px; bottom: 2px; }
  .cell .note-dot { top: 6px; right: 6px; }
  .cell .pill-start { width: 15px; height: 15px; top: 4px; right: 4px; }
  .cell .pill-start svg { width: 8px; height: 8px; }
  .lg-hint { display: none; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile.hero { grid-column: span 2; }
  .tile .big { font-size: 36px; }
  .year-stats { grid-template-columns: 1fr 1fr; }
  .filters { align-items: stretch; width: 100%; }
  .seg-pills { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .seg-pills button { white-space: nowrap; padding: 7px 12px; }
  .chart-head .link-btn { white-space: nowrap; }
  .med-grid { grid-template-columns: 1fr; }
  .cmp-list { grid-template-columns: 1fr; }
  .keypad { grid-template-columns: repeat(3, 70px); gap: 12px 20px; }
  .keypad button { width: 70px; height: 70px; }
  .checks { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .chart .trend-line { stroke-dashoffset: 0; }
}
