/* =====================================================================
   ARMS application styles.
   Built on Bootstrap 5's own CSS variables so light/dark theming comes for
   free: everything below reads --bs-* tokens rather than hard-coded colours.
   ===================================================================== */

:root {
    --arms-sidebar-width: 260px;
    --arms-topbar-height: 64px;
    --arms-radius: .75rem;

    /* Status language, used identically everywhere:
       green = OK/verified, amber = CHECK, grey = not encoded, blue = submitted. */
    --arms-ok: var(--bs-success);
    --arms-check: var(--bs-warning);
    --arms-none: var(--bs-secondary);
    --arms-submitted: var(--bs-primary);
}

[data-bs-theme="light"] {
    --arms-sidebar-bg: #0f172a;
    --arms-sidebar-fg: #cbd5e1;
    --arms-sidebar-fg-active: #ffffff;
    --arms-sidebar-active-bg: rgba(255, 255, 255, .1);
    --arms-app-bg: #f4f6fa;
    --arms-card-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

[data-bs-theme="dark"] {
    --arms-sidebar-bg: #0b1220;
    --arms-sidebar-fg: #94a3b8;
    --arms-sidebar-fg-active: #ffffff;
    --arms-sidebar-active-bg: rgba(255, 255, 255, .08);
    --arms-app-bg: #0f1729;
    --arms-card-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

body {
    background: var(--arms-app-bg);
    -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- Shell */

.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--arms-sidebar-width);
    background: var(--arms-sidebar-bg);
    color: var(--arms-sidebar-fg);
    display: flex;
    flex-direction: column;
    z-index: 1045;
    transition: transform .2s ease;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.app-brand {
    display: flex; align-items: center; gap: .75rem;
    padding: 1rem 1.25rem;
    min-height: var(--arms-topbar-height);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.app-brand-mark {
    width: 36px; height: 36px; flex: 0 0 36px;
    display: grid; place-items: center;
    border-radius: .6rem;
    background: linear-gradient(135deg, var(--bs-primary), #6610f2);
    color: #fff; font-size: 1.1rem;
}
.app-brand-text strong { display: block; color: #fff; letter-spacing: .5px; line-height: 1.1; }
.app-brand-text small  { display: block; font-size: .7rem; opacity: .7; }

.app-nav { padding: .75rem 0; flex: 1 1 auto; }
.app-nav-heading {
    padding: .9rem 1.25rem .35rem;
    font-size: .68rem; font-weight: 700;
    letter-spacing: .09em; text-transform: uppercase;
    opacity: .5;
}
.app-nav-link {
    display: flex; align-items: center; gap: .75rem;
    padding: .6rem 1.25rem;
    color: var(--arms-sidebar-fg);
    text-decoration: none;
    font-size: .9rem;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s;
}
.app-nav-link i { font-size: 1.05rem; width: 1.25rem; text-align: center; }
.app-nav-link:hover { background: var(--arms-sidebar-active-bg); color: var(--arms-sidebar-fg-active); }
.app-nav-link.active {
    background: var(--arms-sidebar-active-bg);
    color: var(--arms-sidebar-fg-active);
    border-left-color: var(--bs-primary);
    font-weight: 600;
}
.app-sidebar-footer { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: .75rem; }

.app-main {
    flex: 1 1 auto;
    margin-left: var(--arms-sidebar-width);
    display: flex; flex-direction: column;
    min-width: 0;                /* lets wide tables scroll instead of stretching the page */
}

.app-topbar {
    position: sticky; top: 0; z-index: 1030;
    display: flex; align-items: center; gap: 1rem;
    min-height: var(--arms-topbar-height);
    padding: .5rem 1.25rem;
    background: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
}
.app-topbar-title { flex: 1 1 auto; min-width: 0; }
.app-topbar-title h1 { font-size: 1.15rem; font-weight: 600; margin: 0; line-height: 1.3; }
.app-topbar-title p  { font-size: .82rem; margin: 0; color: var(--bs-secondary-color); }
.app-topbar-actions { display: flex; align-items: center; gap: .5rem; }

.app-sidebar-toggle { display: none; font-size: 1.4rem; padding: .25rem .5rem; color: var(--bs-body-color); }

.btn-icon {
    width: 38px; height: 38px;
    display: inline-grid; place-items: center;
    border-radius: 50%;
    border: 1px solid transparent;
    color: var(--bs-body-color);
    background: transparent;
}
.btn-icon:hover { background: var(--bs-secondary-bg); }
.app-topbar-actions .dropdown .btn-icon { width: auto; border-radius: 2rem; padding: .25rem .6rem .25rem .25rem; }

.app-avatar {
    width: 32px; height: 32px; flex: 0 0 32px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--bs-primary); color: #fff;
    font-weight: 600; font-size: .85rem;
}

.app-content { flex: 1 1 auto; padding: 1.5rem 1.25rem; }
.app-footer {
    display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; justify-content: space-between;
    padding: 1rem 1.25rem;
    font-size: .78rem;
    color: var(--bs-secondary-color);
    border-top: 1px solid var(--bs-border-color);
}

.app-sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 1040;
}

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.is-open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .app-sidebar-toggle { display: block; }
    .app-content { padding: 1rem .85rem; }
}

/* ------------------------------------------------------------ Offline */

.app-offline-banner {
    display: flex; align-items: center; gap: .6rem;
    padding: .65rem 1rem;
    margin-bottom: 1rem;
    border-radius: var(--arms-radius);
    background: var(--bs-warning-bg-subtle);
    color: var(--bs-warning-text-emphasis);
    border: 1px solid var(--bs-warning-border-subtle);
    font-size: .875rem;
}

/* -------------------------------------------------------------- Cards */

.card {
    border-radius: var(--arms-radius);
    border-color: var(--bs-border-color);
    box-shadow: var(--arms-card-shadow);
}
.card-header {
    background: transparent;
    border-bottom-color: var(--bs-border-color);
    font-weight: 600;
    padding: .85rem 1.15rem;
}

/* KPI tiles on the district dashboard. */
.kpi-card { height: 100%; }
.kpi-card .card-body { padding: 1.1rem 1.15rem; }
.kpi-label {
    font-size: .72rem; font-weight: 700;
    letter-spacing: .07em; text-transform: uppercase;
    color: var(--bs-secondary-color);
    margin-bottom: .35rem;
    display: flex; align-items: center; gap: .4rem;
}
.kpi-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; margin-bottom: .15rem; }
.kpi-value.is-headline { font-size: 2.15rem; }
.kpi-sub { font-size: .8rem; color: var(--bs-secondary-color); margin: 0; }

.kpi-delta { font-size: .8rem; font-weight: 600; display: inline-flex; align-items: center; gap: .2rem; }
.kpi-delta.up   { color: var(--bs-success); }
.kpi-delta.down { color: var(--bs-danger); }
.kpi-delta.flat { color: var(--bs-secondary-color); }

/* ------------------------------------------------------------- Status */

.status-badge {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .2rem .55rem;
    border-radius: 2rem;
    font-size: .74rem; font-weight: 600;
    white-space: nowrap;
}
.status-badge::before {
    content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor;
}
.status-ok          { color: var(--bs-success-text-emphasis);   background: var(--bs-success-bg-subtle); }
.status-check       { color: var(--bs-warning-text-emphasis);   background: var(--bs-warning-bg-subtle); }
.status-not_encoded { color: var(--bs-secondary-color);         background: var(--bs-secondary-bg); }
.status-submitted   { color: var(--bs-primary-text-emphasis);   background: var(--bs-primary-bg-subtle); }
.status-verified    { color: var(--bs-success-text-emphasis);   background: var(--bs-success-bg-subtle); }
.status-draft       { color: var(--bs-secondary-color);         background: var(--bs-secondary-bg); }

/* -------------------------------------------------------------- Charts */

.chart-box { position: relative; width: 100%; }
.chart-box canvas { max-width: 100%; }
.chart-box.h-sm  { height: 240px; }
.chart-box.h-md  { height: 320px; }
.chart-box.h-lg  { height: 420px; }
.chart-box.h-xl  { height: 520px; }

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

/* Wide tables scroll inside their own container -- the page body never does. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table > :not(caption) > * > * { padding: .55rem .65rem; }
.table thead th {
    font-size: .74rem; font-weight: 700;
    letter-spacing: .04em; text-transform: uppercase;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--bs-border-color); }

.table-sticky-head thead th { position: sticky; top: 0; z-index: 2; background: var(--bs-body-bg); }

/* --------------------------------------------------------- Encode form */

.encode-panel { margin-bottom: 1.25rem; }
.encode-panel .card-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }

