/* ADHD Tracker — Direction A "Calm": warm porcelain, dusty lavender, rounded and soft.
   Same bones in both themes; only the tokens change. */

:root {
    --bg: #fbf9f6;
    --paper: #ffffff;
    --line: #ece7e0;
    --ink: #2b2a33;
    --dim: #837f92;
    --accent: #8b7fd1;      /* dusty lavender */
    --accent-contrast: #ffffff;
    --cellfill: #8b7fd1;
    --work: #7f9bd1; --health: #7fa88c; --home: #d9ab5f; --social: #cf82a8;
    --must: #d97a6a; --should: #d9ab5f; --want: #7fa88c;
    --danger: #d96a5f;
    --radius: 14px;
    --radius-lg: 18px;
    --shadow: 0 6px 20px rgba(60, 50, 90, .06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12111a;
        --paper: #1c1a28;
        --line: #2e2b3e;
        --ink: #eceaf5;
        --dim: #9a93b3;
        --accent: #a79bf0;
        --accent-contrast: #12111a;
        --cellfill: #a79bf0;
        --work: #8fa9e8; --health: #8bc4a0; --home: #e8bf7a; --social: #e096bd;
        --must: #ef8f7e; --should: #e8bf7a; --want: #8bc4a0;
        --danger: #ef8f7e;
        --shadow: 0 6px 20px rgba(0, 0, 0, .25);
    }
}

/* Explicit override from the in-app theme toggle — wins over the OS preference either way. */
:root[data-theme="dark"] {
    --bg: #12111a; --paper: #1c1a28; --line: #2e2b3e; --ink: #eceaf5; --dim: #9a93b3;
    --accent: #a79bf0; --accent-contrast: #12111a; --cellfill: #a79bf0;
    --work: #8fa9e8; --health: #8bc4a0; --home: #e8bf7a; --social: #e096bd;
    --must: #ef8f7e; --should: #e8bf7a; --want: #8bc4a0; --danger: #ef8f7e;
    --shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
:root[data-theme="light"] {
    --bg: #fbf9f6; --paper: #ffffff; --line: #ece7e0; --ink: #2b2a33; --dim: #837f92;
    --accent: #8b7fd1; --accent-contrast: #ffffff; --cellfill: #8b7fd1;
    --work: #7f9bd1; --health: #7fa88c; --home: #d9ab5f; --social: #cf82a8;
    --must: #d97a6a; --should: #d9ab5f; --want: #7fa88c; --danger: #d96a5f;
    --shadow: 0 6px 20px rgba(60, 50, 90, .06);
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
    min-height: 100dvh;
}

a { color: inherit; }

/* ---------- responsive shell ---------- */
.shell { display: block; }
.sidebar, .rail { display: none; }
.center { display: flex; flex-direction: column; min-height: 100dvh; }

main {
    flex: 1;
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
    padding: 0 16px calc(84px + env(safe-area-inset-bottom));
}

.topbar { display: none; }

@media (min-width: 900px) {
    .shell {
        display: grid;
        grid-template-columns: 224px minmax(0, 1fr) 272px;
        max-width: 1280px;
        margin: 0 auto;
        min-height: 100dvh;
    }
    .tabbar { display: none !important; }
    .mobile-only { display: none !important; }
    main { padding-bottom: 40px; max-width: 660px; }
    .sidebar {
        display: flex; flex-direction: column;
        border-right: 1px solid var(--line);
        background: var(--paper);
        padding: 22px 0;
        position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    }
    .rail {
        display: block;
        border-left: 1px solid var(--line);
        background: var(--paper);
        padding: 24px 18px;
        position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    }
}

/* ---------- header (serif italic date — the identity) ---------- */
.apphead { padding: 22px 0 10px; margin-bottom: 4px; }
.apphead .day { font-size: .7rem; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); }
.apphead .day a { color: var(--dim); text-decoration: none; }
.apphead .date { font-weight: 800; font-size: 1.55rem; letter-spacing: -.01em; }
.apphead .area-tint { color: var(--area, var(--ink)); }
.title-input {
    display: block; width: 100%; border: none; background: none; padding: 2px 0; margin: 0;
    font-family: inherit; font-weight: 800; font-size: 1.55rem; letter-spacing: -.01em; color: var(--ink);
    border-bottom: 2px solid transparent;
}
.title-input:focus { outline: none; border-bottom-color: var(--accent); }
.title-input::placeholder { color: var(--dim); font-weight: 700; }
.week-nav { display: flex; gap: 12px; align-items: baseline; }
.week-nav a { font-size: 1.1rem; text-decoration: none; color: var(--accent); }

