/* ============================================================================
   zaalt.mn admin — design system. Brand: navy #1F3352, gold #C9A227.
   Layered on vendored Bootstrap 5. System font stack (full Cyrillic, zero load).
   Tokens → typography → shell → components. Keep this the single source of
   admin styling; page templates use the classes here, no inline <style>.
   ========================================================================== */

:root {
    /* Brand */
    --z-navy: #1F3352;
    --z-navy-dark: #16263E;
    --z-navy-darker: #101C2F;
    --z-gold: #C9A227;
    --z-gold-dark: #B4901F;
    --z-gold-soft: rgba(201, 162, 39, 0.15);

    /* Neutrals */
    --z-bg: #F4F6F9;
    --z-surface: #FFFFFF;
    --z-border: #E3E7EE;
    --z-border-strong: #D2D9E4;
    --z-ink: #1E2A3A;          /* primary text */
    --z-ink-soft: #46536A;     /* secondary text */
    --z-ink-muted: #5F6B7D;    /* tertiary / captions — ≥ 4.5:1 on every admin surface (was #8A94A6, 2.8–3.1:1) */
    --z-head-bg: #EDF0F5;      /* table headers, wells */

    /* Semantic status (text + soft background pairs) */
    --z-success: #2F6B43;   --z-success-bg: #EAF5EE;
    --z-warn: #7D560E;      --z-warn-bg: #FBF3E1;   /* text 5.9:1 on its tint (was #9A6B12, 4.2:1) */
    --z-danger: #B4462E;    --z-danger-bg: #FBEDE9;
    --z-info: #2C5591;      --z-info-bg: #EAF0FA;

    /* Links + outline-primary buttons: Bootstrap's own darker blue (its #0d6efd is 4.2:1 on --z-bg) */
    --z-link: #0A58CA;       --z-link-rgb: 10, 88, 202;
    --z-link-hover: #084298; --z-link-hover-rgb: 8, 66, 152;
    --bs-link-color: var(--z-link);             --bs-link-color-rgb: var(--z-link-rgb);
    --bs-link-hover-color: var(--z-link-hover); --bs-link-hover-color-rgb: var(--z-link-hover-rgb);

    /* Type scale */
    --z-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
    --z-fs-xs: 0.72rem;
    --z-fs-sm: 0.82rem;
    --z-fs-base: 0.9rem;
    --z-fs-md: 1rem;
    --z-fs-lg: 1.2rem;
    --z-fs-xl: 1.55rem;
    --z-lh: 1.55;

    /* Spacing / radius / shadow / motion */
    --z-space-1: 0.35rem;
    --z-space-2: 0.6rem;
    --z-space-3: 1rem;
    --z-space-4: 1.5rem;
    --z-radius: 0.55rem;
    --z-radius-sm: 0.35rem;
    --z-shadow-sm: 0 1px 2px rgba(16, 28, 47, 0.06), 0 1px 3px rgba(16, 28, 47, 0.05);
    --z-shadow-md: 0 4px 14px rgba(16, 28, 47, 0.09);
    --z-ease: cubic-bezier(.25, .46, .45, .94);
    --z-dur-fast: .16s;
    --z-ring: 0 0 0 .2rem rgba(31, 51, 82, .16);

    --z-sidebar-w: 236px;
    --z-topbar-h: 54px;
}

/* ---------- base typography ---------- */