/* Raw inputs are white/editable; every derived figure is visibly read-only.
   min-width matches .derived's floor below -- without it, table-layout:auto
   starves these unconstrained inputs first when a wide encode grid overflows
   its container, squeezing them down to a couple of px and hiding their
   typed value entirely (worst on the mid-table band columns). */
.input-raw { min-width: 3rem; max-width: 7.5rem; }
.input-raw::-webkit-outer-spin-button,
.input-raw::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-raw[type=number] { -moz-appearance: textfield; }

.derived {
    display: inline-block;
    min-width: 4rem;
    padding: .25rem .5rem;
    border-radius: .375rem;
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    text-align: right;
}
.derived.is-strong { color: var(--bs-body-color); }
.derived.is-match  { background: var(--bs-success-bg-subtle); color: var(--bs-success-text-emphasis); }
.derived.is-mismatch { background: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis); }

.encode-grid { width: 100%; }
.encode-grid th, .encode-grid td { vertical-align: middle; }
.encode-grid .level-name { min-width: 11rem; }
.encode-grid .level-desc { font-size: .74rem; color: var(--bs-secondary-color); display: block; font-weight: 400; }

/* Deliberately NOT sticky: the action bar below already occupies the bottom
   edge, and two stacked overlays hid the last rows of the EOSY table. */
