/* DIRECTION-AGNOSTIC BY CONSTRUCTION.
   Everything on the inline (writing-direction) axis is expressed with
   logical properties - margin-inline-start rather than margin-left,
   text-align: start rather than left, border-inline-start rather than
   border-left - so `dir="rtl"` on <html> (set from the language object in
   lang/<code>.json) mirrors the entire layout with no second stylesheet
   and no per-direction overrides to keep in step.
   Block-axis properties (margin-bottom, border-top, padding-block) are
   left as-is deliberately: they don't change meaning between LTR and RTL
   in a horizontal writing mode, so rewriting them would be churn that
   makes the diff harder to review without buying anything. */
:root {
    --paper: #F7F6F2;
    --ink: #202A34;
    --ink-soft: #56626E;
    --line: #D9D5C9;
    --present: #2F6F4E;
    --present-bg: #E7F0E9;
    --absent: #9AA3AC;
    --alert: #A4491F;
    --alert-bg: #F5E4DA;
    --conflict: #96660A;
    --conflict-bg: #F3E6C8;
    --card: #FFFFFF;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 15px;
}

.shell {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 0;
    border-bottom: 2px solid var(--ink);
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

.brand {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
    text-decoration: none;
    letter-spacing: 0.01em;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 2px solid var(--present);
    color: var(--present);
    border-radius: 50%;
    font-size: 14px;
    margin-inline-end: 6px;
    vertical-align: middle;
}

nav a {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border-bottom: 2px solid transparent;
    padding-bottom: 4px;
}

nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 18px;
}

nav a:hover { color: var(--ink); border-bottom-color: var(--present); }
nav a.nav-active { color: var(--ink); border-bottom-color: var(--present); }

.btn-linklike {
    background: none;
    border: none;
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border-bottom: 2px solid transparent;
    padding: 0 0 4px;
    cursor: pointer;
    font-family: inherit;
}
.btn-linklike:hover { color: var(--ink); border-bottom-color: var(--present); }

h1 {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 28px;
    margin: 0 0 4px;
}

h2 {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 20px;
    margin: 0 0 14px;
}

.subhead {
    color: var(--ink-soft);
    margin: 0 0 26px;
    font-size: 14px;
}

.flash-stack { margin-bottom: 20px; }
.flash {
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 14px;
    margin-bottom: 8px;
    border: 1px solid transparent;
}
.flash-success { background: var(--present-bg); color: var(--present); border-color: var(--present); }
.flash-error { background: var(--alert-bg); color: var(--alert); border-color: var(--alert); }
.inline-error-note { margin-top: 6px; font-size: 12px; padding: 6px 10px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 22px;
    margin-bottom: 22px;
    max-width: 100%;
    overflow-x: auto;
}

.stat-row {
    display: flex;
    gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}
.stat {
    flex: 1;
    min-width: 140px;
    background: var(--card);
    border: 1px solid var(--line);
    border-inline-start: 4px solid var(--present);
    border-radius: 6px;
    padding: 16px 18px;
}
.stat .num {
    font-family: Georgia, serif;
    font-size: 30px;
    font-weight: 700;
    display: block;
}
.stat .label {
    color: var(--ink-soft);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}
th {
    text-align: start;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-soft);
    border-bottom: 2px solid var(--ink);
    padding: 8px 10px;
}
.sort-link {
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 12px;
}
td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
tr.inactive td { color: var(--absent); font-style: italic; }

a.link { color: var(--present); text-decoration: none; font-weight: 600; }
a.link:hover { text-decoration: underline; }
a.link-danger { color: var(--alert); }

.row-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

form.inline { display: inline; }

.btn {
    display: inline-block;
    background: var(--ink);
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--present); }
.btn-ghost {
    background: transparent;
    color: var(--ink-soft);
    border: 1px solid var(--line);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--ink); background: transparent; }
.btn-small { padding: 5px 10px; font-size: 12px; }

.field { margin-bottom: 14px; }
.field label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
    margin-bottom: 5px;
}
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--ink);
}
.field input[type="checkbox"], .field input[type="radio"] {
    width: auto;
    margin-inline-end: 6px;
    vertical-align: middle;
}
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

/* --- Roster / sign-in sheet (attendance page signature element) --- */
.roster {
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
}
.roster-group-title {
    background: var(--ink);
    color: #fff;
    padding: 8px 16px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.roster-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
}
.roster-row:last-child { border-bottom: none; }
.roster-row.checked,
.roster-row:has(input:checked) { background: var(--present-bg); }

.check-stamp {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    accent-color: var(--present);
    cursor: pointer;
}
.roster-name { font-weight: 600; flex: 1; }
.roster-meta { color: var(--ink-soft); font-size: 13px; }

.permission-row {
    display: block;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--ink-soft);
}
.permission-row input { margin-inline-end: 6px; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--ink-soft);
}

/* Utility classes - used instead of inline style="" attributes, since our
   Content-Security-Policy (default-src 'self') doesn't allow inline styles. */
