/* ==========================================================================
   Or School Portal — shared mobile design system
   Plain CSS only (the Tailwind Play CDN does not compile external files).
   All tokens are namespaced --ds-* so they never fight legacy :root blocks
   in css/style.css or css/shared.css.
   ========================================================================== */

:root {
    /* Brand */
    --ds-primary: #006194;
    --ds-primary-dark: #004B73;
    --ds-primary-soft: #E6F1F7;
    --ds-on-primary: #ffffff;

    /* Surfaces */
    --ds-surface: #f8f9ff;
    --ds-card: #ffffff;
    --ds-canvas: #F8FAFC;
    --ds-container-low: #eff4ff;

    /* Text */
    --ds-text: #0b1c30;
    --ds-text-muted: #3f4850;
    --ds-outline: #707881;

    /* Lines */
    --ds-border: #E2E8F0;
    --ds-border-strong: #CBD5E1;

    /* Status */
    --ds-success: #10B981;
    --ds-warning: #F59E0B;
    --ds-danger: #EF4444;
    --ds-info: #0284C7;

    /* Shape */
    --ds-radius-lg: 16px;
    --ds-radius-md: 12px;
    --ds-radius-sm: 8px;
    --ds-radius-pill: 9999px;

    /* Spacing */
    --ds-gap-xs: 4px;
    --ds-gap-sm: 8px;
    --ds-gap-md: 12px;
    --ds-gap-lg: 16px;
    --ds-gap-xl: 24px;

    /* Chrome heights */
    --ds-header-h: calc(4rem + env(safe-area-inset-top, 0px));
    --ds-nav-h: calc(4rem + env(safe-area-inset-bottom, 0px));

    --ds-font: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --ds-shadow-sm: 0 1px 2px rgba(11, 28, 48, .06);
    --ds-shadow-md: 0 6px 18px rgba(11, 28, 48, .10);
    --ds-shadow-sheet: 0 -10px 34px rgba(11, 28, 48, .18);
}

/* Taller fixed header (e.g. caretakers.html uses h-20) */
body[data-header-height="80"] {
    --ds-header-h: calc(5rem + env(safe-area-inset-top, 0px));
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    max-width: 100%;
    /* Legacy pages occasionally let a fixed-width child push the RTL page
       origin sideways. Clip the page scroll, keep inner scrollers working. */
    overflow-x: clip;
}

body {
    max-width: 100%;
    overflow-x: clip;
}

body[data-ds-font="app"],
body.app-body {
    font-family: var(--ds-font);
}

/* Legacy glassmorphism pages force Manrope with !important. Keep their card
   language for now, but the portal must still read as one product. */
body[data-ds-font="app"] {
    font-family: var(--ds-font) !important;
}

body {
    -webkit-tap-highlight-color: rgba(0, 97, 148, .12);
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid rgba(0, 97, 148, .45);
    outline-offset: 2px;
    border-radius: var(--ds-radius-sm);
}

::selection {
    background: rgba(0, 97, 148, .18);
}

/* --------------------------------------------------------------------------
   Page shell
   Replaces the per-page pt-20 / pt-24 / pt-28 drift.
   -------------------------------------------------------------------------- */

.app-main {
    padding-top: calc(var(--ds-header-h) + var(--ds-gap-lg));
    padding-bottom: calc(var(--ds-gap-lg) + env(safe-area-inset-bottom, 0px));
}

.app-main--nav {
    padding-bottom: calc(var(--ds-nav-h) + var(--ds-gap-lg));
}

.app-main--plain {
    padding-top: var(--ds-gap-lg);
}

/* Sticky section offset so anchors are not hidden under the header */
:where(h1, h2, h3)[id] {
    scroll-margin-top: calc(var(--ds-header-h) + var(--ds-gap-sm));
}

/* --------------------------------------------------------------------------
   App header
   -------------------------------------------------------------------------- */

