/*
 * CaVaToi — one stylesheet, no build step, no framework.
 *
 * Two things drive every choice here: the people filling in the daily
 * questionnaire may be old, tired or shaky, and the host gives us 1 GB. So:
 * large touch targets, real text sizes, high contrast, and no dependencies.
 *
 * [data-a11y="1"] on <html> turns on reinforced accessibility: everything grows
 * and contrast goes up. It is a scale factor, not a separate stylesheet.
 */

:root {
    --font-base: 17px;
    --scale: 1;

    --teal-900: #10403d;
    --teal-700: #1f6f6b;
    --teal-100: #e3f1f0;

    --ink: #14211f;
    --ink-soft: #52635f;
    --paper: #f6f8fb;
    --card: #ffffff;
    --line: #d7dfe3;

    --good: #1d7a4c;
    --warn: #a35a06;
    --bad: #a62828;

    --radius: 10px;
    --gap: 1rem;
    --touch: 44px;
}

:root[data-a11y="1"] {
    --font-base: 22px;
    --scale: 1.15;
    --ink: #000000;
    --ink-soft: #2b3734;
    --paper: #ffffff;
    --line: #000000;
    --touch: 56px;
}

* { box-sizing: border-box; }

html {
    font-size: var(--font-base);
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    line-height: 1.55;
    color: var(--ink);
    background: var(--paper);
}

:root[data-a11y="1"] body { font-weight: 500; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: calc(1.6rem * var(--scale)); }
h2 { font-size: calc(1.25rem * var(--scale)); }

p { margin: 0 0 0.9em; }

a { color: var(--teal-700); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, label:focus-within {
    outline: 3px solid var(--teal-700);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: -9999px;
    background: var(--teal-900);
    color: #fff;
    padding: 0.6rem 1rem;
    z-index: 10;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

/* ---- shell ---- */

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--gap);
    padding: 0.7rem 1rem;
    background: var(--teal-900);
    color: #fff;
}
.topbar a { color: #fff; }

.brand {
    font-weight: 700;
    font-size: calc(1.1rem * var(--scale));
    text-decoration: none;
    margin-right: auto;
}

.nav-toggle {
    display: none;
    min-width: var(--touch);
    min-height: var(--touch);
    font-size: 1.3rem;
    background: transparent;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: var(--radius);
}

.primary-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    list-style: none;
    margin: 0;
    padding: 0;
}
.primary-nav a {
    display: inline-block;
    padding: 0.5rem 0.4rem;
    min-height: var(--touch);
    text-decoration: none;
    border-bottom: 3px solid transparent;
}
.primary-nav a[aria-current="page"] { border-bottom-color: #fff; font-weight: 600; }
.primary-nav a:hover { text-decoration: underline; }

.topbar-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.9rem;
}
.topbar-right select {
    min-height: 2rem;
    border-radius: 6px;
    border: 1px solid var(--line);
}

.inline-form { display: inline; margin: 0; }

.link-button {
    background: none;
    border: 0;
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
    font: inherit;
    padding: 0.4rem 0;
    min-height: var(--touch);
}

.container {
    max-width: 48rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.footer {
    padding: 1rem;
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.85rem;
}

@media (max-width: 42rem) {
    .nav-toggle { display: inline-block; }
    .primary-nav { flex-basis: 100%; display: none; }
    .primary-nav[data-open="1"] { display: block; }
    .primary-nav ul { flex-direction: column; }
    .primary-nav a { border-bottom: 1px solid rgba(255, 255, 255, 0.25); border-radius: 0; }
}

/* ---- guest pages ---- */

body.guest {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1rem;
    background: var(--teal-100);
}
.guest-card {
    width: min(26rem, 100%);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.75rem;
}
.guest-brand {
    font-size: calc(1.5rem * var(--scale));
    color: var(--teal-900);
    margin-bottom: 1.25rem;
}
.guest-prefs {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
    font-size: 0.85rem;
}

/* ---- blocks ---- */

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1.25rem;
}
.panel-warning { border-left: 6px solid var(--warn); }

.lede { font-size: calc(1.05rem * var(--scale)); color: var(--ink-soft); }
.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }

