/* ==================================================================
   School ERP - back-office design system
   Identity: indigo ink + saffron accent on warm paper.
   Gabarito (headings) / Public Sans (body), tabular numerals for data.
   Mobile-first: the sidebar collapses to a drawer under 900px.
   ================================================================== */

:root {
    /* --brand / --accent / --font-* are injected per-institute by theme_css_vars() */
    --paper: #F6F5F1;
    --surface: #FFFFFF;
    --surface-2: #FBFAF7;
    --ink: #1A1D26;
    --ink-2: #4A4F5E;
    --ink-3: #7A8090;
    --line: #E4E2DA;
    --line-2: #EFEDE6;
    --ok: #1F7A4C;
    --ok-soft: #E4F3EA;
    --warn: #B26A00;
    --warn-soft: #FBF0DC;
    --bad: #B3261E;
    --bad-soft: #FBE9E7;
    --info: #2B5F9E;
    --info-soft: #E7EFF9;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 2px rgba(26, 29, 38, .06), 0 6px 18px rgba(26, 29, 38, .05);
    --shadow-lg: 0 12px 40px rgba(26, 29, 38, .16);
    --sidebar-w: 246px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font-body, system-ui, sans-serif);
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    font-variant-numeric: tabular-nums;
}

h1, h2, h3, h4, .h {
    font-family: var(--font-head, system-ui, sans-serif);
    font-weight: 700;
    letter-spacing: -.01em;
    margin: 0;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/*
 * Urdu mode. The Latin face is listed FIRST on purpose: font fallback works
 * glyph by glyph, so English words, names and digits render in the app's own
 * sans and only Arabic-script text falls through to Nastaliq. Nastaliq listed
 * first drags every Latin character into its bundled serif.
 * Nastaliq needs generous line-height - its ascenders and descenders are tall.
 */
[dir="rtl"] body { font-family: var(--font-body-face, 'Public Sans'), 'Noto Nastaliq Urdu', system-ui, sans-serif; line-height: 1.95; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] .stat .v, [dir="rtl"] .brand-name {
    font-family: var(--font-head-face, 'Gabarito'), 'Noto Nastaliq Urdu', system-ui, sans-serif;
}
[dir="rtl"] input, [dir="rtl"] select, [dir="rtl"] textarea, [dir="rtl"] button, [dir="rtl"] .btn {
    font-family: var(--font-body-face, 'Public Sans'), 'Noto Nastaliq Urdu', system-ui, sans-serif;
}
[dir="rtl"] .sidebar-nav a { font-size: 15px; padding-block: 7px; }
[dir="rtl"] h1 { line-height: 1.7; }
[dir="rtl"] .topbar h1 { line-height: 1.6; }

/* ------------------------------------------------------------------ */
/* App shell                                                           */
/* ------------------------------------------------------------------ */

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

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--brand);
    color: #fff;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.22) transparent;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 60;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-brand {
    padding: 18px 18px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .14);
    display: flex; gap: 10px; align-items: center;
}
.sidebar-brand img { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; background: #fff; padding: 3px; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 8px; flex: 0 0 34px;
    background: var(--accent); color: #22262F;
    display: grid; place-items: center;
    font-family: var(--font-head); font-weight: 800; font-size: 15px;
}
.brand-text { min-width: 0; }
.brand-name {
    font-family: var(--font-head); font-weight: 700; font-size: 14.5px; line-height: 1.25;
    display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.brand-sub { font-size: 11px; opacity: .68; text-transform: uppercase; letter-spacing: .08em; }

.sidebar-nav { padding: 10px 10px 20px; flex: 1; }

.nav-group-label {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em;
    opacity: .5; padding: 18px 11px 6px; font-weight: 700;
}
[dir="rtl"] .nav-group-label { letter-spacing: 0; text-transform: none; font-size: 12.5px; opacity: .6; }

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.22); border-radius: 3px; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 11px; margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, .84);
    font-size: 14px; font-weight: 500;
    border-inline-start: 3px solid transparent;
    text-decoration: none;
}
.sidebar-nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }
.sidebar-nav a.active {
    background: rgba(255, 255, 255, .14);
    color: #fff;
    border-inline-start-color: var(--accent);
    font-weight: 600;
}
.nav-icon { width: 18px; height: 18px; flex: 0 0 18px; opacity: .9; }
.nav-icon svg { width: 18px; height: 18px; display: block; }