.app-header {
    position: fixed;
    inset-inline: 0;
    top: 0;
    z-index: 50;
    background: rgba(248, 249, 255, .92);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--ds-border);
    box-shadow: var(--ds-shadow-sm);
    padding-top: env(safe-area-inset-top, 0px);
}

.app-header__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-gap-sm);
    height: 4rem;
    max-width: 80rem;
    margin-inline: auto;
    padding-inline: var(--ds-gap-lg);
}

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

.app-header__brand img {
    height: 32px;
    width: auto;
    object-fit: contain;
    flex: 0 0 auto;
}

.app-header__title {
    font-size: 18px;
    line-height: 24px;
    font-weight: 700;
    color: var(--ds-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header__subtitle {
    font-size: 12px;
    line-height: 16px;
    font-weight: 500;
    color: var(--ds-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 44x44 back / action control */
.app-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 44px;
    block-size: 44px;
    border-radius: var(--ds-radius-pill);
    color: var(--ds-text-muted);
    background: transparent;
    border: 0;
    cursor: pointer;
    flex: 0 0 auto;
    text-decoration: none;
    transition: background-color .15s ease, color .15s ease;
}

.app-icon-btn:hover {
    background: var(--ds-container-low);
    color: var(--ds-primary);
}

/* --------------------------------------------------------------------------
   Tabs
   Works with the existing .tab-btn / .dtab-btn / .rq-tab / .category-tab
   classes. Never rename them: page controllers depend on those selectors.
   -------------------------------------------------------------------------- */

.app-tabs {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: var(--ds-gap-xs);
    padding: 4px;
    background: var(--ds-container-low);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-pill);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scroll-padding-inline: var(--ds-gap-lg);
    overscroll-behavior-x: contain;
    /* Do not re-add touch-action: pan-y — it blocks horizontal tab swipes. */
    touch-action: auto;
    margin-bottom: var(--ds-gap-lg);
}

.app-tabs::-webkit-scrollbar {
    display: none;
}

.app-tabs > * {
    flex: 0 0 auto !important;
    min-height: 44px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 14px !important;
    border-radius: var(--ds-radius-pill);
    white-space: nowrap !important;
    scroll-snap-align: start;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    border: 0;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}

/* Active / inactive states for the legacy variant classes */
.app-tabs :is(.tab-btn, .dtab-btn, .rq-tab, .category-tab):not(.active) {
    background: transparent;
    color: var(--ds-text-muted);
}

.app-tabs :is(.tab-btn, .dtab-btn, .rq-tab, .category-tab):not(.active):hover {
    background: #e5eeff;
    color: var(--ds-text);
}

.app-tabs :is(.tab-btn, .dtab-btn, .rq-tab, .category-tab).active {
    background: var(--ds-primary);
    color: var(--ds-on-primary);
    box-shadow: 0 2px 6px rgba(0, 97, 148, .25);
}

/* Six or more tabs: two readable rows instead of a hidden scroller */
.app-tabs--wrap {
    flex-wrap: wrap;
    overflow-x: visible;
    border-radius: var(--ds-radius-lg);
    touch-action: auto;
}

.app-tabs--wrap > * {
    flex: 1 1 calc(50% - var(--ds-gap-xs)) !important;
    white-space: normal !important;
    line-height: 1.15;
    padding: 8px 10px !important;
}

/* Non-tab content that lives inside a tab strip (counters, links) */
.app-tabs > .app-tabs__meta {
    flex: 1 1 100% !important;
    min-height: 0 !important;
    padding: 4px 6px !important;
    background: transparent !important;
    color: var(--ds-text-muted) !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    cursor: default !important;
    scroll-snap-align: none !important;
}

/* Scrollable strips: fade the inline-end edge so hidden tabs are obvious */
.app-tabs--fade {
    -webkit-mask-image: linear-gradient(to left, transparent 0, #000 20px);
    mask-image: linear-gradient(to left, transparent 0, #000 20px);
}

/* Compact strip for headers that host nav tabs next to a title */
.app-tabs--compact > * {
    padding: 0 9px !important;
    font-size: 12px !important;
    gap: 4px !important;
}

@media (min-width: 640px) {
    .app-tabs--wrap > * {
        flex: 0 0 auto !important;
        white-space: nowrap !important;
    }
}

/* --------------------------------------------------------------------------
   Cards and lists
   -------------------------------------------------------------------------- */

.app-card {
    background: var(--ds-card);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow-sm);
}

.app-list {
    display: flex;
    flex-direction: column;
    background: var(--ds-card);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    overflow: hidden;
}

.app-list__item {
    display: flex;
    align-items: center;
    gap: var(--ds-gap-md);
    min-height: 56px;
    padding: 12px 14px;
    color: var(--ds-text);
    text-decoration: none;
    border-bottom: 1px solid var(--ds-border);
}

.app-list__item:last-child {
    border-bottom: 0;
}

.app-list__item:active {
    background: var(--ds-container-low);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ds-gap-sm);
    min-height: 44px;
    min-width: 44px;
    padding: 0 18px;
    border-radius: var(--ds-radius-md);
    border: 1px solid transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.app-btn--primary {
    background: var(--ds-primary);
    color: var(--ds-on-primary);
}

.app-btn--primary:hover {
    background: var(--ds-primary-dark);
}

.app-btn--secondary {
    background: var(--ds-card);
    color: var(--ds-primary);
    border-color: var(--ds-border-strong);
}

.app-btn--secondary:hover {
    background: var(--ds-container-low);
}

.app-btn--ghost {
    background: transparent;
    color: var(--ds-text-muted);
}

.app-btn--danger {
    background: var(--ds-danger);
    color: #fff;
}

.app-btn[disabled],
.app-btn[aria-disabled="true"] {
    opacity: .55;
    cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.app-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app-field > label,
.app-label {
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    color: var(--ds-text);
}

.app-input,
.app-field :is(input, select, textarea) {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 16px; /* prevents browser auto-zoom on focus */
    line-height: 1.3;
    color: var(--ds-text);
    background: var(--ds-card);
    border: 1px solid var(--ds-border-strong);
    border-radius: var(--ds-radius-md);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.app-field :is(input, select, textarea):focus {
    outline: none;
    border-color: var(--ds-primary);
    box-shadow: 0 0 0 3px rgba(0, 97, 148, .15);
}

.app-field textarea {
    min-height: 96px;
    resize: vertical;
}

.app-help {
    font-size: 12px;
    line-height: 16px;
    color: var(--ds-text-muted);
}

.app-error {
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    color: var(--ds-danger);
}

/* Sticky submit bar above the bottom nav */
.app-form-actions {
    position: sticky;
    bottom: calc(var(--ds-nav-h) + var(--ds-gap-sm));
    z-index: 20;
    display: flex;
    gap: var(--ds-gap-sm);
    padding: var(--ds-gap-sm) 0;
    background: linear-gradient(to top, var(--ds-surface) 70%, rgba(248, 249, 255, 0));
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */

.app-table-scroll {
    position: relative;
    width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    /* Only contain horizontal overscroll; a generic `contain` swallows the
       vertical page scroll when the gesture starts over the table. */
    overscroll-behavior-x: contain;
    overscroll-behavior-y: auto;
    border-radius: var(--ds-radius-md);
}

.app-table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--ds-container-low);
}

.app-table-scroll--sticky-col :is(th, td):first-child {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    background: var(--ds-card);
    box-shadow: 1px 0 0 var(--ds-border);
}

.app-table-scroll--sticky-col thead th:first-child {
    z-index: 3;
    background: var(--ds-container-low);
}

.app-table-scroll--sticky-col tbody tr:nth-child(even) :is(th, td):first-child {
    background: #f7faff;
}

/* Scroll affordance for wide tables */
.app-table-scroll--hint {
    box-shadow: inset -14px 0 12px -14px rgba(11, 28, 48, .35);
}

/* Inside a page card on a phone the page itself should scroll, not a
   fixed-height inner box sitting above the bottom navigation. */
@media (max-width: 767px) {
    .app-table-scroll--auto {
        max-height: none !important;
    }
}

/* --------------------------------------------------------------------------
   Bottom sheets (mobile) / dialogs (desktop)
   -------------------------------------------------------------------------- */

.app-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(11, 28, 48, .45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.app-sheet {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 61;
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 24px);
    background: var(--ds-card);
    border-radius: 20px 20px 0 0;
    box-shadow: var(--ds-shadow-sheet);
    overflow: hidden;
}

.app-sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-gap-sm);
    padding: 14px var(--ds-gap-lg) 10px;
    border-bottom: 1px solid var(--ds-border);
    flex: 0 0 auto;
}

.app-sheet__title {
    font-size: 16px;
    line-height: 24px;
    font-weight: 700;
    color: var(--ds-text);
}

.app-sheet__body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: var(--ds-gap-lg);
}

.app-sheet__footer {
    position: sticky;
    bottom: 0;
    flex: 0 0 auto;
    display: flex;
    gap: var(--ds-gap-sm);
    padding: var(--ds-gap-md) var(--ds-gap-lg);
    padding-bottom: calc(var(--ds-gap-md) + env(safe-area-inset-bottom, 0px));
    background: var(--ds-card);
    border-top: 1px solid var(--ds-border);
}

@media (min-width: 768px) {
    .app-sheet {
        position: relative;
        inset: auto;
        width: min(560px, calc(100vw - 32px));
        margin: auto;
        max-height: min(85dvh, 720px);
        border-radius: var(--ds-radius-lg);
    }

    .app-sheet-backdrop {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 16px;
    }
}

/* --------------------------------------------------------------------------
   Empty / loading / error states
   -------------------------------------------------------------------------- */

.app-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--ds-gap-sm);
    padding: 32px 20px;
    text-align: center;
    color: var(--ds-text-muted);
}

