/*
 * mobile-shell.css — one shared touch/phone layer for the four panel shells
 * (public+teacher, admin, school_admin, student).
 *
 * Why a separate file: the shells each carry a large inline <style> block and
 * page templates override pieces of it locally. Duplicating phone rules in four
 * places is how they drift — the teacher shell ended up hardened while the
 * student shell still shipped Tahoma at 100vh. This file is linked LAST in
 * <head> (after the shell's inline style, before page CSS) and every rule is
 * scoped under `body` or `.main-content` so it outranks a page-level
 * `.form-control { font-size: 14px }`.
 *
 * Only what is genuinely systemic lives here: viewport height, safe areas, tap
 * targets, input zoom, table overflow, bottom navigation, flash messages.
 */

/* ── 1. Real viewport height ──────────────────────────────────────────────
   100vh on a phone is the *largest* viewport (URL bar hidden). Anything sized
   with it — the fixed sidebar, a full-height flex row — overflows by the height
   of the browser chrome and the bottom of the drawer becomes unreachable.
   mobile-shell.js publishes the measured value as --shell-vh; 100dvh is used
   wherever the browser supports it. */
:root { --shell-vh: 1vh; --shell-bottom-nav-h: 0px; }

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

.sidebar {
    /* The shells all say min-height:100vh on the drawer. min-height beats the
       corrected height below, so it has to be neutralised here or the drawer
       keeps its unreachable bottom on Android and iOS Safari. */
    min-height: 0;
    height: calc(var(--shell-vh) * 100);
    overscroll-behavior: contain;
}
body,
.wrapper,
.main-wrapper {
    min-height: calc(var(--shell-vh) * 100);
}
@supports (height: 100dvh) {
    .sidebar { height: 100dvh; }
    body,
    .wrapper,
    .main-wrapper { min-height: 100dvh; }
}