/* ---------- budget cells ---------- */
.budget { display: flex; gap: 8px; align-items: center; padding: 12px 0 4px; }
.budget .lbl { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); min-width: 34px; }
.budget .cells { display: flex; gap: 4px; flex-wrap: wrap; }
.budget .cell { width: 22px; height: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 3px; }
.budget .cell.f { background: var(--cellfill); border-color: var(--cellfill); }
.budget .cell.warn { background: var(--should); border-color: var(--should); }
.budget .cell.hot { background: var(--must); border-color: var(--must); }
.budget .frac { margin-left: auto; font-size: .78rem; font-variant-numeric: tabular-nums; color: var(--dim); white-space: nowrap; }
.budget.over .frac { color: var(--must); font-weight: 700; }

/* ---------- section labels ---------- */
.sect {
    font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--dim);
    padding: 18px 2px 6px; display: flex; justify-content: space-between; align-items: baseline;
}
.sect .wip { font-weight: 700; letter-spacing: .02em; text-transform: none; }
.sect .wip.hot { color: var(--must); }

/* ---------- task rows ---------- */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
    display: flex; align-items: center; gap: 10px;
    height: 60px;
    padding: 0 12px 0 14px;
    background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.row.off { opacity: .55; }
.row.started { box-shadow: inset 0 0 0 1.5px var(--accent); border-radius: var(--radius); }
.tick { position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; }

.box {
    width: 19px; height: 19px; flex-shrink: 0;
    border: 2px solid var(--line); border-radius: 50%;
    background: transparent; cursor: pointer; padding: 0;
}
.box.done { background: var(--accent); border-color: var(--accent); position: relative; }
.box.done::after { content: "✓"; color: var(--accent-contrast); position: absolute; inset: 0; display: grid; place-items: center; font-size: .7rem; }

/* Fixed row height means content must clip, not wrap-and-grow — every row stays the same size
   regardless of how long the task name or how many meta badges it has. */
