/* =====================================================================
   Student Carpool Management System - Styles
   Mobile-first, responsive (phone / tablet / desktop), light & dark.
   ===================================================================== */

:root {
    --primary: #1d4ed8;
    --primary-600: #1e40af;
    --primary-soft: #e0e8ff;
    --accent: #f59e0b;
    --success: #15803d;
    --success-soft: #dcfce7;
    --warning: #b45309;
    --warning-soft: #fef3c7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --muted-soft: #eef0f4;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #64748b;
    --border: #e2e8f0;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
    --shadow-lg: 0 10px 40px rgba(15, 23, 42, .18);
    --sidebar-w: 260px;
    --topbar-h: 60px;
    --bottom-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #6d8dff;
        --primary-600: #8ba4ff;
        --primary-soft: #1e2a4d;
        --success: #4ade80;
        --success-soft: #133322;
        --warning: #fbbf24;
        --warning-soft: #3a2c0c;
        --danger: #f87171;
        --danger-soft: #3b1515;
        --info: #38bdf8;
        --info-soft: #0c2b3d;
        --muted-soft: #232a38;
        --bg: #0e131d;
        --surface: #161c28;
        --surface-2: #1b2230;
        --text: #e6eaf2;
        --text-2: #b4bdcc;
        --text-3: #8791a3;
        --border: #283143;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
    }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
small, .muted { color: var(--text-3); }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

.icon { width: 20px; height: 20px; flex-shrink: 0; }

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

.app { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .25s ease;
    padding-top: var(--safe-t);
}
.sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }

.brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1rem 1.25rem;
    font-weight: 700; font-size: 1.05rem; color: var(--text);
    border-bottom: 1px solid var(--border);
}
.brand:hover { text-decoration: none; }
.brand img { border-radius: 10px; }

.side-nav { flex: 1; overflow-y: auto; padding: .75rem; }
.side-nav a {
    display: flex; align-items: center; gap: .75rem;
    padding: .65rem .85rem; margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 500;
}
.side-nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.side-nav a.active { background: var(--primary-soft); color: var(--primary); }
.side-nav .pill {
    margin-left: auto; background: var(--danger); color: #fff;
    font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 99px;
}

.side-user {
    display: flex; align-items: center; gap: .65rem;
    padding: .9rem 1rem calc(.9rem + var(--safe-b));
    border-top: 1px solid var(--border);
}
.side-user-info { flex: 1; min-width: 0; }
.side-user-info strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .92rem; }
.side-user-info small { font-size: .8rem; }

.backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
    z-index: 40; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

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

.topbar {
    position: sticky; top: 0; z-index: 30;
    height: calc(var(--topbar-h) + var(--safe-t));
    padding: var(--safe-t) 1rem 0;
    display: flex; align-items: center; gap: .75rem;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; font-size: 1.1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 40px; height: 40px; border-radius: 12px;
    border: 0; background: transparent; color: var(--text-2); cursor: pointer;
    position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.bell .dot {
    position: absolute; top: 4px; right: 3px;
    min-width: 18px; height: 18px; padding: 0 4px;
    background: var(--danger); color: #fff; border-radius: 99px;
    font-size: .68rem; font-weight: 700; display: grid; place-items: center;
    border: 2px solid var(--surface);
}

.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    display: inline-grid; place-items: center; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: #fff; font-weight: 700; font-size: .85rem;
}
.avatar:hover { text-decoration: none; }
.avatar-sm { width: 34px; height: 34px; font-size: .75rem; }

.content {
    flex: 1;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 1rem 1rem .5rem;
}

.site-footer {
    text-align: center; color: var(--text-3); font-size: .82rem;
    padding: .5rem 1rem calc(var(--bottom-h) + var(--safe-b) + 1rem);
}

/* Bottom navigation (phones & tablets) */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    height: calc(var(--bottom-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .05);
}
.bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font: inherit; font-size: .7rem; font-weight: 600;
    color: var(--text-3); background: none; border: 0; cursor: pointer;
}
.bottom-nav a:hover { text-decoration: none; }
.bottom-nav .active { color: var(--primary); }
.bottom-nav .icon { width: 22px; height: 22px; }

/* Desktop */
@media (min-width: 1024px) {
    .sidebar { transform: none; }
    .sidebar.open { box-shadow: none; }
    .main { margin-left: var(--sidebar-w); }
    .menu-btn, .bottom-nav, .backdrop { display: none; }
    .content { padding: 1.5rem 2rem 2rem; }
    .site-footer { padding: .5rem 2rem 1.5rem; }
}

/* Tablet: roomier content */
@media (min-width: 640px) and (max-width: 1023px) {
    .content { padding-left: 1.5rem; padding-right: 1.5rem; }
    .bottom-nav a, .bottom-nav button { font-size: .75rem; }
}

.offline-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    background: var(--warning); color: #fff; font-size: .85rem; font-weight: 600;
    display: flex; align-items: center; justify-content: center; gap: .5rem;
    padding: calc(.35rem + var(--safe-t)) 1rem .35rem;
}
.offline-bar .icon { width: 16px; height: 16px; }

/* ---------------- Components ---------------- */

.page-head {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: .75rem; margin-bottom: 1rem;
}
.page-head h2 { margin: 0; }
.page-head p { margin: .15rem 0 0; color: var(--text-3); font-size: .9rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap;
    padding: .9rem 1.1rem; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; display: flex; align-items: center; gap: .5rem; }
.card-body { padding: 1.1rem; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 1rem; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (max-width: 639px) {
    .grid-4 .stat { flex-direction: column; align-items: flex-start; gap: .5rem; padding: .85rem; }
    .grid-4 .stat-icon { width: 38px; height: 38px; }
}
@media (min-width: 640px) {
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }
    .grid-main { grid-template-columns: 2fr 1fr; }
}

