/* Smart CDR — mobile-first */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-alt: #fafbfc;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --ink: #111827;
    --ink-muted: #6b7280;
    --ink-faint: #9ca3af;
    --primary: #2563eb;
    --primary-ink: #ffffff;
    --primary-soft: #dbeafe;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --error: #b91c1c;
    --error-soft: #fee2e2;
    --success: #047857;
    --success-soft: #d1fae5;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 2px 8px rgba(17, 24, 39, 0.06);
    --tap: 44px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    /* Always render in the light palette, even on dark-mode devices,
       so form controls / scrollbars don't flip to dark. */
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Niramit", "Sarabun", "Noto Sans Thai", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.45;
    min-height: 100dvh;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
}

p {
    margin: 0 0 0.75rem;
}

.muted { color: var(--ink-muted); }
.meta { color: var(--ink-faint); font-size: 0.85rem; }

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover { text-decoration: underline; }

code {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.9em;
    background: var(--surface-alt);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 1.1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
    outline: 3px solid var(--primary-soft);
    outline-offset: 2px;
}
.btn-primary {
    background: var(--primary);
    color: var(--primary-ink);
    border-color: var(--primary);
}
.btn-secondary {
    background: var(--surface);
    color: var(--primary);
    border-color: var(--border-strong);
}
.btn-full { width: 100%; }