.validation-banner { z-index: 5; }
.validation-issue { display: flex; gap: .5rem; align-items: flex-start; font-size: .85rem; padding: .15rem 0; }

.encode-actions {
    position: sticky; bottom: 0; z-index: 6;
    display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
    margin-top: 1.25rem;
    padding: .85rem 1rem;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--arms-radius);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .06);
}

/* Reserve room under the sticky action bar so that, at full scroll, it rests
   over empty padding rather than covering the last input rows. */
.app-content:has(.encode-actions) { padding-bottom: 7rem; }

/* Progress rail on the encoder landing page. */
.progress-thin { height: .5rem; border-radius: 1rem; }

/* Column-abbreviation legend under the encode grid. */
.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: .9rem 1.5rem;
}
.legend-grid dt { font-weight: 700; font-size: .82rem; }
.legend-grid dd { margin: .1rem 0 0; font-size: .8rem; color: var(--bs-secondary-color); }

/* ------------------------------------------------------------- Heatmap */

.heatmap { border-collapse: separate; border-spacing: 2px; }
.heatmap td.cell {
    text-align: center;
    font-size: .78rem; font-weight: 600;
    border-radius: .3rem;
    min-width: 3.2rem;
    color: var(--bs-body-color);
}

/* ---------------------------------------------------------- Auth pages */

.auth-body { background: var(--arms-app-bg); }
.auth-wrap { display: flex; min-height: 100vh; }

.auth-hero {
    flex: 1 1 50%;
    background: linear-gradient(150deg, #0d6efd 0%, #4c1d95 55%, #0f172a 100%);
    color: #fff;
    align-items: center; justify-content: center;
    padding: 3rem;
}
.auth-hero-inner { max-width: 30rem; }
.auth-hero-mark {
    display: inline-grid; place-items: center;
    width: 60px; height: 60px;
    border-radius: 1rem;
    background: rgba(255, 255, 255, .15);
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
}
.auth-hero h2 { font-weight: 700; line-height: 1.15; }
.auth-hero-badges { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.1rem; }
.auth-hero-badge {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .3rem .7rem;
    border-radius: 2rem;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .25);
    font-size: .78rem; font-weight: 600;
}
.auth-hero-points { list-style: none; padding: 0; margin: 2rem 0 0; }
.auth-hero-points li { display: flex; gap: .6rem; align-items: flex-start; padding: .4rem 0; font-size: .92rem; opacity: .92; }

.auth-panel { flex: 1 1 50%; display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; }
.auth-panel-inner { width: 100%; max-width: 24rem; position: relative; }
.auth-theme-toggle { position: absolute; top: -3rem; right: 0; }
.auth-mark {
    display: inline-grid; place-items: center;
    width: 52px; height: 52px; border-radius: .9rem;
    background: linear-gradient(135deg, var(--bs-primary), #6610f2);
    color: #fff; font-size: 1.5rem;
}

/* ----------------------------------------------- Demo panel (local only) */

.demo-panel {
    border: 1px dashed var(--bs-warning-border-subtle);
    border-radius: var(--arms-radius);
    background: var(--bs-warning-bg-subtle);
    padding: .85rem;
}
.demo-list {
    border-radius: .5rem;
    overflow: hidden;
    background: var(--bs-body-bg);
}
.demo-list .list-group-item { background: transparent; }
.demo-avatar {
    width: 30px; height: 30px; flex: 0 0 30px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
    font-size: .85rem;
}

/* ------------------------------------------------------- DataTables fit */

div.dataTables_wrapper div.dataTables_filter input { margin-left: .5rem; }
div.dataTables_wrapper div.dataTables_length select { min-width: 4.5rem; }
table.dataTable > thead .sorting::after,
table.dataTable > thead .sorting_asc::after,
table.dataTable > thead .sorting_desc::after { opacity: .35; }

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

@media print {
    .app-sidebar, .app-topbar, .app-footer, .encode-actions,
    .no-print, .dataTables_filter, .dataTables_length, .dataTables_paginate { display: none !important; }
    .app-main { margin-left: 0; }
    .app-content { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    body { background: #fff; }
}