.r-body { flex: 1; min-width: 0; text-decoration: none; overflow: hidden; }
.r-name {
    display: block; font-weight: 600; font-size: .92rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.r-name.strike { text-decoration: line-through; color: var(--dim); font-weight: 500; }
.r-meta {
    display: flex; gap: 8px; flex-wrap: nowrap; overflow: hidden;
    font-size: .7rem; color: var(--dim); margin-top: 1px; white-space: nowrap;
}
.r-meta > span { flex-shrink: 0; }
.r-meta > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.mot { font-weight: 700; font-size: .64rem; letter-spacing: .08em; text-transform: uppercase; }
.mot.must { color: var(--must); }
.mot.should { color: var(--should); }
.mot.want { color: var(--want); }
.due { color: var(--must); }

/* Truncated text (.r-name / .project-name) auto-scrolls back and forth to reveal what the ellipsis
   hid, instead of being a dead end. JS (marquee.js) measures overflow and flips on .marquee-active +
   sets --marquee-shift/--marquee-duration; CSS-only until then (plain ellipsis). */
.r-name.marquee-active, .project-name.marquee-active { text-overflow: clip; }
.r-name .marquee-text, .project-name .marquee-text { display: inline-block; }
.r-name.marquee-active .marquee-text, .project-name.marquee-active .marquee-text {
    animation: marquee-bounce var(--marquee-duration, 6s) ease-in-out infinite;
    animation-delay: .8s;
}
@keyframes marquee-bounce {
    0%, 12% { transform: translateX(0); }
    45%, 58% { transform: translateX(var(--marquee-shift, 0)); }
    92%, 100% { transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
    .r-name.marquee-active .marquee-text, .project-name.marquee-active .marquee-text { animation: none; }
}
.est { font-size: .74rem; color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.est.live { color: var(--accent); font-weight: 700; }

.startbtn {
    background: none; border: 1.5px solid var(--line); border-radius: 10px;
    color: var(--dim); width: 28px; height: 28px; cursor: pointer; font-size: .8rem;
}
.startbtn:hover { color: var(--accent); border-color: var(--accent); }
.stopbtn { font-size: .68rem; }
.stopbtn:hover { color: var(--must); border-color: var(--must); }

.later-fold {
    display: flex; justify-content: space-between; align-items: center;
    border: 1.5px dashed var(--line); border-radius: var(--radius);
    padding: 11px 14px; margin-top: 16px;
    font-size: .84rem; color: var(--dim); text-decoration: none;
}
.later-fold b { color: var(--ink); }

.later-item {
    background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.later-item .row { border: none; box-shadow: none; border-radius: 0; background: transparent; }
.later-actions { display: flex; justify-content: space-between; align-items: center; padding: 0 14px 10px 46px; }
.later-actions .age { font-size: .7rem; color: var(--dim); }

/* ---------- goals ---------- */
.goalhead { display: flex; align-items: baseline; gap: 10px; padding: 18px 2px 6px; }
.goalhead .g-name { font-weight: 700; font-size: .94rem; }
.goalhead .g-name.muted { color: var(--dim); font-weight: 600; }
.goalhead .g-frac { font-size: .72rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.goalhead .g-del { margin-left: auto; }
.goalhead.today .g-name { color: var(--accent); }
.g-underline { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 0 2px 8px; }
.g-underline i { display: block; height: 100%; background: var(--accent); }

/* ---------- areas ---------- */
.area-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 14px; }
.area-card {
    background: linear-gradient(155deg, color-mix(in srgb, var(--area) 12%, var(--paper)), var(--paper) 65%);
    border: 1px solid color-mix(in srgb, var(--area) 30%, var(--line));
    border-radius: var(--radius-lg); padding: 16px 14px; text-decoration: none;
    box-shadow: var(--shadow);
}
.area-card .a-name { display: block; font-weight: 700; font-size: 1rem; }
.area-card .a-meta { font-size: .72rem; color: var(--dim); }

.addbar { display: flex; gap: 10px; margin-top: 20px; align-items: flex-start; }
.newgoal summary { list-style: none; cursor: pointer; }
.newgoal summary::-webkit-details-marker { display: none; }
.newgoal .form { margin-top: 10px; background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius-lg); padding: 14px; }
.newgoal .form input[type="text"] { margin-bottom: 8px; }

/* ---------- habits ---------- */
.habitline { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 0; }
.hpill {
    border: 1.4px solid var(--dim); border-radius: 20px; padding: 6px 13px;
    font-size: .8rem; font-weight: 600; background: var(--paper); color: var(--ink); cursor: pointer;
}
.hpill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.hpill small { font-weight: 400; opacity: .75; }

.habit-card { margin-top: 12px; }
.habit-card .habit-name { font-weight: 700; }
.habit-week { display: flex; gap: 6px; margin-top: 10px; }
.day-dot {
    width: 34px; height: 34px; border-radius: 50%;
    border: 1.5px solid var(--line); background: var(--bg); color: var(--dim);
    font-size: .68rem; cursor: pointer;
}
.day-dot.on { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.habit-delete { text-align: right; margin-top: 6px; }
.streak { font-size: .8rem; color: var(--should); }

/* ---------- mood ---------- */
.mood-strip { display: flex; gap: 6px; padding: 8px 0; }
.mood-strip form { flex: 1; }
.mood-btn {
    width: 100%; text-align: center; font-size: 1.25rem; padding: 7px 0;
    background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
    cursor: pointer; filter: grayscale(.85);
}
.mood-btn.on { filter: none; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.mood-bars { display: flex; gap: 3px; align-items: flex-end; height: 70px; }
.mood-bar { flex: 1; height: 100%; display: flex; align-items: flex-end; background: var(--bg); border-radius: 3px; overflow: hidden; }
.mood-bar .fill { width: 100%; background: var(--accent); border-radius: 3px; }

/* ---------- sidebar (desktop) ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 1rem; padding: 0 20px 16px; } .brand .neuron-slot { width: 30px; flex-shrink: 0; color: var(--accent); }
.snav { display: flex; flex-direction: column; }
.snav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 20px; font-size: .87rem; font-weight: 600;
    color: var(--dim); text-decoration: none;
}
.snav a:hover { color: var(--ink); }
.snav svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.s-sect { font-size: .64rem; letter-spacing: .13em; text-transform: uppercase; color: var(--dim); padding: 20px 20px 6px; }
.s-area {
    display: flex; align-items: center; gap: 9px;
    padding: 6px 20px; font-size: .86rem; font-weight: 600;
    color: var(--ink); text-decoration: none;
}
.s-area .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.s-area .n { margin-left: auto; font-size: .7rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.s-goal { display: block; padding: 3px 20px 3px 37px; font-size: .78rem; color: var(--dim); text-decoration: none; }
.s-goal:hover { color: var(--ink); }
.s-bottom { margin-top: auto; padding: 16px 20px 0; font-size: .82rem; }
.s-bottom a { color: var(--dim); text-decoration: none; }

/* ---------- rail (desktop) ---------- */
.rail h3 { font-size: .66rem; letter-spacing: .13em; text-transform: uppercase; color: var(--dim); margin: 20px 0 6px; }
.rail h3:first-child { margin-top: 0; }
.rail .hint { font-size: .74rem; }

/* ---------- mobile tab bar ---------- */
.tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    display: flex; justify-content: space-around;
    background: var(--paper); border-top: 1px solid var(--line);
    padding: 7px 4px calc(7px + env(safe-area-inset-bottom));
}
.tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: .62rem; font-weight: 600; color: var(--dim);
    text-decoration: none; min-width: 54px; padding: 3px 2px;
}
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- generic UI ---------- */
.panel { background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius-lg); padding: 16px; margin: 14px 0; box-shadow: var(--shadow); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.med-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.med-head form { display: contents; }

/* A row of small text actions (mark taken / reminders / refilled / +time / delete) that used to have
   no layout rule at all and stacked as bare block-level forms — now a wrapping chip row instead. */
.row-actions {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
    margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
}
.row-actions > form { display: contents; }
.row-actions > .inline-edit[open] { flex-basis: 100%; margin-top: 6px; }

.banner { border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; font-size: .88rem; border: 1.5px solid; }
.banner.warn { color: var(--must); border-color: var(--must); background: color-mix(in srgb, var(--must) 8%, var(--paper)); }
.banner.ok { color: var(--health); border-color: var(--health); background: color-mix(in srgb, var(--health) 8%, var(--paper)); }

.empty { color: var(--dim); text-align: center; padding: 14px 0; }
.empty.small { padding: 8px 2px; font-size: .84rem; text-align: left; }
.hint { color: var(--dim); font-size: .82rem; margin: 8px 0 0; }
.hint a { color: var(--accent); }

.btn {
    display: inline-block; background: var(--accent); color: var(--accent-contrast);
    border: none; border-radius: var(--radius); padding: 12px 18px;
    font-size: .92rem; font-weight: 700; text-align: center; text-decoration: none;
    cursor: pointer; margin: 8px 0;
}
.btn.ghost { background: var(--paper); color: var(--ink); border: 1.4px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1.4px solid var(--danger); }
.btn.wide { display: block; width: 100%; }

.link { background: none; border: none; color: var(--accent); font-size: .82rem; cursor: pointer; padding: 4px 0; text-decoration: none; }
.link.danger { color: var(--danger); }

/* ---------- forms ---------- */
input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], select, textarea {
    width: 100%;
    background: var(--bg);
    color: var(--ink);
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    font: inherit;
}
@media (prefers-color-scheme: dark) {
    input, select, textarea { color-scheme: dark; }
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.form .field { display: block; margin-bottom: 12px; min-width: 0; }
.form .field .label { display: block; margin-bottom: 4px; }
.field-pair { display: flex; gap: 10px; }
.field-pair .field { flex: 1; }
.label { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }

.seg { display: flex; gap: 8px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; width: 0; }
.seg span {
    display: block; text-align: center;
    background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px;
    padding: 9px 4px; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.seg input:checked + span.m-must { background: var(--must); border-color: var(--must); color: #fff; }
.seg input:checked + span.m-should { background: var(--should); border-color: var(--should); color: #fff; }
.seg input:checked + span.m-want { background: var(--want); border-color: var(--want); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.qa-context { margin: 2px 0 14px; }
.qa-context .chips { padding: 0 0 8px; }
.qa-context .chip-filter { background: none; border: none; cursor: pointer; font: inherit; }
.qa-panel { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 0 0; }
.qa-panel select { width: auto; flex: 1; min-width: 140px; }
.qa-panel .label { flex-shrink: 0; }
.qa-panel.qa-health { gap: 14px; }
.qa-panel.qa-social .habitline { padding: 4px 0 0; }

.quickadd { display: flex; gap: 8px; margin: 14px 0 4px; }
.quickadd button {
    flex: 0 0 46px; background: var(--accent); color: var(--accent-contrast);
    border: none; border-radius: var(--radius); font-size: 1.3rem; cursor: pointer;
}

.area-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.area-row input[type="color"] { flex: 0 0 36px; width: 36px; height: 36px; padding: 2px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg); }
.area-row input[type="text"] { flex: 1; }
.area-row .link { flex-shrink: 0; }

.more-list { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; }
.more-link {
    display: flex; justify-content: space-between;
    background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius-lg);
    padding: 14px; font-weight: 600; text-decoration: none;
}
.more-link span { color: var(--dim); }
.logout { margin-top: 28px; }
.danger-zone { margin-top: 22px; }

/* ---------- area dashboard (stat strip + big project/goal cards) ---------- */
.stat-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 0 4px; }
.stat-chip {
    font-size: .78rem; padding: 6px 12px; border-radius: 20px;
    background: color-mix(in srgb, var(--dim) 12%, var(--paper));
    color: var(--dim); border: 1px solid var(--line);
}
.stat-chip b { color: var(--ink); font-weight: 700; }
.stat-chip.started { background: color-mix(in srgb, var(--accent) 16%, var(--paper)); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.stat-chip.started b { color: var(--accent); }
.stat-chip.waiting b { color: var(--should); }

.project-grid { display: grid; grid-template-columns: 1fr; gap: 12px; padding-top: 4px; }
@media (min-width: 640px) {
    .project-grid { grid-template-columns: 1fr 1fr; }
}

.project-card {
    display: flex; gap: 14px; align-items: center;
    height: 84px;
    background: linear-gradient(155deg, color-mix(in srgb, var(--area) 10%, var(--paper)), var(--paper) 60%);
    border: 1px solid color-mix(in srgb, var(--area) 30%, var(--line));
    border-radius: 14px; padding: 16px;
    text-decoration: none; color: inherit;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.project-ring {
    flex-shrink: 0; width: 52px; height: 52px; border-radius: 50%;
    background: conic-gradient(var(--area) var(--p), color-mix(in srgb, var(--area) 16%, var(--paper)) 0);
    display: grid; place-items: center;
}
.project-ring i {
    width: 40px; height: 40px; border-radius: 50%; background: var(--paper);
    display: grid; place-items: center; font-style: normal; font-size: .68rem; font-weight: 800; color: var(--ink);
}
.project-body { display: flex; flex-direction: column; justify-content: center; gap: 3px; min-width: 0; height: 100%; }
.project-name, .project-meta {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.project-name { font-weight: 700; font-size: 1rem; }
.project-meta { font-size: .74rem; color: var(--dim); }

/* ---------- area modules (people / health / project detail) ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.chip-filter {
    flex-shrink: 0; color: var(--dim); background: var(--paper);
    border: 1px solid var(--line); border-radius: 20px;
    padding: 6px 14px; font-size: .84rem; font-weight: 600; text-decoration: none;
}
.chip-filter.on { color: #fff; background: var(--chip, var(--accent)); border-color: var(--chip, var(--accent)); }

.g-link { text-decoration: none; color: inherit; }
.a-kind { display: inline-block; margin-top: 6px; font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: var(--area); }

.person-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 4px; }
@media (min-width: 640px) {
    .person-grid { grid-template-columns: 1fr 1fr 1fr; }
}
.person-card {
    display: flex; flex-direction: column; gap: 3px;
    background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius-lg);
    padding: 14px; text-decoration: none; color: inherit;
}
.person-card.overdue { border-color: color-mix(in srgb, var(--must) 45%, var(--line)); background: color-mix(in srgb, var(--must) 6%, var(--paper)); }
.person-summary.overdue { box-shadow: inset 3px 0 0 var(--must); }
.highlight-add { margin: 10px 0; }

.person.overdue { box-shadow: inset 3px 0 0 var(--must); }
.inline-edit summary { list-style: none; cursor: pointer; }
.inline-edit summary::-webkit-details-marker { display: none; }
.inline-edit .form, .inline-edit .quickadd { margin-top: 10px; }
.inline-edit .form input[type="text"] { margin-bottom: 8px; }

.done-fold summary { color: var(--dim); font-size: .84rem; cursor: pointer; padding: 10px 0 6px; }

.notes-fold summary.sect-inline {
    font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
    color: var(--dim); cursor: pointer; list-style: none;
}
.notes-fold summary::-webkit-details-marker { display: none; }
.notes-fold textarea { margin: 10px 0 8px; }

.timeline { border-left: 2px solid var(--line); margin: 10px 0 0 6px; padding-left: 14px; display: grid; gap: 10px; }
.tl-entry { display: flex; gap: 10px; align-items: baseline; position: relative; }
.tl-entry::before {
    content: ""; position: absolute; left: -19px; top: 5px;
    width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.tl-entry.system::before { background: var(--dim); }
.tl-entry.system .tl-text { color: var(--dim); font-size: .82rem; }
.tl-source { color: var(--accent); font-weight: 700; margin-right: 3px; }

.crumbs { font-size: .68rem; color: var(--dim); display: flex; gap: 4px; flex-wrap: wrap; margin: 2px 0; }
.crumbs a { color: var(--dim); text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }

.sect { position: relative; }
.timeline-toggle { font-size: .68rem; color: var(--accent); text-decoration: none; font-weight: 600; text-transform: none; letter-spacing: 0; }
.tl-date { flex-shrink: 0; font-size: .7rem; color: var(--dim); font-variant-numeric: tabular-nums; min-width: 46px; }
.tl-text { flex: 1; font-size: .88rem; }
.tl-entry .link { padding: 0; }

.med-times { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.med-times form { display: contents; }
.med-times button {
    background: var(--bg); border: 1px solid var(--line); border-radius: 20px;
    padding: 5px 11px; font-size: .74rem; color: var(--dim); cursor: pointer;
}

.weight-bars { margin-top: 10px; }
.weight-bars .fill { background: var(--health); }

.kind-select { flex: 0 0 96px; width: 96px; }

input[type="file"] {
    width: 100%; color: var(--dim); font-size: .85rem;
    background: var(--bg); border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 10px;
}

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 20px; background: var(--bg); color: var(--ink); font: 15px/1.5 "Segoe UI", system-ui, sans-serif; }
.login-box { width: 100%; max-width: 320px; text-align: center; }
.login-box .date { font-weight: 800; font-size: 1.4rem; margin-bottom: 18px; }
.login-box input { margin-bottom: 10px; text-align: center; font-size: 1.15rem; }

@media (prefers-reduced-motion: no-preference) {
    .hpill, .box, .mood-btn, .startbtn { transition: background .12s, border-color .12s, color .12s; }
}


/* ---------- brain logo mark ---------- */
.neuron-slot { display: block; }
.neuron-mark { display: block; width: 100%; height: auto; overflow: visible; color: var(--accent); }
.neuron-mark .brain-outline { fill: color-mix(in srgb, currentColor 8%, transparent); stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: .92; }
.neuron-mark .edge { fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; opacity: .4; }
.neuron-mark .edge-pulse { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; opacity: 0; stroke-dasharray: 10 220; stroke-dashoffset: 10; }
.neuron-mark .node { fill: currentColor; opacity: .7; transform-origin: center; transform-box: fill-box; }
@media (prefers-reduced-motion: no-preference) {
    .neuron-mark.firing .edge-pulse { animation: pulseTravel .6s ease-out forwards; animation-delay: var(--d, 0s); }
    .neuron-mark.firing .node { animation: nodeBloom .5s ease-out forwards; animation-delay: var(--d, 0s); }
    .neuron-mark.settled .node { animation: nodeBreathe 3.8s ease-in-out infinite; animation-delay: var(--d, 0s); }
}
@keyframes pulseTravel { 0% { opacity: 0; stroke-dashoffset: 10; } 12% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; stroke-dashoffset: -220; } }
@keyframes nodeBloom { 0% { opacity: .7; transform: scale(1); } 35% { opacity: 1; transform: scale(1.7); } 100% { opacity: .9; transform: scale(1); } }
@keyframes nodeBreathe { 0%, 100% { opacity: .65; } 50% { opacity: 1; } }

/* ---------- opening splash: neurons fire, then the app fades in ---------- */
.splash {
    position: fixed; inset: 0; z-index: 100;
    display: grid; place-items: center;
    background: var(--bg);
    transition: opacity .4s ease;
}
.splash.done { opacity: 0; pointer-events: none; }
.splash .neuron-slot { width: min(46vw, 190px); }
@media (prefers-reduced-motion: reduce) {
    .splash { display: none; }
}

/* ---------- custom pickers: motivation slider, date calendar, time wheel ---------- */
@property --mot-pct { syntax: '<percentage>'; inherits: true; initial-value: 50%; }

.mot-field { --mot-pct: 50%; }
.mot-slider-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.mot-slider-value { font-weight: 800; font-size: 1rem; }
.mot-range { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; margin: 2px 0; cursor: pointer; }
.mot-range::-webkit-slider-runnable-track {
    height: 9px; border-radius: 6px; transition: background .1s;
    background: linear-gradient(to right, var(--want) 0%, var(--should) 50%, var(--must) 100%);
}
.mot-range::-webkit-slider-thumb {
    -webkit-appearance: none; margin-top: -9.5px; width: 26px; height: 26px; border-radius: 50%;
    background: var(--paper); border: 4px solid var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.22);
}
.mot-range::-moz-range-track { height: 9px; border-radius: 6px; background: linear-gradient(to right, var(--want), var(--should), var(--must)); }
.mot-range::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--paper); border: 4px solid var(--accent); cursor: pointer; }
.mot-ticks { display: flex; justify-content: space-between; font-size: .7rem; color: var(--dim); margin-top: 2px; }

.conc-form { margin-top: 4px; }
.conc-range { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; margin: 2px 0; cursor: pointer; }
.conc-range::-webkit-slider-runnable-track {
    height: 9px; border-radius: 6px;
    background: linear-gradient(to right, color-mix(in srgb, var(--accent) 22%, var(--paper)), var(--accent));
}
.conc-range::-webkit-slider-thumb {
    -webkit-appearance: none; margin-top: -9.5px; width: 26px; height: 26px; border-radius: 50%;
    background: var(--paper); border: 4px solid var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.22);
}
.conc-range::-moz-range-track { height: 9px; border-radius: 6px; background: linear-gradient(to right, color-mix(in srgb, var(--accent) 22%, var(--paper)), var(--accent)); }
.conc-range::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--paper); border: 4px solid var(--accent); cursor: pointer; }