.sidebar-foot {
    padding: 12px 16px 16px;
    border-top: 1px solid rgba(255, 255, 255, .14);
    font-size: 12.5px; color: rgba(255, 255, 255, .72);
}
.sidebar-foot .user-name { display: block; color: #fff; font-weight: 600; font-size: 13.5px; }
.sidebar-foot a { color: var(--accent); }

.main {
    flex: 1;
    min-width: 0;
    margin-inline-start: var(--sidebar-w);
    display: flex; flex-direction: column;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 12px 22px;
    display: flex; align-items: center; gap: 14px;
    position: sticky; top: 0; z-index: 40;
    min-height: 58px;
}
.topbar h1 { font-size: 19px; flex: 1; min-width: 0; }
.topbar-sub { color: var(--ink-3); font-size: 12.5px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#session-switch { width: auto; min-width: 190px; max-width: 240px; padding-block: 6px; font-size: 13.5px; }

.menu-toggle {
    display: none; background: none; border: 1px solid var(--line);
    border-radius: var(--radius-sm); width: 36px; height: 36px; cursor: pointer;
    align-items: center; justify-content: center; color: var(--ink);
}

.content { padding: 20px 22px 60px; flex: 1; }
.content > .page-intro { margin-bottom: 16px; color: var(--ink-2); max-width: 70ch; font-size: 14px; }

.scrim { display: none; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    body.nav-open .sidebar { transform: translateX(0); }
    .main { margin-inline-start: 0; }
    .menu-toggle { display: flex; }
    .content { padding: 16px 14px 70px; }
    .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
    .topbar h1 { font-size: 17px; flex: 1 1 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* Actions become a second row that scrolls sideways instead of piling up. */
    .topbar-actions {
        flex: 1 0 100%; order: 3; flex-wrap: nowrap; overflow-x: auto;
        padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .topbar-actions::-webkit-scrollbar { display: none; }
    .topbar-actions > * { flex: 0 0 auto; }
    .topbar-actions #session-switch { min-width: 180px; max-width: 210px; }
    /* Nothing on a touch screen should be smaller than a fingertip. */
    .btn, .btn.sm, .btn.small, .tabs a, .tabs button, select, input:not([type=checkbox]):not([type=radio]) { min-height: 40px; }
    .btn.sm, .btn.small { padding-inline: 12px; }
    body.nav-open .scrim {
        display: block; position: fixed; inset: 0; z-index: 50;
        background: rgba(20, 22, 30, .45);
    }
}

/* ------------------------------------------------------------------ */
/* Cards, sections, layout utilities                                   */
/* ------------------------------------------------------------------ */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}
.card-head {
    padding: 13px 16px;
    border-bottom: 1px solid var(--line-2);
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    background: var(--surface-2);
}
.card-head h2, .card-head h3 { font-size: 15.5px; flex: 1; min-width: 140px; }
.card-head .sub { color: var(--ink-3); font-size: 12.5px; font-weight: 400; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line-2); background: var(--surface-2); }

.section-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
    color: var(--ink-3); font-weight: 700; margin-bottom: 8px;
    display: flex; align-items: center; gap: 8px;
}
.section-label::after { content: ""; flex: 1; height: 2px; background: var(--accent); opacity: .28; border-radius: 2px; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
/* Summary tiles: as many across as fit, never an orphan on its own row. */
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
@media (max-width: 620px) {
    .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .grid.stats > :last-child:nth-child(odd) { grid-column: 1 / -1; }
}
@media (max-width: 360px) { .grid.stats { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 900px) {
    .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
    .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
    .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat .v { font-size: 20px; }
    .stat .k { font-size: 10px; }
}
@media (max-width: 360px) {
    .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
}

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.right { text-align: end; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.hidden { display: none !important; }

/* Stat tiles */
.stat {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 14px 15px;
    display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }
.stat .v { font-family: var(--font-head); font-size: 25px; font-weight: 700; line-height: 1.15; }
.stat .d { font-size: 12px; color: var(--ink-3); }
.stat.accent { border-inline-start: 3px solid var(--accent); }
.stat.good .v { color: var(--ok); }
.stat.bad .v { color: var(--bad); }
.stat.warn .v { color: var(--warn); }

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

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 700px) {
    .card-head { flex-wrap: wrap; gap: 8px; }
    .card-head h2 { flex: 1 1 100%; }
    .filters .field { flex: 1 1 calc(50% - 10px); min-width: 0; }
    .table-wrap table.data { min-width: 560px; }
    .table-wrap table.data td:first-child { min-width: 160px; }
    /* Codes, dates and amounts must not break in the middle ("STD-" / "00001"). */
    .table-wrap table.data td:not(:first-child) { white-space: nowrap; }
    /* A soft edge shows there is more to the right. */
    .table-wrap { background:
        linear-gradient(to right, var(--surface) 30%, transparent) left / 24px 100% no-repeat local,
        linear-gradient(to left, var(--surface) 30%, transparent) right / 24px 100% no-repeat local,
        linear-gradient(to right, rgba(26,29,38,.10), transparent) left / 12px 100% no-repeat scroll,
        linear-gradient(to left, rgba(26,29,38,.10), transparent) right / 12px 100% no-repeat scroll; }
}

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
    text-align: start; font-weight: 600; font-size: 11.5px;
    text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3);
    padding: 10px 12px; border-bottom: 1px solid var(--line);
    background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tbody tr:hover { background: var(--brand-soft, #F3F5FA); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: end; font-variant-numeric: tabular-nums; }
table.data .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
table.data.compact th, table.data.compact td { padding: 7px 9px; font-size: 13px; }

.empty {
    padding: 34px 18px; text-align: center; color: var(--ink-3);
}
.empty .big { font-family: var(--font-head); font-size: 16px; color: var(--ink-2); margin-bottom: 4px; }

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 8px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    font-family: var(--font-body); font-size: 14px; font-weight: 600;
    cursor: pointer; text-decoration: none; line-height: 1.3;
    transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn.disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #23262E; }
.btn.accent:hover { background: var(--accent-dark); }
.btn.danger { color: var(--bad); border-color: #E9C9C6; background: #fff; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-inline-start: -1px; }
.btn-group .btn:first-child { border-start-start-radius: var(--radius-sm); border-end-start-radius: var(--radius-sm); margin-inline-start: 0; }
.btn-group .btn:last-child { border-start-end-radius: var(--radius-sm); border-end-end-radius: var(--radius-sm); }
.btn-group .btn.on { background: var(--brand); border-color: var(--brand); color: #fff; z-index: 1; }

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

.field { margin-bottom: 13px; min-width: 0; }
.field > label, .lbl {
    display: block; font-size: 12.5px; font-weight: 600;
    color: var(--ink-2); margin-bottom: 5px;
}
.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.req::after { content: " *"; color: var(--bad); }

input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="password"], input[type="email"], input[type="tel"], input[type="search"],
input[type="url"], select, textarea {
    width: 100%; padding: 8px 11px;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: #fff; color: var(--ink);
    font-family: var(--font-body); font-size: 14px; line-height: 1.4;
}
textarea { min-height: 88px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 8l3-3.5' fill='none' stroke='%237A8090' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 14px 14px; padding-inline-end: 30px; }
/* The chevron sits at the inline END in both directions; only its physical side flips. */
[dir="rtl"] select { background-position: left 10px center; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft2, rgba(43, 58, 103, .16));
}
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--ink-2); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { flex: 0 0 auto; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) {
    .form-grid, .form-grid.three { grid-template-columns: minmax(0, 1fr); }
}

.filters {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
    padding: 12px 16px; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); margin-bottom: 16px;
}
.filters .field { margin-bottom: 0; min-width: 150px; flex: 1 1 150px; }
.filters .field.narrow { flex: 0 1 130px; }
.filters .actions { display: flex; gap: 8px; }

/* ------------------------------------------------------------------ */
/* Badges, chips, pills                                                */
/* ------------------------------------------------------------------ */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; line-height: 1.7;
    background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.accent { background: var(--accent-soft); color: var(--accent-dark); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .tabs button {
    padding: 9px 14px; font-size: 14px; font-weight: 600; color: var(--ink-3);
    border: 0; background: none; cursor: pointer; white-space: nowrap;
    border-bottom: 2px solid transparent; font-family: var(--font-body);
}
.tabs a:hover, .tabs button:hover { color: var(--ink); text-decoration: none; }
.tabs a.active, .tabs button.active { color: var(--brand); border-bottom-color: var(--accent); }

.avatar {
    width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
    background: var(--brand-soft); color: var(--brand);
    display: inline-grid; place-items: center; flex: 0 0 34px;
    font-weight: 700; font-size: 12.5px; font-family: var(--font-head);
}
.avatar.lg { width: 56px; height: 56px; flex-basis: 56px; font-size: 19px; }

.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person .pn { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; }
.person .ps { font-size: 12px; color: var(--ink-3); }

/* ------------------------------------------------------------------ */
/* Modal + toast                                                       */
/* ------------------------------------------------------------------ */

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(20, 22, 30, .5);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 24px 14px; z-index: 200; overflow-y: auto;
}
.modal {
    background: var(--surface); border-radius: var(--radius);
    width: 100%; max-width: 620px; box-shadow: var(--shadow-lg);
    margin: auto 0;
}
.modal.wide { max-width: 900px; }
.modal.narrow { max-width: 420px; }
.modal-head {
    padding: 14px 18px; border-bottom: 1px solid var(--line-2);
    display: flex; align-items: center; gap: 12px;
}
.modal-head h3 { font-size: 16.5px; flex: 1; }
.modal-body { padding: 18px; max-height: min(70vh, 720px); overflow-y: auto; }
.modal-foot {
    padding: 13px 18px; border-top: 1px solid var(--line-2);
    display: flex; gap: 9px; justify-content: flex-end; background: var(--surface-2);
    border-end-start-radius: var(--radius); border-end-end-radius: var(--radius);
}
.modal-close { background: none; border: 0; font-size: 22px; color: var(--ink-3); cursor: pointer; line-height: 1; padding: 0 4px; }

#toast-container {
    position: fixed; inset-block-end: 18px; inset-inline-end: 18px;
    z-index: 300; display: flex; flex-direction: column; gap: 8px;
    max-width: min(360px, calc(100vw - 28px));
}
.toast {
    background: var(--ink); color: #fff; padding: 11px 15px;
    border-radius: var(--radius-sm); font-size: 14px; box-shadow: var(--shadow-lg);
    border-inline-start: 3px solid var(--accent);
}
.toast.ok { border-inline-start-color: #4ADE80; }
.toast.err { border-inline-start-color: #F87171; }

.banner {
    padding: 11px 14px; border-radius: var(--radius-sm);
    font-size: 13.5px; margin-bottom: 14px;
    border: 1px solid var(--line); background: var(--surface);
    display: flex; gap: 10px; align-items: flex-start;
}
.banner.info { background: var(--info-soft); border-color: #C9DCF2; color: #1E4675; }
.banner.warn { background: var(--warn-soft); border-color: #EFD9AE; color: #7A4A00; }
.banner.bad { background: var(--bad-soft); border-color: #F0C8C4; color: #8C1D18; }
.banner.ok { background: var(--ok-soft); border-color: #BFE3CE; color: #145C38; }
.banner a { text-decoration: underline; }

/* Progress meter used by attendance %, fee collection %, budgets */
.meter { height: 7px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.meter.good > span { background: var(--ok); }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }

/* ------------------------------------------------------------------ */
/* Dashboard and charts (Module 40)                                    */
/* ------------------------------------------------------------------ */

.page-hello { margin: 0 0 14px; }
.page-hello h1 { font-family: var(--font-head); font-size: 24px; margin: 0 0 2px; }
.page-hello p { margin: 0; font-size: 13px; }

a.stat { text-decoration: none; color: inherit; transition: border-color .12s ease, transform .12s ease; }
a.stat:hover { border-color: var(--brand); transform: translateY(-1px); }

.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.plain-list li:last-child { border-bottom: 0; }
.plain-list a { color: inherit; text-decoration: none; }
.plain-list a:hover { text-decoration: underline; }
.tone-warn { color: var(--warn); }
.tone-bad { color: var(--bad); }

.todo-list { display: flex; flex-direction: column; gap: 6px; }
.todo {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink); text-decoration: none;
    transition: border-color .12s ease, background .12s ease;
}
.todo:hover { border-color: var(--brand); background: var(--brand-soft, #F3F5FA); text-decoration: none; }
.todo .count {
    min-width: 34px; height: 30px; padding: 0 9px; border-radius: 8px;
    display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; font-size: 15px;
    background: var(--brand-soft, #EAEBF0); color: var(--brand); flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
}
.todo.warn .count { background: var(--warn-soft); color: var(--warn); }
.todo.bad .count { background: var(--bad-soft); color: var(--bad); }
.todo .label { flex: 1; min-width: 0; font-size: 14px; }
.todo .chev { color: var(--ink-3); flex: 0 0 auto; }
[dir="rtl"] .todo .chev svg { transform: scaleX(-1); }

.notice { padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.notice:last-child { border-bottom: 0; }

/* Charts inherit the text colour so their gridlines follow the theme. */
.card-body svg { color: var(--ink); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; font-size: 12.5px; }
.legend-row { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.chart-pair { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 16px; align-items: center; }
@media (max-width: 640px) { .chart-pair { grid-template-columns: 1fr; } }

/* WhatsApp bot reply preview (Module 43) */
.wa-preview {
    white-space: pre-wrap; word-break: break-word; margin: 12px 0 0;
    background: #E7F6EA; border: 1px solid #BFE3CE; border-radius: 12px 12px 12px 3px;
    padding: 11px 13px; font: 13.5px/1.5 var(--font-body); color: #10331F; max-width: 340px;
}

/* OCR intake (Module 50) */
.ocr-filled { background: #FFF8E1; border-color: #E8C87A; }
.ocr-progress { margin: 12px 0; }
.ocr-progress .meter { margin-bottom: 6px; }
.ocr-raw { max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-word;
           background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 9px;
           padding: 10px; font-size: 12px; margin: 8px 0 0; }
#ocr-preview { max-width: 100%; height: auto; margin-top: 12px; border-radius: 10px;
               border: 1px solid var(--line-2); display: block; }

/*
 * Right-to-left: let each string pick its own base direction.
 *
 * Built-in details like "12 marked, 3 absent" stay English even in Urdu mode,
 * and the bidi algorithm otherwise drags their leading number to the wrong end
 * ("marked, 0 absent 1"). plaintext makes each run read the way it was written,
 * which also protects admin-entered text of either language.
 */
[dir="rtl"] .card-head .sub,
[dir="rtl"] .stat .d,
[dir="rtl"] .stat .v,
[dir="rtl"] .small,
[dir="rtl"] td,
[dir="rtl"] .badge { unicode-bidi: plaintext; }
/* plaintext gives a bare number an LTR base, which would park it on the left of
   a right-to-left tile; keep every line of a tile on the same edge. */
[dir="rtl"] .stat > * { text-align: right; }
/* Same for table cells: an English code or name sits on the right edge like
   every other cell instead of drifting left, but still reads left-to-right. */
[dir="rtl"] td:not(.center), [dir="rtl"] td .small:not(.center) { text-align: right; }
/* Wrappers inside a cell start a fresh paragraph, so a date such as
   "05 Sept 2026" would otherwise come out as "Sept 2026 05". */
[dir="rtl"] td > * { unicode-bidi: plaintext; }

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

@media print {
    .sidebar, .topbar, .no-print, .filters, .btn, #toast-container, .scrim { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    body { background: #fff; font-size: 12px; }
    .card { border: 0; box-shadow: none; margin: 0 0 10px; break-inside: avoid; }
    .card-head { background: none; border-bottom: 1px solid #999; }
    table.data th { background: none; color: #000; border-bottom: 1px solid #000; }
    .print-only { display: block !important; }
    @page { margin: 12mm; }
}
.print-only { display: none; }

.print-head { display: none; }
@media print { .print-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; border-bottom: 2px solid #000; padding-bottom: 8px; } }