.card-narrow { max-width: 480px; margin-inline: auto; }
.card-login { max-width: 360px; margin-inline: auto; }
.index-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.card-account { max-width: 400px; margin-inline: auto; }
.mb-sm { margin-bottom: 14px; }
.mb-md { margin-bottom: 20px; }
.mt-sm { margin-top: 14px; }
.btn-danger { background: var(--alert); }
.btn-danger:hover { background: #832f10; }

/* Logged-out language selector (login page; index/404 when those land).
   The submit button is only needed when JS is unavailable - app.js adds
   `js` to <body> and submits the form on change, which hides it. */
.language-picker {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.language-picker label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
}
.language-picker select {
    padding: 7px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
    color: var(--ink);
    flex: 1;
}
body.js .js-hide { display: none; }

.app-footer {
    text-align: center;
    color: var(--ink-soft);
    font-size: 12px;
    padding: 24px 0 10px;
}

.tag-covered, .tag-uncovered, .tag-full, .tag-prefers, .tag-avoid {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
}
.tag-covered { background: var(--present-bg); color: var(--present); }
.tag-uncovered { background: var(--alert-bg); color: var(--alert); }
.tag-full { background: var(--alert-bg); color: var(--alert); margin-inline-start: 6px; }

.session-pick-btn {
    display: block;
    width: 100%;
    text-align: start;
    margin-bottom: 10px;
    font-size: 15px;
    padding: 14px 18px;
}
.session-pick-btn:last-child { margin-bottom: 0; }

/* --- Planning match page --- */
.match-row.needs-driver-row { background: var(--alert-bg); }
.driver-select {
    padding: 7px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 13px;
    background: #fff;
    min-width: 220px;
}
.driver-select.pref-prefers { border-color: var(--present); background: var(--present-bg); }
.driver-select.pref-avoid { border-color: var(--alert); background: var(--alert-bg); }
.driver-select.pref-conflict { border-color: var(--conflict); background: var(--conflict-bg); }

/* Color the OPTIONS themselves, not just the select box after something is
   chosen - so the preference is visible while still deciding, not only
   after saving. Background-color/color on <option> is supported by every
   major browser even though most other CSS on native <select> isn't. */
option[data-pref="prefers"] { background-color: var(--present-bg); color: var(--present); }
option[data-pref="avoid"] { background-color: var(--alert-bg); color: var(--alert); }
option[data-pref="conflict"] { background-color: var(--conflict-bg); color: var(--conflict); }
.tag-prefers { background: var(--present-bg); color: var(--present); }
.tag-avoid { background: var(--alert-bg); color: var(--alert); }
.pref-note { display: block; font-size: 12px; margin-top: 2px; }

/* --- Transportation --- */
.trip-block {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 14px 16px;
    margin-bottom: 16px;
    background: #FCFBF8;
}
.trip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    gap: 10px;
    flex-wrap: wrap;
}
.trip-driver {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.inline-add {
    display: flex;
    align-items: center;
    gap: 8px;
}
.inline-add select {
    padding: 7px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 13px;
    background: #fff;
}
select {
    font-family: inherit;
}

.add-rider-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
    /* Was `padding: 10px 10px 10px 0` - flush to the start edge, padded on
       the end. Split onto the two axes so the flush edge follows the
       reading direction instead of always being the left one. */
    padding-block: 10px;
    padding-inline: 0 10px;
    border-top: 1px dashed var(--line);
}
.add-rider-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--present);
}

.route-quick-assign {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 14px;
    margin-bottom: 16px;
}

.address-block {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 14px;
    margin-bottom: 12px;
}
.route-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 0;
    border-top: 1px solid var(--line);
}
.route-row:first-of-type { border-top: none; padding-top: 4px; }

/* --- Mobile --- */
@media (max-width: 640px) {
    body { font-size: 14px; }
    .shell { padding: 0 14px 40px; }
    .topbar { padding: 16px 0; margin-bottom: 20px; }
    h1 { font-size: 23px; }
    h2 { font-size: 18px; }

    .card { padding: 16px; }

    /* Side-by-side fields don't fit a phone width - stack them instead. */
    .field-row { flex-direction: column; gap: 0; }

    /* Row actions (Edit / Deactivate / Delete etc.) wrap instead of forcing
       the whole row - and by extension the whole page - wider than the
       screen. */
    .row-actions { white-space: normal; flex-wrap: wrap; row-gap: 8px; }

    .driver-select { min-width: 0; width: 100%; }
    .inline-add { flex-wrap: wrap; }
    .inline-add select { flex: 1 1 160px; }

    /* A stat card's min-width is a floor meant for desktop layout - at
       phone width it needs to be able to shrink further, and its label
       needs to wrap, so unusually long content (a raw fallback key when a
       translation is missing, or just a longer language) can't push the
       card past the edge of the screen the way a fixed floor would. */
    .stat { min-width: 0; }
    .stat .label { overflow-wrap: break-word; }

    /* Comfortable tap targets. */
    .btn, .btn-linklike, input:not([type="checkbox"]):not([type="radio"]), select, textarea { min-height: 40px; }
    .check-stamp { width: 24px; height: 24px; }

    table { font-size: 13px; }
    th, td { padding: 8px 6px; }
}
