/*
 * SmartDrive - the one stylesheet.
 *
 * Written mobile first, and that is not a slogan: the base rules below ARE the telephone
 * layout, and the two media queries widen it. A desktop-first stylesheet with phone
 * overrides is how an application ends up usable on a telephone in the places somebody
 * remembered and broken in the rest (C12).
 *
 * The three sizes that were designed against: 390 px (telephone), 820 px (tablet),
 * 1280 px and up (the office). Table rows become cards below 820, the menu collapses into
 * a button, modals go full screen, and every target that can be tapped is at least 44 px.
 */

:root
{
    --ink: #1f2937;
    --ink-soft: #6b7280;
    --line: #e5e7eb;
    --paper: #ffffff;
    --page: #f5f6f8;
    --brand: #16509b;
    --brand-dark: #0f3a73;
    --brand-soft: #e8f0fb;
    --good: #1f7a33;
    --good-soft: #e7f6ea;
    --bad: #b3261e;
    --bad-soft: #fbe3da;
    --warn: #8a5a00;
    --warn-soft: #fdf3dc;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
    /* The smallest thing a finger is expected to hit. */
    --tap: 44px;
    --header: 56px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body
{
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--page);
    /* No horizontal scroll, at any width. */
    overflow-x: hidden;
}

h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 6px; }
p { margin: 0 0 12px; }
a { color: var(--brand); }

/* Everything that reacts to a click says so. (C1) */
button, .clickable, summary, [role="button"], .row-card, .tab, .menu-link
{
    cursor: pointer;
}

button:disabled, .clickable[aria-disabled="true"] { cursor: not-allowed; opacity: 0.55; }

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

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar
{
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--header);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow);
}

.topbar .brand { font-weight: 700; letter-spacing: 0.2px; }
.topbar .school { font-size: 0.8rem; opacity: 0.85; margin-left: 4px; }
.topbar .spacer { flex: 1; }

.icon-button
{
    min-width: var(--tap);
    min-height: var(--tap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: inherit;
    font-size: 1.05rem;
}

.icon-button:hover { background: rgba(255, 255, 255, 0.14); }

/* The menu is a drawer on a telephone and a column on a desktop. */
.layout { flex: 1; display: flex; min-height: 0; }

.menu
{
    position: fixed;
    inset: var(--header) 0 0 0;
    z-index: 25;
    background: var(--paper);
    padding: 8px 12px 24px;
    overflow-y: auto;
    /* Closed by default: on a telephone the content comes first. */
    display: none;
}

.menu[data-open="true"] { display: block; }

.menu .group { margin: 12px 0 4px; font-size: 0.75rem; text-transform: uppercase;
               letter-spacing: 0.6px; color: var(--ink-soft); }

.menu-link
{
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--tap);
    padding: 8px 10px;
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
}

.menu-link:hover { background: var(--brand-soft); }
.menu-link[aria-current="page"] { background: var(--brand-soft); color: var(--brand-dark);
                                  font-weight: 600; }
.menu-link .fa-solid, .menu-link .fa-regular { width: 1.1rem; text-align: center;
                                               color: var(--brand); }

.content { flex: 1; min-width: 0; padding: 16px; }

/* A 16 px gutter on a telephone, never edge to edge. */
@media (max-width: 480px)
{
    .content { padding: 16px; }
}

/* ---------------------------------------------------------------- cards */

.card
{
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin: 0 0 16px;
}

.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }

.tiles { display: grid; grid-template-columns: 1fr; gap: 12px; }