/* Stat tiles */
.stat {
    display: flex; align-items: center; gap: .9rem;
    padding: 1rem 1.1rem; margin: 0;
}
.stat-icon {
    width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
    display: grid; place-items: center;
    background: var(--primary-soft); color: var(--primary);
}
.stat-icon.green { background: var(--success-soft); color: var(--success); }
.stat-icon.amber { background: var(--warning-soft); color: var(--warning); }
.stat-icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.stat-label { color: var(--text-3); font-size: .85rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    min-height: 42px; padding: .5rem 1rem;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    font: inherit; font-weight: 600; font-size: .92rem;
    background: var(--primary); color: #fff; cursor: pointer;
    transition: background .15s, transform .05s;
    white-space: nowrap;
}
.btn:hover { background: var(--primary-600); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 18px; height: 18px; }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .84rem; }
.btn-lg { min-height: 50px; padding: .7rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-light { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-light:hover { background: var(--muted-soft); }
.btn-ghost { background: transparent; color: var(--primary); border-color: var(--border); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #166534; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #991b1b; }
.btn-warning { background: #d97706; }
.btn-warning:hover { background: #b45309; }
.btn[disabled] { opacity: .55; pointer-events: none; }
@media (prefers-color-scheme: dark) {
    .btn { color: #0b1020; }
    .btn-light, .btn-ghost { color: var(--text); }
    .btn-ghost { color: var(--primary); }
}

.btn-group { display: flex; flex-wrap: wrap; gap: .4rem; }
.inline { display: inline; margin: 0; }

/* Badges */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 10px; border-radius: 99px;
    font-size: .75rem; font-weight: 700; letter-spacing: .01em;
    background: var(--muted-soft); color: var(--text-2);
    white-space: nowrap;
}
.badge-active, .badge-approved, .badge-completed, .badge-dropped_off { background: var(--success-soft); color: var(--success); }
.badge-pending, .badge-scheduled, .badge-waiting { background: var(--warning-soft); color: var(--warning); }
.badge-in_progress, .badge-picked_up, .badge-to_school, .badge-parent { background: var(--info-soft); color: var(--info); }
.badge-disabled, .badge-rejected, .badge-cancelled, .badge-absent, .badge-inactive { background: var(--danger-soft); color: var(--danger); }
.badge-admin { background: #ede9fe; color: #6d28d9; }
.badge-driver, .badge-from_school { background: var(--primary-soft); color: var(--primary); }

/* Alerts */
.alert {
    padding: .8rem 1rem; border-radius: var(--radius-sm);
    margin-bottom: 1rem; font-weight: 500;
    border: 1px solid transparent;
    transition: opacity .4s;
}
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error, .alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); }

/* Forms */
.form-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) {
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid .full { grid-column: 1 / -1; }
}
.field { display: flex; flex-direction: column; gap: .35rem; }
.field label, .label { font-weight: 600; font-size: .88rem; color: var(--text-2); }
.field .hint { font-size: .8rem; color: var(--text-3); }
.req::after { content: " *"; color: var(--danger); }

input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number],
input[type=date], input[type=time], input[type=search], select, textarea {
    width: 100%;
    min-height: 44px;
    padding: .55rem .8rem;
    font: inherit; font-size: 16px; /* 16px prevents iOS zoom */
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.25rem; }

.days-picker { display: flex; flex-wrap: wrap; gap: .4rem; }
.days-picker label {
    position: relative; cursor: pointer;
}
.days-picker input { position: absolute; opacity: 0; pointer-events: none; }
.days-picker span {
    display: inline-grid; place-items: center;
    min-width: 50px; height: 40px; padding: 0 .6rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-weight: 600; color: var(--text-2); background: var(--surface);
}
.days-picker input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.days-picker input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }

.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; }

.filters {
    display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end;
    margin-bottom: 1rem;
}
.filters .field { flex: 1 1 160px; }
.filters .btn { flex: 0 0 auto; }

/* Tables -> cards on phones */
.table-wrap { width: 100%; overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .75rem 1rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); background: var(--surface-2); font-weight: 700; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table .actions-cell { text-align: right; white-space: nowrap; }
.table .actions-cell .btn-group { justify-content: flex-end; }
.cell-title { font-weight: 600; }
.cell-sub { font-size: .82rem; color: var(--text-3); }
.cell-sub .icon, .sub .icon, .dd .icon, dd .icon, small .icon { width: 14px; height: 14px; vertical-align: -2px; }

@media (max-width: 719px) {
    table.responsive thead { display: none; }
    table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
    table.responsive tr {
        padding: .75rem 1rem;
        border-bottom: 1px solid var(--border);
    }
    table.responsive tr:last-child { border-bottom: 0; }
    table.responsive td {
        border: 0; padding: .25rem 0;
        display: flex; justify-content: space-between; align-items: center; gap: 1rem;
        text-align: right;
    }
    table.responsive td::before {
        content: attr(data-label);
        font-size: .78rem; font-weight: 700; color: var(--text-3);
        text-transform: uppercase; letter-spacing: .03em; text-align: left;
    }
    table.responsive td[data-label=""]::before, table.responsive td:not([data-label])::before { content: none; }
    table.responsive td.primary-cell { display: block; text-align: left; padding-bottom: .4rem; }
    table.responsive td.primary-cell::before { content: none; }
    table.responsive .actions-cell { justify-content: flex-start; padding-top: .6rem; }
    table.responsive .actions-cell::before { content: none; }
    table.responsive .actions-cell .btn-group { justify-content: flex-start; }
}

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
    display: flex; align-items: center; gap: .85rem;
    padding: .85rem 1.1rem; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: .85rem; color: var(--text-3); }