/* --- Page layouts --- */
.page-center {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    padding-top: calc(1.25rem + var(--safe-top));
    padding-bottom: calc(1.25rem + var(--safe-bottom));
}
.card-narrow {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    text-align: center;
}
.brand-mark {
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.badge-error { background: var(--error-soft); color: var(--error); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-success { background: var(--success-soft); color: var(--success); }

/* --- App shell (post-login) --- */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    padding-top: calc(var(--safe-top) + 0.25rem);
    height: calc(56px + var(--safe-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.app-bar-title {
    font-weight: 700;
    letter-spacing: -0.01em;
}
.app-bar-action {
    min-width: var(--tap);
    min-height: var(--tap);
    display: grid;
    place-items: center;
    color: var(--ink-muted);
    font-size: 1.25rem;
    border-radius: var(--radius-sm);
}
.app-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: calc(var(--tap) + 1.5rem + var(--safe-bottom) + 32px);
}

.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.hero-greeting { font-size: 1rem; }

.role-pill {
    display: inline-block;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.role-superadmin { background: #fef3c7; color: #92400e; }
.role-vp { background: #ede9fe; color: #5b21b6; }
.role-disciplinedept { background: #fee2e2; color: #991b1b; }
.role-hrt { background: var(--success-soft); color: var(--success); }
.role-teacher { background: var(--primary-soft); color: var(--primary); }

/* --- Stats --- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
@media (min-width: 480px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}
.stat-label { color: var(--ink-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.1; margin: 0.25rem 0; }
.stat-foot { color: var(--ink-faint); font-size: 0.8rem; }
.stat-foot-warn { color: var(--warn); }

/* --- Action tiles --- */
.actions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 600px) {
    .actions-grid { grid-template-columns: repeat(4, 1fr); }
}
.action-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    text-align: center;
    box-shadow: var(--shadow);
    min-height: 110px;
    color: inherit;
    text-decoration: none;
}
.action-tile-disabled { opacity: 0.55; pointer-events: none; }
.action-emoji { font-size: 1.7rem; }
.action-label { font-weight: 600; font-size: 0.95rem; }
.action-foot { font-size: 0.7rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.04em; }

/* --- Admin panel --- */
.admin-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}
.inline-form { margin: 0 0 0.5rem; }

.flash {
    margin: 0.75rem 0 0;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    border: 1px solid transparent;
}
.flash-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.flash-error { background: var(--error-soft); color: var(--error); border-color: var(--error); }
.flash-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

/* Full-width toast banner that slides across the top of the screen, then auto-dismisses.
   Used for the "บันทึกแล้ว" save confirmation. */
.flash-toast {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 2000;
    margin: 0;
    padding: 1rem 1.25rem;
    border: 0;
    border-radius: 0;
    text-align: center;
    font-size: 1.15rem;
    font-weight: 700;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.18);
    animation: flashToastIn 0.28s ease-out;
}
.flash-toast.hide { animation: flashToastOut 0.4s ease-in forwards; }
@keyframes flashToastIn {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}
@keyframes flashToastOut {
    from { transform: translateY(0);     opacity: 1; }
    to   { transform: translateY(-100%); opacity: 0; }
}

/* --- Bottom nav --- */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding-bottom: var(--safe-bottom);
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: var(--tap);
    padding: 0.4rem 0.25rem;
    color: var(--ink-muted);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 600;
}
.nav-item .nav-icon { font-size: 1.15rem; }
.nav-item.active { color: var(--primary); }
.nav-item-disabled { opacity: 0.45; pointer-events: none; }

/* Desktop: transform bottom nav into a top horizontal nav strip below the app-bar */
@media (min-width: 720px) {
    .bottom-nav {
        position: sticky;
        top: calc(56px + var(--safe-top));
        bottom: auto;
        z-index: 9;
        grid-template-columns: repeat(4, 1fr);
        justify-items: stretch;
        gap: 0.5rem;
        padding: 0.4rem 1rem;
        background: var(--surface);
        border-top: 0;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
        padding-bottom: 0.4rem;
    }
    .nav-item {
        flex-direction: row;
        gap: 0.4rem;
        font-size: 0.9rem;
        padding: 0.45rem 0.9rem;
        border-radius: var(--radius-sm);
        min-height: 40px;
    }
    .nav-item .nav-icon { font-size: 1rem; }
    .nav-item.active {
        background: var(--primary-soft);
    }
    .nav-item:hover:not(.nav-item-disabled):not(.active) {
        background: var(--surface-alt);
        color: var(--ink);
    }

    .app-main {
        max-width: 960px;
        padding-bottom: 2rem;
        padding-top: 1.25rem;
    }

    /* Wider list pages */
    .card-list { grid-template-columns: 1fr; }
}

@media (min-width: 1100px) {
    /* Pad the app-bar / nav content to look intentional on big screens */
    .app-bar {
        padding: 0 2rem;
        padding-top: calc(var(--safe-top) + 0.25rem);
    }
    .bottom-nav {
        padding: 0.4rem 2rem;
    }

    /* On real desktop, hint two-column card list */
    .app-main { max-width: 1080px; }
    .card-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

/* --- Forms (Phase 1) --- */
fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 0.85rem 1rem 1rem;
    margin: 0 0 0.85rem;
    box-shadow: var(--shadow);
}
legend {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-muted);
    padding: 0 0.4rem;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="date"], textarea, select {
    width: 100%;
    min-height: var(--tap);
    padding: 0.55rem 0.75rem;
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { min-height: 96px; resize: vertical; }

input.is-invalid, textarea.is-invalid, select.is-invalid {
    border-color: var(--error);
    background: var(--error-soft);
}
input.is-invalid:focus, textarea.is-invalid:focus, select.is-invalid:focus {
    border-color: var(--error);
    box-shadow: 0 0 0 3px var(--error-soft);
}

.check {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: var(--tap);
    margin: 0.4rem 0;
    cursor: pointer;
}
.check input { width: 20px; height: 20px; }

.step { position: relative; }

.step.is-locked { opacity: 0.55; }
.step.is-locked legend { color: var(--ink-muted); }
.step.is-locked select,
.step.is-locked input,
.step.is-locked textarea {
    background: var(--bg);
    color: var(--ink-faint);
    cursor: not-allowed;
}
.step-lock-hint {
    margin: 0.4rem 0 0;
    font-size: 13px;
    color: var(--ink-muted);
}

.radio-cards { display: grid; gap: 0.5rem; }
@media (min-width: 480px) { .radio-cards { grid-template-columns: 1fr 1fr; } }
.radio-card {
    position: relative;
    display: block;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.9rem;
    cursor: pointer;
    background: var(--surface);
    transition: border-color 0.1s, box-shadow 0.1s;
}
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card-body strong { display: block; font-size: 1rem; }
.radio-card-body small { color: var(--ink-muted); }
.radio-card:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 1px var(--primary);
}

/* Student picker */
.picker[data-state="empty"] .picker-chip { display: none; }
.picker[data-state="picked"] .picker-empty { display: none; }
.picker-results {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.picker-results li { border-bottom: 1px solid var(--border); }
.picker-results li:last-child { border-bottom: none; }
.picker-result {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    padding: 0.65rem 0.85rem;
    background: transparent;
    border: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    min-height: var(--tap);
}
.picker-result:hover, .picker-result:focus-visible { background: var(--surface-alt); }
.pr-name { font-weight: 600; }
.pr-meta { color: var(--ink-muted); font-size: 0.85rem; }
.picker-noresult {
    padding: 0.85rem; color: var(--ink-muted); text-align: center;
}
.picker-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    background: var(--primary-soft);
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
}
.picker-chip-name { font-weight: 700; }
.picker-chip-meta { color: var(--ink-muted); font-size: 0.85rem; display: flex; gap: 0.5rem; }
.picker-clear {
    background: transparent; border: 0; color: var(--primary);
    font-size: 1.1rem; cursor: pointer; min-width: var(--tap); min-height: var(--tap);
}

/* Live preview */
.preview-card {
    background: var(--surface);
    border: 1px solid var(--primary);
    border-left-width: 4px;
    border-radius: var(--radius);
    margin: 0 0 1rem;
    overflow: hidden;
}
.preview-head {
    background: var(--primary-soft);
    color: var(--primary);
    padding: 0.4rem 0.85rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.preview-body { padding: 0.85rem; }
.preview-body > div:first-child { font-weight: 600; font-size: 1.05rem; margin-bottom: 0.5rem; }
.preview-meta { display: flex; gap: 1rem; color: var(--ink-muted); font-size: 0.9rem; }
.preview-warn { margin-top: 0.5rem; color: var(--warn); font-weight: 600; }

/* Sticky action bar */
.sticky-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, var(--bg) 60%, transparent);
    padding: 0.75rem 0;
    display: flex;
    gap: 0.5rem;
}
.sticky-actions .btn { flex: 1; }

