/* Shared styles for every page. Loaded by shared/layout.php.
 *
 * Every colour comes from the tokens in :root below. Dark mode only swaps
 * the token values (further down), so components never need their own
 * dark-mode rules. Rule of thumb: never type a hex colour below the tokens.
 */

/* ========== design tokens: light (default) ========== */
:root {
    color-scheme: light;

    --bg: #f5f7f6;
    --surface: #ffffff;
    --surface-2: #eff3f2;          /* hover fills, progress tracks, subtle panels */
    --border: #e2e8e6;
    --border-strong: #cbd5d1;      /* inputs, buttons */
    --text: #17201d;
    --text-2: #45514d;             /* labels, secondary text */
    --muted: #6b7672;

    --accent: #0f766e;             /* teal: calm, "balance" */
    --accent-hover: #0c5f58;
    --accent-soft: #e2f3f0;
    --on-accent: #ffffff;          /* text on an accent background */
    --link: #0f766e;
    --brand-panel: #0f3d3a;        /* login brand side */

    --green: #15803d;  --green-soft: #e4f5e9;
    --amber: #b45309;  --amber-soft: #fdf3e2;
    --red:   #b42318;  --red-soft:   #fdecea;
    --orange: #c2410c; --blue: #1d4ed8; --purple: #6d28d9;   /* health entry types */

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
    --shadow-lg: 0 20px 50px rgba(16, 24, 40, .18);
    --focus: 0 0 0 3px rgba(15, 118, 110, .25);
    --radius: 14px;
    --radius-sm: 10px;

    /* charts: task status = one blue hue, light -> dark (ordinal: not done -> done) */
    --chart-todo: #93bdf0;
    --chart-progress: #3b87e3;
    --chart-done: #1a4f93;
    --chart-work: #2a78d6;
    --chart-grid: #e6eae8;
    --chart-axis: #c7cfcc;
    --chart-ink-muted: #7a8581;

    /* task types: categorical slots 1-4, same everywhere a type is shown */
    --type-school: #2a78d6;
    --type-work: #eb6834;
    --type-personal: #1baf7a;
    --type-relax: #eda100;
}

/* ========== design tokens: dark ==========
 * Two ways in: the toggle in the nav sets <html data-theme="dark">, or the
 * device prefers dark and the user hasn't forced light. Same values in both
 * blocks (CSS can't share one block between a selector and a media query).
 * Inside @media screen so printing / PDF always uses the light colours.
 */
@media screen {
    :root[data-theme="dark"] {
        color-scheme: dark;
        --bg: #0e1312; --surface: #161c1b; --surface-2: #1e2624; --border: #283230; --border-strong: #3a4743;
        --text: #e6edeb; --text-2: #c0cbc8; --muted: #8e9a96;
        --accent: #2bb3a3; --accent-hover: #43c6b6; --accent-soft: rgba(43, 179, 163, .14); --on-accent: #06201d;
        --link: #5fd6c6; --brand-panel: #0a2724;
        --green: #4ade80; --green-soft: rgba(74, 222, 128, .12);
        --amber: #fbbf24; --amber-soft: rgba(251, 191, 36, .12);
        --red: #f87171;   --red-soft: rgba(248, 113, 113, .12);
        --orange: #fb923c; --blue: #60a5fa; --purple: #a78bfa;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 1px 3px rgba(0, 0, 0, .5); --shadow-lg: 0 20px 50px rgba(0, 0, 0, .6);
        --focus: 0 0 0 3px rgba(43, 179, 163, .35);
        /* on a dark background the most important value (done) is the LIGHTEST */
        --chart-todo: #2f5f99; --chart-progress: #4f8fe0; --chart-done: #a5cbf6; --chart-work: #4f9cf0;
        --chart-grid: #252e2c; --chart-axis: #3a4743; --chart-ink-muted: #8e9a96;
        --type-school: #4f9cf0; --type-work: #f0834f; --type-personal: #34c48f; --type-relax: #f2b632;
    }
}
@media screen and (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0e1312; --surface: #161c1b; --surface-2: #1e2624; --border: #283230; --border-strong: #3a4743;
        --text: #e6edeb; --text-2: #c0cbc8; --muted: #8e9a96;
        --accent: #2bb3a3; --accent-hover: #43c6b6; --accent-soft: rgba(43, 179, 163, .14); --on-accent: #06201d;
        --link: #5fd6c6; --brand-panel: #0a2724;
        --green: #4ade80; --green-soft: rgba(74, 222, 128, .12);
        --amber: #fbbf24; --amber-soft: rgba(251, 191, 36, .12);
        --red: #f87171;   --red-soft: rgba(248, 113, 113, .12);
        --orange: #fb923c; --blue: #60a5fa; --purple: #a78bfa;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 1px 3px rgba(0, 0, 0, .5); --shadow-lg: 0 20px 50px rgba(0, 0, 0, .6);
        --focus: 0 0 0 3px rgba(43, 179, 163, .35);
        --chart-todo: #2f5f99; --chart-progress: #4f8fe0; --chart-done: #a5cbf6; --chart-work: #4f9cf0;
        --chart-grid: #252e2c; --chart-axis: #3a4743; --chart-ink-muted: #8e9a96;
        --type-school: #4f9cf0; --type-work: #f0834f; --type-personal: #34c48f; --type-relax: #f2b632;
    }
}

