/*
 * Kapka a Kapicka.
 *
 * Unlike the other applications here this one follows the reader's own setting rather
 * than being dark always. It is opened by parents on a phone at seven in the morning,
 * and a school application that ignores the system theme reads as somebody else's tool
 * rather than the school's. Every colour is a custom property; the dark block below
 * only ever redefines those.
 */
:root {
    --bg:          #f6f7f9;
    --surface:     #ffffff;
    --surface-2:   #f0f2f5;
    --surface-3:   #e5e8ed;
    --border:      #d9dde4;
    --border-soft: #e8ebef;
    --text:        #1f2430;
    --text-muted:  #59616f;
    --text-faint:  #858d9b;
    --accent:      #2563eb;
    --accent-soft: #e5edfd;
    --ok:          #157347;
    --ok-soft:     #e3f4ea;
    --warn:        #a2620a;
    --warn-soft:   #fdf1dd;
    --danger:      #b3261e;
    --danger-soft: #fdeceb;

    --radius:   10px;
    --radius-s: 7px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:          #0f1115;
        --surface:     #171a21;
        --surface-2:   #1e222b;
        --surface-3:   #262b36;
        --border:      #2a2f3a;
        --border-soft: #21252e;
        --text:        #e6e8ec;
        --text-muted:  #9aa1ad;
        --text-faint:  #6b7280;
        --accent:      #5b8dff;
        --accent-soft: #1b2942;
        --ok:          #4fb47a;
        --ok-soft:     #16301f;
        --warn:        #e0a13a;
        --warn-soft:   #33280f;
        --danger:      #f0705c;
        --danger-soft: #3a1d19;
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }
h1 { font-size: 24px; font-weight: 650; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 17px; font-weight: 620; margin: 26px 0 10px; }
h3 { font-size: 15px; font-weight: 620; margin: 18px 0 8px; }
p { margin: 8px 0; }