/* --- Filter bar (list) --- */
.filter-bar {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.seg {
    display: inline-grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    padding: 3px;
    overflow: hidden;
    width: 100%;
}
.seg-item {
    text-align: center;
    padding: 0.45rem 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-muted);
    text-decoration: none;
    border-radius: 999px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.seg-item.is-active {
    background: var(--primary);
    color: var(--primary-ink);
}
.result-count { margin: 0.25rem 0 0.75rem; }

/* --- Card list (list page) --- */
.card-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.6rem;
}
.card-link {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
}
.card-link:hover, .card-link:focus-visible { border-color: var(--primary); }
.card-head {
    display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem;
}
.card-title { font-weight: 700; }
.card-time { color: var(--ink-faint); font-size: 0.8rem; white-space: nowrap; }
.card-sub { color: var(--ink-muted); font-size: 0.85rem; margin-top: 0.15rem; }
.card-cat { margin: 0.4rem 0 0.5rem; line-height: 1.35; }
.card-pills { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.pill {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--surface-alt);
    color: var(--ink-muted);
}
.pill-level1 { background: var(--warn-soft); color: var(--warn); }
.pill-level2 { background: var(--error-soft); color: var(--error); }
.pill-active { background: var(--primary-soft); color: var(--primary); }
.pill-resolved { background: var(--success-soft); color: var(--success); }
.pill-meeting { background: #ede9fe; color: #5b21b6; }
.pill-score { background: var(--surface-alt); color: var(--ink); border: 1px solid var(--border); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 1rem 0 0; }
.pager-info { color: var(--ink-muted); font-size: 0.9rem; }
.btn-disabled { opacity: 0.4; pointer-events: none; }

.empty {
    text-align: center;
    padding: 2rem 1rem;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}
.empty-emoji { font-size: 2.5rem; margin-bottom: 0.4rem; }

/* --- Detail page --- */
.detail-hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
}
.detail-hero h1 { margin: 0 0 0.15rem; }
.detail-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
}
.detail-block h2 { font-size: 0.95rem; }
.dl-row {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 0.5rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
}
.dl-row:last-child { border-bottom: 0; }
.dl-row dt { color: var(--ink-muted); font-size: 0.85rem; font-weight: 500; margin: 0; }
.dl-row dd { margin: 0; }
@media (max-width: 480px) {
    .dl-row { grid-template-columns: 1fr; gap: 0.1rem; }
    .dl-row dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
}

.action-details { margin: 0.5rem 0; }
.action-details > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.action-details > summary::-webkit-details-marker { display: none; }
.stacked-form {
    display: grid;
    gap: 0.5rem;
    margin: 0.5rem 0;
}
.row-actions {
    display: flex; gap: 0.5rem; margin-top: 0.5rem;
}
.row-actions .btn { flex: 1; }
.actions-block { display: grid; gap: 0.5rem; }