.picker { position: relative; }
.picker-trigger {
    width: 100%; background: var(--paper); color: var(--ink); border: 1.5px solid var(--line);
    border-radius: var(--radius); padding: 12px 14px; font: inherit;
    display: flex; align-items: center; justify-content: space-between; cursor: pointer; text-align: left;
}
.picker-trigger svg { width: 15px; height: 15px; flex-shrink: 0; transition: transform .18s; fill: none; stroke: currentColor; stroke-width: 1.8; color: var(--dim); }
.picker.open .picker-trigger svg { transform: rotate(180deg); }
.picker-panel { display: none; margin-top: 8px; }
.picker.open .picker-panel { display: block; }
.picker-panel-inner { background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius-lg); padding: 10px; box-shadow: var(--shadow); }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head button { background: none; border: none; cursor: pointer; font-size: 1rem; line-height: 1; padding: 4px 8px; color: var(--ink); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; font-size: .8rem; }
.cal-grid .dow { font-size: .64rem; color: var(--dim); padding-bottom: 4px; }
.cal-grid button { border: none; background: none; cursor: pointer; padding: 7px 0; border-radius: 8px; font: inherit; color: var(--ink); }
.cal-grid button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.cal-grid button.sel { background: var(--accent); color: var(--accent-contrast); }
.cal-body .link.danger { display: block; text-align: center; margin-top: 6px; }

