/* ──────────────────────────────────────────────────────────────
   Design tokens (P0 — "manuscript / scholarly" direction).
   All new work and migrations key off these variables; avoid
   hardcoding hexes in templates. Financial semantics (due / clear)
   are intentionally unchanged. See AGENTS.md §4 + the frontend
   review note in planning/.
   ────────────────────────────────────────────────────────────── */
:root {
    /* canvas + structure */
    --bg: #f4f1e9;            /* parchment (was #f5f5f5) */
    --surface: #fffdf8;       /* card / panel, warm white (was #fff) */
    --surface-2: #f6f3ea;     /* subtle inset panel (was #f8fafc) */
    --ink: #20283d;           /* primary text (was #333) */
    --ink-muted: #6b6f7a;     /* secondary text (was #666/#888/#64748b) */
    --ink-faint: #9aa0ac;     /* tertiary text (was #999/#94a3b8) */
    --line: #e7e1d4;          /* hairlines (was #ddd/#eee/#e5e7eb/#e2e8f0) */

    /* brand + accent */
    --brand: #283655;         /* ink-indigo — primary actions, links */
    --brand-hover: #1c2740;
    --brand-soft: #eef1f7;    /* tinted primary backgrounds (was #eff6ff) */
    --sidebar-bg: #20283d;
    --accent: #b45309;        /* marigold — active nav, sparing highlights */
    --accent-soft: #fdf6ec;

    /* financial + feature semantics (values unchanged on purpose) */
    --due: #dc2626;   --due-bg: #fef2f2;  --due-border: #fca5a5;
    --clear: #16a34a; --clear-bg: #f0fdf4; --clear-border: #bbf7d0;
    --remind: #7c3aed; --remind-bg: #faf5ff; --remind-border: #e9d5ff;

    /* system */
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(32,40,61,.06);
    --shadow: 0 1px 2px rgba(32,40,61,.04), 0 6px 18px rgba(32,40,61,.07);
    --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
    --font-body: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-body); background: var(--bg); color: var(--ink); }