.flash, .alert {
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.flash { background: #e6f4ea; border: 1px solid var(--good); color: #14532d; }
.alert-error { background: #fdeaea; border: 1px solid var(--bad); color: #7f1d1d; }
.alert-info { background: var(--teal-100); border: 1px solid var(--teal-700); }

.badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: var(--teal-100);
    color: var(--teal-900);
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-warning { background: #fdf0d5; color: #7c4a03; }

/* ---- forms ---- */

.stack > * + * { margin-top: 1.1rem; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 1rem; }

label { font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"],
select, textarea {
    font: inherit;
    min-height: var(--touch);
    padding: 0.55rem 0.7rem;
    border: 2px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    width: 100%;
}
textarea { min-height: 6rem; resize: vertical; }

.code-input {
    font-size: calc(1.6rem * var(--scale));
    letter-spacing: 0.4em;
    text-align: center;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: var(--touch);
    padding: 0.6rem 1.2rem;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    border: 2px solid var(--teal-700);
    border-radius: var(--radius);
    background: #fff;
    color: var(--teal-900);
    cursor: pointer;
}
.button-primary { background: var(--teal-700); color: #fff; }
.button-danger { border-color: var(--bad); color: var(--bad); }
.button-large { font-size: calc(1.1rem * var(--scale)); padding: 0.9rem 1.5rem; width: 100%; }

.filters { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-bottom: 1rem; }
.filters select { width: auto; min-width: 10rem; }

.radio-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0;
    font-weight: 400;
    min-height: var(--touch);
}

/* ---- the daily check-in ---- */

.moment-switch { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1.25rem; }
.chip {
    padding: 0.5rem 1rem;
    min-height: var(--touch);
    display: inline-flex;
    align-items: center;
    border: 2px solid var(--teal-700);
    border-radius: 999px;
    text-decoration: none;
    color: var(--teal-900);
    background: #fff;
}
.chip-active { background: var(--teal-700); color: #fff; }
.chip-date { color: var(--ink-soft); margin-left: auto; }

.checkin { display: flex; flex-direction: column; gap: 1.25rem; }

.question {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    padding: 1rem 1.1rem;
    margin: 0;
}
.question legend {
    font-weight: 700;
    font-size: calc(1.1rem * var(--scale));
    padding: 0 0.3rem;
}
.question[disabled] { opacity: 0.65; }

.scale { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.scale-option, .bool-option {
    flex: 1 1 3.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: calc(var(--touch) + 1rem);
    padding: 0.5rem 0.3rem;
    border: 2px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    cursor: pointer;
    text-align: center;
    font-weight: 400;
}
.scale-option input, .bool-option input, .skip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.scale-number { font-size: calc(1.3rem * var(--scale)); font-weight: 700; }
.scale-caption { font-size: 0.75rem; color: var(--ink-soft); }

.scale-selected { border-color: var(--teal-700); background: var(--teal-100); }
.scale-option:has(input:focus-visible), .bool-option:has(input:focus-visible) {
    outline: 3px solid var(--teal-700);
    outline-offset: 2px;
}

.bool-group { display: flex; gap: 0.75rem; }
.bool-option { flex: 1 1 50%; font-size: calc(1.1rem * var(--scale)); font-weight: 600; }

.skip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--ink-soft);
    cursor: pointer;
    min-height: var(--touch);
}
.skip:has(input:checked) { color: var(--ink); font-weight: 600; }

.checkin-actions { position: sticky; bottom: 0; padding: 0.75rem 0; background: linear-gradient(to top, var(--paper) 70%, transparent); }

/* ---- sharing console ---- */

.person-head { border-bottom: 1px solid var(--line); padding-bottom: 0.6rem; margin-bottom: 1rem; }
.person-actions { margin-top: 1rem; }

.grant { border: 0; padding: 0; margin: 0 0 1.25rem; }
.grant legend { font-weight: 700; padding: 0; }

.grant-levels { display: grid; gap: 0.5rem; margin-top: 0.5rem; }
.grant-level {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas: "name name" "help help";
    gap: 0.1rem 0.6rem;
    padding: 0.7rem 0.9rem;
    border: 2px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 400;
    min-height: var(--touch);
}
.grant-level input { position: absolute; opacity: 0; }
.grant-level-name { grid-area: name; font-weight: 600; }
.grant-level-help { grid-area: help; }
.grant-selected { border-color: var(--teal-700); background: var(--teal-100); }
.grant-level:has(input:focus-visible) { outline: 3px solid var(--teal-700); outline-offset: 2px; }

/* ---- data display ---- */

.table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.table th, .table td {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.table th { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); }
.table-dense td, .table-dense th { padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.row-muted { opacity: 0.6; }

@media (max-width: 36rem) {
    .table, .table thead, .table tbody, .table tr, .table td, .table th { display: block; }
    .table thead { display: none; }
    .table tr { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 0.75rem; padding: 0.5rem; }
    .table td { border: 0; padding: 0.25rem 0.5rem; }
}

.drift-list, .alert-list, .task-list, .session-list, .invite-list,
.access-list, .transmission-list { list-style: none; margin: 0; padding: 0; }

.drift {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 1rem;
    padding: 0.6rem 0.75rem;
    border-left: 5px solid var(--line);
    margin-bottom: 0.4rem;
    background: #fbfcfd;
}
.drift-label { font-weight: 600; flex: 1 1 10rem; }
.drift-up { border-left-color: var(--good); }
.drift-down { border-left-color: var(--bad); }
.drift-flat { border-left-color: var(--line); }
.drift-verdict { font-size: 0.85rem; font-weight: 600; }
.drift-up .drift-verdict { color: var(--good); }
.drift-down .drift-verdict { color: var(--bad); }

.alert-list li { padding: 0.5rem 0.75rem; border-left: 5px solid var(--warn); margin-bottom: 0.4rem; }
.severity-critical { border-left-color: var(--bad); font-weight: 600; }
.severity-info { border-left-color: var(--teal-700); }

.task-list li, .session-list li, .access-list li, .invite-list li {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    align-items: baseline;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--line);
}
.access-list li { justify-content: space-between; }
.task-time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--teal-900); min-width: 3.5rem; }
.task-done { opacity: 0.55; text-decoration: line-through; }

.transmission-list li { padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.transmission-list li.important { border-left: 5px solid var(--warn); padding-left: 0.7rem; }

.done { color: var(--good); font-weight: 600; }

.chart { margin: 0 0 1rem; color: var(--teal-700); }
.chart svg { width: 100%; height: 10rem; display: block; }

.meter { height: 0.9rem; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.meter-fill { height: 100%; background: var(--teal-700); }
.meter-warning .meter-fill { background: var(--warn); }

.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; }

.secret { font-size: calc(1.1rem * var(--scale)); letter-spacing: 0.1em; word-break: break-all; }
code { background: #eef2f4; padding: 0.1rem 0.3rem; border-radius: 4px; font-size: 0.9em; }

.totp-setup { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: #fbfcfd; }

@media print {
    .topbar, .footer, .checkin-actions, .filters, .button { display: none; }
    body { background: #fff; }
    .panel { border: 1px solid #000; break-inside: avoid; }
}

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