/* ── 2. Safe areas (notch, home bar, landscape cut-outs) ───────────────── */
@supports (padding: env(safe-area-inset-top)) {
    .topbar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    .main-content {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-bottom: calc(24px + env(safe-area-inset-bottom) + var(--shell-bottom-nav-h));
    }
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ── 3. Touch targets ────────────────────────────────────────────────────
   iOS HIG / Material both ask for ~44px; Bootstrap's defaults are ~38px and
   .btn-sm/.btn-close are far below that, which is why "delete" links read as
   dead taps on a phone. Coarse-pointer only: a mouse user keeps the dense UI. */
@media (pointer: coarse) {
    .btn:not(.btn-link):not(.btn-close):not(.sidebar-toggle) {
        min-height: 44px;
    }
    .btn-sm,
    .btn-group-sm > .btn {
        min-height: 40px;
        padding-left: 12px;
        padding-right: 12px;
    }
    .btn-close {
        min-width: 40px;
        min-height: 40px;
        padding: 10px;
        opacity: .7;
    }
    body .main-content .form-control,
    body .main-content .form-select,
    body .main-content input:not([type=checkbox]):not([type=radio]):not([type=hidden]),
    body .main-content select,
    body .main-content textarea {
        min-height: 44px;
        /* 16px is the threshold under which iOS Safari auto-zooms the page on
           focus and never zooms back out. `!important` is load-bearing here,
           not a shortcut: page-level styles (and ID-qualified ones like
           #class_id, #bulkClassSelect) are injected through {% block
           extra_css %}, which sits AFTER partials/shell_css.html, so a plain
           selector in this file can never win the cascade no matter how many
           classes it stacks. Every panel page gets the same floor. */
        font-size: 16px !important;
    }
    body .main-content .btn:not(.btn-link):not(.btn-close),
    body .main-content .form-control-sm,
    body .main-content .form-select-sm {
        font-size: 16px !important;
    }
    body .main-content .btn:not(.btn-link):not(.btn-close) { min-height: 44px; }
    body .main-content .btn-sm,
    body .main-content .btn-group-sm > .btn { min-height: 40px; }
    .form-check-input {
        width: 1.35em;
        height: 1.35em;
        margin-top: .15em;
        flex: 0 0 auto;
    }
    .form-check-label { min-height: 28px; display: inline-block; }
    .page-link {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .sidebar-nav a,
    .sidebar .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    a, button, label, summary {
        touch-action: manipulation;   /* drops the 300ms double-tap delay */
    }
}

/* ── 4. Tables ───────────────────────────────────────────────────────────
   Panels are full of 8–12 column grids; unwrapped they push the page wider
   than the screen and the shell's `overflow-x: hidden` silently clips the
   action column — the buttons exist but cannot be reached. mobile-shell.js
   wraps any bare <table> inside .main-content in .table-wrap-x. */
.table-wrap-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    position: relative;
}
.table-wrap-x > table {
    margin-bottom: 0;
}
/* The scroll affordance: columns to the right are only discoverable if the
   edge looks cut off. */
.table-wrap-x[data-scrollable="1"] {
    -webkit-mask-image: linear-gradient(to left, transparent 0, #000 18px);
    mask-image: linear-gradient(to left, transparent 0, #000 18px);
}
.table-wrap-x[data-scrollable="1"].is-scrolled-end {
    -webkit-mask-image: none;
    mask-image: none;
}
@media (max-width: 767.98px) {
    .main-content .table thead th,
    .main-content .table tbody td {
        padding: 9px 10px;
        font-size: .82rem;
        white-space: nowrap;
    }
    .main-content .table .wrap-cell,
    .main-content .table td.wrap-cell { white-space: normal; min-width: 180px; }
}

/* Images/videos never force the page wider than the screen. */
.main-content img,
.main-content video { max-width: 100%; height: auto; }
.main-content img[width],
.main-content .avatar,
.main-content .thumbnail { height: auto; }

/* ── 5. Phone spacing pass ─────────────────────────────────────────────── */
@media (max-width: 767.98px) {
    .main-content { padding: 16px; }
    .main-content .card-body { padding: 15px; }
    .main-content .card-header { padding: 12px 15px; }
    .main-content h1, .main-content h2 { font-size: 1.2rem; }
    .main-content h3, .main-content h4 { font-size: 1.05rem; }
    .main-content .stat-card { padding: 15px; }
    .main-content .stat-card .number { font-size: 22px; }
    /* Two-column form grids collapse to one column — the usual cause of a
       half-width field that cannot be typed in. */
    .main-content .row > [class*="col-md-"],
    .main-content .row > [class*="col-lg-"] { padding-left: 8px; padding-right: 8px; }
}

/* ── 6. Bottom navigation ────────────────────────────────────────────────
   The off-canvas drawer is fine for a 12-item admin menu but wrong for a
   student: five destinations, thumb-reachable, no menu to open. */
.shell-bottom-nav {
    display: none;
    position: fixed;
    right: 0; left: 0; bottom: 0;
    z-index: 1035;
    background: var(--surface, #fff);
    border-top: 1px solid var(--border, #e2e8f0);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}
.shell-bottom-nav a {
    flex: 1 1 0;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: .68rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text2, #475569);
    text-decoration: none;
    padding: 6px 2px;
}
.shell-bottom-nav a i { font-size: 1.25rem; }
.shell-bottom-nav a.active { color: var(--primary, #4f46e5); }
.shell-bottom-nav a:focus-visible {
    outline: 2px solid var(--primary, #4f46e5);
    outline-offset: -2px;
}
@media (max-width: 991.98px) {
    .shell-bottom-nav.has-bottom-nav { display: flex; }
    body.has-bottom-nav .main-content {
        padding-bottom: calc(72px + env(safe-area-inset-bottom));
    }
}

/* ── 7. Flash messages ─────────────────────────────────────────────────── */
.shell-flash {
    position: relative;
    z-index: 1050;
}
.shell-flash .alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
    border-radius: 10px;
    font-size: .92rem;
}
.shell-flash .alert .bi { font-size: 1.1rem; line-height: 1.5; flex: 0 0 auto; }
@media (max-width: 767.98px) {
    .shell-flash { margin: 0 -16px 12px; padding: 0 16px; }
}

/* ── 8. Empty states ─────────────────────────────────────────────────────
   "No data yet" pages used to be a bare sentence, which reads as a broken
   panel. The macro in templates/macros/ui.html emits this markup. */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text2, #475569);
}
.empty-state .empty-state-icon {
    width: 64px; height: 64px;
    margin: 0 auto 14px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: rgba(79, 70, 229, .10);
    color: var(--primary, #4f46e5);
    font-size: 1.75rem;
}
.empty-state h3 { font-size: 1.05rem; font-weight: 700; margin: 0 0 6px; color: var(--text, #0f172a); }
.empty-state p { font-size: .9rem; margin: 0 auto 16px; max-width: 42ch; }

/* ── 9. Lab مقطع/پایه badges ──────────────────────────────────────────────
   Every simulator now advertises which level (and optionally which single
   پایه) it belongs to; templates/macros/lab.html emits this markup. Students
   scan these badges on a phone before they tap anything, so they must stay on
   one line, keep a legible size at 390px, and never push the card title off. */
.lab-level-badge,
.lab-grade-badge {
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.5;
    padding: .22rem .5rem;
    border-radius: 99px;
    white-space: nowrap;
    letter-spacing: 0;
}
/* One colour per مقطع, so the shelf is scannable without reading the words. */
.lab-level-elementary { background: rgba(22, 163, 74, .14) !important; color: #15803d !important; }
.lab-level-middle     { background: rgba(37, 99, 235, .14) !important; color: #1d4ed8 !important; }
.lab-level-high       { background: rgba(124, 58, 237, .14) !important; color: #6d28d9 !important; }
.badge-subtle { --bs-badge-bg: transparent; }
.lab-grade-badge { background: rgba(100, 116, 139, .14); color: #334155; }
.lab-badges { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
/* A simulator that does NOT belong to the student's پایه stays listed but is
   visually demoted, so a teacher can see the mismatch instead of wondering why
   the row is missing. */
.lab-mismatch { opacity: .55; }
.lab-match-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background:#16a34a; margin-inline-end:5px; }
@media (max-width: 575.98px) {
    .lab-level-badge, .lab-grade-badge { font-size: .66rem; padding: .18rem .45rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
