/* ═══════════════════════════════════════════
   Jam3ah — Instructor portal
   Self-contained. Deliberately NOT importing admin.css: only the design
   TOKENS below are copied from it, so the two files can never couple.
   Phone-first — most teachers open this on a phone.
   ═══════════════════════════════════════════ */

/* NO @import of Google Fonts here (admin.css has one). This portal must have
   zero external dependencies: a render-blocking font request on a phone in
   Kuwait is the slowest thing on the page, and the portal has to work when the
   network is poor. The families are named first so a device that already has
   them uses them; everything else falls back to the system UI font. */

/* ── Design tokens (copied from public/admin/admin.css) ── */
:root {
    --bg-primary: #0A0D1A;
    --bg-secondary: #101428;
    --bg-card: rgba(16, 20, 40, 0.7);
    --bg-input: rgba(16, 20, 40, 0.6);

    --text-primary: #F1F3F9;
    --text-secondary: #9BA3C2;
    --text-muted: #636D8C;

    --accent-primary: #2E3192;
    --accent-light: #7B80D4;

    --border-default: rgba(155, 163, 194, 0.12);
    --border-focus: #2E3192;

    --error-color: #EF4136;
    --success-color: #22C55E;
    --warn-color: #F0A62A;

    --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    /* Nothing on this page may scroll the BODY sideways. Wide content
       (the month grid) scrolls inside its own container instead. */
    overflow-x: hidden;
}

.bg-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse at top left, rgba(46, 49, 146, 0.10) 0%, transparent 55%),
        radial-gradient(ellipse at bottom right, rgba(239, 65, 54, 0.04) 0%, transparent 55%);
}

[hidden] {
    display: none !important;
}

/* ── Boot + takeover screens ── */
.boot,
.gate {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
}

.spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid var(--border-default);
    border-top-color: var(--accent-light);
    animation: spin 0.9s linear infinite;
}

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

.gate-card {
    width: 100%;
    max-width: 460px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 28px 22px;
}

.gate-icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.gate-card h1 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.gate-card p {
    font-size: 0.95rem;
    line-height: 1.6;
}

.gate-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 18px;
}

.gate-actions:empty {
    display: none;
}

/* ── Shell ── */
.app {
    position: relative;
    z-index: 1;
    max-width: 880px;
    margin: 0 auto;
    /* Bottom + sides clear the home indicator and the landscape notch. The TOP
       needs no inset: index.html keeps the iOS status bar as its own strip. */
    padding: 0 max(14px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left));
}

.top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 0 12px;
    border-bottom: 1px solid var(--border-default);
}

.top-main {
    min-width: 0;
}