.list-item.unread { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
a.list-item { color: inherit; }
a.list-item:hover { text-decoration: none; background: var(--surface-2); }

.empty {
    text-align: center; padding: 2.5rem 1rem; color: var(--text-3);
}
.empty .icon { width: 44px; height: 44px; margin-bottom: .5rem; opacity: .6; }
.empty p { margin: .25rem 0 1rem; }

/* Definition list */
.dl { display: grid; grid-template-columns: 1fr; gap: .15rem 1rem; margin: 0; }
.dl dt { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); margin-top: .6rem; }
.dl dd { margin: 0; font-weight: 500; }
@media (min-width: 640px) {
    .dl { grid-template-columns: 160px 1fr; }
    .dl dt { margin-top: 0; padding: .45rem 0; }
    .dl dd { padding: .45rem 0; }
}

/* Attendance (trip) rows */
.attend {
    display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
    padding: .9rem 1.1rem; border-bottom: 1px solid var(--border);
}
.attend:last-child { border-bottom: 0; }
.attend .who { flex: 1 1 200px; min-width: 0; display: flex; gap: .75rem; align-items: center; }
.attend .order {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
    display: grid; place-items: center; font-weight: 700; font-size: .85rem;
    background: var(--muted-soft); color: var(--text-2);
}
.attend .btn-group .btn { min-height: 44px; }
@media (max-width: 639px) {
    .attend .btn-group { width: 100%; }
    .attend .btn-group form { flex: 1; }
    .attend .btn-group .btn { width: 100%; }
}

.progress { height: 8px; border-radius: 99px; background: var(--muted-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--success); border-radius: 99px; transition: width .4s; }

.trip-card { display: flex; flex-direction: column; gap: .5rem; padding: 1rem 1.1rem; }
.trip-card .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.meta { display: flex; flex-wrap: wrap; gap: .35rem 1rem; color: var(--text-3); font-size: .85rem; }
.meta span { display: inline-flex; align-items: center; gap: .3rem; }
.meta .icon { width: 15px; height: 15px; }

.live-dot {
    display: inline-block; width: 9px; height: 9px; border-radius: 50%;
    background: var(--success); margin-right: .35rem;
    animation: pulse 1.6s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent); }
    70% { box-shadow: 0 0 0 8px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

.tabs { display: flex; gap: .35rem; overflow-x: auto; margin-bottom: 1rem; padding-bottom: 2px; }
.tabs a {
    padding: .45rem .9rem; border-radius: 99px; white-space: nowrap;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-2); font-weight: 600; font-size: .88rem;
}
.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.back-link { display: inline-flex; align-items: center; gap: .3rem; font-weight: 600; margin-bottom: .75rem; }
.back-link .icon { width: 18px; height: 18px; }

/* ---------------- Auth pages ---------------- */

.auth-wrap {
    min-height: 100vh;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: calc(1.5rem + var(--safe-t)) 1rem calc(1rem + var(--safe-b));
    background:
        radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--primary) 22%, transparent), transparent),
        radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--accent) 18%, transparent), transparent),
        var(--bg);
}
.auth-card {
    width: 100%; max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 1.75rem 1.5rem;
}
.auth-card.wide { max-width: 920px; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem 1.1rem; margin-bottom: .4rem; font-weight: 600; }

/* ---------------- Minimisable drawer (desktop) ---------------- */
.collapse-btn { display: none; }
@media (min-width: 1024px) {
    .sidebar { transition: width .2s ease; }
    .main { transition: margin-left .2s ease; }
    .brand { padding-right: 56px; }
    .collapse-btn { display: inline-grid; position: absolute; top: 14px; right: 10px; }
    html.nav-mini { --sidebar-w: 76px; }
    html.nav-mini .brand { justify-content: center; padding: 1rem 0 3.4rem; }
    html.nav-mini .brand span,
    html.nav-mini .side-nav a > span:not(.pill),
    html.nav-mini .side-user-info { display: none; }
    html.nav-mini .collapse-btn { top: 62px; right: 18px; transform: rotate(180deg); }
    html.nav-mini .side-nav { padding: .5rem; }
    html.nav-mini .side-nav a { justify-content: center; padding: .7rem 0; position: relative; }
    html.nav-mini .side-nav .pill { position: absolute; top: 3px; right: 6px; padding: 0 5px; font-size: .62rem; }
    html.nav-mini .side-user { flex-direction: column; padding-left: 0; padding-right: 0; gap: .4rem; }
}