/* ---------- Topbar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar__inner { max-width: 1100px; margin: 0 auto; padding: 0 20px; min-height: 54px; display: flex; align-items: center; gap: 14px; }
.brand { font-weight: 700; letter-spacing: -.02em; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--text-muted); padding: 6px 11px; border-radius: var(--radius-s); font-size: 15.5px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }

.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu__face { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 650; }
.usermenu__list { position: absolute; right: 0; top: 42px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-width: 240px; box-shadow: 0 12px 30px rgba(0,0,0,.18); }
.usermenu__who { display: flex; flex-direction: column; padding: 4px 6px 10px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.usermenu__list a, .usermenu__list form button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 8px 6px; font: inherit; cursor: pointer; border-radius: var(--radius-s); }
.usermenu__list a:hover, .usermenu__list form button:hover { background: var(--surface-2); text-decoration: none; }

/* Which school an administrator is looking at. Never shown to a parent. */
.schoolswitch { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.schoolswitch a { padding: 4px 12px; border-radius: 999px; font-size: 14px; color: var(--text-muted); white-space: nowrap; }
.schoolswitch a:hover { text-decoration: none; color: var(--text); }
.schoolswitch a.is-active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* ---------- Layout ---------- */
.main { max-width: 1100px; margin: 0 auto; padding: 22px 20px 80px; }
.main--bare { max-width: 460px; padding-top: 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--text-muted); font-weight: 500; }
.faint { color: var(--text-faint); font-size: 14px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card__head h2 { margin: 0; }
details.card summary { cursor: pointer; color: var(--text-muted); }
details.card[open] summary { margin-bottom: 12px; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile__label { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.tile__value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile__value.is-debt { color: var(--danger); }
.tile__value.is-credit { color: var(--ok); }
.tile__note { font-size: 13px; color: var(--text-faint); }

/* ---------- Flashes ---------- */
.flashes { margin-bottom: 16px; }
.flash { padding: 11px 14px; border-radius: var(--radius-s); border: 1px solid var(--border); background: var(--surface); margin-bottom: 8px; }
.flash--ok { border-color: var(--ok); background: var(--ok-soft); }
.flash--error { border-color: var(--danger); background: var(--danger-soft); }

/* ---------- Week of lunches ---------- */
.weeknav { display: flex; align-items: center; gap: 10px; }
.weeknav strong { min-width: 190px; text-align: center; font-variant-numeric: tabular-nums; }

.week { display: grid; gap: 8px; grid-template-columns: repeat(5, 1fr); }
.day {
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; min-height: 128px;
}
.day__head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.day__name { font-weight: 620; text-transform: capitalize; }
.day__date { font-size: 13px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.day__meal { font-size: 14.5px; flex: 1; }
.day__soup { color: var(--text-muted); font-size: 13.5px; }
.day--today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day--closed { background: var(--surface-2); }
.day--nocook { background: var(--surface-2); color: var(--text-faint); }
.day--off .day__meal { opacity: .5; text-decoration: line-through; }

/* The switch itself. A label wrapping a checkbox, so the whole strip is the target. */
.eat { display: flex; align-items: center; gap: 8px; font-size: 14.5px; cursor: pointer; padding: 6px 8px; border-radius: var(--radius-s); background: var(--surface-2); }
.eat input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.eat:hover { background: var(--surface-3); }
.eat.is-locked { cursor: default; background: transparent; padding-left: 0; color: var(--text-faint); }
.eat.is-locked:hover { background: transparent; }
.eat__state { font-weight: 550; }
.eat--yes .eat__state { color: var(--ok); }
.eat--no .eat__state { color: var(--text-faint); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: top; }
.table th { color: var(--text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td { font-weight: 620; border-top: 2px solid var(--border); border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table--narrow { max-width: 620px; }
.amount--in { color: var(--ok); }
.amount--out { color: var(--text); }
tr.is-inactive td { opacity: .55; }

/* ---------- Forms ---------- */
.form__row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.form__row label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--text-muted); flex: 1 1 160px; }
.form__row label.wide { flex: 3 1 320px; }
.form__check { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--text) !important; flex: 0 1 auto !important; }
.form__check input { accent-color: var(--accent); width: 17px; height: 17px; }
.form__actions { display: flex; gap: 10px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=time], input[type=number], input[type=search], select, textarea {
    background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-s);
    padding: 8px 10px; font: inherit; font-size: 15px; width: 100%;
}
textarea { min-height: 72px; resize: vertical; }
input:disabled, select:disabled { opacity: .6; }
.weekdays { display: flex; gap: 6px; flex-wrap: wrap; }
.weekdays label { flex-direction: column; align-items: center; gap: 3px; background: var(--surface-2); border-radius: var(--radius-s); padding: 6px 10px; flex: 0 0 auto; cursor: pointer; }

.meta { display: grid; grid-template-columns: max-content 1fr; gap: 5px 16px; margin: 4px 0 0; font-size: 14.5px; }
.meta dt { color: var(--text-faint); }
.meta dd { margin: 0; }

/* ---------- Buttons and badges ---------- */
.btn { display: inline-block; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 8px 14px; font: inherit; font-size: 15px; cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn--danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn--small { padding: 5px 10px; font-size: 14px; }
.btn--link { border: 0; background: none; color: var(--accent); padding: 0; }
.badge { display: inline-block; font-size: 12px; font-weight: 620; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-muted); vertical-align: middle; }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--school { background: var(--accent-soft); color: var(--accent); }

/* ---------- Login and errors ---------- */
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card .btn { width: 100%; margin-top: 4px; }
.auth-or { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 13px; margin: 20px 0 14px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.error-detail { font-family: var(--mono); font-size: 13px; white-space: pre-wrap; color: var(--warn); }

.empty { color: var(--text-faint); padding: 18px 0; }

@media (max-width: 860px) {
    .week { grid-template-columns: 1fr; }
    .day { min-height: 0; flex-direction: row; align-items: center; flex-wrap: wrap; }
    .day__head { flex: 0 0 96px; flex-direction: column; align-items: flex-start; gap: 0; }
    .day__meal { flex: 1 1 160px; }
    .eat { flex: 0 0 auto; }
}
@media (max-width: 720px) {
    .topbar__inner { padding: 0 12px; gap: 10px; }
    .main { padding: 14px 12px 60px; }
    .table { font-size: 14px; }
    .table th, .table td { padding: 7px 6px; }
    .weeknav strong { min-width: 140px; font-size: 15px; }
}