.app-empty__icon {
    font-size: 36px;
    color: var(--ds-outline);
}

.app-empty__title {
    font-size: 16px;
    line-height: 24px;
    font-weight: 700;
    color: var(--ds-text);
}

.app-empty__text {
    font-size: 12px;
    line-height: 18px;
}

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */

.app-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--ds-radius-pill);
    font-size: 11px;
    line-height: 14px;
    font-weight: 700;
    white-space: nowrap;
}

.app-badge--info { background: rgba(2, 132, 199, .12); color: #0369a1; }
.app-badge--success { background: rgba(16, 185, 129, .14); color: #047857; }
.app-badge--warning { background: rgba(245, 158, 11, .16); color: #b45309; }
.app-badge--danger { background: rgba(239, 68, 68, .14); color: #b91c1c; }
.app-badge--neutral { background: #eef2f7; color: var(--ds-text-muted); }

/* --------------------------------------------------------------------------
   Utilities
   -------------------------------------------------------------------------- */

.app-hidden {
    display: none !important;
}

.app-scroll-x {
    display: flex;
    gap: var(--ds-gap-sm);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.app-scroll-x::-webkit-scrollbar {
    display: none;
}

.app-sticky-actions {
    position: sticky;
    top: calc(var(--ds-header-h) + var(--ds-gap-sm));
    z-index: 20;
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .app-tabs,
    .app-btn,
    .app-list__item,
    .app-sheet {
        scroll-behavior: auto;
        transition: none !important;
    }

    .app-tabs {
        scroll-snap-type: none;
    }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */

@media print {
    .app-header,
    .app-bottom-nav,
    .app-tabs,
    .app-form-actions {
        display: none !important;
    }

    .app-main {
        padding: 0 !important;
    }
}