.btn-danger {
    background: var(--error);
    color: #fff;
    border-color: var(--error);
}
.danger-zone {
    margin-top: 1.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border-strong);
}

/* --- Attendance / Tidiness Phase 5 --- */
.att-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0.5rem 0 0.75rem;
}
.bulk-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.roster {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.4rem;
}
.roster-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
    align-items: center;
    padding: 0.55rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.roster-name { line-height: 1.2; }
.roster-name strong { font-size: 0.95rem; }
.roster-name .muted { display: block; font-size: 0.78rem; }

.status-grid {
    display: grid;
    grid-template-columns: repeat(4, 36px);
    gap: 4px;
}
.status-radio {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--ink-muted);
    user-select: none;
}
.status-radio input { position: absolute; opacity: 0; }
.status-radio.is-active.status-present { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.status-radio.is-active.status-late { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.status-radio.is-active.status-absent { background: var(--error-soft); color: var(--error); border-color: var(--error); }
.status-radio.is-active.status-excused { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

.tidy-grid {
    display: grid;
    grid-template-columns: repeat(2, auto);
    gap: 0.25rem 0.6rem;
    align-items: center;
}
.tidy-cell {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    cursor: pointer;
    min-height: 28px;
}
.tidy-cell input { width: 18px; height: 18px; }
@media (min-width: 480px) {
    .tidy-grid { grid-template-columns: repeat(4, auto); }
}

/* --- Kiosk Phase 6 --- */
.kiosk-body {
    background: linear-gradient(135deg, var(--primary-soft), var(--bg));
    min-height: 100dvh;
}
.kiosk-screen {
    max-width: 480px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem;
    padding-top: calc(2.5rem + var(--safe-top));
    padding-bottom: calc(2.5rem + var(--safe-bottom));
    text-align: center;
}
.kiosk-title {
    text-align: center;
    color: var(--primary);
    font-size: 1.4rem;
    margin: 0 0 1.5rem;
    letter-spacing: 0.02em;
}
.kiosk-prompt {
    font-size: 1.1rem;
    color: var(--ink-muted);
    margin-bottom: 0.75rem;
}
.kiosk-pin-input {
    width: 100%;
    text-align: center;
    font-size: 2.5rem !important;
    letter-spacing: 1rem;
    padding: 0.75rem !important;
    margin: 0 0 1rem;
    font-family: ui-monospace, monospace !important;
}
.kiosk-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;
    margin: 1rem 0;
}
.kiosk-key {
    min-height: 64px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 1.6rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.08s, background 0.1s;
}
.kiosk-key:active { transform: scale(0.97); background: var(--primary-soft); }
.kiosk-key-alt { font-size: 1.3rem; color: var(--ink-muted); }
.kiosk-submit { margin-top: 0.5rem; }

.kiosk-greeting {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}
.kiosk-greeting-name { font-size: 1.4rem; font-weight: 700; }
.kiosk-greeting-meta { color: var(--ink-muted); margin-top: 0.2rem; }

.kiosk-big-btn {
    width: 100%;
    min-height: 80px !important;
    font-size: 1.2rem !important;
    margin-bottom: 0.75rem;
}
.kiosk-back { display: block; }
.kiosk-foot {
    margin-top: 2rem;
    color: var(--ink-faint);
    font-size: 0.85rem;
}

/* --- Reports Phase 4 --- */

/* Date range picker bar */
.date-range-bar {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.5rem;
    align-items: end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
}
.date-range-bar label { display: block; min-width: 0; }
.date-range-bar label.grow { grid-column: 1 / -1; }
.date-range-bar .btn { min-height: var(--tap); white-space: nowrap; }
@media (min-width: 600px) {
    .date-range-bar { grid-template-columns: 2fr 1fr 1fr auto; }
}

/* Compact 6-up stat grid */
.stat-grid-tight {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
@media (min-width: 480px) {
    .stat-grid-tight { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 720px) {
    .stat-grid-tight { grid-template-columns: repeat(6, 1fr); }
}
.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 0.75rem;
    box-shadow: var(--shadow);
    min-height: 80px;
}
.stat-tile-label {
    color: var(--ink-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.stat-tile-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
    margin: 0.15rem 0;
}
.stat-tile-value.stat-l1 { color: var(--warn); }
.stat-tile-value.stat-l2 { color: var(--error); }
.stat-tile-foot { color: var(--ink-faint); font-size: 0.72rem; }

/* Horizontal bar list */
.bar-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.5rem;
}
.bar-list li { width: 100%; }
.bar-row-link, .bar-list > li > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(80px, 1.5fr) 40px;
    align-items: center;
    gap: 0.6rem;
    color: inherit;
    text-decoration: none;
}
@media (max-width: 480px) {
    .bar-row-link, .bar-list > li > div {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        gap: 0.2rem;
    }
    .bar-count { text-align: left; }
}
.bar-label {
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bar-track {
    height: 18px;
    background: var(--surface-alt);
    border-radius: 999px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    background: linear-gradient(to right, var(--primary), var(--primary-soft));
    border-radius: 999px;
    min-width: 3px;
}
.bar-fill-alt {
    background: linear-gradient(to right, var(--warn), #fcd34d);
}
.bar-count {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.bar-row-link:hover .bar-fill { filter: brightness(1.08); }

/* Hub section (reports.php bottom CTAs) */
.report-hub {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin: 1rem 0 1.5rem;
}

/* Event list (student timeline) */
.event-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.5rem;
}
.event-row {
    display: grid;
    grid-template-columns: 110px 1fr auto;
    gap: 0.6rem;
    align-items: center;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
}
.event-row:hover { border-color: var(--primary); }
.event-when {
    font-variant-numeric: tabular-nums;
    color: var(--ink-muted);
    font-size: 0.85rem;
}
.event-label { font-weight: 600; }
.event-sub { font-size: 0.85rem; }
.event-pill {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.2rem;
}
.event-ded {
    color: var(--error);
    font-weight: 700;
    font-size: 0.85rem;
}
@media (max-width: 480px) {
    .event-row {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
    }
    .event-when {
        grid-column: 1 / -1;
        order: -1;
    }
    .event-pill { align-items: flex-end; }
}

/* --- Meetings Phase 3 --- */
.tile-badge {
    position: absolute;
    top: 6px;
    right: 8px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--error);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.action-tile { position: relative; }

.seg-states {
    grid-template-columns: repeat(5, 1fr);
}
.seg-count {
    display: inline-block;
    margin-left: 0.3rem;
    padding: 0 0.3rem;
    min-width: 16px;
    height: 16px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    color: inherit;
}
.seg-item.is-active .seg-count {
    background: rgba(255, 255, 255, 0.25);
}
@media (max-width: 520px) {
    .seg-states { grid-template-columns: repeat(3, 1fr); row-gap: 4px; }
}

/* Timeline (cdr_view meeting section) */
.timeline {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 1rem;
    border-left: 2px solid var(--border);
}
.timeline li {
    position: relative;
    padding: 0.4rem 0 0.6rem 1.25rem;
    margin-left: 0.5rem;
}
.tl-dot {
    position: absolute;
    left: -1.55rem;
    top: 0.55rem;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border-strong);
}
.timeline li.tl-current .tl-dot {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 4px var(--primary-soft);
}
.timeline li.tl-done .tl-dot {
    background: var(--success);
    border-color: var(--success);
}
.tl-head { font-weight: 600; }
.tl-sub { font-size: 0.88rem; }
.tl-sub.muted { color: var(--ink-muted); }

/* --- Lateness Phase 2 --- */
.row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.row-2 label { display: block; }
.field-label {
    display: block;
    color: var(--ink-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0 0 0.65rem;
}
.chip {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: 0.45rem 0.85rem;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.chip:hover, .chip:focus-visible {
    border-color: var(--primary);
}
.chip.is-active {
    background: var(--primary);
    color: var(--primary-ink);
    border-color: var(--primary);
}

/* Floating action button */
.fab {
    position: fixed;
    right: 1rem;
    bottom: calc(var(--tap) + 1.5rem + var(--safe-bottom) + 16px);
    width: 56px;
    height: 56px;
    border-radius: 999px;
    background: var(--primary);
    color: var(--primary-ink);
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
    text-decoration: none;
    z-index: 15;
}
@media (min-width: 720px) {
    .fab { bottom: 1.5rem; }
}
