/* =========================================================
   SYSTEM — design system v2
   Clean, modern, professional: cool-neutral surfaces, a confident
   indigo primary, emerald / rose for money in / out, soft layered
   shadows, one consistent line-icon set (see icons.php) and
   tabular figures for every amount.

   NOTE: the old variable names (--card, --line, --accent, ...) are
   kept on purpose so every page and inline style repaints
   automatically — only the values changed.
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
    color-scheme: light;

    /* -- surfaces -- */
    --bg: #F3F5F9;
    --card: #FFFFFF;
    --card2: #F8FAFC;           /* inputs, table heads, insets */
    --card3: #EEF2F7;
    --line: #E5E9F1;
    --line-strong: #D5DCE8;
    --text: #0F172A;
    --muted: #55627A;
    --muted-2: #8591A6;

    /* -- primary -- */
    --accent: #3556E6;
    --accent-2: #2442CC;        /* darker shade: used for text on light */
    --accent-ink: #FFFFFF;
    --accent-soft: rgba(53, 86, 230, .09);
    --accent-ring: rgba(53, 86, 230, .22);

    /* -- semantic money colors (names kept from v1) -- */
    --sage: #0E9F6E;            /* positive / paid */
    --sage-ink: #067A53;
    --sage-bg: rgba(14, 159, 110, .10);
    --brick: #E0364F;           /* negative / owed */
    --brick-ink: #C42540;
    --brick-bg: rgba(224, 54, 79, .08);
    --amber: #D97706;
    --amber-bg: rgba(217, 119, 6, .10);

    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-card: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px -6px rgba(16, 24, 40, .08);
    --shadow-pop: 0 4px 6px -2px rgba(16, 24, 40, .05), 0 20px 40px -12px rgba(16, 24, 40, .22);

    --font-display: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
    --font-body: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
    --font-mono: 'Inter', 'Vazirmatn', ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    /* Solid color kept explicit: Android Chrome tints the PWA system bar
       from the real background-color (gradients don't count). */
    background-color: var(--bg) !important;
    background-image: none !important;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

a, button, .btn, .app-tab, .app-tabbar, .dropdown-item { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: 0;
    color: var(--text);
}
h2 { font-size: 1.55rem; }
h4 { font-size: 1.2rem; }
h5 { font-size: 1.02rem; }

a { text-decoration: none; color: var(--accent-2); }
a:hover { color: var(--accent); }

.text-muted, small.text-muted, .small.text-muted { color: var(--muted) !important; }

::selection { background: var(--accent-ring); }

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

/* the page itself never scrolls; each panel handles its own overflow
   (fixed + inset:0 pins html/body to the real viewport — see v1 notes:
   no explicit height/width, so iOS standalone mode has no bottom gap) */
html, body { overflow: hidden; position: fixed; inset: 0; }
body { display: flex; flex-direction: column; }

.page-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding: 26px clamp(14px, 3vw, 36px) 40px !important;
    margin-top: 0 !important;
}
@supports (padding: max(0px)) {
    .page-scroll { padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 20px)) !important; }
}
.page-inner { max-width: 1320px; margin: 0 auto; animation: pageIn .28s ease both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* thin scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted-2); background-clip: content-box; border: 2px solid transparent; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* money / figures */
.num, span.num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    letter-spacing: -.1px;
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-block;
}

/* icons */
.ic { flex-shrink: 0; vertical-align: -.2em; }
.btn .ic { vertical-align: -.18em; }

/* =========================== Buttons =========================== */
.btn {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: .92rem;
    border-radius: var(--radius-sm);
    letter-spacing: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    line-height: 1.35;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { font-size: .86rem; padding: 7px 14px; }

.btn-accent {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: var(--accent-ink);
    padding: 10px 18px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .12), inset 0 1px 0 rgba(255, 255, 255, .16);
}
.btn-accent:hover, .btn-accent:focus { background: var(--accent-2); border-color: var(--accent-2); color: var(--accent-ink); box-shadow: 0 6px 16px -6px rgba(53, 86, 230, .6); }
.btn-accent.btn-sm { padding: 7px 14px; }

/* neutral / secondary */
.btn-outline-info, .btn-outline-secondary {
    background: var(--card);
    border: 1px solid var(--line-strong);
    color: var(--text);
    box-shadow: var(--shadow-xs);
}
.btn-outline-info:hover, .btn-outline-secondary:hover,
.btn-outline-info:focus, .btn-outline-secondary:focus {
    background: var(--accent-soft);
    border-color: rgba(53, 86, 230, .45);
    color: var(--accent-2);
}