.tile
{
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.tile .n { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .k { font-size: 0.85rem; color: var(--ink-soft); }

/* ---------------------------------------------------------------- fields */

.field { margin: 0 0 14px; }
.field > label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }

input[type="text"], input[type="password"], input[type="date"], input[type="time"],
input[type="number"], input[type="email"], input[type="search"], input[type="tel"],
select, textarea
{
    width: 100%;
    min-height: var(--tap);
    padding: 8px 10px;
    font: inherit;
    color: inherit;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

textarea { min-height: 7rem; resize: vertical; }

input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible,
a:focus-visible
{
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

/*
 * The hint under a field. This is where an example or an instruction goes, NEVER in a
 * placeholder: a placeholder disappears the moment somebody starts typing, which is
 * exactly when the instruction was needed (C3).
 */
.form-text { font-size: 0.8rem; color: var(--ink-soft); margin-top: 4px; }

.field-error { font-size: 0.8rem; color: var(--bad); margin-top: 4px; }
input:invalid, select:invalid, textarea:invalid { border-color: var(--bad); }

.check { display: flex; align-items: center; gap: 8px; min-height: var(--tap); }
.check input { width: 20px; height: 20px; }
.check label { font-weight: 500; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }

/* ---------------------------------------------------------------- buttons */

.btn
{
    min-height: var(--tap);
    min-width: var(--tap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font: inherit;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--brand);
    color: #fff;
}

.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--page); }
.btn.danger { background: var(--bad); }
.btn.quiet { background: transparent; color: var(--brand); }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
/* An icon on its own keeps the 44 px touch target (C12) and loses the side padding that
   was there to sit beside a word. */
.btn.icon-only { padding: 8px; flex: 0 0 auto; }

/* ---------------------------------------------------------------- tables */

/*
 * A table on a desktop, a stack of cards on a telephone. The cell labels come from
 * data-label, so one markup serves both and nothing is duplicated.
 */
.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th { text-align: left; font-size: 0.78rem; text-transform: uppercase;
                letter-spacing: 0.4px; color: var(--ink-soft); padding: 8px; }
table.data td { padding: 10px 8px; border-top: 1px solid var(--line); vertical-align: top; }
table.data tbody tr:hover { background: var(--brand-soft); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 819px)
{
    table.data thead { display: none; }
    table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
    table.data tr
    {
        background: var(--paper);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        margin-bottom: 10px;
        padding: 6px 12px;
    }
    table.data td { border-top: 0; padding: 6px 0; display: flex; gap: 12px; }
    table.data td::before
    {
        content: attr(data-label);
        flex: 0 0 9rem;
        font-size: 0.78rem;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        color: var(--ink-soft);
    }
    table.data td.num { text-align: left; }
    table.data td:empty { display: none; }
}

/* ---------------------------------------------------------------- filters */

/*
 * On a telephone the filters collapse behind one button, because six filter controls
 * take the whole screen before the data starts.
 */
.filters { display: none; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters[data-open="true"] { display: flex; }
.filters .field { margin: 0; min-width: 10rem; flex: 1; }
.filter-toggle { display: inline-flex; }

/* ---------------------------------------------------------------- badges */

.badge
{
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--page);
    color: var(--ink-soft);
}

.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand-dark); }

.count-dot
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--bad);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
}

/* ---------------------------------------------------------------- notices */

.notice
{
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--paper);
    margin: 0 0 16px;
}