/* Header */
.header { background: var(--surface); color: var(--ink); padding: 12px 16px; position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.header h1 { font-size: 20px; font-family: var(--font-display); font-weight: 600; letter-spacing: 0.01em; }

/* Hamburger toggle (mobile only) */
.sidebar-toggle { display: none; background: none; border: none; color: var(--ink); font-size: 22px; cursor: pointer; padding: 4px 8px; }

/* Layout: sidebar + content */
.layout { display: flex; min-height: calc(100vh - 48px); }

/* Sidebar */
.sidebar {
    width: 200px;
    min-width: 200px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    position: sticky;
    top: 48px;
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
    overflow-y: auto;
    z-index: 15;
}
.sidebar a {
    color: #cbd5e1;
    text-decoration: none;
    padding: 12px 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}
.sidebar a:hover {
    background: rgba(255,255,255,0.06);
    color: #f1f5f9;
}
.sidebar a.active {
    background: rgba(180,83,9,0.16);
    color: #f0b366;
    border-left-color: var(--accent);
    font-weight: 600;
}

/* Sidebar user section (bottom) */
.sidebar-spacer { flex: 1; }

/* Email-remove button on add/edit forms.
   - Sits on the LEFT of the row (order:-1 in the flex container).
   - Red by default so the destructive intent is unmistakable.
   - Deeper red on hover/focus.
   - 36×36 hit target so phones can land taps reliably.
   - JS handler asks for confirmation before deleting a non-empty
     email (see template scripts). */
.email-remove {
    order: -1; /* moves to the start of the flex row */
    flex: 0 0 auto;
    width: 36px; height: 36px;
    border: 1px solid #fecaca;
    background: #fee2e2;
    border-radius: 8px;
    cursor: pointer;
    color: #b91c1c;
    font-size: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    line-height: 1;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    padding: 0;
    margin-right: 2px;
}
.email-remove:hover, .email-remove:focus {
    background: #fecaca;
    color: #7f1d1d;
    border-color: #fca5a5;
    outline: none;
}
.email-remove:active { transform: scale(0.94); }

/* Section labels group related links (e.g. Messaging → Compose, Outbox).
   Quiet caps-style header; the entries underneath get a small inset so
   the grouping reads visually. */
.sidebar-section {
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 20px 4px;
}
.sidebar a.sidebar-sub {
    padding-left: 32px;
    font-size: 13px;
}
.sidebar-user {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 0;
    cursor: pointer;
    user-select: none;
    display: flex;
    flex-direction: column;
}
.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
}
.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #3b82f6;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}
.sidebar-user-name { color: #f1f5f9; font-size: 13px; font-weight: 600; }
.sidebar-user-role { color: #94a3b8; font-size: 11px; text-transform: capitalize; }
.sidebar-user-arrow {
    margin-left: auto;
    color: #94a3b8;
    font-size: 12px;
    transition: transform 0.2s;
}
.sidebar-user.open .sidebar-user-arrow { transform: rotate(90deg); }
.sidebar-user-menu {
    display: none;
    flex-direction: column;
    background: rgba(0,0,0,0.15);
    order: -1;
}
.sidebar-user.open .sidebar-user-menu { display: flex; }
.sidebar-user-menu a {
    color: #cbd5e1;
    text-decoration: none;
    padding: 10px 20px 10px 58px;
    font-size: 13px;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-user-menu a:hover {
    background: rgba(255,255,255,0.06);
    color: #f1f5f9;
}

/* Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 14;
}

/* Content area */
.content {
    flex: 1;
    max-width: 700px;
    margin: 0 auto;
    padding: 20px 16px;
}

/* Mobile: sidebar off-canvas */
@media (max-width: 768px) {
    .sidebar-toggle { display: block; }
    .sidebar {
        position: fixed;
        top: 48px;
        left: -220px;
        width: 220px;
        min-width: 220px;
        height: calc(100vh - 48px);
        height: calc(100dvh - 48px);
        transition: left 0.25s ease;
        box-shadow: 4px 0 16px rgba(0,0,0,0.2);
    }
    body.sidebar-open .sidebar { left: 0; }
    body.sidebar-open .sidebar-overlay { display: block; }
    .content { max-width: 100%; }
}

/* Search bar */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; background: var(--surface); color: var(--ink); }
.search-bar button { padding: 10px 16px; background: var(--brand); color: white; border: none; border-radius: 8px; font-size: 16px; cursor: pointer; }

/* Filter & Sort toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.filter-pills { display: flex; gap: 4px; }
.filter-pill { padding: 5px 10px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; cursor: pointer; color: var(--ink-muted); transition: all 0.15s; }
.filter-pill span { font-weight: 700; }
.filter-pill:hover { border-color: var(--brand); color: var(--brand); }
.filter-pill.active { background: var(--brand); color: white; border-color: var(--brand); }
.toolbar-selects { display: flex; gap: 6px; }
.toolbar-select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 12px; color: var(--ink); cursor: pointer; }
.toolbar-select:focus { outline: none; border-color: var(--brand); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h3 { font-size: 17px; margin-bottom: 4px; font-family: var(--font-display); font-weight: 600; }
.card .meta { font-size: 13px; color: var(--ink-muted); margin-bottom: 4px; }
.card .subjects { font-size: 13px; color: var(--brand); }
.card .student-id { font-size: 12px; color: var(--ink-faint); font-family: monospace; font-variant-numeric: tabular-nums; }
.card .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.card .balance { font-size: 14px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.balance-due { color: var(--due); }
.balance-clear { color: var(--clear); }

/* Compact student cards */
.card-compact { padding: 10px 14px; margin-bottom: 8px; }
.card-compact h3 { font-size: 15px; margin-bottom: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-family: var(--font-display); font-weight: 600; }
.card-row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-name-block { flex: 1; min-width: 0; }
.card-meta-line { font-size: 12px; color: var(--ink-muted); line-height: 1.5; word-break: break-word; }
.card-balance { font-size: 14px; font-weight: 700; white-space: nowrap; padding-top: 2px; font-variant-numeric: tabular-nums; }
.card-balance-btn { font-size: 14px; font-weight: 700; white-space: nowrap; padding: 4px 10px; border-radius: 8px; text-decoration: none; transition: background 0.15s; display: inline-block; font-variant-numeric: tabular-nums; }
.card-balance-btn.balance-due { color: var(--due); background: var(--due-bg); border: 1px solid var(--due-border); }
.card-balance-btn.balance-due:hover { background: #fee2e2; }
.card-balance-btn.balance-clear { color: var(--clear); background: var(--clear-bg); border: 1px solid var(--clear-border); }
.card-balance-btn.balance-clear:hover { background: #dcfce7; }
.card-actions-compact { display: flex; gap: 4px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.card-actions-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); margin-left: 62px; }
@media (max-width: 480px) { .card-actions-row { margin-left: 0; } }
.badge-checked-in { background: #dbeafe; color: #1d4ed8; }

/* Pill buttons (compact with short text labels) */
.pill { display: inline-flex; align-items: center; gap: 2px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 12px; text-decoration: none; color: var(--ink); transition: background 0.15s; white-space: nowrap; line-height: 1.3; }
.pill:hover { background: var(--surface-2); }
.pill-primary { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.pill-primary:hover { background: #e2e7f1; }
.pill-danger { border-color: var(--due-border); color: var(--due); background: var(--due-bg); }
.pill-danger:hover { background: #fee2e2; }
.pill-green { border-color: var(--clear-border); color: var(--clear); background: var(--clear-bg); }
.pill-green:hover { background: #dcfce7; }

/* Quick modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: white; border-radius: 12px; padding: 24px; width: 100%; max-width: 380px; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 8px 30px rgba(0,0,0,0.2); }
.modal-box h3 { font-size: 16px; margin-bottom: 16px; font-family: var(--font-display); font-weight: 600; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge-active { background: var(--clear-bg); color: #166534; }
.badge-inactive { background: var(--due-bg); color: #991b1b; }

/* Buttons */
.btn { padding: 8px 16px; border: none; border-radius: 8px; font-size: 14px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-danger { background: var(--due); color: white; }
.btn-outline { background: var(--surface); color: var(--brand); border: 1px solid var(--brand); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* FAB */
.fab { position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; background: var(--accent); color: white; border: none; border-radius: 50%; font-size: 28px; cursor: pointer; box-shadow: 0 6px 16px rgba(180,83,9,0.4); z-index: 10; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.form-group input, .form-group select { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; background: var(--surface); color: var(--ink); }
.form-group input:focus, .form-group select:focus, .search-bar input:focus, .search-wrap > input:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(40,54,85,0.14);
}
/* Checkboxes/radios inside .form-group are sized for inline rows;
   the 100%-width rule above is for text fields, not toggles. */
.form-group input[type="checkbox"], .form-group input[type="radio"] {
    width: auto; padding: 0; border: 0; margin: 0;
    flex: 0 0 auto;
}
.checkbox-group { display: flex; flex-wrap: wrap; gap: 10px; }
.checkbox-group label { font-weight: normal; display: flex; align-items: center; gap: 4px; font-size: 14px; }
.checkbox-all { font-weight: 600 !important; color: #2563eb; }

/* Misc */
.empty { text-align: center; padding: 40px 16px; color: var(--ink-faint); }
.back-link { display: inline-block; margin-bottom: 16px; color: var(--brand); text-decoration: none; font-size: 14px; }
.count { font-size: 13px; color: var(--ink-muted); margin-bottom: 12px; }
.readonly-field { background: var(--surface-2) !important; color: var(--ink-muted); }

/* Login (no sidebar, centered) */
.login-container { max-width: 360px; margin: 80px auto; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px 24px; box-shadow: var(--shadow); }
.login-card h2 { text-align: center; margin-bottom: 24px; color: var(--brand); font-family: var(--font-display); font-weight: 600; }
.error { background: var(--due-bg); color: #991b1b; padding: 10px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; text-align: center; }

/* Container (for non-logged-in pages like login) */
.container { max-width: 600px; margin: 0 auto; padding: 16px; }

/* Hide FAB behind sidebar overlay on mobile */
body.sidebar-open .fab { z-index: 5; }

@media (max-width: 480px) {
    .card-row-top { flex-direction: column; }
    .card-row-top > div:last-child { align-items: flex-start; width: 100%; }
    .card-row-top > div:last-child > div:first-child { flex-wrap: wrap; }
}

/* ── Clearable search bars ──
   A small ✕ appears at the right of a search input whenever it has
   text; clicking it (handled in base.html / base_library.html) clears
   the input and re-runs its input listener. Visibility is pure-CSS via
   :not(:placeholder-shown), so no per-keystroke JS is needed. Markup:
   <div class="search-wrap"><input placeholder="…"><button class="search-clear">✕</button></div> */
.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap > input { flex: 1; padding-right: 32px; }
.search-clear {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    border: none; background: transparent; cursor: pointer;
    color: #9ca3af; font-size: 18px; line-height: 1; padding: 0 5px;
    border-radius: 50%; display: none;
}
.search-clear:hover { color: #4b5563; background: #f1f5f9; }
.search-wrap > input:not(:placeholder-shown) + .search-clear { display: block; }
.search-wrap > input:not(:placeholder-shown) ~ .search-icon { display: none; }

/* Shared month/year picker (templates/_month_picker.html) — used on the
   salary and staff-attendance pages. 2026-07-11. */
.year-pill, .month-cell {
    display: inline-block; text-align: center; padding: 6px 10px; border-radius: 8px;
    border: 1px solid #ddd; background: #fff; color: #333; font-size: 13px;
    text-decoration: none; cursor: pointer;
}
.month-cell { padding: 8px 0; }
.year-pill.active, .month-cell.active { background: #2563eb; color: #fff; border-color: #2563eb; font-weight: 700; }
.year-pill:hover, .month-cell:hover { border-color: #2563eb; }
.month-cell.disabled { opacity: 0.35; cursor: default; pointer-events: none; background: #f8f8f8; }
.step-arrow { text-decoration: none; }
.step-arrow.disabled { opacity: 0.35; pointer-events: none; }
