:root {
    --brand: #245b49;
    --brand-hover: #173f35;
    --brand-subtle: #eaf2ee;
    --ochre: #b78632;
    --ochre-subtle: #fbf6ec;
    --error: #b13c32;
    --error-subtle: #fbeae8;
    --success: #1f6b45;
    --success-subtle: #e7f4ed;
    --page: #f7f7f2;
    --surface: #ffffff;
    --border: #dce2d9;
    --text: #263e35;
    --text-muted: #627067;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow-sm: 0 2px 8px rgba(23, 63, 53, 0.06);
    --shadow-md: 0 8px 24px rgba(23, 63, 53, 0.1);
}

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

html,
body {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    background-color: var(--page);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    min-height: 100vh;
}

[hidden] {
    display: none !important;
}

.mobile-shell {
    max-width: 520px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--page);
    position: relative;
}

@media (min-width: 540px) {
    body {
        background: #ecece4;
    }
    .mobile-shell {
        box-shadow: 0 0 40px rgba(23, 63, 53, 0.12);
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}

/* Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 58px;
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    flex-shrink: 0;
}

.header-title {
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.icon-btn:hover,
.icon-btn:focus-visible {
    background: var(--brand-subtle);
    border-color: var(--brand);
    outline: none;
}

/* Main viewport */
.app-main {
    flex: 1;
    padding: 16px 16px calc(88px + env(safe-area-inset-bottom, 0px));
    transition: opacity 0.16s ease;
}

.app-main.fade-out {
    opacity: 0.25;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 45;
}

.nav-tab {
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 48px;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.nav-tab.active {
    color: var(--brand);
    background: var(--brand-subtle);
}

/* Typography */
.dap-eyebrow {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ochre);
    margin-bottom: 4px;
}

.dap-display {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 30px;
    font-weight: 400;
    line-height: 1.2;
    color: var(--text);
    margin-bottom: 8px;
}

h1, .h1 { font-size: 24px; font-weight: 700; line-height: 1.25; color: var(--text); }
h2, .h2 { font-size: 20px; font-weight: 700; line-height: 1.3; color: var(--text); }
h3, .h3 { font-size: 17px; font-weight: 700; line-height: 1.35; color: var(--text); }
h4, .h4 { font-size: 15px; font-weight: 600; line-height: 1.4; color: var(--text); }

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--error); }
.text-success { color: var(--success); }
.small { font-size: 13px; line-height: 1.45; }
.xs { font-size: 11.5px; line-height: 1.4; }
.fw-bold { font-weight: 700; }
.fw-semibold { font-weight: 600; }

/* Cards & Surfaces */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
}

.card-interactive {
    display: block;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.12s ease;
    text-decoration: none;
    color: inherit;
}

.card-interactive:hover,
.card-interactive:focus-visible {
    border-color: var(--brand);
    outline: none;
}

.hero-card {
    background: linear-gradient(155deg, #ffffff 0%, #f1f5f0 100%);
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 16px;
}

/* Forms & Controls */
.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 5px;
}

.form-control,
.form-select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    font-size: 15px;
    color: var(--text);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    appearance: none;
    -webkit-appearance: none;
}

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23263e35' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    min-height: 88px;
    resize: vertical;
}

.form-control:focus,
.form-select:focus {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
    border-color: var(--brand);
}

.input-with-toggle {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-toggle .form-control {
    padding-right: 68px;
}

.toggle-visibility-btn {
    position: absolute;
    right: 6px;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    background: var(--page);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
}

.form-check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.form-check-input {
    width: 20px;
    height: 20px;
    margin-top: 2px;
    accent-color: var(--brand);
    flex-shrink: 0;
}

.form-text {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 18px;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    min-height: 44px;
    padding: 8px 14px;
    font-size: 14px;
}

.button1,
.btn-primary {
    background-color: var(--brand);
    color: #ffffff;
    border-color: var(--brand);
}

.button1:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
    background-color: var(--brand-hover);
    border-color: var(--brand-hover);
}

.dap-secondary,
.btn-secondary {
    background-color: var(--surface);
    color: var(--brand);
    border-color: var(--border);
}

.dap-secondary:hover:not(:disabled),
.btn-secondary:hover:not(:disabled) {
    background-color: var(--brand-subtle);
    border-color: var(--brand);
}

.btn-success {
    background-color: var(--success);
    color: #ffffff;
    border-color: var(--success);
}

.btn-danger-outline {
    background-color: var(--surface);
    color: var(--error);
    border-color: #e9b9b5;
}

/* Alerts & Banners */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 13.5px;
    margin-bottom: 12px;
}

.alert-info {
    background: var(--brand-subtle);
    border-color: #b7d2c8;
    color: var(--brand-hover);
}

.alert-success {
    background: var(--success-subtle);
    border-color: #b2dfc6;
    color: #14492e;
}

.alert-warning {
    background: var(--ochre-subtle);
    border-color: #e6cf9f;
    color: #6c4c13;
}

.alert-danger {
    background: var(--error-subtle);
    border-color: #eab7b2;
    color: #7d231b;
}