.btn-outline-danger {
    background: var(--card);
    border: 1px solid rgba(224, 54, 79, .35);
    color: var(--brick-ink);
}
.btn-outline-danger:hover, .btn-outline-danger:focus { background: var(--brick-bg); border-color: var(--brick); color: var(--brick-ink); }

.btn-danger { background: var(--brick); border: 1px solid var(--brick); color: #fff; }
.btn-danger:hover, .btn-danger:focus { background: var(--brick-ink); border-color: var(--brick-ink); color: #fff; }

.btn-success { background: var(--sage); border: 1px solid var(--sage); color: #fff; }
.btn-success:hover, .btn-success:focus { background: var(--sage-ink); border-color: var(--sage-ink); color: #fff; }

.btn-xs { padding: 5px 11px; font-size: .8rem; border-radius: 8px; gap: 5px; }

.btn-logout {
    background: transparent;
    border: 1px solid var(--line-strong);
    color: var(--muted);
}
.btn-logout:hover, .btn-logout:focus { background: var(--brick-bg); border-color: rgba(224, 54, 79, .4); color: var(--brick-ink); }

.btn-close { opacity: .55; }

/* =========================== Forms =========================== */
label, .form-label { color: var(--text); font-size: .86rem; font-weight: 600; margin-bottom: 6px; }

.form-control, .form-select {
    background-color: var(--card);
    border: 1px solid var(--line-strong);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: var(--font-body);
    font-size: .94rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:hover, .form-select:hover { border-color: var(--muted-2); }
.form-control:focus, .form-select:focus {
    background-color: var(--card);
    color: var(--text);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-ring);
}
.form-control::placeholder { color: var(--muted-2); }
.form-control[type="file"] { padding: 8px 12px; }
.form-control[type="file"]::file-selector-button {
    background: var(--card3); border: 0; border-radius: 8px; padding: 6px 12px;
    margin-inline-end: 12px; color: var(--text); font-weight: 600; font-family: var(--font-body);
}
.form-control[type="date"] { font-family: var(--font-mono); direction: ltr; text-align: left; }
html[dir="rtl"] .form-control[type="date"] { text-align: right; }
.form-control[type="number"] { font-family: var(--font-mono); }

.form-check-input { background-color: var(--card); border: 1.5px solid var(--line-strong); margin-top: .3em; }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { box-shadow: 0 0 0 4px var(--accent-ring); border-color: var(--accent); }
.form-check-label { color: var(--text); font-weight: 500; font-size: .92rem; }

hr { border-color: var(--line); opacity: 1; }

/* =========================== Alerts =========================== */
.alert {
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    font-size: .92rem;
    box-shadow: var(--shadow-xs);
}
.alert-danger  { background: #FFF1F3; border-color: rgba(224, 54, 79, .28); color: #A61B33; }
.alert-success { background: #ECFDF5; border-color: rgba(14, 159, 110, .3); color: #046045; }
.alert-warning { background: #FFF8EB; border-color: rgba(217, 119, 6, .3); color: #92510A; }
.alert code { color: inherit; background: rgba(0, 0, 0, .06); padding: 1px 6px; border-radius: 5px; direction: ltr; unicode-bidi: isolate; }

/* =========================== Panels =========================== */
.card-panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--shadow-card);
}
.card-panel > h5:first-child { padding-bottom: 14px; margin-bottom: 18px !important; border-bottom: 1px solid var(--line); }

/* =========================== Tables =========================== */
.table-dark-custom {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--line);
    --bs-table-striped-bg: transparent;
    --bs-table-hover-bg: #F6F8FD;
    --bs-table-hover-color: var(--text);
    color: var(--text);
    margin-bottom: 0;
    font-family: var(--font-body);
    border-collapse: separate;
    border-spacing: 0;
}
.table-dark-custom thead th {
    background: var(--card2);
    color: var(--muted);
    border-bottom: 1px solid var(--line-strong);
    border-top: none;
    white-space: nowrap;
    font-size: .78rem;
    font-weight: 700;
    padding: 12px 16px;
}
.table-dark-custom td {
    border-bottom: 1px solid var(--line);
    border-top: none;
    vertical-align: middle;
    font-size: .9rem;
    padding: 12px 16px;
    background: transparent;
}
.table-dark-custom tbody tr:last-child td { border-bottom: none; }
.table-dark-custom tbody tr { transition: background-color .12s ease; }
.table-dark-custom.table-hover tbody tr:hover > * { background: #F6F8FD; color: var(--text); }
.table-dark-custom td.text-end { white-space: nowrap; }

tr.status-active > td { background: var(--sage-bg) !important; }
tr.status-disabled > td { background: var(--brick-bg) !important; }

.badge-status-active, .badge-status-disabled {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 11px; border-radius: 999px; font-size: .76rem; font-weight: 700;
}
.badge-status-active { background: var(--sage-bg); color: var(--sage-ink); }
.badge-status-disabled { background: var(--brick-bg); color: var(--brick-ink); }

/* debt status badges (with a status dot) */
.badge-debt-open, .badge-debt-partial, .badge-debt-paid {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 11px; border-radius: 999px; font-size: .76rem; font-weight: 700; white-space: nowrap;
}
.badge-debt-open::before, .badge-debt-partial::before, .badge-debt-paid::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.badge-debt-open    { background: var(--brick-bg); color: var(--brick-ink); }
.badge-debt-partial { background: var(--amber-bg); color: #A15A07; }
.badge-debt-paid    { background: var(--sage-bg); color: var(--sage-ink); }

/* progress bars */
.debt-progress-track { height: 10px; border-radius: 999px; background: var(--card3); overflow: hidden; }
.debt-progress-fill { height: 100%; background: linear-gradient(90deg, var(--sage), #34D399); border-radius: 999px; transition: width .5s cubic-bezier(.22, 1, .36, 1); }
.debt-progress-track-mini { height: 6px; min-width: 90px; }
.debt-progress-track-mini.is-open .debt-progress-fill { background: linear-gradient(90deg, var(--brick), #FB7185); }
.debt-progress-track-mini.is-partial .debt-progress-fill { background: linear-gradient(90deg, var(--amber), #FBBF24); }
.debt-progress-track-mini.is-paid .debt-progress-fill { background: linear-gradient(90deg, var(--sage), #34D399); }
.debt-progress-pct { font-size: .72rem; color: var(--muted-2); margin-top: 3px; font-variant-numeric: tabular-nums; }

/* debt hero */
.debt-hero {
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    padding: 24px 26px;
    position: relative;
    overflow: hidden;
    background: var(--card);
    box-shadow: var(--shadow-card);
}
.debt-hero::after {
    content: ""; position: absolute; inset-inline-start: -40px; top: -60px; width: 190px; height: 190px; border-radius: 50%;
    background: currentColor; opacity: .07; pointer-events: none;
}
.debt-hero.is-open    { background: linear-gradient(135deg, #FFF3F5, var(--card) 70%); border-color: rgba(224, 54, 79, .28); color: var(--brick); }
.debt-hero.is-partial { background: linear-gradient(135deg, #FFF8EB, var(--card) 70%); border-color: rgba(217, 119, 6, .28); color: var(--amber); }
.debt-hero.is-paid    { background: linear-gradient(135deg, #EAFBF4, var(--card) 70%); border-color: rgba(14, 159, 110, .28); color: var(--sage); }
.debt-hero .debt-hero-label { color: var(--muted); font-size: .86rem; font-weight: 600; margin-bottom: 6px; }
.debt-hero .debt-hero-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 2.15rem; font-weight: 700; line-height: 1.15; letter-spacing: -.5px; }
.debt-hero.is-open .debt-hero-value    { color: var(--brick-ink); }
.debt-hero.is-partial .debt-hero-value { color: #A15A07; }
.debt-hero.is-paid .debt-hero-value    { color: var(--sage-ink); }
.debt-hero .debt-hero-sub { color: var(--muted); font-size: .82rem; margin-top: 10px; }

/* scrolling table area */
.table-scroll-area {
    max-height: 520px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--card);
}
.table-scroll-area thead th { position: sticky; top: 0; z-index: 1; }
.table-scroll-area .table-dark-custom { min-width: 640px; }

@media (max-width: 767px) {
    .table-scroll-area { max-height: 380px; }
    .table-dark-custom td, .table-dark-custom thead th { padding: 10px 12px; font-size: .84rem; }
    h2 { font-size: 1.3rem; }
    .card-panel { padding: 16px; border-radius: var(--radius-md); }
}

/* =========================== Chips =========================== */
.scope-badge {
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--card); border: 1px solid var(--line);
    color: var(--muted); padding: 6px 13px; border-radius: 999px;
    font-size: .8rem; font-weight: 600; box-shadow: var(--shadow-xs);
}
.scope-badge .ic { color: var(--accent); }

/* =========================== App shell =========================== */
.app-masthead {
    flex: 0 0 auto;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    padding: 10px 22px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(22px, env(safe-area-inset-left));
    padding-right: max(22px, env(safe-area-inset-right));
}
.app-masthead-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; max-width: 1320px; margin: 0 auto; }

.app-brand { display: flex; align-items: center; gap: 12px; color: var(--text); }
.app-brand:hover { color: var(--text); }
.app-brand-mark, .brand-mark { flex-shrink: 0; width: 38px; height: 38px; border-radius: 11px; box-shadow: 0 6px 14px -6px rgba(43, 63, 208, .55); }
.app-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.app-brand-name { font-family: var(--font-mono); font-weight: 700; font-size: 1.08rem; color: var(--text); letter-spacing: .6px; }
.app-brand-tag { font-size: .72rem; color: var(--muted-2); font-weight: 500; margin-top: 1px; }

.app-user { display: flex; align-items: center; gap: 10px; }
.app-user-chip {
    display: flex; align-items: center; gap: 10px;
    background: var(--card2); border: 1px solid var(--line);
    padding-block: 4px; padding-inline: 14px 5px; border-radius: 999px;
}
.app-user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, #5B7CFA, #2B3FD0);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.app-user-name { font-size: .82rem; font-weight: 700; color: var(--text); line-height: 1.25; }
.app-user-role { font-size: .7rem; color: var(--muted-2); line-height: 1.25; }

/* tab bar */
.app-tabbar {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 4px;
    padding: 0 22px;
    padding-left: max(22px, env(safe-area-inset-left));
    padding-right: max(22px, env(safe-area-inset-right));
    overflow-x: auto;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 14px -12px rgba(16, 24, 40, .25);
    scrollbar-width: none;
    position: relative; z-index: 5;
}
.app-tabbar::-webkit-scrollbar { display: none; }
@media (max-width: 767px) { .app-tabbar { display: none; } }

.mobile-nav-toggle {
    display: none; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 11px;
    border: 1px solid var(--line); background: var(--card); color: var(--text); flex-shrink: 0;
}
.mobile-nav-toggle:hover, .mobile-nav-toggle:focus { background: var(--card2); color: var(--accent-2); }
@media (max-width: 767px) { .mobile-nav-toggle { display: inline-flex; } }

.app-tab {
    flex-shrink: 0; display: inline-flex; align-items: center; gap: 8px;
    padding: 14px 14px; font-size: .88rem; font-weight: 600;
    color: var(--muted); border: 0; border-radius: 0; white-space: nowrap;
    position: relative; background: transparent;
}
.app-tab .ic, .app-tab svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.app-tab:hover { color: var(--text); }
.app-tab.dropdown-toggle::after { margin-inline-start: 2px; border-width: .3em .3em 0; opacity: .6; }
.app-tabbar .app-tab.active { color: var(--accent-2); }
.app-tabbar .app-tab.active::before {
    content: ""; position: absolute; inset: auto 10px 0 10px; height: 3px;
    border-radius: 3px 3px 0 0; background: var(--accent);
}
.app-tab-sep { width: 1px; height: 22px; background: var(--line-strong); flex-shrink: 0; margin: 0 8px; }

.app-scope-pill {
    display: inline-flex; align-items: center; gap: 9px;
    background: var(--accent-soft); border: 1px solid rgba(53, 86, 230, .22);
    color: var(--accent-2); padding-block: 5px; padding-inline: 14px 6px; margin: 8px 0;
    border-radius: 999px; font-size: .84rem; font-weight: 700; flex-shrink: 0;
}
.app-scope-pill:hover { background: rgba(53, 86, 230, .14); color: var(--accent-2); }
.app-scope-pill .pill-logo, .app-scope-pill .pill-logo-fallback,
.school-scope-pill .pill-logo, .school-scope-pill .pill-logo-fallback {
    width: 26px; height: 26px; border-radius: 50%; object-fit: cover;
    background: var(--card); display: flex; align-items: center; justify-content: center;
    font-size: .74rem; font-weight: 800; flex-shrink: 0; color: var(--accent-2);
    box-shadow: 0 0 0 1px rgba(53, 86, 230, .18);
}

/* dropdowns */
.app-dropdown { position: relative; flex-shrink: 0; }
.app-dropdown-menu {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 8px; margin-top: 6px;
    box-shadow: var(--shadow-pop);
    min-width: 250px; position: relative; overflow: hidden;
}
.app-dropdown-menu-portal { position: fixed; margin-top: 0; z-index: 1080; }
.app-dropdown-menu.show { animation: appDropdownPop .16s cubic-bezier(.2, .9, .25, 1.05); }
@keyframes appDropdownPop { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }

.app-dropdown-menu .dropdown-item {
    color: var(--text); border-radius: 10px; padding: 8px 10px;
    font-size: .88rem; font-weight: 600;
    display: flex; align-items: center; gap: 11px;
    transition: background .12s ease, color .12s ease;
}
.app-dropdown-menu .dropdown-item + .dropdown-item { margin-top: 2px; }
.app-dropdown-menu .dropdown-item-icon {
    width: 32px; height: 32px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    border-radius: 9px; background: var(--card3); color: var(--muted); transition: background .12s ease, color .12s ease;
}
.app-dropdown-menu .dropdown-item-icon svg { width: 17px; height: 17px; }
.app-dropdown-menu .dropdown-item:hover, .app-dropdown-menu .dropdown-item:focus { background: var(--card2); color: var(--text); }
.app-dropdown-menu .dropdown-item:hover .dropdown-item-icon { background: var(--accent-soft); color: var(--accent-2); }
.app-dropdown-menu .dropdown-item.active { background: var(--accent-soft); color: var(--accent-2); font-weight: 700; }
.app-dropdown-menu .dropdown-item.active .dropdown-item-icon { background: var(--accent); color: #fff; }

/* mobile drawer */
.app-mobile-nav { width: min(310px, 86vw); background: var(--card); color: var(--text); border-inline-end: 1px solid var(--line); }
.app-mobile-nav .offcanvas-header { border-bottom: 1px solid var(--line); padding: 14px 18px; }
.app-mobile-nav .offcanvas-title { font-family: var(--font-display); font-weight: 700; display: flex; align-items: center; gap: 10px; }
.app-mobile-nav .offcanvas-title .brand-mark { width: 30px; height: 30px; border-radius: 9px; }
.app-mobile-nav .offcanvas-body {
    padding: 12px; padding-bottom: max(14px, calc(env(safe-area-inset-bottom) + 10px));
    display: flex; flex-direction: column; gap: 2px; overflow-y: auto;
}
.mobile-nav-link { justify-content: flex-start; padding: 11px 12px; border-radius: 11px; white-space: normal; width: 100%; }
.mobile-nav-link .ic, .mobile-nav-link svg { width: 19px; height: 19px; }
.mobile-nav-link.active { background: var(--accent-soft); color: var(--accent-2); }
.mobile-nav-link.active::before { display: none; }
.mobile-nav-link:hover { background: var(--card2); }
.mobile-nav-link.app-scope-pill { padding-block: 8px; padding-inline: 12px 8px; margin: 0 0 8px; background: var(--accent-soft); }
.mobile-nav-section { color: var(--muted-2); font-size: .72rem; font-weight: 700; padding: 12px 12px 4px; }
.mobile-nav-sep { height: 1px; background: var(--line); margin: 8px 6px; }

@media (max-width: 767px) {
    .app-masthead { padding: 9px 14px; padding-top: max(9px, env(safe-area-inset-top)); padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
    .app-brand-tag { display: none; }
    .app-user-name, .app-user-role { display: none; }
    .app-user-chip { padding: 4px; }
    .page-scroll { padding-top: 18px !important; }
}

/* =========================== Login =========================== */
.auth-wrapper {
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    overflow-y: auto; overflow-x: hidden;
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    background: var(--card);
}
.auth-hero {
    position: relative; overflow: hidden; color: #fff;
    background:
        radial-gradient(900px 500px at 85% -10%, rgba(120, 148, 255, .55), transparent 60%),
        radial-gradient(700px 480px at -10% 110%, rgba(66, 214, 164, .22), transparent 60%),
        linear-gradient(155deg, #1B2A7A 0%, #121B52 55%, #0C1238 100%);
    padding: max(40px, env(safe-area-inset-top)) clamp(32px, 5vw, 72px) 40px;
    display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
}
.auth-hero::before {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background-image: linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
    background-size: 44px 44px;
    -webkit-mask-image: radial-gradient(ellipse at 30% 30%, #000 20%, transparent 75%);
            mask-image: radial-gradient(ellipse at 30% 30%, #000 20%, transparent 75%);
}
.auth-hero > * { position: relative; }
.auth-hero .app-brand { color: #fff; }
.auth-hero .app-brand-name { color: #fff; font-size: 1.2rem; }
.auth-hero .app-brand-tag { color: rgba(255, 255, 255, .6); }
.auth-hero .brand-mark { box-shadow: 0 10px 24px -8px rgba(0, 0, 0, .5); }
.auth-hero h2 { color: #fff; font-size: clamp(1.7rem, 3vw, 2.4rem); font-weight: 800; line-height: 1.35; margin: 0 0 14px; }
.auth-hero p.lead { color: rgba(255, 255, 255, .72); font-size: 1rem; max-width: 460px; margin: 0 0 28px; }
.auth-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; max-width: 460px; }
.auth-points li { display: flex; align-items: center; gap: 12px; color: rgba(255, 255, 255, .88); font-size: .95rem; font-weight: 500; }
.auth-points .pt-ic { width: 34px; height: 34px; border-radius: 10px; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .16); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.auth-hero .foot { color: rgba(255, 255, 255, .45); font-size: .78rem; }

.auth-pane {
    display: flex; align-items: center; justify-content: center;
    padding: max(28px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
    background: var(--card);
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card .auth-mobile-brand { display: none; justify-content: center; margin-bottom: 26px; }
.auth-card h1 { font-size: 1.65rem; font-weight: 800; margin-bottom: 6px; }
.auth-card p.subtitle { color: var(--muted); font-size: .92rem; margin-bottom: 28px; }
.auth-card label { display: block; }
.auth-card .input-icon { position: relative; }
.auth-card .input-icon .ic { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }
.auth-card .input-icon .form-control { padding-block: 12px; padding-inline: 42px 14px; }
.auth-card .btn-accent { padding: 12px 18px; font-size: .97rem; }
.auth-card .secure-note { display: flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted-2); font-size: .78rem; margin-top: 22px; }

@media (max-width: 900px) {
    .auth-wrapper { grid-template-columns: 1fr; background: var(--bg); }
    .auth-hero { display: none; }
    .auth-pane { background: var(--bg); }
    .auth-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 30px 24px; box-shadow: var(--shadow-card); }
    .auth-card .auth-mobile-brand { display: flex; }
}

/* =========================== Page header pattern =========================== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 14px; margin-bottom: 22px; }
.page-head h2 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .88rem; margin-top: 2px; }

/* =========================== Schools list =========================== */
.dash-search { max-width: 440px; margin: 0 0 24px; position: relative; }
.dash-search .ic { position: absolute; inset-inline-start: 15px; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }
.dash-search input {
    background: var(--card); border: 1px solid var(--line-strong); color: var(--text);
    border-radius: 12px; padding-block: 11px; padding-inline: 44px 16px; box-shadow: var(--shadow-xs);
}
.dash-search input:focus { background: var(--card); color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }

.school-card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
    padding: 20px; height: 100%; display: flex; flex-direction: column; color: var(--text);
    box-shadow: var(--shadow-card); position: relative;
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.school-card:hover { border-color: rgba(53, 86, 230, .4); transform: translateY(-3px); color: var(--text); box-shadow: 0 2px 4px rgba(16, 24, 40, .04), 0 18px 32px -14px rgba(53, 86, 230, .3); }
.school-card .logo-wrap {
    width: 56px; height: 56px; border-radius: 15px; background: var(--accent-soft);
    display: flex; align-items: center; justify-content: center; overflow: hidden; margin-bottom: 16px;
    font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; color: var(--accent-2);
}
.school-card .logo-wrap img { width: 100%; height: 100%; object-fit: cover; }
.school-card h3 { font-size: 1.02rem; font-weight: 700; margin-bottom: 14px; font-family: var(--font-body); line-height: 1.45; }
.school-card .meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.school-card .meta > span {
    display: inline-flex; align-items: center; gap: 6px; background: var(--card2); border: 1px solid var(--line);
    border-radius: 999px; padding: 4px 11px; color: var(--muted); font-size: .78rem; font-weight: 600;
}
.school-card .meta .ic { color: var(--accent); }
.school-card .go {
    position: absolute; top: 20px; inset-inline-end: 20px; width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; color: var(--muted-2); background: var(--card2);
    transition: background .18s ease, color .18s ease, transform .18s ease;
}
.school-card:hover .go { background: var(--accent); color: #fff; transform: translateX(-3px); }
html[dir="ltr"] .school-card:hover .go { transform: translateX(3px); }

.empty-state { text-align: center; color: var(--muted); padding: 64px 20px; background: var(--card); border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); }
.empty-state svg { color: var(--muted-2); margin-bottom: 14px; }

/* =========================== Stat cards =========================== */
.stat-card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md);
    padding: 16px 18px; height: 100%; box-shadow: var(--shadow-card);
    display: flex; align-items: center; gap: 14px;
}
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-soft); color: var(--accent-2);
}
.stat-card .stat-icon.tone-green { background: var(--sage-bg); color: var(--sage-ink); }
.stat-card .stat-icon.tone-rose  { background: var(--brick-bg); color: var(--brick-ink); }
.stat-card .stat-icon.tone-amber { background: var(--amber-bg); color: #A15A07; }
.stat-card .stat-body { min-width: 0; }
.stat-card .stat-label { color: var(--muted); font-size: .78rem; margin-bottom: 2px; font-weight: 600; line-height: 1.45; }
.stat-card .stat-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 1.4rem; font-weight: 700; color: var(--text); letter-spacing: -.4px; line-height: 1.3; }

/* investment card */
.invest-card {
    display: flex; align-items: center; gap: 18px; height: 100%;
    border-radius: var(--radius-lg); padding: 22px 24px; border: 1px solid var(--line);
    position: relative; overflow: hidden; box-shadow: var(--shadow-card); background: var(--card);
}
.invest-card::after { content: ""; position: absolute; inset-inline-start: -50px; top: -70px; width: 200px; height: 200px; border-radius: 50%; background: currentColor; opacity: .07; pointer-events: none; }
.invest-card.invest-positive { background: linear-gradient(135deg, #EAFBF4, var(--card) 72%); border-color: rgba(14, 159, 110, .3); color: var(--sage); }
.invest-card.invest-negative { background: linear-gradient(135deg, #FFF3F5, var(--card) 72%); border-color: rgba(224, 54, 79, .3); color: var(--brick); }
.invest-card .invest-icon {
    width: 56px; height: 56px; border-radius: 16px; flex-shrink: 0; background: currentColor;
    display: flex; align-items: center; justify-content: center; position: relative;
}
.invest-card .invest-icon svg { color: #fff; width: 26px; height: 26px; }
.invest-card .invest-label { color: var(--muted); font-size: .85rem; margin-bottom: 4px; font-weight: 600; }
.invest-card.invest-positive .invest-value { color: var(--sage-ink); }
.invest-card.invest-negative .invest-value { color: var(--brick-ink); }
.invest-card .invest-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 1.75rem; font-weight: 700; line-height: 1.2; letter-spacing: -.6px; }
.invest-card .invest-formula { color: var(--muted-2); font-size: .76rem; margin-top: 5px; }

.thumb-sm { width: 42px; height: 42px; border-radius: 10px; object-fit: cover; background: var(--card3); border: 1px solid var(--line); }

/* subtle motion on cards */
.card-panel, .stat-card, .invest-card { transition: box-shadow .18s ease; }


/* narrow phones: stat cards stack (icon above) so big amounts never clip */
@media (max-width: 575px) {
    .stat-card { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; }
    .stat-card .stat-icon { width: 38px; height: 38px; border-radius: 10px; }
    .stat-card .stat-icon svg { width: 19px; height: 19px; }
    .stat-card .stat-value { font-size: 1.2rem; }
    .stat-card .stat-body { width: 100%; }
    .invest-card { padding: 18px; gap: 14px; }
    .invest-card .invest-icon { width: 46px; height: 46px; border-radius: 13px; }
    .invest-card .invest-value, .debt-hero .debt-hero-value { font-size: 1.5rem; }
    .page-head { margin-bottom: 16px; }
}

/* =========================== Confirm dialog =========================== */
.modal-backdrop.show { opacity: .45; background: #0B1226; }
.confirm-modal .modal-content { border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); background: var(--card); color: var(--text); }
.confirm-modal .modal-body { padding: 28px 26px 18px; text-align: center; }
.confirm-modal .confirm-ic { width: 54px; height: 54px; border-radius: 50%; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; background: var(--brick-bg); color: var(--brick-ink); }
.confirm-modal .confirm-title { font-weight: 800; font-size: 1.1rem; margin-bottom: 6px; }
.confirm-modal .confirm-text { color: var(--muted); font-size: .92rem; margin: 0; }
.confirm-modal .modal-footer { border-top: 0; padding: 6px 22px 22px; display: flex; gap: 10px; }
.confirm-modal .modal-footer .btn { flex: 1; margin: 0; padding: 10px 14px; }

/* =========================== Installed (standalone) =========================== */
@media (display-mode: standalone) {
    .app-masthead { padding-top: max(14px, calc(env(safe-area-inset-top) + 4px)); }
    .auth-pane { padding-top: max(28px, calc(env(safe-area-inset-top) + 12px)); }
}

/* =========================== Install banner =========================== */
.install-banner {
    position: fixed; top: 0; left: 0; right: 0; z-index: 2000;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    display: flex; justify-content: center; pointer-events: none;
    transform: translateY(-130%); opacity: 0;
    transition: transform .45s cubic-bezier(.22, 1, .36, 1), opacity .35s ease;
}
.install-banner.is-visible { transform: translateY(0); opacity: 1; }
.install-banner[hidden] { display: none !important; }
.install-banner-card {
    pointer-events: auto; width: 100%; max-width: 560px; display: flex; align-items: flex-start; gap: 12px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
    padding-block: 14px; padding-inline: 14px 12px; box-shadow: var(--shadow-pop); position: relative; overflow: hidden;
}
.install-banner-card::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--accent); }
.install-banner-icon {
    flex: 0 0 auto; width: 42px; height: 42px; border-radius: 12px; background: var(--accent-soft);
    display: flex; align-items: center; justify-content: center; color: var(--accent-2);
}
.install-banner-icon svg { width: 22px; height: 22px; }
.install-banner-body { flex: 1 1 auto; min-width: 0; }
.install-banner-eyebrow { display: inline-flex; align-items: center; gap: 6px; font-size: .68rem; font-weight: 700; color: var(--accent-2); margin-bottom: 2px; }
.install-banner-eyebrow .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); animation: install-banner-pulse 1.8s ease-in-out infinite; }
@keyframes install-banner-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.install-banner-title { font-family: var(--font-display); font-weight: 700; font-size: .95rem; color: var(--text); margin: 0 0 2px; }
.install-banner-desc { font-size: .8rem; color: var(--muted); line-height: 1.55; margin: 0; }
.install-banner-steps { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin-top: 8px; font-size: .74rem; color: var(--muted); }
.install-banner-steps .step { display: inline-flex; align-items: center; gap: 4px; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding-block: 3px; padding-inline: 9px 7px; color: var(--text); }
.install-banner-steps .step svg { width: 13px; height: 13px; color: var(--accent); }
.install-banner-steps .arrow { color: var(--muted-2); font-size: .7rem; }
.install-banner-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.install-banner-actions .btn { padding: 7px 16px; font-size: .82rem; border-radius: 999px; }
.install-banner-dismiss-link { background: none; border: none; color: var(--muted); font-size: .8rem; font-weight: 600; cursor: pointer; padding: 7px 6px; }
.install-banner-dismiss-link:hover { color: var(--text); }
.install-banner-close {
    flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--card2);
    color: var(--muted); display: flex; align-items: center; justify-content: center; cursor: pointer; line-height: 1; font-size: .95rem;
    transition: background .15s ease, color .15s ease;
}
.install-banner-close:hover { background: var(--card3); color: var(--text); }
@media (max-width: 560px) {
    .install-banner { padding-left: 8px; padding-right: 8px; }
    .install-banner-card { border-radius: var(--radius-md); padding: 12px 10px; }
    .install-banner-steps { font-size: .7rem; }
}
@media (display-mode: standalone) { .install-banner { display: none !important; } }


/* =========================== Languages (ku / ar / en) =========================== */
/* English reads best in Inter; Kurdish + Arabic keep Vazirmatn. */
html[lang="en"] {
    --font-body: 'Inter', 'Vazirmatn', 'Segoe UI', system-ui, sans-serif;
    --font-display: 'Inter', 'Vazirmatn', 'Segoe UI', system-ui, sans-serif;
}
html[lang="en"] body { letter-spacing: -.003em; }

/* Three-way language switcher. Fixed visual order (EN | KU | AR) in every language. */
.lang-switch {
    display: inline-flex; align-items: center; gap: 2px; padding: 3px;
    background: var(--card3); border: 1px solid var(--line); border-radius: 999px;
    direction: ltr; flex-shrink: 0;
}
.lang-opt {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 4px 12px; border-radius: 999px; line-height: 1.5;
    font-size: .78rem; font-weight: 600; color: var(--muted); text-decoration: none;
    transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.lang-opt:hover { color: var(--text); }
.lang-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.lang-opt.active { background: var(--card); color: var(--accent-2); box-shadow: var(--shadow-xs); }
.lang-opt .lang-short { display: none; letter-spacing: .4px; }

/* Masthead: switcher shown from tablet up; on phones it lives in the menu drawer. */
@media (max-width: 767px) { .app-user > .lang-switch { display: none; } }

/* Drawer + login page variants */
.mobile-nav-lang { padding: 6px 12px 12px; }
.mobile-nav-lang .lang-switch { width: 100%; }
.mobile-nav-lang .lang-opt { flex: 1; }
.auth-pane { position: relative; }
.auth-lang { position: absolute; top: max(18px, env(safe-area-inset-top)); inset-inline-end: max(18px, env(safe-area-inset-right)); z-index: 3; }
@media (max-width: 575px) {
    .auth-lang .lang-opt { padding: 4px 10px; }
    .auth-lang .lang-full { display: none; }
    .auth-lang .lang-short { display: inline; }
}
@media (max-width: 900px) { .auth-card { margin-top: 36px; } }

/* LTR (English) refinements for pieces that were drawn for right-to-left */
html[dir="ltr"] .alert code { text-align: left; }
html[dir="ltr"] .app-brand-tag, html[dir="ltr"] .app-user-role { letter-spacing: .1px; }