/* Parent dashboard: ride in progress */
.live-banner {
    display: flex; align-items: center; gap: .85rem; margin-bottom: 1rem;
    padding: .9rem 1rem; border-radius: var(--radius); color: #fff;
    background: linear-gradient(135deg, #1d4ed8, #7c3aed); box-shadow: var(--shadow);
}
.live-banner:hover { text-decoration: none; filter: brightness(1.05); }
.live-banner .grow { flex: 1; min-width: 0; }
.live-banner strong { display: block; font-size: 1rem; }
.live-banner small { color: rgba(255, 255, 255, .85); }
.live-banner .live-dot { background: #4ade80; }
.live-banner-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .18); flex-shrink: 0; }
.live-banner .btn { background: #fff; color: #1d4ed8; }

/* ---------------- Reports ---------------- */
.report-types { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); margin-bottom: 1rem; }
.report-types a {
    display: flex; gap: .7rem; align-items: flex-start; padding: .8rem .9rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
}
.report-types a:hover { text-decoration: none; border-color: var(--primary); }
.report-types a.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary) inset; }
.report-types .stat-icon { width: 38px; height: 38px; }
.report-types strong { display: block; font-size: .92rem; }
.report-types small { display: block; font-size: .78rem; line-height: 1.35; }
.presets { display: flex; flex-wrap: wrap; gap: .4rem .5rem; align-items: center; margin-top: .9rem; font-size: .85rem; }
.presets a { padding: .2rem .7rem; border-radius: 99px; border: 1px solid var(--border); color: var(--text-2); font-weight: 600; }
.presets a:hover { text-decoration: none; border-color: var(--primary); }
.presets a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.kpi-row { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.kpi-row .kpi { padding: .7rem .85rem; border-radius: var(--radius-sm); background: var(--surface-2); border-left: 4px solid var(--primary); }
.kpi-row small { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kpi-row strong { font-size: 1.35rem; font-weight: 800; }
.report-table .total-row td { font-weight: 800; background: var(--primary-soft); border-top: 2px solid var(--primary); }
.export-btns .btn { min-height: 38px; }

/* ---------------- Manual / Help / About ---------------- */
.doc { max-width: 920px; }
.doc h2 { display: flex; align-items: center; gap: .5rem; font-size: 1.2rem; margin: 0 0 .75rem; scroll-margin-top: 80px; }
.doc h3 { font-size: 1rem; margin: 1.1rem 0 .4rem; scroll-margin-top: 80px; }
.doc p, .doc li { color: var(--text-2); }
.doc ol, .doc ul { padding-left: 1.3rem; margin: 0 0 1rem; }
.doc li { margin-bottom: .4rem; }
.doc li strong, .doc p strong { color: var(--text); }
.ui {
    display: inline-block; padding: 0 .45rem; border-radius: 6px; white-space: nowrap;
    background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .88em;
}
.tip { border-left: 4px solid var(--primary); background: var(--surface-2); padding: .7rem .9rem; border-radius: 0 10px 10px 0; margin: .75rem 0 1rem; color: var(--text-2); }
.tip.warn { border-left-color: #d97706; }
.toc { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.toc a {
    display: flex; align-items: center; gap: .55rem; padding: .7rem .85rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
    color: var(--text); font-weight: 600;
}
.toc a:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.toc a.mine { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.legend { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin: .5rem 0 1rem; }
.legend div { display: flex; align-items: center; gap: .6rem; color: var(--text-2); }
.legend .swatch { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.doc table.table { margin-bottom: 1rem; }
.faq-search { position: relative; margin-bottom: 1rem; }
.faq-search .icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.faq-search input { padding-left: 2.5rem; }
.faq details { border-bottom: 1px solid var(--border); }
.faq details:last-child { border-bottom: 0; }
.faq summary {
    list-style: none; cursor: pointer; padding: .9rem 1.1rem; font-weight: 700;
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-size: 1.3rem; color: var(--text-3); line-height: 1; }
.faq details[open] summary::after { content: "–"; }
.faq details > div { padding: 0 1.1rem 1rem; color: var(--text-2); }
.faq details > div p:last-child, .faq details > div ul:last-child, .faq details > div ol:last-child { margin-bottom: 0; }
.faq .cat { padding: .6rem 1.1rem; background: var(--surface-2); font-size: .78rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); border-bottom: 1px solid var(--border); }
.about-hero { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.about-hero img { border-radius: 22px; box-shadow: var(--shadow); }
.about-hero h2 { font-size: 1.5rem; margin: 0; }
.feature-list { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.feature-list div { display: flex; gap: .7rem; align-items: flex-start; }
.feature-list .stat-icon { width: 38px; height: 38px; }
.feature-list strong { display: block; }
.feature-list small { display: block; color: var(--text-3); }
@media print {
    .toc, .faq-search, .footer-links, .no-print { display: none !important; }
    .faq details > div { display: block !important; }
    .doc .card { break-inside: avoid-page; border: 0; }
}
.layout-auth .site-footer { padding: 1.25rem 1rem 0; margin: 0; }
/* Logo (white artwork: shown on a white tile so it also looks right in dark mode) */
.auth-logo { text-align: center; margin: -.25rem 0 1.25rem; }
.auth-logo img { display: inline-block; width: 170px; height: auto; background: #fff; border-radius: 18px; padding: 6px; }
.auth-logo p { margin: .5rem 0 0; color: var(--text-3); font-size: .9rem; }
.brand img { background: #fff; border-radius: 10px; padding: 2px; box-shadow: 0 1px 3px rgba(15, 23, 42, .15); }
.brand-fab { background: #fff; }
.brand-fab img { border-radius: 50%; }
.about-logo { width: 150px; height: auto; background: #fff; border-radius: 20px; padding: 6px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.5rem; }
.auth-brand img { border-radius: 14px; }
.auth-brand h1 { font-size: 1.3rem; margin: 0; }
.auth-brand p { margin: 0; color: var(--text-3); font-size: .9rem; }
.auth-card .field { margin-bottom: 1rem; }
.auth-foot { text-align: center; margin-top: 1.25rem; color: var(--text-3); font-size: .92rem; }
.role-choice { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.role-choice label { cursor: pointer; }
.role-choice input { position: absolute; opacity: 0; }
.role-choice .opt {
    display: flex; flex-direction: column; align-items: center; gap: .3rem;
    padding: .9rem .5rem; border: 2px solid var(--border); border-radius: var(--radius-sm);
    font-weight: 600; color: var(--text-2); text-align: center;
}
.role-choice .opt small { font-weight: 400; font-size: .76rem; }
.role-choice input:checked + .opt { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* Utilities */
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.flex { display: flex; align-items: center; gap: .5rem; }
.flex-wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.nowrap { white-space: nowrap; }
.hide-sm { display: none; }
@media (min-width: 640px) { .hide-sm { display: initial; } }
[hidden] { display: none !important; }

@media print {
    .sidebar, .topbar, .bottom-nav, .btn, .filters, .offline-bar { display: none !important; }
    .main { margin: 0 !important; }
    .card { box-shadow: none; }
}

/* =====================================================================
   Live GPS map (ride-hailing style)
   ===================================================================== */
.layout-live { overflow: hidden; height: 100vh; height: 100dvh; }
.live-app { position: fixed; inset: 0; }
.live-map { position: absolute; inset: 0; background: var(--muted-soft); }
.leaflet-container { font-family: var(--font); }
@media (prefers-color-scheme: dark) {
    .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.6); }
    .leaflet-control-attribution { background: rgba(22, 28, 40, .8) !important; color: var(--text-3); }
    .leaflet-control-attribution a { color: var(--text-2); }
    .leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border); }
}
.layout-live .leaflet-top { top: calc(var(--safe-t) + 64px); }

.live-topbar {
    position: absolute; z-index: 1000;
    top: calc(var(--safe-t) + 12px); left: 12px; right: 12px;
    display: flex; align-items: center; gap: .6rem; pointer-events: none;
}
.live-topbar > * { pointer-events: auto; }
.live-fab {
    width: 44px; height: 44px; border-radius: 50%;
    display: inline-grid; place-items: center;
    background: var(--surface); color: var(--text); border: 0; cursor: pointer;
    box-shadow: 0 2px 10px rgba(15, 23, 42, .25);
}
.live-fab:hover { text-decoration: none; }
.brand-fab img { border-radius: 8px; }
.live-recenter { position: absolute; z-index: 1000; right: 10px; top: calc(var(--safe-t) + 150px); color: var(--primary); }
.live-pill {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .5rem .9rem; border-radius: 99px;
    background: var(--surface); color: var(--text);
    font-weight: 700; font-size: .85rem;
    box-shadow: 0 2px 10px rgba(15, 23, 42, .25);
}
.live-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); }
.live-pill.ok .dot { background: #16a34a; animation: pulse 1.6s infinite; }
.live-pill.bad .dot { background: #f59e0b; }
.live-toast { position: absolute; z-index: 1100; top: calc(var(--safe-t) + 66px); left: 12px; right: 12px; max-width: 480px; margin: 0 auto; box-shadow: var(--shadow-lg); }

/* Bottom sheet (phones/tablets) / side panel (desktop) */
.live-sheet {
    position: absolute; z-index: 1000; left: 0; right: 0; bottom: 0;
    max-height: 46vh; max-height: 46dvh; overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface); color: var(--text);
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -8px 30px rgba(15, 23, 42, .22);
    padding: 0 1.1rem calc(.75rem + var(--safe-b));
    transition: max-height .3s ease;
}
.live-sheet.expanded { max-height: 86vh; max-height: 86dvh; }
.live-sheet.collapsed { max-height: 150px; overflow: hidden; }
.sheet-handle { display: block; width: 100%; padding: .6rem 0 .5rem; border: 0; cursor: pointer; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.sheet-handle span { display: block; width: 44px; height: 5px; border-radius: 99px; background: var(--border); margin: 0 auto; }
@media (min-width: 900px) {
    .live-sheet {
        top: calc(var(--safe-t) + 72px); left: 16px; bottom: 16px; right: auto;
        width: 390px; max-height: none; border-radius: 18px; padding-top: 1rem;
    }
    .live-sheet.collapsed, .live-sheet.expanded { max-height: none; overflow-y: auto; }
    .sheet-handle { display: none; }
    .layout-live .leaflet-top.leaflet-right { top: 12px; }
    .live-recenter { top: 100px; }
    .live-toast { left: 420px; }
}
.sheet-msg { padding: 1.5rem .5rem; text-align: center; color: var(--text-3); }
.sheet-head { position: relative; padding: .25rem 0 .5rem; }
.sheet-head::after { content: ""; display: block; clear: both; }
.sheet-eta { float: right; text-align: right; margin: 0 0 .25rem .75rem; line-height: 1.1; }
.sheet-eta strong { display: block; font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.sheet-eta small { color: var(--text-3); font-weight: 600; }
.sheet-title { font-size: 1.15rem; font-weight: 800; line-height: 1.3; }
.sheet-sub { color: var(--text-2); font-size: .9rem; margin-top: .15rem; }
.sheet-meta { color: var(--text-3); font-size: .8rem; margin-top: .3rem; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .9rem 0 .25rem; }
.sheet-actions form, .sheet-actions > a { flex: 1 1 140px; }
.sheet-actions .btn { width: 100%; }
.sheet-driver {
    display: flex; align-items: center; gap: .75rem;
    margin-top: .9rem; padding: .85rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.sheet-driver .grow { flex: 1; min-width: 0; }
.plate {
    display: inline-block; padding: 0 .4rem; border-radius: 5px; font-weight: 800; letter-spacing: .04em;
    background: #fef3c7; color: #0f172a; border: 1px solid #d6b44b; font-family: ui-monospace, Consolas, monospace; font-size: .8rem;
}
.call-btn { flex-shrink: 0; }
.sheet-list-title { margin: 1rem 0 .25rem; font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.sheet-list { list-style: none; margin: 0; padding: 0; }
.sheet-list li { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.sheet-list li:last-child { border-bottom: 0; }
.sheet-list .grow { flex: 1; min-width: 0; }
.sheet-list small { display: block; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop-num { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .8rem; }
.sheet-trip { margin-top: .9rem; font-size: .8rem; color: var(--text-3); }
.sheet-footer { margin-top: .75rem; text-align: center; font-size: .75rem; color: var(--text-3); }

/* Map markers */
.car-marker { position: relative; width: 48px; height: 48px; }
.car-body {
    position: absolute; left: 5px; top: 5px; width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center; color: #fff;
    background: #1d4ed8; border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
}
.car-pulse { position: absolute; inset: 0; border-radius: 50%; background: rgba(29, 78, 216, .35); animation: carpulse 2s infinite; }
@keyframes carpulse { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(1.5); opacity: 0; } }
.car-heading { position: absolute; inset: -9px; }
.car-heading::before {
    content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
    border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 10px solid #1d4ed8;
}
.car-marker.stale .car-body { background: #64748b; }
.car-marker.stale .car-pulse { display: none; }
.car-marker.stale .car-heading::before { border-bottom-color: #64748b; }

.stop-marker {
    width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
    display: grid; place-items: center; background: #f59e0b; border: 3px solid #fff;
    box-shadow: 0 3px 8px rgba(0, 0, 0, .3);
}
.stop-marker span { transform: rotate(45deg); color: #fff; font-weight: 800; font-size: .8rem; display: grid; place-items: center; }
.stop-marker.school { width: 38px; height: 38px; background: #7c3aed; }
.stop-marker.mine { outline: 3px solid rgba(29, 78, 216, .55); outline-offset: 2px; }
.st-waiting { background: #f59e0b; }
.st-picked_up { background: #0284c7; }
.st-dropped_off { background: #16a34a; }
.st-absent { background: #94a3b8; }

/* Driver GPS sharing control */
.gps-panel {
    display: flex; align-items: center; gap: .6rem;
    padding: .6rem .75rem; margin-bottom: .5rem;
    border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
}
.gps-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; background: var(--text-3); }
.gps-on .gps-dot { background: #16a34a; animation: pulse 1.6s infinite; }
.gps-wait .gps-dot { background: #f59e0b; }
.gps-err .gps-dot { background: #dc2626; }
.gps-err { border-color: var(--danger); }
.gps-text { flex: 1; font-size: .88rem; font-weight: 600; }

/* Location picker (forms) */
.map-picker { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.picker-tools { display: flex; flex-wrap: wrap; gap: .5rem; padding: .6rem; border-bottom: 1px solid var(--border); }
.picker-tools input { flex: 1 1 200px; min-height: 40px; }
.picker-map { height: 300px; }
.picker-info { padding: .5rem .75rem; font-size: .82rem; color: var(--text-3); border-top: 1px solid var(--border); }
.picker-results { list-style: none; margin: 0; padding: 0; max-height: 180px; overflow-y: auto; }
.picker-results li { padding: .5rem .75rem; border-bottom: 1px solid var(--border); font-size: .85rem; cursor: pointer; }
.picker-results li:hover, .picker-results li:focus { background: var(--primary-soft); outline: none; }
.track-link { display: flex; gap: .5rem; flex-wrap: wrap; }
.track-link input { flex: 1 1 240px; font-size: .85rem; }

/* =====================================================================
   Messaging
   ===================================================================== */
.chat {
    display: grid; grid-template-columns: 1fr; height: calc(100dvh - 230px); min-height: 460px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.chat-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.chat-list-head { display: flex; align-items: center; gap: .5rem; padding: .85rem 1rem; font-weight: 800; border-bottom: 1px solid var(--border); }
.chat-list-items { overflow-y: auto; flex: 1; }
.chat-item {
    width: 100%; display: flex; align-items: center; gap: .7rem; padding: .75rem 1rem;
    background: none; border: 0; border-bottom: 1px solid var(--border); text-align: left; cursor: pointer; color: var(--text); font: inherit;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--primary-soft); }
.chat-item .grow { flex: 1; min-width: 0; }
.chat-item strong { display: block; }
.chat-item small, .chat-item .chat-last { display: block; color: var(--text-3); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .chat-last { color: var(--text-2); }
.chat-meta { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; }
.chat-meta .pill { background: var(--danger); color: #fff; font-size: .7rem; font-weight: 800; padding: 1px 7px; border-radius: 99px; }
.chat-avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 1.1rem; flex-shrink: 0; background: var(--primary-soft); }
.chat-avatar.private { background: #ede9fe; }
.chat-thread { display: none; flex-direction: column; min-height: 0; }
.chat.thread-open .chat-list { display: none; }
.chat.thread-open .chat-thread { display: flex; }
.chat-thread-head { display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem; border-bottom: 1px solid var(--border); }
.chat-thread-head .grow { flex: 1; min-width: 0; }
.chat-title { font-weight: 800; }
.chat-members { font-size: .75rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; background: var(--bg); display: flex; flex-direction: column; gap: .5rem; }
.chat-empty { margin: auto; text-align: center; color: var(--text-3); padding: 1.5rem; max-width: 320px; }
.chat-day { text-align: center; margin: .5rem 0; }
.chat-day span { font-size: .72rem; font-weight: 700; color: var(--text-3); background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: .15rem .7rem; }
.msg { display: flex; gap: .45rem; align-items: flex-end; max-width: 85%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: .7rem; font-weight: 800; flex-shrink: 0; }
.msg-bubble { padding: .5rem .75rem; border-radius: 16px 16px 16px 4px; background: var(--surface); border: 1px solid var(--border); min-width: 70px; }
.msg.mine .msg-bubble { background: #1d4ed8; color: #fff; border-color: #1d4ed8; border-radius: 16px 16px 4px 16px; }
.msg-name { font-size: .75rem; font-weight: 800; margin-bottom: .1rem; }
.msg-body { white-space: normal; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-time { font-size: .68rem; opacity: .7; text-align: right; margin-top: .15rem; }
.role { font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; padding: 0 .35rem; border-radius: 4px; color: #fff; vertical-align: 1px; }
.r-parent { background: #16a34a; } .r-driver { background: #1d4ed8; } .r-student { background: #f97316; } .r-admin { background: #7c3aed; } .r-me { background: #0ea5e9; }
.chat-form { display: flex; gap: .5rem; align-items: flex-end; padding: .6rem; padding-bottom: calc(.6rem + var(--safe-b)); border-top: 1px solid var(--border); background: var(--surface); width: 100%; min-width: 0; }
/* The global rule gives textareas width:100%, which pushed the Send button out of view */
.chat-input { flex: 1 1 auto; width: auto; min-width: 0; min-height: 44px; max-height: 140px; resize: none; border-radius: 22px; padding: .6rem 1rem; }
.chat-form .btn { flex: 0 0 auto; border-radius: 22px; min-width: 72px; }
.chat-thread, .chat-messages { min-width: 0; }
.chat { width: 100%; min-width: 0; }
@media (min-width: 900px) {
    .chat { grid-template-columns: 320px 1fr; }
    .chat .chat-list, .chat.thread-open .chat-list { display: flex; }
    .chat .chat-thread { display: flex; }
    .chat-back { display: none; }
}

/* Badges on bottom bars */
.bottom-nav a, .s-tabbar button { position: relative; }
.s-badge {
    position: absolute; top: 6px; left: 50%; margin-left: 6px; min-width: 18px; height: 18px; padding: 0 4px;
    border-radius: 99px; background: var(--danger); color: #fff; font-size: .65rem; font-weight: 800; display: grid; place-items: center;
}

/* =====================================================================
   Family locations: people markers, pairing, switches
   ===================================================================== */
.person-marker {
    width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: .75rem; border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
}
.person-marker.me { width: 34px; height: 34px; font-size: .6rem; animation: carpulse-me 2s infinite; }
@keyframes carpulse-me { 0% { box-shadow: 0 0 0 0 rgba(14, 165, 233, .5); } 100% { box-shadow: 0 0 0 14px rgba(14, 165, 233, 0); } }
.person-marker.stale { opacity: .55; filter: grayscale(.6); }
.person-dot { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; color: #fff; font-size: .72rem; font-weight: 800; }
.sheet-list li.no-pan { cursor: default; border-bottom: 0; }
.family-map { height: 340px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.family-list #lmSheetBody .sheet-list-title { margin-top: .75rem; }

.pair-box { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: center; padding: 1rem; border: 2px dashed var(--primary); border-radius: var(--radius); background: var(--primary-soft); }
.pair-box img { background: #fff; border-radius: 12px; padding: 6px; }
.pair-box > div { flex: 1 1 240px; }
.pair-code { font-family: ui-monospace, Consolas, monospace; font-size: 2rem; font-weight: 800; letter-spacing: .15em; color: var(--primary); margin: .25rem 0; }
.pair-input { font-family: ui-monospace, Consolas, monospace; font-size: 1.5rem !important; letter-spacing: .2em; text-align: center; text-transform: uppercase; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; cursor: pointer; }
.switch-row small { display: block; color: var(--text-3); }
.switch-row small[data-state="on"] { color: var(--success); font-weight: 600; }
.switch-row small[data-state="err"] { color: var(--danger); }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--border); position: relative; cursor: pointer; flex-shrink: 0; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch:checked { background: #16a34a; }
.switch:checked::after { transform: translateX(20px); }

/* =====================================================================
   Student App shell
   ===================================================================== */
.student-app { --tabbar-h: 62px; }
.s-tabbar {
    position: absolute; z-index: 1200; left: 0; right: 0; bottom: 0;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    display: flex; background: var(--surface); border-top: 1px solid var(--border);
}
.s-tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: 0; cursor: pointer; color: var(--text-3); font: inherit; font-size: .72rem; font-weight: 700; }
.s-tabbar button.active { color: var(--primary); }
.s-tabbar .icon { width: 23px; height: 23px; }
.student-app .live-sheet { bottom: calc(var(--tabbar-h) + var(--safe-b)); border-radius: 22px 22px 0 0; }
.student-app .live-sheet { max-height: 40vh; max-height: 40dvh; }
.student-app .live-sheet.expanded { max-height: 75dvh; }
.s-panel { position: absolute; inset: 0 0 calc(var(--tabbar-h) + var(--safe-b)) 0; z-index: 1100; background: var(--bg); padding-top: var(--safe-t); display: flex; flex-direction: column; }
.s-panel .chat { flex: 1; height: auto; min-height: 0; border-radius: 0; border: 0; }
.s-scroll { overflow-y: auto; display: block; }
.s-me { max-width: 560px; margin: 0 auto; padding: 1.25rem 1rem 2rem; }
@media (min-width: 900px) {
    .student-app .live-sheet { bottom: calc(var(--tabbar-h) + 16px); max-height: none; }
}
.student-app .live-toast { z-index: 1300; }

/* =====================================================================
   Profile photos
   ===================================================================== */
.avatar { overflow: hidden; }
.avatar img, .has-photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
/* Small round faces keep their colour as a ring around the photo */
.person-dot.has-photo, .stop-num.has-photo, .msg-avatar.has-photo { padding: 2px; overflow: hidden; }

/* Upload card */
.photo-card .card-body { padding: .9rem 1.1rem; }
.photo-form { display: flex; align-items: center; gap: 1rem; margin: 0; }
.photo-form .grow { flex: 1; min-width: 0; }
.photo-preview { width: 76px; height: 76px; font-size: 1.4rem; position: relative; cursor: pointer; flex-shrink: 0; overflow: visible; }
.photo-preview img { border-radius: 50%; }
.photo-cam {
    position: absolute; right: -2px; bottom: -2px; width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center; background: var(--primary); color: #fff; border: 2px solid var(--surface);
}
.photo-cam .icon { width: 14px; height: 14px; }
.photo-form label.btn { cursor: pointer; }

/* Driver trip checklist: student photo with pickup number */
.attend .order.has-photo { width: 46px; height: 46px; padding: 0; position: relative; overflow: visible; background: none; }
.attend .order.has-photo img { border: 2px solid var(--border); }
.attend .order.has-photo b {
    position: absolute; right: -4px; bottom: -4px; min-width: 20px; height: 20px; border-radius: 99px;
    display: grid; place-items: center; font-size: .68rem; background: var(--primary); color: #fff; border: 2px solid var(--surface);
}

/* Map: student stop pins with photo (ring colour = status) */
.photo-pin {
    --st: #f59e0b;
    position: relative; width: 46px; height: 46px; border-radius: 50%; padding: 3px;
    background: var(--st); box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
}
.photo-pin.st-waiting { --st: #f59e0b; }
.photo-pin.st-picked_up { --st: #0284c7; }
.photo-pin.st-dropped_off { --st: #16a34a; }
.photo-pin.st-absent { --st: #94a3b8; }
.photo-pin.st-absent img { filter: grayscale(1); opacity: .7; }
.photo-pin img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 2px solid #fff; display: block; background: #fff; }
.photo-pin::after {
    content: ""; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%);
    border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 11px solid var(--st);
}
.photo-pin b {
    position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 99px;
    display: grid; place-items: center; background: #0f172a; color: #fff; font-size: .7rem; font-weight: 800; border: 2px solid #fff;
}
.photo-pin.mine { outline: 3px solid rgba(29, 78, 216, .55); outline-offset: 2px; }

/* Map: parent / student / "you" pins with photo (ring colour = role) */
.person-marker.has-photo { padding: 0; overflow: hidden; background: #fff; }
.person-marker.has-photo.r-parent { box-shadow: 0 0 0 3px #16a34a, 0 3px 10px rgba(0, 0, 0, .35); }
.person-marker.has-photo.r-student { box-shadow: 0 0 0 3px #f97316, 0 3px 10px rgba(0, 0, 0, .35); }
.person-marker.has-photo.me { width: 40px; height: 40px; box-shadow: 0 0 0 3px #0ea5e9, 0 3px 10px rgba(0, 0, 0, .35); animation: none; }
.photo-pin .pin-ini {
    width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center;
    background: #fff; color: #0f172a; font-weight: 800; font-size: .8rem; letter-spacing: .02em; border: 2px solid #fff;
}

/* Quick messages */
.chat-quick { display: flex; gap: .4rem; overflow-x: auto; padding: .5rem .6rem 0; background: var(--surface); border-top: 1px solid var(--border); scrollbar-width: none; }
.chat-quick::-webkit-scrollbar { display: none; }
.quick-chip {
    flex-shrink: 0; padding: .4rem .8rem; border-radius: 99px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text-2); font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.quick-chip:hover, .quick-chip:focus { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); outline: none; }
.chat-quick:not([hidden]) + .chat-form { border-top: 0; }
.qm-row { gap: .5rem; flex-wrap: wrap; }
.qm-row.qm-off { opacity: .5; }
.qm-form { display: flex; gap: .5rem; flex: 1 1 420px; align-items: center; margin: 0; }
.qm-form input[type=number] { width: 72px; flex: 0 0 72px; min-height: 38px; }
.qm-form input[type=text] { flex: 1; min-height: 38px; }
.qm-form select { width: 130px; flex: 0 0 130px; min-height: 38px; }

/* Backups & updates */
.backup-item { align-items: flex-start; }
.secret { background: var(--surface-2); border: 1px solid var(--border); padding: 0 .4rem; border-radius: 6px; font-weight: 800; letter-spacing: .08em; }
.dialog { border: 0; border-radius: var(--radius); padding: 1.4rem; max-width: 460px; width: calc(100% - 32px); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: rgba(15, 23, 42, .55); }
.dialog h3 { display: flex; gap: .5rem; align-items: center; }
.diff-list { max-height: 320px; overflow-y: auto; font-family: ui-monospace, Consolas, monospace; font-size: .8rem; margin: 0; padding: 0; list-style: none; }
.diff-list li { padding: .25rem .5rem; border-bottom: 1px solid var(--border); display: flex; gap: .5rem; }
.diff-list .tag { font-weight: 800; min-width: 62px; }
.tag-new { color: var(--success); } .tag-changed { color: var(--info); } .tag-deleted { color: var(--danger); }
.log-box { background: #0f172a; color: #cbd5e1; font-family: ui-monospace, Consolas, monospace; font-size: .8rem; padding: .8rem 1rem; border-radius: var(--radius-sm); max-height: 260px; overflow-y: auto; white-space: pre-wrap; }
.badge-superadmin { background: #0f172a; color: #fbbf24; }
.badge-admin { background: #ede9fe; color: #6d28d9; }
@media (prefers-color-scheme: dark) { .badge-superadmin { background: #fbbf24; color: #0f172a; } }
.protected-note { display: inline-flex; align-items: center; gap: .3rem; font-size: .75rem; font-weight: 700; color: var(--text-3); }
.protected-note .icon { width: 14px; height: 14px; }

/* Messages page on phones/tablets: fit the chat between the top bar and the bottom navigation
   so the typing bar and Send button are never hidden behind the bottom bar. */
@media (max-width: 1023px) {
    .content:has(> .chat) {
        flex: 0 0 auto; /* do not stretch under the bottom navigation */
        display: flex; flex-direction: column;
        height: calc(100dvh - var(--topbar-h) - var(--safe-t) - var(--bottom-h) - var(--safe-b));
        padding-bottom: .5rem; overflow: hidden;
    }
    .content:has(> .chat) > .page-head { margin-bottom: .5rem; flex-shrink: 0; }
    .content:has(> .chat) > .page-head p { display: none; }
    .content:has(> .chat) > .alert { flex-shrink: 0; }
    .content:has(> .chat) > .chat { flex: 1 1 auto; height: auto; min-height: 0; }
    .main:has(> .content > .chat) > .site-footer { display: none; }
}

/* System reset & readiness */
.check-item { align-items: flex-start; }
.check-dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; color: #fff; }
.check-dot .icon { width: 16px; height: 16px; }
.check-dot.ok { background: #16a34a; } .check-dot.bad { background: #dc2626; } .check-dot.info { background: #64748b; }
.reset-opt { display: flex; gap: .75rem; align-items: flex-start; padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: .5rem; cursor: pointer; }
.reset-opt input { width: 20px; height: 20px; margin-top: 2px; flex-shrink: 0; }
.reset-opt small { display: block; color: var(--text-3); }
.reset-opt:has(input:checked) { border-color: var(--danger); background: var(--danger-soft); }