.time-quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.time-quick button {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    background: var(--paper); border: 1.5px solid var(--line); color: var(--ink);
    border-radius: var(--radius); padding: 10px 12px; cursor: pointer; font: inherit; text-align: left;
}
.time-quick button:hover { border-color: var(--accent); }
.time-quick button b { font-size: .84rem; }
.time-quick button span { font-size: .74rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.time-custom-link {
    display: inline-flex; align-items: center; gap: 5px; background: none; border: none; cursor: pointer;
    font: inherit; font-size: .82rem; font-weight: 600; color: var(--accent); padding: 10px 2px 0;
}
.time-custom-link svg { width: 11px; height: 11px; transition: transform .18s; fill: none; stroke: currentColor; stroke-width: 2; }
.time-custom-link.open svg { transform: rotate(90deg); }
.wheel-panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .2s ease; }
.wheel-panel > div { overflow: hidden; }
.time-custom-link.open + .wheel-panel { grid-template-rows: 1fr; }

.wheel-picker {
    position: relative; display: flex; gap: 4px; height: 160px; margin-top: 10px;
    -webkit-mask-image: linear-gradient(to bottom, transparent, #000 28%, #000 72%, transparent);
    mask-image: linear-gradient(to bottom, transparent, #000 28%, #000 72%, transparent);
}
.wheel-highlight {
    position: absolute; left: 0; right: 0; top: 60px; height: 40px; pointer-events: none; z-index: 1;
    border-radius: 10px; background: color-mix(in srgb, var(--accent) 9%, transparent);
    border-top: 1.5px solid var(--line); border-bottom: 1.5px solid var(--line);
}
.wheel-col { flex: 1; height: 160px; overflow-y: auto; scroll-snap-type: y mandatory; padding: 60px 0; scrollbar-width: none; -ms-overflow-style: none; }
.wheel-col::-webkit-scrollbar { display: none; }
.wheel-item {
    height: 40px; display: flex; align-items: center; justify-content: center; scroll-snap-align: center;
    font-size: 1.02rem; font-variant-numeric: tabular-nums; cursor: pointer; color: var(--dim);
    transition: color .1s, font-size .1s, font-weight .1s;
}
.wheel-item.sel { color: var(--accent); font-weight: 800; font-size: 1.22rem; }

/* ---------- advanced-options fold ---------- */
.adv-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: .84rem; font-weight: 700; border: none; background: none; padding: 8px 0; color: var(--accent); }
.adv-toggle svg { width: 12px; height: 12px; transition: transform .18s; fill: none; stroke: currentColor; stroke-width: 2; }
.adv-toggle.open svg { transform: rotate(90deg); }
.adv-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .22s ease; }
.adv-body > div { overflow: hidden; padding-top: 4px; }
.adv-toggle.open + .adv-body { grid-template-rows: 1fr; }

