/*
 * Daar Al Quran — phone app shell + mobile defaults.
 * Loaded by every layout after theme-arabesque.css (via layouts/partials/app-head).
 *
 *   1. Tokens
 *   2. All widths: shell pieces that also exist on desktop (sidebar logout button, badges, focus)
 *   3. Tablet drawer (<= 1024px)
 *   4. Phone shell (< 768px): app bar, bottom tab bar, "المزيد" sheet, page frame
 *   5. Phone defaults: touch targets, inputs, buttons, cards, modals as bottom sheets
 *   6. Tables: .table-cards (stacked cards on phones) and .table-sticky-first
 *   7. Motion & hover-less devices
 *
 * Phone breakpoint is < 768px; tablets and desktop keep the sidebar layout.
 */

/* 1. Tokens ------------------------------------------------------------- */
:root {
    /* One teal across the site: the shell reads the theme's tokens (theme-arabesque.css).
       The fallbacks are the same values, for pages that don't load the theme (guest/auth). */
    --app-teal: var(--primary, #0D9488);
    --app-teal-dark: var(--primary-dark, #0F766E);
    --app-teal-darker: var(--primary-darker, #115E59);
    --app-teal-light: var(--primary-light, #14B8A6);
    --app-teal-tint: rgba(13, 148, 136, .12);
    --app-gold: var(--accent, #D4AF37);
    --app-gold-ink: #3B2A14;
    --app-ink: #1A1A2E;
    --app-ink-2: #4A4A68;
    --app-muted: #5B6475;
    --app-bg: var(--bg-primary, #F0FDFA);
    --app-line: #E3E9E9;
    --app-danger: #B42318;
    --app-bar-h: 56px;
    --app-tabbar-h: 60px;
    --app-ease: cubic-bezier(.2, .8, .2, 1);
}

.min-w-0 { min-width: 0; }

/* Links, pills and tabs in the site teal instead of Bootstrap blue. */
:root {
    --bs-link-color: #0F766E;
    --bs-link-color-rgb: 15, 118, 110;
    --bs-link-hover-color: #115E59;
    --bs-link-hover-color-rgb: 17, 94, 89;
}
.nav { --bs-nav-link-color: var(--app-teal-dark); --bs-nav-link-hover-color: var(--app-teal-darker); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--app-teal-dark); }

/* Checkboxes, radios and switches in the site teal instead of Bootstrap blue. */
.form-check-input:checked { background-color: var(--app-teal); border-color: var(--app-teal); }
.form-check-input:focus { border-color: var(--app-teal-light); box-shadow: 0 0 0 .2rem rgba(13, 148, 136, .2); }

/* 2. All widths ---------------------------------------------------------- */
.app-bar,
.app-tabbar,
.app-sheet-grip { display: none; }

/* Logout is a real <button> now; make it look like the other menu links. */
.sidebar-nav-link.app-logout {
    width: 100%;
    background: none;
    border: 0;
    font: inherit;
    font-weight: 500;
    text-align: start;
    cursor: pointer;
    color: var(--danger, #EF4444);
}
.sidebar-nav-link.app-logout .nav-icon { color: inherit; }
.sidebar-nav-link.app-logout:hover { background: var(--danger-light, #FEE2E2); color: var(--app-danger); }

.sidebar-nav-link .nav-badge-warning { background: var(--warning, #F59E0B); color: #1C1917; }
.sidebar-nav-sublink { padding-inline-start: 2.75rem; }
.sidebar-nav-link[aria-expanded="true"] .app-collapse-caret { transform: rotate(180deg); }
.app-collapse-caret { transition: transform .2s ease; }

/* The user card + close button at the top of the menu: phones/tablets, or always when the layout asks. */
.app-sheet-top { display: none; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--border-color, #E2E8F0); }
.app-sheet-top.is-always { display: flex; }
.app-avatar {
    width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--app-gold); color: var(--app-gold-ink); font-weight: 700; font-size: 1.125rem;
}
.app-sheet-user-text { min-width: 0; }
.app-sheet-user-text strong { display: block; color: var(--app-ink); font-size: 1rem; line-height: 1.35; overflow-wrap: anywhere; }
.app-sheet-user-text small { display: block; color: var(--app-muted); font-size: .8125rem; }
.app-sheet-close {
    display: none; margin-inline-start: auto; flex-shrink: 0;
    width: 44px; height: 44px; border-radius: 50%; border: 0;
    background: #EEF3F3; color: var(--app-ink); font-size: 1.05rem; cursor: pointer;
}
.app-sheet-close:active { background: #E1EAEA; }

.app-scrim {
    position: fixed; inset: 0; z-index: 1040;
    background: rgba(6, 30, 30, .45);
    opacity: 0; transition: opacity .25s ease;
    -webkit-tap-highlight-color: transparent;
}
.app-scrim.active { opacity: 1; }
.app-scrim[hidden] { display: none; }

a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
.app-tab:focus-visible {
    outline: 3px solid var(--app-gold);
    outline-offset: 2px;
}

/* 3. Tablet drawer --------------------------------------------------------- */
@media (max-width: 1024px) {
    .sidebar-arabesque { z-index: 1045; }
    .app-sheet-top { display: flex; }
    .app-sheet-close { display: inline-flex; align-items: center; justify-content: center; }
}

/* 4. Phone shell ------------------------------------------------------------ */
@media (max-width: 767.98px) {
    :root {
        --navbar-height: calc(var(--app-bar-h) + env(safe-area-inset-top, 0px));
        --border-radius: 16px;
        --border-radius-sm: 10px;
        --spacing-xl: 1rem;
    }

    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
    html.app-sheet-open,
    html.app-sheet-open body { overflow: hidden; }
    body { background-color: var(--app-bg); overflow-x: hidden; }
    /* Last line of defence against sideways page scroll; clip (unlike hidden) never becomes a scroller,
       so sticky elements keep working and fixed bars are unaffected. */
    #app { overflow-x: clip; }

    /* The desktop navbar, the old bottom nav and the footer give way to the app chrome. */
    .navbar-arabesque,
    .bottom-nav,
    .footer-arabesque,
    .sidebar-overlay { display: none !important; }

    /* Pages wrapped in their own container: the page frame already provides the 16px gutter. */
    .main-content > .container-fluid,
    .main-content > .container { padding-left: 0; padding-right: 0; }
    .main-content > .container-fluid.py-4,
    .main-content > .container.py-4 { padding-top: 0 !important; }
    .main-content > .container.mt-4,
    .main-content > .container-fluid.mt-4 { margin-top: 0 !important; }
    .main-content > .container-fluid.px-4 { padding-left: 0 !important; padding-right: 0 !important; }

    .main-content {
        margin: var(--navbar-height) 0 0 !important;
        padding: 16px 16px calc(var(--app-tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px) !important;
        min-height: 100dvh;
    }

    /* Top app bar */
    .app-bar {
        display: grid;
        grid-template-columns: 1fr minmax(0, auto) 1fr;
        align-items: center;
        gap: 4px;
        position: fixed; top: 0; left: 0; right: 0; z-index: 1030;
        height: var(--navbar-height);
        padding: env(safe-area-inset-top, 0px) max(4px, env(safe-area-inset-right, 0px)) 0 max(4px, env(safe-area-inset-left, 0px));
        background: var(--app-bar-bg, var(--app-teal-dark));
        color: #fff;
        box-shadow: 0 6px 18px -12px rgba(6, 40, 40, .55);
    }
    .app-bar::after {
        content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
        background: linear-gradient(90deg, transparent 0%, var(--app-gold) 25%, var(--app-gold) 75%, transparent 100%);
        opacity: .9;
    }
    .app-bar-side { display: flex; align-items: center; min-width: 44px; }
    .app-bar-end { justify-content: flex-end; }
    .app-bar-title {
        margin: 0; color: #fff; text-align: center;
        font-size: 1.0625rem; font-weight: 600; line-height: 1.3;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .app-bar-btn,
    .app-bar-logo {
        position: relative; flex-shrink: 0;
        width: 44px; height: 44px; border-radius: 50%;
        display: inline-flex; align-items: center; justify-content: center;
        color: #fff; font-size: 1.125rem; text-decoration: none;
        transition: background-color .15s ease;
    }
    .app-bar-btn:hover,
    .app-bar-btn:focus { color: #fff; }
    .app-bar-btn:active { background: rgba(255, 255, 255, .18); }
    .app-bar-logo img { width: 30px; height: 30px; display: block; }
    .app-bar-badge {
        position: absolute; top: 5px; inset-inline-end: 3px;
        min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
        background: var(--app-gold); color: var(--app-gold-ink);
        font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
        box-shadow: 0 0 0 2px var(--app-bar-bg, var(--app-teal-dark));
    }

    /* Bottom tab bar */
    .app-tabbar {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(0, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
        height: calc(var(--app-tabbar-h) + env(safe-area-inset-bottom, 0px));
        padding: 0 max(2px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(2px, env(safe-area-inset-left, 0px));
        background: rgba(255, 255, 255, .97);
        border-top: 1px solid var(--app-line);
        box-shadow: 0 -6px 20px -14px rgba(6, 40, 40, .35);
    }
    @supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
        .app-tabbar { background: rgba(255, 255, 255, .88); -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px); }
    }
    .app-tab {
        position: relative;
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        min-width: 0; min-height: 52px; padding: 0;
        appearance: none; background: none; border: 0; font: inherit;
        color: var(--app-muted); text-decoration: none; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .app-tab:hover { color: var(--app-teal-dark); }
    .app-tab-icon {
        position: relative;
        width: 56px; max-width: 100%; height: 30px; border-radius: 15px;
        display: flex; align-items: center; justify-content: center;
        font-size: 1.15rem;
        transition: background-color .2s ease;
    }
    .app-tab-label {
        max-width: 100%; padding: 0 2px;
        font-size: 12px; font-weight: 500; line-height: 1.2;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .app-tab:active .app-tab-icon { background: rgba(13, 148, 136, .18); }
    .app-tab.is-active { color: var(--app-teal-dark); }
    .app-tab.is-active .app-tab-icon { background: var(--app-teal-tint); }
    .app-tab.is-active .app-tab-label { font-weight: 700; }
    /* Active marker: a small gold eight-pointed star (two squares) sitting on the bar's top edge. */
    .app-tab.is-active::before,
    .app-tab.is-active::after {
        content: ''; position: absolute; top: -5px; left: 50%;
        width: 8px; height: 8px; margin-left: -4px;
        background: var(--app-gold);
    }
    .app-tab.is-active::after { transform: rotate(45deg); }
    .app-tab-badge {
        position: absolute; top: -3px; inset-inline-start: 50%; margin-inline-start: 6px;
        min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
        background: var(--app-gold); color: var(--app-gold-ink);
        font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
        box-shadow: 0 0 0 2px #fff;
    }
    .app-tab-dot {
        position: absolute; top: 2px; inset-inline-start: 50%; margin-inline-start: 8px;
        width: 9px; height: 9px; border-radius: 50%;
        background: var(--app-gold); box-shadow: 0 0 0 2px #fff;
    }

    /* "المزيد": the sidebar becomes a bottom sheet */
    .sidebar-arabesque.app-sheet {
        position: fixed; top: auto; bottom: 0; left: 0; right: 0;
        width: auto; height: auto; max-height: 86vh; max-height: 86dvh;
        z-index: 1045;
        padding: 0 0 calc(env(safe-area-inset-bottom, 0px) + 12px);
        background: #fff;
        border: 0; border-radius: 22px 22px 0 0;
        box-shadow: 0 -14px 40px rgba(6, 40, 40, .22);
        overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
        transform: translateY(105%);
        visibility: hidden;
        transition: transform .3s var(--app-ease), visibility 0s linear .3s;
    }
    .sidebar-arabesque.app-sheet.open {
        transform: none;
        visibility: visible;
        transition: transform .3s var(--app-ease), visibility 0s;
    }
    .app-sheet .is-tab { display: none !important; }
    .app-sheet .sidebar-header { display: none; }
    .app-sheet-grip { display: block; width: 40px; height: 5px; border-radius: 3px; background: #CDD6D6; margin: 8px auto 0; }
    .app-sheet-top { border-bottom: 0; padding: 10px 16px 8px; }
    .app-sheet .role-switcher { padding: 0 16px 8px; }
    .app-sheet .sidebar-nav { padding: 0 12px 4px; }
    .app-sheet .sidebar-divider { margin: 6px 8px; }
    .app-sheet .sidebar-section-title {
        margin: 0; padding: 10px 8px 4px;
        font-size: .8125rem; font-weight: 600; color: var(--app-muted);
        text-transform: none; letter-spacing: 0;
    }
    .app-sheet .sidebar-nav-item { margin: 0; }
    .app-sheet .sidebar-nav-link {
        min-height: 52px; padding: 6px 8px; gap: 12px;
        border-radius: 12px; color: var(--app-ink); font-weight: 500;
    }
    .app-sheet .sidebar-nav-link .nav-icon {
        width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
        display: inline-flex; align-items: center; justify-content: center;
        background: #EEF5F5; color: var(--app-teal); font-size: 1rem;
    }
    .app-sheet .sidebar-nav-link:hover { background: transparent; color: var(--app-ink); }
    .app-sheet .sidebar-nav-link:active { background: #EEF3F3; }
    .app-sheet .sidebar-nav-link.active { background: var(--app-teal-tint); color: var(--app-teal-dark); box-shadow: none; font-weight: 600; }
    .app-sheet .sidebar-nav-link.active .nav-icon { background: var(--app-teal); color: #fff; }
    .app-sheet .sidebar-nav-sublink { padding-inline-start: 24px; }
    .app-sheet .sidebar-nav-link.app-logout { color: var(--app-danger); }
    .app-sheet .sidebar-nav-link.app-logout .nav-icon { background: #FDECEA; color: var(--app-danger); }

    /* Sticky things inside pages sit under the app bar, never under the tab bar. */
    .sticky-top-app { position: sticky; top: var(--navbar-height); z-index: 5; }
}

/* 5. Phone defaults ------------------------------------------------------- */
@media (max-width: 767.98px) {
    a, button, input, select, textarea, label, summary, .btn { touch-action: manipulation; }
    a, button, .btn, .card a { -webkit-tap-highlight-color: rgba(13, 148, 136, .12); }

    img, video, iframe, canvas { max-width: 100%; }
    pre { white-space: pre-wrap; word-break: break-word; }

    /* No iOS focus-zoom: every text field is 16px; every control is a comfortable touch target. */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
    select, textarea,
    .form-control, .form-control-sm, .form-control-lg,
    .form-select, .form-select-sm, .form-select-lg { font-size: 16px !important; }
    .form-control:not(textarea), .form-select { min-height: 44px; }
    .form-check { min-height: 1.875rem; }
    .form-check-input { width: 1.2em; height: 1.2em; margin-top: .2em; }
    .form-switch .form-check-input { width: 2.3em; }
    .form-check-label { padding-block: .2rem; }
    .form-label { font-weight: 600; font-size: .9375rem; }
    .input-group > .btn { min-height: 44px; }

    .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
    .btn.d-block, .btn.w-100 { display: flex; }
    .btn-sm { min-height: 40px; min-width: 40px; padding-inline: .7rem; }
    .btn-group > .btn, .btn-group-sm > .btn { min-height: 44px; }
    .btn:active:not(:disabled) { filter: brightness(.94); }
    .btn-close { box-sizing: content-box; padding: 14px; margin: -10px; }

    /* Primary form actions span the width, like native forms. Search bars and inline rows are left alone. */
    form:not(.input-group):not(.d-flex) > .btn[type="submit"]:not(.btn-sm):not(.btn-link),
    form > div:not(.input-group):not(.row):not(.d-flex) > .btn[type="submit"]:not(.btn-sm):not(.btn-link):only-child { width: 100%; }
    form .d-flex:has(> .btn[type="submit"]:not(.btn-sm)):not(:has(> input, > select, > .form-control, > .form-select, > .input-group)) > .btn:not(.btn-sm) { flex: 1 1 auto; }

    /* Cards: one radius per level, quieter shadows, tight but breathable padding. */
    .card { --bs-card-inner-border-radius: calc(var(--border-radius) - 1px); box-shadow: 0 1px 2px rgba(16, 40, 40, .06), 0 4px 14px -8px rgba(16, 40, 40, .14) !important; }
    .card .card { border-radius: 12px !important; box-shadow: none !important; border: 1px solid var(--app-line) !important; }
    .card-body { padding: 14px; }
    .card-header, .card-footer { padding: 12px 14px; }
    .card-header h5, .card-header .h5 { font-size: 1rem; }
    /* A title + filter button group in a card header: the buttons take their own full-width row. */
    .card-header.d-flex:has(> .btn-group) { flex-wrap: wrap; gap: 8px; }
    .card-header.d-flex > .btn-group { width: 100%; }
    .card-header.d-flex > .btn-group > .btn { flex: 1 1 0; }
    /* Same for page headers built as a flex row (title + action button). */
    .page-header.d-flex { flex-wrap: wrap; gap: 10px; }
    /* Card headers laid out as title column + tools column: the tools take a full row. */
    .card-header > .row { row-gap: 8px; }
    .card-header > .row > .col-auto { flex: 1 1 100%; width: 100%; }
    .card-header > .row > .col-auto.d-flex { flex-wrap: wrap; }
    .card-header > .row > .col-auto .input-group { flex: 1 1 100%; width: auto !important; }
    /* Search + filter forms in a card header: the search box takes a full row, filters share the next. */
    .card-header form.d-flex:has(> .input-group) { flex: 1 1 100%; flex-wrap: wrap; gap: 8px; margin: 0 !important; }
    .card-header form.d-flex:has(> .input-group) > .input-group { flex: 1 1 100%; width: auto !important; margin: 0 !important; }
    .card-header form.d-flex:has(> .input-group) > .form-select { flex: 1 1 0; width: auto !important; min-width: 0; margin: 0 !important; }
    /* Message lists (student + teacher inbox): subject on its own line, date underneath. */
    .message-header { flex-direction: column; gap: 2px; min-height: 44px; }
    .message-header h5 { font-size: 1rem; line-height: 1.4; }
    .message-header small { color: var(--app-muted); }
    .mb-4 { margin-bottom: 1rem !important; }

    .page-header { padding: 12px 14px; margin-bottom: 12px; }
    .page-header h4, .page-header .h4 { font-size: 1.125rem; }
    .page-header .page-title { display: flex; align-items: center; gap: .6rem; margin: 0; font-size: 1.125rem; font-weight: 700; }
    .page-header .page-header-icon { font-size: 1rem; color: var(--app-teal); }
    .page-header .btn { flex-shrink: 0; }
    /* Header actions drop under the title instead of squeezing it into three lines. */
    .page-header > .row > .col-auto:not(:empty) { flex: 1 1 100%; width: 100%; }
    .page-header > .row { row-gap: 10px; }
    .page-header > .row > .col-auto .btn:not(.btn-sm) { width: 100%; }
    /* In-page back links duplicate the app bar's back button. */
    .app-hide-phone, .app-back-link { display: none !important; }
    .page-header > .row > .col-auto:not(:has(> :not(.app-hide-phone, .app-back-link))) { display: none; }

    /* Page heads (one convention for every role page):
         .page-head           the page's header block (usually also .page-header)
         .page-head__title    the page title: the app bar already shows it, so phones hide it
         .page-head__sub      a subtitle that stays (muted, one short paragraph)
         .page-head__tools    the header's buttons / search / tabs: stay, as a compact toolbar row
         .app-back-link       an in-page back link: hidden, the app bar has the back button
       A page that hides its title must make the app bar show it (@section('app_title') or 'title').
       When nothing but the title and back links is left, the whole head goes away. */
    .page-head__title { display: none !important; }
    .page-header.page-head,
    .page-head {
        background: transparent !important; border: 0 !important; border-radius: 0 !important;
        box-shadow: none !important; padding: 0 !important; margin: 0 0 12px !important;
    }
    .page-head:not(:has(.page-head__sub, .page-head__tools > :not(.app-back-link, .app-hide-phone))) { display: none !important; }
    .page-head + .mt-4, .page-head + .mt-1 { margin-top: 0 !important; }
    .page-head > .row { margin: 0; row-gap: 8px; }
    .page-head > .row > * { padding: 0; }
    .page-head > .row > .col:not(:has(> :not(.page-head__title))) { display: none; }
    .page-head__sub { display: block; margin: 0 !important; color: var(--app-muted) !important; font-size: .875rem !important; line-height: 1.55; }
    .page-head__tools:not(.nav) { display: flex !important; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; }
    .page-head__tools:not(.nav) > .btn,
    .page-head__tools:not(.nav) > form { flex: 1 1 auto; width: auto !important; margin: 0 !important; }
    .page-head__tools:not(.nav) > .btn-group { flex: 1 1 100%; margin: 0 !important; }
    .page-head__tools.flex-column { align-items: stretch; }
    .page-head__tools.nav { width: 100%; }

    .list-group-item { padding: 12px 14px; }
    .list-group-item-action:active,
    a.list-group-item:active { background: #EEF3F3; }

    .alert, .alert-arabesque { border-radius: 14px; padding: 12px 14px; font-size: .9375rem; }
    .badge { font-weight: 600; }

    .table-responsive, .overflow-auto, .overflow-x-auto { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
    .table { font-size: .9375rem; }

    /* Tab strips scroll sideways; the shell script fades the edge that hides more tabs
       (.app-fade-l / .app-fade-r) and scrolls the active tab into view. */
    .nav-tabs, .nav-pills { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-padding-inline: 24px; }
    .nav-tabs::-webkit-scrollbar, .nav-pills::-webkit-scrollbar { display: none; }
    .nav-tabs > .nav-item, .nav-pills > .nav-item { flex-shrink: 0; }
    .nav-tabs .nav-link, .nav-pills .nav-link { white-space: nowrap; min-height: 44px; display: flex; align-items: center; }
    .nav-pills .nav-link { padding-inline: .8rem; }
    .app-fade-l { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 32px); mask-image: linear-gradient(to right, transparent 0, #000 32px); }
    .app-fade-r { -webkit-mask-image: linear-gradient(to left, transparent 0, #000 32px); mask-image: linear-gradient(to left, transparent 0, #000 32px); }
    .app-fade-l.app-fade-r {
        -webkit-mask-image: linear-gradient(to right, transparent 0, #000 32px, #000 calc(100% - 32px), transparent 100%);
        mask-image: linear-gradient(to right, transparent 0, #000 32px, #000 calc(100% - 32px), transparent 100%);
    }

    /* .app-segmented: a short tab strip (2-3 choices: days, views) as a phone segmented control.
       Every choice gets an equal share of the width, so nothing is ever cut off; pages give long
       labels a short phone form (.d-md-none / .d-none.d-md-inline). */
    .nav.app-segmented {
        display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px;
        margin: 0 !important; padding: 4px; overflow: visible;
        background: #E7EFEE; border: 0; border-radius: 14px;
        -webkit-mask-image: none; mask-image: none;
    }
    .card-header:has(> .nav.app-segmented),
    .card-header:has(> div > .nav.app-segmented) { padding: 10px !important; background: transparent; border-bottom: 0; }
    .card-header > .d-flex:has(> .nav.app-segmented) { flex-wrap: wrap; gap: 8px; }
    .card-header > .d-flex > .nav.app-segmented { flex: 1 1 100%; }
    .nav.app-segmented > .nav-item { min-width: 0; margin: 0; }
    .nav.app-segmented .nav-link {
        width: 100%; min-height: 44px; margin: 0 !important; padding: 6px 8px;
        justify-content: center; gap: 6px; text-align: center;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        border: 0 !important; border-radius: 10px !important;
        background: transparent; color: var(--app-ink-2) !important;
        font-size: .9375rem; font-weight: 600; line-height: 1.25;
    }
    .nav.app-segmented .nav-link > i { margin: 0 !important; }
    .nav.app-segmented .nav-link:has(> .app-seg-sub) { flex-direction: column; gap: 0; padding-block: 5px; }
    .nav.app-segmented .app-seg-label,
    .nav.app-segmented .app-seg-sub { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
    .nav.app-segmented .app-seg-sub { font-size: .75rem; font-weight: 500; color: var(--app-muted); }
    .nav.app-segmented .nav-link.active {
        background: #fff !important; color: var(--app-teal-dark) !important;
        box-shadow: 0 1px 2px rgba(16, 40, 40, .1), 0 2px 8px -4px rgba(16, 40, 40, .25);
    }

    .dropdown-item { min-height: 44px; display: flex; align-items: center; gap: .5rem; }
    .pagination .theme-page-btn, .theme-page-btn { min-width: 44px; height: 44px; }

    /* Bootstrap modals open as bottom sheets. */
    .modal-dialog,
    .modal-dialog.modal-dialog-centered,
    .modal-dialog.modal-dialog-scrollable {
        position: fixed; left: 0; right: 0; bottom: 0;
        width: 100%; max-width: none !important; height: auto; min-height: 0;
        margin: 0 !important; display: block;
    }
    .modal.fade .modal-dialog { transform: translateY(100%); transition: transform .3s var(--app-ease); }
    .modal.show .modal-dialog { transform: none; }
    /* The sheet never grows past the screen: its body scrolls, the header stays.
       (.modal-dialog-scrollable is listed too: Bootstrap's own max-height:100%
       for it would otherwise win, and a long list pushed the header off-screen.) */
    .modal-content,
    .modal-dialog-scrollable .modal-content {
        border: 0; border-radius: 22px 22px 0 0;
        max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px - env(safe-area-inset-top, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        overflow: hidden;
    }
    .modal-content::before {
        content: ''; display: block; flex-shrink: 0;
        width: 40px; height: 5px; border-radius: 3px; background: #CDD6D6; margin: 8px auto 0;
    }
    .modal-header { border-bottom: 0; padding: 8px 16px 4px; }
    .modal-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 8px 16px 16px; }
    .modal-footer { border-top: 1px solid var(--app-line); padding: 10px 12px; flex-wrap: nowrap; gap: 8px; }
    .modal-footer > * { margin: 0; }
    .modal-footer > .btn { flex: 1 1 0; }
}

/* 6. Tables --------------------------------------------------------------- */
/* Opt in with <table class="table table-cards">. Cells get their label from the column header
   (added by the shell script) or from an explicit data-label. Helper classes on cells:
   .tc-title (card heading, no label), .tc-actions (button row), .tc-hide (hidden on phones). */
@media (max-width: 767.98px) {
    table.table-cards,
    table.table-cards > tbody { display: block; width: 100%; }
    table.table-cards { border: 0; margin-bottom: 0; }
    table.table-cards > thead {
        position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
        overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
    }
    table.table-cards > tbody > tr {
        display: block; position: relative;
        margin-bottom: 10px; padding: 4px 14px;
        background: var(--bg-card, #fff);
        border: 1px solid var(--app-line); border-radius: 14px;
        box-shadow: 0 1px 2px rgba(16, 40, 40, .05);
    }
    table.table-cards > tbody > tr:last-child { margin-bottom: 0; }
    /* Cards need a gutter when the table sits edge-to-edge in a card. */
    .card-body.p-0 > .table-responsive > table.table-cards,
    .card-body.p-0 > table.table-cards,
    .card > .table-responsive > table.table-cards { padding: 10px; }
    table.table-cards > tbody > tr > td,
    table.table-cards > tbody > tr > th {
        display: flex; align-items: center; justify-content: space-between; gap: 12px;
        min-height: 42px; padding: 8px 0 !important;
        border: 0 !important; border-bottom: 1px solid #EEF2F2 !important;
        background: transparent !important; box-shadow: none !important;
        text-align: end !important; white-space: normal !important;
        overflow-wrap: anywhere;
    }
    table.table-cards > tbody > tr > :last-child { border-bottom: 0 !important; }
    table.table-cards > tbody > tr > [data-label]::before {
        content: attr(data-label);
        flex: 0 0 auto; max-width: 48%;
        color: var(--app-muted); font-size: .8125rem; font-weight: 600; text-align: start;
    }
    table.table-cards > tbody > tr > [data-label=""]::before { content: none; }
    table.table-cards > tbody > tr > .tc-title {
        justify-content: flex-start; text-align: start !important;
        font-size: 1rem; font-weight: 700; color: var(--app-ink);
    }
    table.table-cards > tbody > tr > .tc-title::before,
    table.table-cards > tbody > tr > .tc-actions::before,
    table.table-cards > tbody > tr > .tc-full::before { content: none; }
    table.table-cards > tbody > tr > .tc-full { display: block; text-align: start !important; }
    table.table-cards > tbody > tr > .tc-actions { justify-content: flex-end; flex-wrap: wrap; }
    table.table-cards > tbody > tr > .tc-actions .btn { min-width: 44px; min-height: 44px; }
    table.table-cards > tbody > tr > .tc-hide { display: none; }
    /* Table-level shortcuts: hide the row-number column, use the first/second cell as the title, last as actions. */
    table.table-cards.tc-hide-first > tbody > tr > :first-child:not([colspan]) { display: none; }
    table.table-cards.tc-title-first > tbody > tr > :first-child:not([colspan]),
    table.table-cards.tc-title-second > tbody > tr > :nth-child(2),
    table.table-cards > tbody > tr > .tc-title {
        flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px;
        text-align: start !important;
        font-size: 1rem; font-weight: 700; color: var(--app-ink);
    }
    table.table-cards.tc-title-first > tbody > tr > :first-child::before,
    table.table-cards.tc-title-second > tbody > tr > :nth-child(2)::before,
    table.table-cards.tc-actions-last > tbody > tr > :last-child::before { content: none; }
    table.table-cards.tc-actions-last > tbody > tr > :last-child:not([colspan]) { justify-content: flex-end; flex-wrap: wrap; }
    table.table-cards.tc-actions-last > tbody > tr > :last-child .btn { min-width: 44px; min-height: 44px; }
    /* A selection checkbox in the first column sits in the card's top corner. */
    table.table-cards.tc-check-first > tbody > tr > :first-child:not([colspan]) {
        position: absolute; top: 4px; inset-inline-end: 6px;
        min-height: 44px; min-width: 44px; padding: 0 !important; border: 0 !important;
        justify-content: center;
    }
    table.table-cards.tc-check-first > tbody > tr > :first-child::before { content: none; }
    table.table-cards.tc-check-first > tbody > tr > :first-child input[type="checkbox"] { width: 22px; height: 22px; }
    table.table-cards.tc-check-first > tbody > tr > :nth-child(2) { padding-inline-end: 48px !important; }
    table.table-cards > tbody > tr > td[colspan] { justify-content: center; text-align: center !important; }
    table.table-cards > tbody > tr > td[colspan]::before { content: none; }
    table.table-cards > tbody > tr:hover { background: var(--bg-card, #fff); }
    .table-responsive:has(> table.table-cards) { overflow: visible !important; max-height: none !important; border: 0 !important; }

    /* Horizontal tables that must stay tables: keep the first (name) column pinned while scrolling. */
    table.table-sticky-first > thead > tr > :first-child,
    table.table-sticky-first > tbody > tr > :first-child {
        position: sticky; inset-inline-start: 0; z-index: 2;
        background: var(--bg-card, #fff);
        box-shadow: inset -1px 0 0 var(--app-line);
    }
    table.table-sticky-first > thead > tr > :first-child { z-index: 3; background: var(--bg-secondary, #ECFEFF); }
}

/* 6b. Guest / sign-in pages (layouts/app.blade.php, body.guest-app) ------- */
@media (max-width: 767.98px) {
    .guest-app { --bs-border-radius: 14px; }
    .guest-app #app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
    .guest-app #app > main { flex: 1 0 auto; }
    .guest-app .form-group { margin-bottom: 16px; }
    .guest-app main .card-header { font-size: 1.25rem; font-weight: 700; color: var(--app-ink); }
    .guest-app .navbar { padding-top: env(safe-area-inset-top, 0px); }
    .guest-app .navbar-toggler { min-width: 44px; min-height: 44px; }
    .guest-app .navbar-collapse .nav-link { min-height: 44px; display: flex; align-items: center; }
    .guest-app main.py-4 { padding-top: 16px !important; padding-bottom: 24px !important; }
    .guest-app main > .container { padding-left: 16px; padding-right: 16px; }
    .guest-app main .card {
        border-radius: 22px !important; overflow: hidden;
        box-shadow: 0 1px 2px rgba(16, 40, 40, .06), 0 14px 34px -20px rgba(16, 40, 40, .4) !important;
    }
    .guest-app main .card-header {
        background: transparent !important; border-bottom: 0 !important;
        padding: 20px 20px 0 !important;
    }
    .guest-app main .card-header h4,
    .guest-app main .card-header h5 { font-size: 1.375rem; font-weight: 700; }
    .guest-app main .card-body { padding: 20px !important; }
    .guest-app main .card-body img { max-height: 72px !important; }
    .guest-app .form-label { font-weight: 600; margin-bottom: 6px; }
    .guest-app .form-control,
    .guest-app .form-select { min-height: 52px !important; }
    .guest-app .input-group-text { min-width: 48px; justify-content: center; background: #F1F7F6; color: var(--app-teal-dark); }
    .guest-app main .btn-primary:not(.btn-sm):not(.input-group > .btn),
    .guest-app main .btn-success:not(.btn-sm):not(.input-group > .btn),
    .guest-app main form .btn[type="submit"]:not(.btn-sm):not(.input-group > .btn) {
        min-height: 52px; font-size: 1.0625rem; font-weight: 600; border-radius: 14px; width: 100%;
    }
    .guest-app main .btn-link { min-height: 44px; }
    .guest-app main .card-footer {
        background: #F7FAFA !important; border-top: 1px solid var(--app-line);
        padding: 16px 20px !important;
    }
    .guest-app main .card-footer a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }
    .guest-app .invalid-feedback { font-size: .875rem; }
    .guest-app .footer { margin-top: 0 !important; padding: 16px 0 calc(16px + env(safe-area-inset-bottom, 0px)) !important; font-size: .875rem; }
}

/* 7. Motion & hover-less devices ------------------------------------------ */
@media (hover: none) {
    .card:hover,
    .stat-tile-card:hover,
    .dashboard-stats .card:hover,
    .quick-action-btn:hover,
    .mod-stat-card:hover,
    .role-switcher-link:hover { transform: none !important; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