.brand {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.brand-sub {
    color: var(--accent-light);
    font-weight: 500;
}

.who {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
    overflow-wrap: anywhere;
}

.top-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chip-btn {
    font-family: var(--font-body);
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: 999px;
    padding: 7px 12px;
    cursor: pointer;
    white-space: nowrap;
}

.chip-btn:hover {
    border-color: var(--accent-light);
    color: var(--text-primary);
}

.chip-btn.on {
    color: var(--success-color);
    border-color: rgba(34, 197, 94, 0.4);
}

/* ── Tabs ── */
.tabs {
    display: grid;
    /* Run 13 added the Messages tab — four across. */
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 10px 0;
    background: var(--bg-primary);
}

.tab {
    display: block;
    text-align: center;
    text-decoration: none;
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 10px 6px;
    white-space: nowrap;
}

.tab.active {
    color: #fff;
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.main {
    padding-top: 4px;
}

/* ⚠ The tab bar above is sticky at top:0 and opaque. Anything the BROWSER
   scrolls to by itself — a focused input, an anchor, scrollIntoView() — is
   otherwise parked underneath it and stops receiving taps entirely
   (document.elementFromPoint returns the tab, so the tap changes tab instead).
   Proved twice: the pinned card's ✕ and the availability week chips.
   Keep this larger than the tab bar's rendered height. */
.week-chip,
.seg-btn,
.btn,
.mini-btn,
.blk,
.blk-del,
.cal-chip,
.s-card,
.panel,
.fld input,
.fld select,
.note-row textarea,
.chat-composer textarea,
.chat-head {
    scroll-margin-top: 86px;
}

.foot {
    margin-top: 32px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── Generic bits ── */
h2 {
    font-family: var(--font-display);
    font-size: 0.98rem;
    font-weight: 600;
}

.lead {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-bottom: 12px;
}

.muted {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.small {
    font-size: 0.78rem;
}

.hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.hint.dirty {
    color: var(--warn-color);
}

.err {
    font-size: 0.82rem;
    color: var(--error-color);
    margin-top: 8px;
    min-height: 1px;
}

.err:empty {
    display: none;
}

.section-label {
    font-family: var(--font-display);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-top: 16px;
}

.panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.empty {
    padding: 26px 14px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    background: var(--bg-card);
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-md);
}

.notice {
    font-size: 0.85rem;
    line-height: 1.55;
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    background: rgba(123, 128, 212, 0.10);
    border: 1px solid rgba(123, 128, 212, 0.32);
    color: var(--text-primary);
    margin-bottom: 12px;
}

.notice-warn {
    background: rgba(240, 166, 42, 0.10);
    border-color: rgba(240, 166, 42, 0.38);
}

/* ── Buttons ── */
/* `a.btn` is used on the gate screen — without this the browser underlines it
   and it stops reading as a button. */
.btn {
    display: inline-block;
    text-align: center;
    text-decoration: none;
    font-family: var(--font-display);
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-input);
    color: var(--text-primary);
    padding: 11px 16px;
    cursor: pointer;
}

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

.btn-primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    filter: brightness(1.15);
}

.btn-ghost:hover:not(:disabled) {
    border-color: var(--accent-light);
}

.btn-block {
    display: block;
    width: 100%;
}

.mini-btn {
    font-family: var(--font-body);
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    cursor: pointer;
    min-width: 34px;
}

.mini-btn:hover {
    border-color: var(--accent-light);
    color: var(--text-primary);
}

/* ── Segmented control ── */
.seg {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: 999px;
    margin-bottom: 12px;
}

.seg-btn {
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    border-radius: 999px;
    padding: 7px 16px;
    cursor: pointer;
}

.seg-btn.active {
    background: var(--accent-primary);
    color: #fff;
}

/* ── Session cards ── */
.cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.s-card {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-left: 3px solid var(--accent-light);
    border-radius: var(--radius-md);
    padding: 13px 14px;
}

.s-card.st-completed {
    border-left-color: var(--success-color);
}

.s-card.st-cancelled {
    border-left-color: var(--error-color);
    opacity: 0.8;
}

.s-card.pinned {
    box-shadow: 0 0 0 1px var(--accent-light);
}

.s-when {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.s-card.st-cancelled .s-when {
    text-decoration: line-through;
}

.s-who {
    font-size: 0.92rem;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.s-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 7px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.s-meta .dot {
    color: var(--text-muted);
}

.pill {
    display: inline-block;
    font-size: 0.7rem;
    letter-spacing: 0.02em;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid transparent;
    white-space: nowrap;
}

.pill-scheduled {
    color: #A5A8FF;
    background: rgba(99, 102, 241, 0.16);
    border-color: rgba(165, 168, 255, 0.35);
}

.pill-completed {
    color: #4ADE80;
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(74, 222, 128, 0.35);
}

.pill-cancelled {
    color: #F87171;
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(248, 113, 113, 0.35);
}

.pill-group {
    color: var(--accent-light);
    background: rgba(123, 128, 212, 0.14);
    border-color: rgba(123, 128, 212, 0.35);
}

.pill-extra {
    color: var(--warn-color);
    background: rgba(240, 166, 42, 0.12);
    border-color: rgba(240, 166, 42, 0.35);
}

.s-names {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.s-focus {
    margin-top: 9px;
    padding: 9px 11px;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: rgba(123, 128, 212, 0.09);
    border-radius: var(--radius-sm);
    overflow-wrap: anywhere;
}

.s-focus b {
    color: var(--accent-light);
    font-weight: 600;
}

.s-actions {
    margin-top: 11px;
}

.btn-join {
    display: inline-block;
    text-decoration: none;
    text-align: center;
    font-family: var(--font-display);
    font-size: 0.88rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent-primary);
    border-radius: var(--radius-sm);
    padding: 10px 22px;
}

.btn-join:hover {
    filter: brightness(1.15);
}

.pinned-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

#pinnedWrap {
    margin-bottom: 16px;
    /* The tab bar is sticky at top:0. Without this, scrollIntoView() parks the
       pinned card UNDER it and its ✕ becomes un-tappable — elementFromPoint
       returns the tab, so "dismiss" silently switched tabs instead. Must stay
       larger than the tab bar's rendered height. */
    scroll-margin-top: 86px;
}

/* ── Month calendar ── */
.cal-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cal-month {
    font-family: var(--font-display);
    font-size: 0.88rem;
    white-space: nowrap;
    min-width: 108px;
    text-align: center;
}

/* On a PHONE all seven days must be on screen. Widening the grid and letting
   it scroll sideways (what the admin panel does) hid Thu–Sat behind a scroll
   the teacher has no reason to suspect — so the phone grid fits instead, and
   the chip drops the student's name (the cards above already carry it).
   The sideways scroll stays as the safety net for very narrow screens. */
.cal-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.cal-wrap {
    min-width: 300px;
}

.cal-chip-who {
    display: none;
}

@media (min-width: 560px) {
    .cal-wrap {
        min-width: 600px;
    }

    .cal-chip-who {
        display: inline;
    }
}

.cal-weekdays,
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-weekdays {
    gap: 1px;
    margin-bottom: 1px;
}

.cal-dayname {
    padding: 6px 4px;
    text-align: center;
    font-family: var(--font-display);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--bg-secondary);
}

.cal-grid {
    gap: 1px;
    background: var(--border-default);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.cal-cell {
    min-height: 76px;
    padding: 3px;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cal-cell.other-month {
    background: rgba(17, 24, 39, 0.45);
}

.cal-cell.other-month .cal-daynum {
    color: var(--text-muted);
    opacity: 0.6;
}

.cal-cell.other-month .cal-chip {
    opacity: 0.55;
}

.cal-cell.cal-today {
    box-shadow: inset 0 0 0 1px var(--accent-light);
}

.cal-daynum {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.cal-cell.cal-today .cal-daynum {
    color: var(--accent-light);
}

.cal-chip {
    display: block;
    width: 100%;
    text-align: left;
    font-family: var(--font-body);
    padding: 2px 3px;
    border: 0;
    border-left: 2px solid transparent;
    border-radius: 3px;
    font-size: 0.6rem;
    line-height: 1.35;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 560px) {
    .cal-chip {
        padding: 3px 5px;
        border-left-width: 3px;
        border-radius: 4px;
        font-size: 0.68rem;
    }

    .cal-cell {
        min-height: 82px;
        padding: 5px;
        gap: 3px;
    }
}

.cal-chip:hover {
    filter: brightness(1.25);
}

.cal-chip-scheduled {
    background: rgba(99, 102, 241, 0.16);
    border-left-color: #A5A8FF;
    color: #A5A8FF;
}

.cal-chip-completed {
    background: rgba(34, 197, 94, 0.14);
    border-left-color: #4ADE80;
    color: #4ADE80;
}

.cal-chip-cancelled {
    background: rgba(239, 68, 68, 0.12);
    border-left-color: #F87171;
    color: #F87171;
    text-decoration: line-through;
}

.cal-chip b {
    font-weight: 600;
}

/* ── Earnings ── */
.earn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.earn-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 14px;
    min-width: 0;
}

.earn-card.hero {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, rgba(46, 49, 146, 0.45), rgba(16, 20, 40, 0.7));
    border-color: rgba(123, 128, 212, 0.35);
}

.earn-label {
    font-size: 0.74rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.earn-value {
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
}

.earn-card.hero .earn-value {
    font-size: 1.8rem;
}

.earn-value .cur {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-left: 4px;
}

#earnActivity {
    margin-top: 10px;
}

/* ── Tables (pending months / transfers) ── */
.tbl-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tbl {
    width: 100%;
    min-width: 320px;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.tbl th {
    text-align: left;
    font-family: var(--font-display);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 500;
    padding: 6px 10px 6px 0;
    border-bottom: 1px solid var(--border-default);
}

.tbl td {
    padding: 9px 10px 9px 0;
    border-bottom: 1px solid var(--border-default);
    color: var(--text-secondary);
    vertical-align: top;
}

.tbl td:first-child {
    color: var(--text-primary);
    white-space: nowrap;
}

.tbl td.num {
    color: var(--text-primary);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.tbl tr:last-child td {
    border-bottom: 0;
}

/* ── Availability ── */
.week-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}

.week-chip {
    text-align: left;
    font-family: var(--font-body);
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    cursor: pointer;
    min-width: 0;
}

.week-chip:hover {
    border-color: var(--accent-light);
}

.week-chip.active {
    border-color: var(--accent-light);
    background: rgba(123, 128, 212, 0.14);
}

.week-chip .wk-date {
    display: block;
    font-family: var(--font-display);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
}

.week-chip .wk-status {
    display: block;
    font-size: 0.71rem;
    margin-top: 3px;
    overflow-wrap: anywhere;
}

.wk-confirmed {
    color: var(--success-color);
}

.wk-carried {
    color: var(--warn-color);
}

.wk-none {
    color: var(--text-muted);
}

#copyWrap {
    margin-bottom: 14px;
}

#copyLastBtn {
    padding: 14px 16px;
    font-size: 0.95rem;
    font-weight: 600;
}

.blocks {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.blocks:empty {
    display: none;
}

.blk {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 10px 11px;
}

.blk-main {
    flex: 1;
    min-width: 0;
}

.blk-when {
    font-size: 0.87rem;
    font-weight: 600;
    color: var(--text-primary);
}

.blk-reason {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
    overflow-wrap: anywhere;
}

.blk-del {
    font-size: 0.85rem;
    line-height: 1;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border-default);
    border-radius: 6px;
    padding: 6px 9px;
    cursor: pointer;
}

.blk-del:hover {
    color: var(--error-color);
    border-color: var(--error-color);
}

.blocks-empty {
    font-size: 0.86rem;
    color: var(--text-muted);
    padding: 4px 0 2px;
}

.add-row {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-default);
}