.notice.info { background: var(--brand-soft); border-color: #c9ddf6; color: var(--brand-dark); }
.notice.good { background: var(--good-soft); border-color: #bfe3c7; color: var(--good); }
.notice.bad { background: var(--bad-soft); border-color: #f3c6b9; color: var(--bad); }
.notice.warn { background: var(--warn-soft); border-color: #ecd9a8; color: var(--warn); }

.empty { text-align: center; color: var(--ink-soft); padding: 28px 12px; }
.empty .fa-solid { font-size: 1.8rem; display: block; margin-bottom: 8px; opacity: 0.5; }

/* ---------------------------------------------------------------- toast */

.toasts
{
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast
{
    pointer-events: auto;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--ink);
    color: #fff;
    box-shadow: var(--shadow);
    font-size: 0.92rem;
}

.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }

/* ---------------------------------------------------------------- modal */

/*
 * Full screen on a telephone, a centred panel from 820 px up. A modal with its own close
 * button does not close on a click outside, and asks before throwing away something typed
 * or chosen (C11): that is in shell.js, this only makes the backdrop inert.
 */
.modal-back
{
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(16, 24, 40, 0.45);
    display: flex;
    align-items: stretch;
    justify-content: center;
}

.modal
{
    background: var(--paper);
    width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
}

.modal-head
{
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-foot
{
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
}

/* ---------------------------------------------------------------- login */

.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center;
              padding: 16px; }
.login-card { width: 100%; max-width: 24rem; }
.login-card .brand-row { text-align: center; margin-bottom: 16px; }
.login-card .brand-row .mark { font-size: 1.6rem; font-weight: 800; color: var(--brand); }
.login-card .brand-row .sub { color: var(--ink-soft); font-size: 0.9rem; }

/* ---------------------------------------------------------------- quiz */

.question { font-size: 1.05rem; font-weight: 600; margin-bottom: 14px; }

.option
{
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    min-height: var(--tap);
    padding: 12px 14px;
    margin-bottom: 8px;
    text-align: left;
    font: inherit;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.option:hover { border-color: var(--brand); background: var(--brand-soft); }
.option[data-state="chosen"] { border-color: var(--brand); background: var(--brand-soft); }
.option[data-state="right"] { border-color: var(--good); background: var(--good-soft); }
.option[data-state="wrong"] { border-color: var(--bad); background: var(--bad-soft); }
.option .letter { font-weight: 700; color: var(--brand); min-width: 1.2rem; }

.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden;
            margin-bottom: 12px; }
.progress > i { display: block; height: 100%; background: var(--brand); }

.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.timer[data-low="true"] { color: var(--bad); }

.figure-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.figure-strip img { height: 7rem; border: 1px solid var(--line); border-radius: var(--radius);
                    background: var(--paper); }

/* ---------------------------------------------------------------- agenda */

.day-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }

.cell
{
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    font-size: 0.92rem;
}

.cell .hh { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.4rem; }
.cell[data-free="true"]:hover { border-color: var(--brand); background: var(--brand-soft); }
.cell[data-state="BOOKED"] { border-left: 4px solid var(--brand); }
.cell[data-state="COMPLETED"] { border-left: 4px solid var(--good); }
.cell[data-state="NO_SHOW"] { border-left: 4px solid var(--bad); }
.cell[data-state="CANCELLED"] { opacity: 0.6; text-decoration: line-through; }

/* ---------------------------------------------------------------- thread */

.msg { padding: 10px 12px; border-radius: var(--radius); margin-bottom: 10px;
       border: 1px solid var(--line); background: var(--paper); }
.msg[data-who="staff"] { background: var(--brand-soft); border-color: #c9ddf6; }
.msg .who { font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 4px; }
.msg .body { white-space: pre-wrap; }

/* ---------------------------------------------------------------- tabs */

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line);
        margin-bottom: 16px; }

.tab
{
    min-height: var(--tap);
    padding: 8px 14px;
    border: 0;
    background: transparent;
    font: inherit;
    font-weight: 600;
    color: var(--ink-soft);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.tab[aria-selected="true"] { color: var(--brand-dark); border-bottom-color: var(--brand); }

/* ---------------------------------------------------------------- utility */

.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.88rem; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor;
           border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- tablet */

@media (min-width: 820px)
{
    .tiles { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .day-grid { grid-template-columns: repeat(2, 1fr); }
    .filters { display: flex; }
    .filter-toggle { display: none; }
    .modal-back { align-items: center; padding: 24px; }
    .modal { max-width: 40rem; border-radius: var(--radius); max-height: 90vh; }
    .content { padding: 20px 24px; }
}

/* ---------------------------------------------------------------- desktop */

@media (min-width: 1024px)
{
    .menu
    {
        position: sticky;
        top: var(--header);
        inset: auto;
        display: block;
        width: 15rem;
        flex: 0 0 15rem;
        height: calc(100vh - var(--header));
        border-right: 1px solid var(--line);
    }

    .menu-toggle { display: none; }
    .tiles { grid-template-columns: repeat(4, 1fr); }
    .day-grid { grid-template-columns: repeat(3, 1fr); }
    .content { max-width: 78rem; }
    .toasts { left: auto; right: 16px; width: 22rem; }
}

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