/* ========== base ========== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* so the hidden attribute wins over classes like .btn */
body {
    margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-underline-offset: 2px; }
h2 { margin-top: 0; letter-spacing: -.01em; }
h3 { letter-spacing: -.005em; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Inline SVG icons from icon() in layout.php */
.icon { width: 18px; height: 18px; flex: none; vertical-align: -3px; }

/* ========== top bar + main nav ========== */
.topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 60px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 17px; text-decoration: none; letter-spacing: -.01em; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--on-accent); font-size: 15px; font-weight: 800; }
.topbar .modules { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav-link { display: inline-flex; align-items: center; gap: 7px; padding: 8px 11px; border-radius: var(--radius-sm); color: var(--muted); font-size: 14px; font-weight: 500; text-decoration: none; white-space: nowrap; transition: background .15s, color .15s; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.topbar .soon { color: var(--muted); opacity: .6; cursor: default; }
.account { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.account-name { margin: 0 6px; white-space: nowrap; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; min-width: 36px; padding: 0 9px; border: 1px solid transparent; border-radius: var(--radius-sm); background: none; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
a.icon-btn { text-decoration: none; }               /* the Account link looks like the other top-bar buttons */
.icon-btn.active { background: var(--accent-soft); color: var(--accent); }
.logout-form { margin: 0; }

/* Theme toggle shows the icon of the mode you'd switch TO */
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .i-sun { display: inline; }
    :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}

/* Module sub-nav (pills) */
.subnav { display: flex; gap: 6px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.subnav a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 13.5px; font-weight: 500; white-space: nowrap; border: 1px solid var(--border); transition: background .15s, color .15s; }
.subnav a:hover { color: var(--text); background: var(--surface-2); }
.subnav a.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ========== layout ========== */
.container { max-width: 780px; margin: 28px auto; padding: 0 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.form-card { max-width: 460px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.form-card h2 { font-size: 22px; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.page-greeting h2 { font-size: 26px; margin: 0; }

/* ========== forms ========== */
label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-top: 14px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], textarea, select {
    width: 100%; padding: 10px 12px; margin-top: 6px; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* Radio "chips" (task type / load / health type): highlighted when chosen */
.chip-row { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.chip-row label { display: inline-flex; align-items: center; gap: 6px; margin-top: 0; padding: 7px 12px; font-size: 13px; color: var(--text-2); border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer; transition: background .15s, border-color .15s; }
.chip-row label:hover { background: var(--surface-2); }
.chip-row label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 500;
    text-decoration: none; text-align: center; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-block { display: flex; width: 100%; margin-top: 20px; }
.btn-danger { background: var(--red); border-color: var(--red); color: var(--surface); }
.btn-danger:hover { background: var(--red); border-color: var(--red); opacity: .9; }
.btn-row { display: flex; gap: 10px; margin-top: 20px; }
.btn-row > * { flex: 1; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }
.btn.is-disabled { opacity: .35; cursor: default; }
.btn:disabled { opacity: .6; cursor: wait; }

/* ========== messages ========== */
.alert { border-radius: var(--radius-sm); padding: 11px 14px; margin-bottom: 14px; font-size: 13.5px; border: 1px solid transparent; }
.alert-success { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 25%, transparent); }
.alert-warning { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.alert-error   { background: var(--red-soft);   border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.alert ul { margin: 0; padding-left: 18px; }
.hint { font-size: 12px; color: var(--green); margin-top: 6px; }

/* ========== logged-out pages: login / signup / password reset (render_auth_open()) ========== */
.auth { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.auth-brand {
    background: radial-gradient(circle at 20% 15%, rgba(255, 255, 255, .08), transparent 45%), var(--brand-panel);
    color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center;
}
.auth-brand-name { display: flex; align-items: center; gap: 10px; font-size: 30px; font-weight: 750; letter-spacing: -.02em; }
.auth-brand-name .brand-mark { width: 38px; height: 38px; font-size: 19px; background: #2bb3a3; color: #06201d; }
.auth-tagline { font-size: 17px; color: rgba(255, 255, 255, .72); margin: 10px 0 36px; max-width: 380px; line-height: 1.45; }
.auth-features { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 20px; max-width: 380px; }
.auth-features li { display: flex; gap: 12px; align-items: flex-start; }
.auth-features strong { display: block; font-size: 15px; }
.auth-features span:not(.auth-dot) { font-size: 13px; color: rgba(255, 255, 255, .6); }
.auth-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 20px; background: var(--surface); }
.auth-form { width: 100%; max-width: 380px; }
.auth-form h2 { margin-bottom: 4px; font-size: 26px; }
.auth-sub { margin: 0 0 20px; }
.auth-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 14px; font-size: 13px; }
.auth-row .check { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; cursor: pointer; }
.auth-switch { margin-top: 22px; }
.password-field { position: relative; }
.password-field input { padding-right: 64px; }   /* room for the Show button */
.password-toggle { position: absolute; right: 6px; top: calc(50% + 3px); transform: translateY(-50%); padding: 4px 9px; border: 0; border-radius: 6px; background: none; color: var(--muted); font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
.password-toggle:hover { background: var(--surface-2); color: var(--text); }
/* Signup honeypot: off-screen instead of display:none (some bots skip display:none fields) */
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
@media (max-width: 760px) {
    /* phones: brand becomes a short header above the form */
    .auth { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }   /* form panel fills the rest of the screen */
    .auth-brand { padding: 24px 20px; }
    .auth-tagline { margin: 6px 0 0; font-size: 14px; }
    .auth-features { display: none; }
    .auth-panel { align-items: flex-start; padding: 28px 20px; }
}

/* ========== pop-ups (<dialog>: task overlap / capacity warning, logout summary) ========== */
.modal { border: 1px solid var(--border); border-radius: 18px; padding: 24px; width: calc(100% - 32px); max-width: 420px; color: var(--text); background: var(--surface); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: rgba(5, 10, 9, .45); backdrop-filter: blur(2px); }   /* dims the page behind a showModal() pop-up */
.modal h3 { margin: 0 0 6px; font-size: 17px; }
.modal h3 + p, .modal ul { margin-top: 0; }
.modal * + h3 { margin-top: 16px; }
.modal ul { padding-left: 18px; font-size: 14px; }
.summary-group { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.summary-group .label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }

/* ========== cards, KPIs, lists (used everywhere) ========== */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.card .label { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; color: var(--muted); }
.card .label .icon { color: var(--accent); width: 17px; height: 17px; }
.card .value { font-size: 30px; font-weight: 650; margin: 6px 0 2px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.card .value small { font-size: 14px; font-weight: 400; }
.card-link { color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
.card-link:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: var(--shadow); transform: translateY(-1px); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.section-head h3 { margin: 0; font-size: 16px; }
.split-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 14px; }
.text-red { color: var(--red); font-weight: 600; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 500; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-2); background: var(--surface); }
.pill-important { border-color: color-mix(in srgb, var(--red) 40%, transparent);   color: var(--red);   background: var(--red-soft);   margin-left: 6px; }
.pill-overlap   { border-color: color-mix(in srgb, var(--amber) 40%, transparent); color: var(--amber); background: var(--amber-soft); margin-left: 6px; }
.pill-reached   { border-color: color-mix(in srgb, var(--green) 40%, transparent); color: var(--green); background: var(--green-soft); }
.pill-repeat    { border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent); background: var(--accent-soft); margin-left: 6px; }

/* "Task deleted. Undo" (shared/undo_helpers.php) */
.undo-flash { display: flex; align-items: center; gap: 10px; }
.link-btn { padding: 0; border: 0; background: none; color: var(--link); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }

/* Repeating tasks (add_task.php): the options only show while "Repeat weekly" is ticked */
.repeat-box { margin-top: 16px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.repeat-box > .check { display: flex; align-items: center; gap: 8px; margin: 0; cursor: pointer; }
.repeat-box:not(:has(#repeat:checked)) .repeat-fields { display: none; }
.series-box { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }
.series-box p { margin: 0 0 8px; }

/* ---------- fatigue dashboard ---------- */
.bars { display: flex; align-items: flex-end; gap: 16px; height: 120px; margin: 14px 4px 26px; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; font-size: 11.5px; color: var(--muted); }
.bar { width: 100%; border-radius: 6px 6px 2px 2px; }

/* ---------- task-style lists (tasks, work log, health) ---------- */
.task-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.task-main { min-width: 0; flex: 1; }
.task-title { color: var(--text); text-decoration: none; font-weight: 550; }
.task-title:hover { color: var(--accent); }
.task-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; align-items: center; margin-left: 12px; }
.move-form { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; }   /* overdue: reason + Today / Tomorrow */
.move-form select { width: auto; margin-top: 0; padding: 5px 8px; font-size: 13px; }
.task-actions select { width: auto; margin-top: 0; padding: 5px 8px; font-size: 13px; }
.task-row.is-done .task-title { text-decoration: line-through; color: var(--muted); }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs a { padding: 9px 12px; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 600; text-align: center; }

/* ---------- work log ---------- */
.cards-3 { grid-template-columns: repeat(3, 1fr); }
.month-nav { display: flex; align-items: center; gap: 10px; }

/* ---------- health journal ---------- */
.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.search-row input { margin-top: 0; flex: 1; }
.month-heading { margin: 22px 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.pill-symptom     { border-color: color-mix(in srgb, var(--orange) 40%, transparent); color: var(--orange); margin-right: 6px; }
.pill-medication  { border-color: color-mix(in srgb, var(--blue) 40%, transparent);   color: var(--blue);   margin-right: 6px; }
.pill-appointment { border-color: color-mix(in srgb, var(--purple) 40%, transparent); color: var(--purple); margin-right: 6px; }
.pill-allergy     { border-color: color-mix(in srgb, var(--red) 40%, transparent);    color: var(--red);    margin-right: 6px; }
.pill-note        { margin-right: 6px; }
/* Health entry form: the time field only shows while "Appointment" is picked */
form:not(:has(input[name=entry_type][value=appointment]:checked)) .appt-time { display: none; }

/* ---------- finance goals ---------- */
.goal-card { margin-bottom: 14px; }
.goal-card.is-reached { opacity: .75; }
.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.progress-fill { height: 100%; background: var(--green); border-radius: 999px; transition: width .4s ease; }
.goal-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.amount-form { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.amount-form input { width: 130px; margin-top: 0; padding: 5px 10px; }

/* ---------- rewards ---------- */
.level-card { display: flex; gap: 18px; align-items: center; margin-bottom: 20px; }
.level-badge { flex: none; width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(140deg, var(--accent), var(--accent-hover)); color: var(--on-accent); font-size: 26px; font-weight: 750; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm); }
.level-main { flex: 1; min-width: 0; }
.level-name { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.level-card-small .level-badge { width: 46px; height: 46px; font-size: 18px; }
.level-card-small .progress { margin: 6px 0 4px; }
.progress-xp .progress-fill { background: var(--accent); }
.callout { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--amber); border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
.callout-bad  { border-left-color: var(--red); }
.callout-good { border-left-color: var(--green); }
.callout strong { display: block; font-size: 14px; }
.callout p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
.win-list { margin: 0; padding-left: 18px; font-size: 14px; }
.award-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.award { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 12px; text-align: center; box-shadow: var(--shadow-sm); }
.award.is-earned { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.award-icon { font-size: 30px; line-height: 1.2; }
.award-name { font-weight: 600; font-size: 14px; margin-top: 6px; }
.award-desc { font-size: 12px; color: var(--muted); }
.award:not(.is-earned) .award-icon { filter: grayscale(1); opacity: .4; }   /* locked = greyed out */
.award:not(.is-earned) .award-name { color: var(--muted); }
.award.is-new { border-color: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.award .progress { height: 6px; margin: 10px 0 3px; }
.xp-plus  { color: var(--green); font-weight: 600; }
.xp-minus { color: var(--red); font-weight: 600; }
.ledger-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.ledger-row:last-child { border-bottom: 0; }
.xp-rules { margin: 18px 0; font-size: 14px; }
.xp-rules summary { cursor: pointer; color: var(--muted); }

/* ---------- home dashboard ---------- */
.container:has(.chart-grid) { max-width: 1040px; }
.cards-4 { grid-template-columns: repeat(4, 1fr); }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.chart-title { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.meter-row { margin-top: 12px; }
/* First-time checklist (index.php) */
.setup-card { margin-bottom: 16px; }
.setup-card .progress { margin: 4px 0 10px; }
.setup-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.setup-list li { display: flex; align-items: center; gap: 8px; }
.setup-list .icon { color: var(--muted); }
.setup-list li.is-done { color: var(--muted); text-decoration: line-through; }
.setup-list li.is-done .icon { color: var(--green); }

/* "Today" card: round tick button before each task (index.php) */
.today-task { display: flex; align-items: center; gap: 10px; min-width: 0; }
.inline-form { display: inline-flex; margin: 0; }
.check-btn { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 22px; height: 22px; padding: 0; border: 2px solid var(--border-strong); border-radius: 50%; background: none; color: transparent; cursor: pointer; transition: border-color .15s, background .15s, color .15s; }
.check-btn .icon { width: 14px; height: 14px; vertical-align: 0; }
.check-btn:hover, .check-btn:focus-visible { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }   /* the tick shows on hover */
.meter-row .progress { margin: 6px 0 0; }

/* ========== week calendar (modules/fatigue/calendar.php) ========== */
.container:has(.cal) { max-width: 1100px; }
.cal-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
/* 1 time column + 7 days. min-width: on phones the calendar scrolls sideways inside its box */
.cal { display: grid; grid-template-columns: 52px repeat(7, minmax(96px, 1fr)); min-width: 760px; }
.cal-corner { border-bottom: 1px solid var(--border); }
.cal-head { padding: 8px 8px 6px; border-left: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-head.is-today { background: var(--accent-soft); }
.cal-date { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-2); }
.cal-date strong { font-size: 17px; color: var(--text); }
.cal-head.is-today .cal-date strong { color: var(--accent); }
.cal-add { margin-left: auto; display: inline-flex; color: var(--muted); border-radius: 6px; padding: 2px; }
.cal-add:hover { color: var(--accent); background: var(--surface-2); }
.cal-add .icon { width: 15px; height: 15px; }
.cal-load { font-size: 11.5px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 2px; }
.cal-load .pill { margin-left: 0; font-size: 10.5px; padding: 0 6px; }
.cal-load-bar { height: 4px; margin-top: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.cal-load-bar div { height: 100%; background: var(--accent); border-radius: 999px; }
.cal-untimed-label { font-size: 11px; padding: 6px 4px; text-align: right; }
.cal-untimed { padding: 4px; border-left: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.cal-chip { display: block; padding: 3px 6px; font-size: 12px; border-radius: 6px; color: var(--text); text-decoration: none;
            border-left: 3px solid var(--ev); background: color-mix(in srgb, var(--ev) 12%, var(--surface));
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-times, .cal-grid { position: relative; height: var(--cal-height); }
.cal-hour { position: absolute; right: 6px; transform: translateY(-50%); font-size: 10.5px; color: var(--chart-ink-muted); white-space: nowrap; }
.cal-hour:first-child { transform: none; }
/* hour lines: a repeating gradient, one line every HOUR_PX (44px) */
.cal-grid { border-left: 1px solid var(--border);
            background-image: repeating-linear-gradient(to bottom, var(--chart-grid) 0 1px, transparent 1px 44px); }
.cal-grid.is-today { background-color: color-mix(in srgb, var(--accent) 4%, transparent); }
.cal-event { position: absolute; box-sizing: border-box; padding: 3px 6px; overflow: hidden; font-size: 11.5px; line-height: 1.3;
             color: var(--text); text-decoration: none; border-radius: 6px; border: 1px solid var(--surface);
             border-left: 3px solid var(--ev); background: color-mix(in srgb, var(--ev) 18%, var(--surface)); }
.cal-event strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.cal-event span { display: block; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event:hover, .cal-chip:hover { z-index: 2; box-shadow: var(--shadow); }
.cal-event.is-work { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--ev) 18%, var(--surface)) 0 6px,
                                                          color-mix(in srgb, var(--ev) 10%, var(--surface)) 6px 12px); }
.cal-event.is-done, .cal-chip.is-done { opacity: .5; }
.cal-event.is-done strong, .cal-chip.is-done { text-decoration: line-through; }
.cal-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--red); z-index: 3; }
.cal-now::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

/* ========== charts (shared/charts.js) ========== */
.chart-toggles { display: inline-flex; gap: 2px; margin-bottom: 10px; padding: 3px; background: var(--surface-2); border-radius: var(--radius-sm); }
.chart-toggle { padding: 4px 11px; border: 0; border-radius: 7px; background: none; color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer; }
.chart-toggle.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.chart-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.chart-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-plot { position: relative; }
.chart-plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .chart-gridline { stroke: var(--chart-grid); stroke-width: 1; }
.chart .chart-baseline { stroke: var(--chart-axis); stroke-width: 1; }
.chart .chart-tick { fill: var(--chart-ink-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .chart-value { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart .chart-empty { fill: var(--chart-ink-muted); font-size: 13px; }
.chart .chart-hit { fill: transparent; cursor: default; outline: none; }
.chart .chart-hit.is-hover { fill: color-mix(in srgb, var(--text) 5%, transparent); }
.chart-tooltip { display: none; position: absolute; z-index: 5; pointer-events: none; min-width: 130px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 12px; }
.chart-tooltip-title { font-weight: 600; margin-bottom: 4px; }
.chart-tooltip-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 6px; align-items: center; color: var(--text-2); }
.chart-tooltip-row strong { color: var(--text); font-variant-numeric: tabular-nums; }
.chart-tooltip-total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.chart-details { margin-top: 8px; font-size: 12px; color: var(--muted); }
.chart-details summary { cursor: pointer; }
.chart-data-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
.chart-data-table th, .chart-data-table td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.chart-data-table th:first-child, .chart-data-table td:first-child { text-align: left; }

/* donut */
.chart-donut-wrap { display: flex; align-items: center; gap: 18px; }
.chart-donut-wrap .chart-plot { flex: 0 0 170px; }
.chart-donut .chart-slice { stroke: var(--surface); stroke-width: 2; }   /* 2px gap between slices */
.chart-donut .chart-slice, .chart-donut circle { outline: none; transition: opacity .1s; }
.chart-donut:has(.is-hover) .chart-slice:not(.is-hover) { opacity: .55; }
.chart-donut-track { fill: none; stroke: var(--surface-2); }
.chart-donut-total { fill: var(--text); font-size: 26px; font-weight: 650; }
.chart-donut-label { fill: var(--chart-ink-muted); font-size: 12px; }
.chart-legend-list { flex: 1; flex-direction: column; gap: 7px; margin: 0; display: flex; }
.chart-legend-row { display: grid; grid-template-columns: 10px 1fr auto 44px; gap: 8px; align-items: center; font-size: 13px; color: var(--text-2); }
.chart-legend-row strong { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.chart-legend-pct { color: var(--chart-ink-muted); text-align: right; font-variant-numeric: tabular-nums; }
.chart-tooltip-sub { color: var(--chart-ink-muted); margin-top: 2px; }

/* ========== reports ========== */
.report-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.report-controls input[type=date] { width: auto; padding: 6px 10px; }
.export-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.report-head { margin-bottom: 16px; }
.report-head h2 { margin: 2px 0; }
.report-section { margin-bottom: 14px; }
.report-stats { display: flex; flex-wrap: wrap; gap: 28px; margin-bottom: 12px; }
.report-stats div { display: flex; flex-direction: column; }
.report-stats strong { font-size: 18px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); padding: 7px 6px; }
.report-table td { border-bottom: 1px solid var(--border); padding: 7px 6px; vertical-align: top; }

/* ========== smaller screens ========== */
@media (max-width: 1100px) {
    .account-name { display: none; }
    .nav-link { padding: 8px 9px; }
}

@media (max-width: 760px) {
    /* No blur on phones: backdrop-filter would make the fixed bottom nav (a child
       of .topbar) position itself inside the top bar instead of the screen. */
    .topbar { height: 56px; padding: 0 14px; gap: 10px; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--surface); }
    .brand { flex: 1; }

    /* Main nav becomes a bottom tab bar (easier to reach with a thumb) */
    .topbar .modules {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; gap: 0; overflow: visible;
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));   /* iPhone home-bar space */
        background: var(--surface); border-top: 1px solid var(--border);
        box-shadow: 0 -4px 16px rgba(0, 0, 0, .05);
    }
    .nav-link { flex: 1; min-width: 0; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 10.5px; border-radius: 8px; }
    .nav-link .icon { width: 22px; height: 22px; }
    .nav-link span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
    .nav-link.active { background: none; }
    .nav-link.active .icon { color: var(--accent); }
    body.has-nav { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }   /* content never hides under the bar */
    .logout-text { display: none; }

    .subnav { padding: 10px 14px; }
    .container { margin: 20px auto; padding: 0 14px; }
    .cards-4 { grid-template-columns: 1fr 1fr; }
    .chart-grid { grid-template-columns: 1fr; }
    .card .value { font-size: 26px; }
}

@media (max-width: 480px) {
    .cards, .cards-3 { grid-template-columns: 1fr; }
    .cards.cards-4 { grid-template-columns: 1fr 1fr; }   /* KPI tiles stay 2-up, they're small */
    .form-card { padding: 20px; }
    .row { flex-direction: column; gap: 0; }
    /* task rows: buttons drop under the title instead of squeezing it */
    .task-row { flex-wrap: wrap; }
    .task-actions { margin-left: 0; justify-content: flex-start; }
}

@media (max-width: 420px) {
    .chart-donut-wrap { flex-direction: column; align-items: stretch; }
    .chart-donut-wrap .chart-plot { flex-basis: auto; max-width: 180px; margin: 0 auto; }
}

/* ========== print (Reports → Print / Save as PDF) ========== */
@media print {
    @page { margin: 14mm; }
    body { background: #fff; font-size: 12px; padding: 0 !important; }
    .topbar, .subnav, .no-print, .chart-details, .chart-toggles, .chart-tooltip { display: none !important; }
    .container { max-width: none; margin: 0; padding: 0; }
    .card { border-color: #ccc; box-shadow: none; break-inside: avoid; }
    .chart-grid { grid-template-columns: 1fr 1fr; }
    .cards-4 { grid-template-columns: repeat(4, 1fr); }
    .report-table tr { break-inside: avoid; }
    a { color: inherit; text-decoration: none; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }   /* keep chart colours */
}