/* ---------- medication schedule picker (Hourly/Daily/Weekly/Custom) ---------- */
.freq-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.freq-grid button {
    border: 1.5px solid var(--line); background: var(--paper); color: var(--dim);
    border-radius: var(--radius); padding: 12px; cursor: pointer; text-align: left; font: inherit;
}
.freq-grid button b { display: block; font-size: .86rem; color: var(--ink); }
.freq-grid button span { font-size: .72rem; }
.freq-grid button.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--paper)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.freq-panels > div { display: none; margin-top: 10px; }
.freq-panels > div.active { display: block; }

/* Turbo's built-in navigation progress bar, tinted to match the app instead of browser-default blue. */
.turbo-progress-bar { background-color: var(--accent); height: 2px; }

/* ---------- modal (creations/edits/views load here instead of a full page navigation) ---------- */
/* Closing is via the page's own "‹ Back" link (already wired to close()), backdrop click, or Escape
   — no separate X, so there's no redundant control competing with Back for the same job. */
dialog.modal {
    border: none; border-radius: var(--radius-lg); padding: 0;
    width: min(560px, 92vw); max-height: 86vh;
    background: var(--paper); color: var(--ink);
    box-shadow: 0 24px 64px rgba(0,0,0,.28);
}
dialog.modal::backdrop { background: rgba(20, 14, 30, .5); backdrop-filter: blur(2px); }
dialog.modal .modal-body { padding: 0 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 86vh; }

/* The fetched page's own .form.panel card is redundant once it's already sitting inside the dialog's
   own card — strip it back to plain content so fields read as page body, not a card-in-a-card. */
dialog.modal .modal-body .form.panel {
    background: none; border: none; box-shadow: none; padding: 0; margin: 14px 0 0;
}

dialog.modal[open] { animation: modal-in .22s cubic-bezier(.2,.8,.3,1); }
dialog.modal[open]::backdrop { animation: modal-backdrop-in .22s ease; }
dialog.modal.closing { animation: modal-out .18s ease forwards; }
dialog.modal.closing::backdrop { animation: modal-backdrop-in .18s ease reverse forwards; }
@keyframes modal-in { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes modal-out { to { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes modal-backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
    dialog.modal[open], dialog.modal.closing, dialog.modal[open]::backdrop, dialog.modal.closing::backdrop { animation: none; }
}

/* On a small screen the modal IS the page — full-bleed, no floating-card chrome, no wasted margin. */
@media (max-width: 480px) {
    dialog.modal { width: 100vw; max-width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; margin: 0; }
    dialog.modal .modal-body { max-height: 100vh; }
}