.add-title {
    font-family: var(--font-display);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 9px;
}

.add-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    align-items: end;
}

.fld {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.fld>span {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.fld-day,
.fld-reason,
.fld-add {
    grid-column: 1 / -1;
}

.fld.check {
    flex-direction: row;
    align-items: center;
    gap: 7px;
    padding-bottom: 10px;
}

.fld.check span {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.fld.check input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
}

.fld input[type="time"],
.fld input[type="text"],
.fld select,
.note-row textarea {
    width: 100%;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 10px 11px;
    /* iOS shrinks a time/select control to its content otherwise */
    min-height: 42px;
    -webkit-appearance: none;
    appearance: none;
}

.fld select {
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
        linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
    background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 30px;
}

.fld input:focus,
.fld select:focus,
.note-row textarea:focus {
    outline: none;
    border-color: var(--border-focus);
}

.fld input.error,
.fld select.error {
    border-color: var(--error-color);
}

.fld-add .btn {
    width: 100%;
}

.note-row {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.note-row label {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.note-row textarea {
    resize: vertical;
    line-height: 1.5;
}

.save-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
}

.save-row .btn {
    min-width: 130px;
}

/* ── Toast ── */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 90;
    /* Purely informational — it must never eat a tap on the form underneath it
       (on a phone it lands right on top of the "All day" checkbox). */
    pointer-events: none;
    max-width: min(92vw, 420px);
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-left: 3px solid var(--accent-light);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.toast.ok {
    border-left-color: var(--success-color);
}

.toast.bad {
    border-left-color: var(--error-color);
}

.toast.warn {
    border-left-color: var(--warn-color);
}

/* ── Wider screens ── */
@media (min-width: 560px) {
    .app {
        padding: 0 max(20px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left));
    }

    .week-strip {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .add-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .fld-day {
        grid-column: 1 / 3;
    }

    .fld-from,
    .fld-to {
        grid-column: auto;
    }

    .fld-allday {
        grid-column: auto;
    }

    .fld-reason {
        grid-column: 1 / 4;
    }

    .fld-add {
        grid-column: 4 / 5;
    }
}

@media (min-width: 720px) {
    .earn-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .earn-card.hero {
        grid-column: auto;
    }

    .earn-card.hero .earn-value {
        font-size: 1.45rem;
    }

    .cal-cell {
        min-height: 96px;
    }
}

/* ══════════════ Messages (Run 13 — student chat) ══════════════ */

/* Four tabs are tighter than three were — shrink on narrow phones so
   "My availability" still fits on one line. */
.tab { position: relative; }
@media (max-width: 520px) {
    .tabs { gap: 4px; }
    .tab { font-size: 0.74rem; padding: 10px 2px; }
}

/* Unread pill pinned to the tab's corner so it never widens the label. */
.tab-badge {
    position: absolute;
    top: 3px;
    right: 5px;
    min-width: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--error-color);
    color: #fff;
    font-family: var(--font-display);
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1.6;
    text-align: center;
}

/* ── Thread list ── */
.msg-thread { cursor: pointer; }
.msg-thread:hover { border-color: var(--accent-light); }
.msg-thread.has-unread { border-color: rgba(239, 65, 54, 0.45); }
.msg-thread-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.msg-thread-main { flex: 1; min-width: 0; }
.msg-preview {
    margin-top: 3px;
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-thread-side {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}
.msg-when { font-size: 0.72rem; color: var(--text-muted); }
.msg-unread {
    min-width: 20px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--error-color);
    color: #fff;
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
}

/* ── One conversation ── */
.chat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
}
.chat-head-who { min-width: 0; }
.chat-head-name {
    display: block;
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}
.chat-head-sub { display: block; font-size: 0.75rem; color: var(--text-muted); }

.chat-msgs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 12px;
    min-height: 40vh;
    max-height: 62vh;
    overflow-y: auto;
}
.chat-msg { max-width: 86%; display: flex; flex-direction: column; }
.chat-msg.from-them { align-self: flex-start; align-items: flex-start; }
.chat-msg.from-me { align-self: flex-end; align-items: flex-end; }
.chat-bubble {
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    unicode-bidi: plaintext; /* Arabic messages read RTL inside the LTR page */
}
.chat-msg.from-them .chat-bubble {
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-bottom-left-radius: 4px;
}
.chat-msg.from-me .chat-bubble {
    background: rgba(46, 49, 146, 0.5);
    border: 1px solid rgba(123, 128, 212, 0.35);
    border-bottom-right-radius: 4px;
}
.chat-meta { margin-top: 3px; font-size: 0.68rem; color: var(--text-muted); }
.chat-img {
    display: block;
    max-width: 220px;
    max-height: 220px;
    border-radius: var(--radius-sm);
    margin-top: 6px;
}
.chat-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    color: var(--accent-light);
    font-size: 0.85rem;
    text-decoration: none;
    overflow-wrap: anywhere;
}
.chat-file:hover { text-decoration: underline; }

.chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-top: 10px;
}
.chat-attach {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    cursor: pointer;
    font-size: 1rem;
}
.chat-attach:hover { border-color: var(--accent-light); }
.chat-composer textarea {
    flex: 1;
    min-width: 0;
    resize: none;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 16px; /* 16px stops iOS Safari zooming the page on focus */
    padding: 10px 12px;
    max-height: 120px;
}
.chat-composer textarea:focus { outline: none; border-color: var(--border-focus); }
.chat-send { flex-shrink: 0; }
.chat-attach-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Run 14 — the Jam3ah Office thread, approval cards, voice notes
   ═══════════════════════════════════════════════════════════════════════════ */
.pill-awaiting {
    color: var(--warn-color);
    background: rgba(240, 166, 42, 0.12);
    border-color: rgba(240, 166, 42, 0.4);
}
.pill-office {
    color: #38BDF8;
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.35);
}
.s-card.st-awaiting { border-left-color: var(--warn-color); }
.s-awaiting {
    margin-top: 9px;
    padding: 9px 11px;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: rgba(240, 166, 42, 0.1);
    border-radius: var(--radius-sm);
}
.approve-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.approve-actions .btn { flex: 1 1 120px; }
.btn-danger {
    background: rgba(239, 65, 54, 0.18);
    border-color: rgba(239, 65, 54, 0.5);
    color: #FCA5A5;
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.15); }
.decline-form {
    margin-top: 11px;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
}
.decline-form label { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 6px; }
.decline-form textarea {
    width: 100%;
    resize: vertical;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 16px;
    padding: 9px 11px;
}
.decline-form .s-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Pinned office card */
.office-thread { border-left-color: #38BDF8; }
#officeCardWrap { margin-bottom: 10px; }

/* Mention card inside a bubble column */
.ref-card {
    min-width: 220px;
    max-width: 100%;
    margin-bottom: 4px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: rgba(123, 128, 212, 0.1);
    border: 1px solid rgba(123, 128, 212, 0.4);
    font-size: 0.85rem;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}
.ref-card.ref-unavailable { color: var(--text-muted); border-style: dashed; background: transparent; }
.ref-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.ref-card-type { font-size: 0.75rem; color: var(--accent-light); font-weight: 600; letter-spacing: 0.02em; }
.ref-card-name { font-weight: 600; }
.ref-card-facts { margin-top: 2px; font-size: 0.8rem; color: var(--text-secondary); }
.ref-card .approve-actions { margin-top: 10px; }

/* Voice notes (markup from /voice.js) */
button.chat-attach { color: var(--text-primary); font-family: inherit; }
.voice-rec-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}
.voice-rec-bar .btn { padding: 8px 12px; }
.voice-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--error-color); animation: voicePulse 1s ease-in-out infinite; flex-shrink: 0; }
@keyframes voicePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.voice-rec-label { flex: 1; }
.voice-rec-time { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.voice-msg {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 200px;
    padding: 6px 10px;
    margin-top: 4px;
    border-radius: var(--radius-md);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
}
.chat-msg.from-me .voice-msg { background: rgba(46, 49, 146, 0.5); border-color: rgba(123, 128, 212, 0.35); }
.voice-play {
    width: 34px; height: 34px; flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid var(--border-default);
    background: var(--accent-primary);
    color: #fff;
    font-size: 0.8rem;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.voice-track { flex: 1; height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; min-width: 80px; }
.voice-bar { height: 100%; width: 0%; background: var(--accent-light); transition: width 0.2s linear; }
.voice-time { font-size: 0.72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.voice-msg.voice-error .voice-time { color: var(--error-color); }
.voice-chip-player { flex: 1; min-width: 0; }
.voice-chip .voice-msg { margin-top: 0; }

/* HEIC chip bubble (non-Safari): the link flows as text inside a bubble. */
.chat-file-bubble { display: block; }
.chat-file.chat-file-plain { display: inline; margin: 0; }
.chat-file-bubble .muted { display: block; margin-top: 2px; }

/* ═══════════════════════════════════════════════════════════════════════════
   Run 15 — the teacher declined: the session is NOT cancelled, it is waiting
   for the office to reassign or cancel it
   ═══════════════════════════════════════════════════════════════════════════ */
.pill-declined {
    color: #FCA5A5;
    background: rgba(239, 65, 54, 0.14);
    border-color: rgba(239, 65, 54, 0.45);
}
.s-card.st-declined { border-left-color: rgba(239, 65, 54, 0.8); }
.s-awaiting.declined { background: rgba(239, 65, 54, 0.1); }
.s-decline-reason { display: inline-block; margin-top: 4px; color: var(--text-secondary); }