.toast-banner {
    position: sticky;
    top: 58px;
    z-index: 39;
    margin: 8px 16px 0;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-brand { background: var(--brand-subtle); color: var(--brand-hover); border-color: #c2dad1; }
.badge-success { background: var(--success-subtle); color: var(--success); border-color: #b9e2cb; }
.badge-warning { background: var(--ochre-subtle); color: #835c16; border-color: #e6cf9f; }
.badge-danger { background: var(--error-subtle); color: var(--error); border-color: #eab7b2; }
.badge-neutral { background: #f1f3ef; color: var(--text-muted); border-color: var(--border); }

/* Layout Helpers */
.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.align-start { align-items: flex-start; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }

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

/* Divider list */
.item-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.list-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    background: var(--surface);
}

/* PIN Entry */
.pin-boxes {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 16px 0;
}

.pin-input-single {
    width: 180px;
    text-align: center;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.45em;
    padding-left: 20px;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(23, 63, 53, 0.48);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Spinner */
.spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    border-top-color: currentColor;
    animation: dap-spin 0.8s linear infinite;
}

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

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


/* Text people may want to copy or edit */
input, textarea, select, .selectable {
    -webkit-user-select: text;
    user-select: text;
}

/* Form validation: one box above the Submit button, plus a mark on each field */
.form-errors {
    margin-bottom: 12px;
    scroll-margin-bottom: 96px;
}
.form-errors ul {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
}
.form-errors li + li {
    margin-top: 2px;
}
.form-errors .error-link {
    background: none;
    border: 0;
    padding: 6px 0;
    min-height: 32px;
    font: inherit;
    color: inherit;
    text-align: left;
    text-decoration: underline;
    cursor: pointer;
}
.is-invalid {
    border-color: var(--error) !important;
    box-shadow: 0 0 0 1px var(--error);
}
.field-error {
    color: var(--error);
    font-size: 12.5px;
    font-weight: 600;
    margin-top: 4px;
}

/* File picker (replaces the raw browser file input) */
.file-native {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
.file-pick {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
}
.file-pick-name {
    flex: 1 1 140px;
    min-width: 0;
    overflow-wrap: anywhere;
}
.btn-link {
    background: none;
    border: 0;
    color: var(--brand);
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    min-height: 44px;
    padding: 0 6px;
    cursor: pointer;
}
.link-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 16px;
    margin-top: 12px;
}
.link-row a {
    color: var(--brand);
    font-weight: 600;
    padding: 12px 0;
}

/* Offline notice */
.offline-banner {
    position: sticky;
    top: 58px;
    z-index: 38;
    background: var(--ochre-subtle);
    color: #6c4c13;
    border-bottom: 1px solid #e6cf9f;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
}

/* School directory: one card per school, one button per open grade */
.grade-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.grade-chip {
    min-height: 44px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--brand);
    background: var(--surface);
    color: var(--brand);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.grade-chip:active {
    background: var(--brand-subtle);
}
.grade-chip:disabled {
    opacity: 0.6;
}
.section-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}


/* Needs-attention list and learner chips */
.attention-item {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font: inherit;
    color: inherit;
    cursor: pointer;
}
.attention-item.urgent { border-left-color: var(--error); background: var(--error-subtle); }
.attention-item .fw-bold { display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Application progress */
.timeline {
    list-style: none;
    display: flex;
    gap: 4px;
    margin: 12px 0 4px;
    padding: 0;
}
.timeline li {
    flex: 1;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    border-top: 4px solid var(--border);
    padding-top: 6px;
}
.timeline li.done { border-top-color: var(--brand); color: var(--brand); }
.timeline li.current { border-top-color: var(--ochre); color: var(--text); }
.timeline li.bad { border-top-color: var(--error); color: var(--error); }

.checklist { list-style: none; margin: 0 0 12px; padding: 0; font-size: 13.5px; }
.checklist li { padding: 2px 0; color: var(--text-muted); }
.checklist li.ok { color: var(--success); font-weight: 600; }
.checklist li::before { content: '\25CB\00a0'; }
.checklist li.ok::before { content: '\2713\00a0'; }

.file-pick-scan { flex-basis: 100%; display: flex; align-items: center; gap: 8px; min-height: 44px; color: var(--text-muted); }

.btn-google {
    background: #fff;
    color: #263e35;
    border-color: var(--border);
}
.divider-text { text-align: center; color: var(--text-muted); font-size: 12.5px; margin: 14px 0; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }

/* Tablets and wide phones in landscape */
@media (min-width: 700px) {
    .mobile-shell, .bottom-nav { max-width: 720px; }
    .app-main { padding-left: 24px; padding-right: 24px; }
    .item-list { gap: 12px; }
}
@media (max-height: 480px) and (orientation: landscape) {
    .app-main { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
    .nav-tab { min-height: 44px; flex-direction: row; justify-content: center; }
}

#mainContent:focus { outline: none; }

details > summary { color: var(--brand); font-weight: 600; }