.admin-body {
    background: var(--z-bg);
    min-height: 100vh;
    font-family: var(--z-font);
    font-size: var(--z-fs-base);
    line-height: var(--z-lh);
    color: var(--z-ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.admin-content h1, .admin-content h2, .admin-content h3,
.admin-content h4, .admin-content h5, .admin-content h6 {
    color: var(--z-navy);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.admin-content .card-title {
    font-size: var(--z-fs-md);
    font-weight: 700;
    color: var(--z-navy);
    letter-spacing: -0.01em;
    margin-bottom: 0;
}

.admin-content .section-hint { font-size: var(--z-fs-sm); color: var(--z-ink-muted); }
.text-muted { color: var(--z-ink-muted) !important; }
code { color: #7A4E9E; }

/* Section heading with an eyebrow label */
.z-eyebrow {
    font-size: var(--z-fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    color: var(--z-ink-muted);
}

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

.admin-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--z-sidebar-w);
    background: linear-gradient(180deg, var(--z-navy) 0%, var(--z-navy-dark) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 1040;
}

.admin-main {
    margin-left: var(--z-sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- sidebar ---------- */

.sidebar-brand {
    padding: 0.9rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #fff;
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.sidebar-mark { flex-shrink: 0; }

.sidebar-brand-text {
    display: block;
    line-height: 1.15;
    font-family: Georgia, "Times New Roman", "Noto Serif", serif;
    letter-spacing: 0;
}

.sidebar-brand .brand-dot { color: var(--z-gold); }

.sidebar-brand small {
    display: block;
    font-family: var(--z-font);
    font-size: 0.68rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    margin-top: 0.1rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0 1rem;
}

.sidebar-section {
    padding: 0.85rem 1.15rem 0.3rem;
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(255, 255, 255, 0.38);
}

.sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.48rem 1.15rem;
    color: rgba(255, 255, 255, 0.78);
    text-decoration: none;
    font-size: var(--z-fs-base);
    border-left: 3px solid transparent;
    transition: background var(--z-dur-fast) var(--z-ease), color var(--z-dur-fast) var(--z-ease);
}

.sidebar-nav .nav-item:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }

.sidebar-nav .nav-item.active {
    color: #fff;
    background: var(--z-navy-darker);
    border-left-color: var(--z-gold);
    font-weight: 600;
}

/* count pill inside a nav item (e.g. flag count) */
.nav-item .nav-count {
    font-size: 0.66rem;
    font-weight: 700;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--z-gold);
    color: var(--z-navy-darker);
    line-height: 1.4;
}

.sidebar-foot {
    padding: 0.65rem 1.15rem;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.38);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ---------- topbar ---------- */

.admin-topbar {
    height: var(--z-topbar-h);
    background: var(--z-navy);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 1px 4px rgba(16, 28, 47, 0.25);
}

.topbar-title { font-weight: 600; font-size: var(--z-fs-md); flex: 1; }

.topbar-user { display: flex; align-items: center; gap: 0.6rem; }
.topbar-user .admin-email { font-size: var(--z-fs-sm); color: rgba(255, 255, 255, 0.72); }

.topbar-status { display: flex; align-items: center; gap: 0.5rem; }

.topbar-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--z-fs-xs);
    font-weight: 600;
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    transition: background var(--z-dur-fast) var(--z-ease);
}
.topbar-chip:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.topbar-chip .chip-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.topbar-chip.chip-ok { color: #BFE6CC; }
.topbar-chip.chip-warn { background: rgba(201, 162, 39, 0.22); color: #F0D48A; }
.topbar-chip.chip-danger { background: rgba(214, 92, 63, 0.28); color: #F4B7A6; }

.logout-btn {
    --bs-btn-border-color: rgba(255, 255, 255, 0.4);
    --bs-btn-color: rgba(255, 255, 255, 0.85);
}

/* ---------- content ---------- */

.admin-content {
    flex: 1;
    padding: 1.35rem;
    max-width: 1540px;
    width: 100%;
}

/* ---------- cards ---------- */

.admin-content .card {
    border: 1px solid var(--z-border);
    border-radius: var(--z-radius);
    background: var(--z-surface);
    box-shadow: var(--z-shadow-sm);
}

.admin-content .card-header {
    background: var(--z-surface);
    border-bottom: 1px solid var(--z-border);
    font-weight: 700;
    color: var(--z-navy);
    padding: 0.75rem 1rem;
    border-radius: var(--z-radius) var(--z-radius) 0 0;
}

/* ---------- tables ---------- */

.admin-content .table {
    font-size: var(--z-fs-sm);
    color: var(--z-ink);
    margin-bottom: 0;
}

.admin-content .table thead th {
    background: var(--z-head-bg);
    color: var(--z-ink-soft);
    font-weight: 600;
    font-size: var(--z-fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    border-bottom: 1px solid var(--z-border-strong);
}

.admin-content .table td { vertical-align: middle; }
.admin-content .table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.admin-content .table tfoot td { font-weight: 700; background: var(--z-head-bg); }

/* ---------- stat tiles ---------- */

.z-tile {
    border: 1px solid var(--z-border);
    border-radius: var(--z-radius);
    background: var(--z-surface);
    box-shadow: var(--z-shadow-sm);
    padding: 0.85rem 1rem;
    height: 100%;
}
.z-tile .z-tile-label {
    font-size: var(--z-fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--z-ink-muted);
    margin-bottom: 0.15rem;
}
.z-tile .z-tile-value {
    font-size: var(--z-fs-xl);
    font-weight: 700;
    color: var(--z-navy);
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
.z-tile .z-tile-sub { font-size: var(--z-fs-xs); color: var(--z-ink-muted); margin-top: 0.15rem; }
.z-tile.z-tile--accent { border-left: 3px solid var(--z-gold); }
.z-tile.z-tile--danger .z-tile-value { color: var(--z-danger); }

/* ---------- badges / status pills ---------- */

.z-badge {
    display: inline-block;
    padding: 0.16rem 0.5rem;
    border-radius: 999px;
    font-size: var(--z-fs-xs);
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}
.z-badge--success { background: var(--z-success-bg); color: var(--z-success); }
.z-badge--warn    { background: var(--z-warn-bg);    color: var(--z-warn); }
.z-badge--danger  { background: var(--z-danger-bg);  color: var(--z-danger); }
.z-badge--info    { background: var(--z-info-bg);    color: var(--z-info); }
.z-badge--muted   { background: var(--z-head-bg);    color: var(--z-ink-soft); }

/* Tier badges (dashboard latest questions) */
.tier-badge {
    display: inline-block;
    padding: 0.14rem 0.5rem;
    border-radius: var(--z-radius-sm);
    font-size: var(--z-fs-xs);
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}
.tier-badge.t0 { background: #8FB3DE; color: #16263E; }
.tier-badge.t1 { background: #5B84B8; }
.tier-badge.t2 { background: #35608F; }
.tier-badge.t3 { background: #1F3352; }
.tier-badge.tx { background: #9AA4B2; color: #16263E; }

/* ---------- money helpers ---------- */

.margin-pos { color: var(--z-success); }
.margin-neg { color: var(--z-danger); }

/* ---------- red flags panel ---------- */

.z-flags { display: grid; gap: 0.55rem; }
.z-flag {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.7rem 0.9rem;
    border-radius: var(--z-radius);
    border: 1px solid var(--z-border);
    border-left-width: 4px;
    background: var(--z-surface);
    box-shadow: var(--z-shadow-sm);
    text-decoration: none;
    color: inherit;
    transition: box-shadow var(--z-dur-fast) var(--z-ease), transform var(--z-dur-fast) var(--z-ease);
}
.z-flag:hover { box-shadow: var(--z-shadow-md); transform: translateY(-1px); color: inherit; }
.z-flag .z-flag-icon { font-size: 1.05rem; line-height: 1.3; }
.z-flag .z-flag-title { font-weight: 700; color: var(--z-ink); font-size: var(--z-fs-base); }
.z-flag .z-flag-detail { font-size: var(--z-fs-sm); color: var(--z-ink-soft); }
.z-flag.flag-danger { border-left-color: var(--z-danger); background: var(--z-danger-bg); }
.z-flag.flag-warn   { border-left-color: var(--z-gold);   background: var(--z-warn-bg); }
.z-flag.flag-ok     { border-left-color: var(--z-success); background: var(--z-success-bg); }
.z-flag.flag-ok .z-flag-title { color: var(--z-success); }

/* ---------- bar / tier charts (shared: dashboard + finance) ---------- */

.z-barchart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 110px;
    border-bottom: 1px solid var(--z-border);
}
.z-barchart .bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
    min-width: 0;
}
.z-barchart .bar {
    background: #35608F;
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: background var(--z-dur-fast) var(--z-ease);
}
.z-barchart .bar-col:hover .bar { background: var(--z-gold); }
.z-barchart .bar.zero { background: #E3E7EE; }
.z-barchart.compact { height: 90px; }

.z-axis { display: flex; gap: 2px; margin-top: 0.3rem; }
.z-axis .tick {
    flex: 1;
    font-size: 0.64rem;
    color: var(--z-ink-muted);
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
}

.z-tierstack {
    display: flex;
    height: 26px;
    border-radius: var(--z-radius-sm);
    overflow: hidden;
    background: var(--z-head-bg);
}
.z-tierstack .seg { min-width: 2px; }
.z-tierstack .seg + .seg { border-left: 2px solid #fff; }

.z-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.1rem;
    margin-top: 0.7rem;
    font-size: var(--z-fs-sm);
    color: var(--z-ink-soft);
}
.z-legend .swatch {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 2px;
    margin-right: 0.35rem;
    vertical-align: baseline;
}
.tier-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 2px;
    margin-right: 0.4rem;
    vertical-align: baseline;
}

/* ---------- feedback list ---------- */

.fb-item {
    border-left: 3px solid var(--z-border);
    padding: 0.4rem 0.75rem;
    margin-bottom: 0.6rem;
}
.fb-item.fb-neg { border-left-color: var(--z-danger); background: var(--z-danger-bg); }
.fb-item .fb-meta { font-size: var(--z-fs-xs); color: var(--z-ink-muted); }

/* ---------- empty state ---------- */

.z-empty {
    text-align: center;
    color: var(--z-ink-muted);
    padding: 1.5rem 1rem;
    font-size: var(--z-fs-sm);
}

/* ---------- legal text (laws / case decisions) ---------- */

.law-text {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: var(--z-fs-base);
    line-height: 1.65;
    color: #2A3646;
}

/* ---------- forms + buttons ---------- */

.form-label { font-size: var(--z-fs-sm); font-weight: 600; color: var(--z-ink-soft); margin-bottom: 0.2rem; }
.form-text { font-size: var(--z-fs-xs); }

.btn { transition: background-color var(--z-dur-fast) var(--z-ease), border-color var(--z-dur-fast) var(--z-ease), color var(--z-dur-fast) var(--z-ease), box-shadow var(--z-dur-fast) var(--z-ease); }
.btn:focus-visible { box-shadow: var(--z-ring); }
.form-control:focus, .form-select:focus { border-color: #2C4468; box-shadow: var(--z-ring); }

.btn-gold {
    background: var(--z-gold);
    border-color: var(--z-gold);
    color: var(--z-navy-darker);
    font-weight: 600;
}
.btn-gold:hover, .btn-gold:focus {
    background: var(--z-gold-dark);
    border-color: var(--z-gold-dark);
    color: var(--z-navy-darker);
}

.btn-outline-primary {
    --bs-btn-color: var(--z-link); --bs-btn-border-color: var(--z-link);
    --bs-btn-hover-bg: var(--z-link); --bs-btn-hover-border-color: var(--z-link);
    --bs-btn-active-bg: var(--z-link-hover); --bs-btn-active-border-color: var(--z-link-hover);
    --bs-btn-disabled-color: var(--z-link); --bs-btn-disabled-border-color: var(--z-link);
}

.btn-ghost {
    background: transparent;
    border-color: var(--z-border-strong);
    color: var(--z-ink-soft);
    font-weight: 600;
}
.btn-ghost:hover { background: var(--z-head-bg); color: var(--z-navy); border-color: var(--z-border-strong); }

/* anchor chips (settings / finance section nav) */
.z-anchors { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* ---------- login page ---------- */

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(1000px 600px at 20% -10%, #2C4A78 0%, var(--z-navy) 45%, var(--z-navy-darker) 100%);
    padding: 1rem;
    font-family: var(--z-font);
}
.login-wrap { width: 100%; max-width: 410px; }
.login-card { border: none; border-radius: 0.75rem; border-top: 4px solid var(--z-gold); box-shadow: var(--z-shadow-md); }
.login-mark { display: block; margin-bottom: 0.85rem; }
.login-logo { font-family: Georgia, "Times New Roman", "Noto Serif", serif; font-size: 1.7rem; font-weight: 700; color: var(--z-navy); }
.login-logo span { color: var(--z-gold); }
.login-sub { font-size: var(--z-fs-sm); text-transform: uppercase; letter-spacing: 0.16em; color: #7A8699; }
.login-foot { text-align: center; margin-top: 1rem; font-size: var(--z-fs-sm); color: rgba(255, 255, 255, 0.45); }

/* ---------- responsive ---------- */

@media (max-width: 991.98px) {
    .admin-sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
    .admin-sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, 0.35); }
    .admin-main { margin-left: 0; }
    .topbar-status .topbar-chip.chip-spend { display: none; } /* keep only the flag pill on mobile */
}

/* Narrow phones: the e-mail pushed «Гарах» 12px past the edge (/settings at 390). */
@media (max-width: 399.98px) {
    .topbar-user .admin-email { display: none; }
}
