/* Design tokens. Light is the default; dark is chosen with the moon/sun button or follows the system setting. */
:root {
    --navy: #3a4566;
    --accent: #8cc8f0;
    --accent-dark: #4f9ad8;
    --primary: #2f7bd0;
    --primary-dark: #1d4f96;
    --primary-soft: #e2eefb;
    --primary-softer: #f3f8fe;
    --ink: #2c3654;
    --muted: #6f7890;
    --line: #d9e4f2;
    --surface: #ffffff;
    --page: #f4f7fc;
    --ok: #2e8b57;
    --ok-soft: #e6f4ec;
    --warn: #b7791f;
    --warn-soft: #fdf3dc;
    --bad: #c0392b;
    --bad-soft: #fbe4e1;
    --radius: 12px;
    --input-bg: #ffffff;
    --input-border: #cfdcec;
    --row-hover: #f6f9fe;
    --chip-muted: #e9eef6;
    --shadow: 0 1px 2px rgba(13, 27, 56, .04), 0 6px 18px rgba(13, 27, 56, .04);
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --grid: #e6ecf5;
}

:root[data-theme="dark"] {
    --navy: #c9d4ec;
    --accent-dark: #8cc8f0;
    --primary: #4d97e6;
    --primary-dark: #9ccff3;
    --primary-soft: #1d3157;
    --primary-softer: #17264a;
    --ink: #e4eaf6;
    --muted: #98a5c2;
    --line: #2a3a5e;
    --surface: #131e36;
    --page: #0b1428;
    --ok: #4fc283;
    --ok-soft: #12352a;
    --warn: #e2b04d;
    --warn-soft: #3a2f14;
    --bad: #f07a6e;
    --bad-soft: #3d1f1c;
    --input-bg: #0f1a31;
    --input-border: #2f4268;
    --row-hover: #18264a;
    --chip-muted: #22314f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 8px 22px rgba(0, 0, 0, .18);
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #233252;
}

:root, [data-bs-theme="light"], [data-bs-theme="dark"] {
    --bs-body-bg: var(--page);
    --bs-body-color: var(--ink);
    --bs-emphasis-color: var(--ink);
    --bs-secondary-color: var(--muted);
    --bs-tertiary-bg: var(--primary-softer);
    --bs-border-color: var(--line);
    --bs-heading-color: var(--ink);
    --bs-body-font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}

html { font-size: 15px; }

body { margin: 0; color: var(--ink); background: var(--page); }

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary); text-decoration: underline; }
.muted { color: var(--muted); }

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

.btn { --bs-btn-border-radius: 8px; --bs-btn-font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; white-space: nowrap; }
.btn-sm { --bs-btn-padding-y: .4rem; --bs-btn-padding-x: .85rem; --bs-btn-font-size: .85rem; --bs-btn-border-radius: 8px; }
.btn .nav-icon { width: 16px; height: 16px; }
.btn-primary {
    --bs-btn-color: #fff; --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary);
    --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #2569b8; --bs-btn-hover-border-color: #2569b8;
    --bs-btn-active-color: #fff; --bs-btn-active-bg: #1d4f96; --bs-btn-active-border-color: #1d4f96;
    --bs-btn-disabled-color: #fff; --bs-btn-disabled-bg: var(--primary); --bs-btn-disabled-border-color: var(--primary);
}
.btn-light, .btn-outline-primary, .btn-outline-secondary {
    --bs-btn-color: var(--primary-dark); --bs-btn-bg: transparent; --bs-btn-border-color: var(--line);
    --bs-btn-hover-color: var(--primary-dark); --bs-btn-hover-bg: var(--primary-softer); --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-color: var(--primary-dark); --bs-btn-active-bg: var(--primary-soft); --bs-btn-active-border-color: var(--primary);
    --bs-btn-disabled-color: var(--muted); --bs-btn-disabled-bg: transparent; --bs-btn-disabled-border-color: var(--line);
    background: var(--bs-btn-bg);
}
.btn-light:hover, .btn-outline-primary:hover, .btn-outline-secondary:hover { background: var(--bs-btn-hover-bg); }
.btn-outline-secondary { --bs-btn-color: var(--ink); --bs-btn-hover-color: var(--ink); --bs-btn-active-color: var(--primary-dark); }
.btn-outline-danger {
    --bs-btn-color: var(--bad); --bs-btn-border-color: var(--line);
    --bs-btn-hover-color: var(--bad); --bs-btn-hover-bg: var(--bad-soft); --bs-btn-hover-border-color: var(--bad);
    --bs-btn-active-color: var(--bad); --bs-btn-active-bg: var(--bad-soft); --bs-btn-active-border-color: var(--bad);
}
.btn-check:checked + .btn, .btn.active { background: var(--primary-soft); }

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

.form-label { font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.form-control, .form-select { background-color: var(--input-bg); border-color: var(--input-border); color: var(--ink); border-radius: 8px; padding-top: .5rem; padding-bottom: .5rem; }
.form-control-sm, .form-select-sm { font-size: .88rem; padding-top: .38rem; padding-bottom: .38rem; border-radius: 8px; min-height: 0; }
.form-control:focus, .form-select:focus { background-color: var(--input-bg); color: var(--ink); border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-control::placeholder { color: var(--muted); opacity: .75; }
.form-control:disabled, .form-control[readonly], .form-select:disabled { background-color: var(--primary-softer); color: var(--muted); }
.form-check-input { background-color: var(--input-bg); border-color: var(--input-border); }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------- Alerts and modals ---------- */

.alert { --bs-alert-border-radius: 10px; border-width: 1px; }
.alert-success { --bs-alert-bg: var(--ok-soft); --bs-alert-color: var(--ok); --bs-alert-border-color: transparent; }
.alert-danger { --bs-alert-bg: var(--bad-soft); --bs-alert-color: var(--bad); --bs-alert-border-color: transparent; }
.alert-warning { --bs-alert-bg: var(--warn-soft); --bs-alert-color: var(--warn); --bs-alert-border-color: transparent; }
.alert-info { --bs-alert-bg: var(--primary-soft); --bs-alert-color: var(--primary-dark); --bs-alert-border-color: transparent; }

.modal-content { --bs-modal-bg: var(--surface); --bs-modal-color: var(--ink); --bs-modal-border-color: var(--line); --bs-modal-border-radius: 16px; --bs-modal-inner-border-radius: 15px; box-shadow: 0 28px 60px rgba(13, 27, 56, .28); }
.modal-header { background: var(--primary-softer); }
.modal-title { font-weight: 700; color: var(--ink); }
[data-bs-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* ---------- Top bar ---------- */

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

.nav-icon { width: 19px; height: 19px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-chev { width: 14px; height: 14px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: .7; transition: transform .2s; }
details[open] > summary .nav-chev { transform: rotate(180deg); }

.appbar {
    --bar-ink: #dbe6f7;
    position: sticky; top: 0; z-index: 1030; color: #fff;
    background: linear-gradient(100deg, #17213d 0%, #1b2d57 55%, #1d4f96 100%);
    box-shadow: 0 6px 22px rgba(13, 27, 56, .22);
}
.appbar-row { display: flex; align-items: center; gap: .9rem; height: 64px; padding: 0 1.25rem; max-width: 1600px; margin: 0 auto; }

.brand { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; color: inherit; }
.brand:hover { text-decoration: none; color: inherit; }
.brand-mark { display: inline-block; flex-shrink: 0; width: 42px; height: 34px; background: url("/brand/logo-mark.svg") center / contain no-repeat; }
.brand.on-dark .brand-mark { filter: brightness(1.35) drop-shadow(0 2px 6px rgba(0, 0, 0, .25)); }
.brand-name { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name strong { color: #fff; font-size: 1rem; }
.brand-name small { color: var(--accent); font-size: .72rem; font-weight: 600; white-space: nowrap; }

.appnav { flex: 1; min-width: 0; display: flex; align-items: center; gap: .15rem; }
.nav-top, .mega > summary {
    list-style: none; cursor: pointer; display: flex; align-items: center; gap: .4rem; padding: .5rem .7rem; border-radius: 10px;
    color: var(--bar-ink); font-weight: 600; font-size: .9rem; white-space: nowrap; position: relative; user-select: none;
    transition: background .15s, color .15s;
}
.mega > summary::-webkit-details-marker, .user-menu > summary::-webkit-details-marker, .lang-menu > summary::-webkit-details-marker { display: none; }
.nav-top:hover, .mega > summary:hover, .mega[open] > summary { background: rgba(255, 255, 255, .12); color: #fff; text-decoration: none; }
.nav-top.current, .mega.current > summary { color: #fff; background: rgba(255, 255, 255, .08); }
.nav-top.current::after, .mega.current > summary::after {
    content: ""; position: absolute; inset-inline: .7rem; bottom: -12px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent);
}
.mega > summary:focus-visible, .user-menu > summary:focus-visible, .lang-menu > summary:focus-visible, .nav-top:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mega-panel {
    position: absolute; top: 100%; inset-inline: 0; margin: 0 auto; width: min(1180px, calc(100% - 2rem)); max-height: calc(100vh - 84px); overflow-y: auto;
    background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 18px 18px;
    box-shadow: 0 28px 60px rgba(13, 27, 56, .25); padding: 1rem 1.1rem 1.2rem; animation: mega-in .16s ease-out;
}
@keyframes mega-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.mega-head { display: flex; align-items: center; gap: .7rem; padding: .2rem .3rem .9rem; border-bottom: 1px solid var(--line); margin-bottom: .7rem; }
.mega-head-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; color: #fff; background: linear-gradient(135deg, #4f9ad8, #1d4f96); }
.mega-head strong { display: block; font-size: 1.05rem; }
.mega-head small { color: var(--muted); font-size: .8rem; }
.mega-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .3rem; }
.mega-card { display: flex; align-items: flex-start; gap: .75rem; padding: .7rem .75rem; border-radius: 12px; color: var(--ink); transition: background .15s; }
.mega-card:hover { background: var(--primary-softer); text-decoration: none; color: var(--ink); }
.mega-card.active { background: var(--primary-soft); }
.mega-icon { display: grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border-radius: 11px; background: var(--primary-soft); color: var(--primary); transition: background .15s, color .15s; }
.mega-card:hover .mega-icon, .mega-card.active .mega-icon { background: var(--primary); color: #fff; }
.mega-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.mega-text b { font-weight: 600; font-size: .94rem; }
.mega-card.active .mega-text b { color: var(--primary-dark); }
.mega-text small { color: var(--muted); font-size: .8rem; margin-top: .1rem; }

.appbar-actions { display: flex; align-items: center; gap: .45rem; flex-shrink: 0; }

.lang-menu { position: relative; }
.lang-menu > summary {
    list-style: none; cursor: pointer; display: flex; align-items: center; gap: .35rem; height: 38px; padding: 0 .7rem;
    border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font-weight: 600; font-size: .85rem; white-space: nowrap;
}
.lang-panel {
    position: absolute; inset-inline-end: 0; top: calc(100% + .45rem); z-index: 70; min-width: 210px; padding: .5rem;
    background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 45px rgba(13, 27, 56, .25); animation: mega-in .16s ease-out;
}
.lang-title { font-size: .75rem; color: var(--muted); padding: .3rem .5rem .35rem; }
.lang-item { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .5rem .6rem; border-radius: 9px; color: var(--ink); }
.lang-item:hover { background: var(--primary-softer); color: var(--ink); text-decoration: none; }
.lang-item.active { background: var(--primary-soft); font-weight: 700; }
.lang-item small { color: var(--muted); }

.theme-toggle {
    display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; cursor: pointer; padding: 0;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.theme-toggle:hover { background: var(--primary-softer); }
.theme-toggle .sun, :root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: inline; }

.appbar .lang-menu > summary, .appbar .theme-toggle { background: rgba(255, 255, 255, .08); color: #fff; border-color: rgba(255, 255, 255, .22); }
.appbar .lang-menu > summary:hover, .appbar .lang-menu[open] > summary, .appbar .theme-toggle:hover { background: rgba(255, 255, 255, .16); }

.user-menu { position: relative; }
.user-menu > summary {
    list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem; padding: .22rem .5rem .22rem .3rem;
    border-radius: 999px; color: #fff; border: 1px solid rgba(255, 255, 255, .22); background: rgba(255, 255, 255, .06);
}
[dir="rtl"] .user-menu > summary { padding: .22rem .3rem .22rem .5rem; }
.user-menu > summary:hover, .user-menu[open] > summary { background: rgba(255, 255, 255, .14); }
.user-avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; font-weight: 700; color: #fff; background: linear-gradient(135deg, #4f9ad8, #5d6fb8); }
.user-avatar.lg { width: 46px; height: 46px; font-size: 1.15rem; }
.user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; font-weight: 600; }
.user-panel {
    position: absolute; inset-inline-end: 0; top: calc(100% + .55rem); width: 260px; padding: .5rem; z-index: 70;
    background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 45px rgba(13, 27, 56, .25); animation: mega-in .16s ease-out;
}
.user-panel-head { display: flex; gap: .7rem; align-items: center; padding: .5rem .5rem .7rem; }
.user-panel-head strong { display: block; line-height: 1.3; }
.user-panel-head small { color: var(--muted); }
.user-panel a, .user-logout {
    display: flex; width: 100%; align-items: center; gap: .6rem; padding: .55rem .6rem; border-radius: 9px; border: 0;
    background: none; color: var(--ink); font: inherit; cursor: pointer; text-align: start;
}
.user-panel a:hover, .user-logout:hover { background: var(--primary-softer); text-decoration: none; color: var(--ink); }
.user-panel .nav-icon { color: var(--muted); }
.user-logout { color: var(--bad); border-top: 1px solid var(--line); border-radius: 0 0 9px 9px; margin-top: .3rem; }
.user-logout:hover { color: var(--bad); }
.user-logout .nav-icon { color: var(--bad); }

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.nav-burger { display: none; place-items: center; width: 42px; height: 42px; border-radius: 11px; cursor: pointer; color: #fff; background: rgba(255, 255, 255, .1); margin: 0; }
.nav-toggle:focus-visible + .nav-burger { outline: 2px solid var(--accent); outline-offset: 2px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.crumbs { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); padding: .9rem 1.5rem 0; max-width: 1600px; width: 100%; margin: 0 auto; }
.crumbs a { display: inline-flex; color: var(--muted); }
.crumbs a:hover { color: var(--primary); }
.crumbs strong { color: var(--ink); font-weight: 600; }
.crumb-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.crumb-sep { opacity: .5; }
[dir="rtl"] .crumb-sep { transform: scaleX(-1); }
.content { padding: 1.1rem 1.5rem 2rem; max-width: 1600px; width: 100%; margin: 0 auto; flex: 1 1 auto; }

@media (max-width: 1500px) {
    .user-name { display: none; }
    .nav-top > .nav-icon, .mega > summary > .nav-icon { display: none; }
}
@media (max-width: 1360px) {
    .appbar-row { gap: .6rem; padding: 0 .9rem; }
    .nav-top, .mega > summary { padding: .5rem .5rem; font-size: .86rem; }
    .brand-name small { display: none; }
    .lang-code { display: none; }
}
@media (max-width: 1160px) {
    .nav-burger { display: grid; order: 3; }
    .appbar-actions { margin-inline-start: auto; }
    .appnav {
        position: fixed; top: 64px; inset-inline: 0; bottom: 0; flex-direction: column; align-items: stretch; gap: .25rem;
        overflow-y: auto; padding: .8rem; background: var(--page); color: var(--ink);
        visibility: hidden; opacity: 0; transition: opacity .2s, visibility .2s;
    }
    .nav-toggle:checked ~ .appnav { visibility: visible; opacity: 1; }
    .nav-top, .mega > summary { color: var(--ink); background: var(--surface); border: 1px solid var(--line); padding: .8rem 1rem; font-size: .98rem; }
    .nav-top > .nav-icon, .mega > summary > .nav-icon { display: inline; color: var(--primary); }
    .mega > summary .nav-chev { margin-inline-start: auto; }
    .nav-top:hover, .mega > summary:hover, .mega[open] > summary, .nav-top.current, .mega.current > summary { background: var(--primary-softer); color: var(--ink); }
    .nav-top.current::after, .mega.current > summary::after { display: none; }
    .nav-top.current, .mega.current > summary { border-inline-start: 4px solid var(--primary); }
    .mega-panel { position: static; width: auto; max-height: none; box-shadow: none; border: 0; border-radius: 0; padding: .3rem 0 .6rem; background: transparent; animation: none; }
    .mega-head { display: none; }
    .mega-grid { grid-template-columns: 1fr; }
    .mega-card { background: var(--surface); }
    .lang-code { display: inline; }
}
@media (max-width: 560px) {
    .appbar-row { padding: 0 .75rem; gap: .5rem; }
    .brand-name { display: none; }
    .lang-code { display: none; }
    .crumbs { padding: .75rem 1rem 0; }
    .content { padding: .9rem 1rem 1.5rem; }
}

/* ---------- Page parts ---------- */

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.page-head h1 { font-size: 1.45rem; font-weight: 700; margin: 0; flex: 1 1 auto; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.panel h2 { font-size: 1.05rem; font-weight: 700; margin: 0 0 .85rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .85rem; }
.panel-head h2 { margin: 0; }
.panel-head a { font-size: .85rem; font-weight: 600; white-space: nowrap; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .7rem; }
.filter-bar .field { min-width: 150px; }
.filter-bar .form-check { align-self: center; margin: 1.3rem 0 0; }

/* Tables run edge to edge inside their panel, with a tinted header. */
.table-wrap { overflow-x: auto; }
.panel > .table-wrap { margin-inline: -1.25rem; }
.panel > .table-wrap:first-child, .panel > .print-only:first-child + .table-wrap { margin-top: -1.1rem; border-radius: var(--radius) var(--radius) 0 0; }
.panel > .table-wrap:last-child { margin-bottom: -1.1rem; border-radius: 0 0 var(--radius) var(--radius); }
.panel > .table-wrap:only-child { border-radius: var(--radius); }
.panel > .table-wrap .table > * > tr > :first-child { padding-inline-start: 1.25rem; }
.panel > .table-wrap .table > * > tr > :last-child { padding-inline-end: 1.25rem; }
.panel > form:only-child > .table-wrap, .panel > form > .table-wrap { margin-inline: -1.25rem; }
.table { --bs-table-bg: transparent; --bs-table-color: var(--ink); --bs-table-border-color: var(--line); --bs-table-hover-bg: var(--row-hover); --bs-table-hover-color: var(--ink); --bs-table-striped-color: var(--ink); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .55rem .7rem; border-bottom-color: var(--line); }
.table-sm > :not(caption) > * > * { padding: .5rem .7rem; }
.table thead th { font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--primary-softer); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table tbody tr:last-child > * { border-bottom-color: transparent; }
.table td { vertical-align: middle; }
.table tfoot td, .table tfoot th { font-weight: 700; border-top: 2px solid var(--ink); background: var(--primary-softer); }
.table .row-group td { font-weight: 700; background: var(--primary-softer); }

/* Amounts stay left-to-right and aligned on any page direction. */
.num { direction: ltr; unicode-bidi: isolate; text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: end; }
.negative { color: var(--bad); }
.code { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: .85em; white-space: pre-wrap; word-break: break-all; }
a.code { font-weight: 600; }
.pad-1 { padding-inline-start: 0 !important; }
.indent-2 { padding-inline-start: 22px !important; }
.indent-3 { padding-inline-start: 40px !important; }
.indent-4 { padding-inline-start: 58px !important; }
.indent-5 { padding-inline-start: 76px !important; }

.status { display: inline-block; font-size: .78rem; padding: .15rem .65rem; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.status-Draft { background: var(--chip-muted); color: var(--muted); }
.status-Posted { background: var(--ok-soft); color: var(--ok); }
.status-Reversed, .status-Voided { background: var(--bad-soft); color: var(--bad); }

/* ---------- Dashboard ---------- */

.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi {
    --kpi: var(--primary); --kpi-soft: var(--primary-soft);
    display: flex; align-items: center; gap: .8rem; padding: 1rem 1.05rem; color: var(--ink); min-width: 0;
    background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--kpi); border-radius: var(--radius); box-shadow: var(--shadow);
    transition: box-shadow .2s, transform .2s;
}
a.kpi:hover { color: var(--ink); text-decoration: none; box-shadow: 0 10px 22px rgba(29, 79, 150, .12); transform: translateY(-2px); }
.kpi-ok { --kpi: var(--ok); --kpi-soft: var(--ok-soft); }
.kpi-warn { --kpi: var(--warn); --kpi-soft: var(--warn-soft); }
.kpi-bad { --kpi: var(--bad); --kpi-soft: var(--bad-soft); }
.kpi-icon { display: grid; place-items: center; width: 42px; height: 42px; flex-shrink: 0; border-radius: 12px; background: var(--kpi-soft); color: var(--kpi); }
.kpi-body { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.kpi .label { font-size: .84rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .value { font-size: 1.28rem; font-weight: 700; line-height: 1.25; }
@media (max-width: 1500px) { .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; } .kpi { flex-direction: column; align-items: flex-start; gap: .5rem; padding: .85rem; } .kpi .value { font-size: 1.1rem; } }

.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.quick-link {
    display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: .95rem .6rem; text-align: center; border-radius: 14px;
    background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-weight: 600; font-size: .87rem;
    transition: transform .15s, border-color .15s, box-shadow .15s;
}
.quick-link:hover { color: var(--ink); text-decoration: none; transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 10px 22px rgba(29, 79, 150, .1); }
.quick-link:hover .mega-icon { background: var(--primary); color: #fff; }

.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; align-items: stretch; }
.dash-grid .panel { margin: 0; min-width: 0; }
@media (max-width: 1160px) { .dash-grid { grid-template-columns: minmax(0, 1fr); } }

.mini-list { display: flex; flex-direction: column; margin: -.25rem -.55rem; }
.mini-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .55rem; border-radius: 9px; color: var(--ink); }
.mini-row + .mini-row { border-top: 1px solid var(--line); }
a.mini-row:hover { background: var(--row-hover); color: var(--ink); text-decoration: none; }
.mini-main { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.mini-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-main small { color: var(--muted); font-size: .8rem; }
.mini-empty { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 1.75rem .5rem; color: var(--muted); text-align: center; }
.mini-empty .nav-icon { width: 28px; height: 28px; color: var(--ok); }

.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg .bar-1 { fill: var(--series-1); }
.chart-svg .bar-2 { fill: var(--series-2); }
.chart-svg .grid { stroke: var(--grid); }
.chart-svg text { fill: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }
.legend .s1 { background: var(--series-1); }
.legend .s2 { background: var(--series-2); }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .82rem; box-shadow: 0 8px 20px rgba(13, 27, 56, .18); white-space: nowrap; }
.chart-hit:hover { fill: rgba(47, 123, 208, .07); }
details summary.muted { cursor: pointer; font-size: .85rem; }

/* ---------- Chart of accounts tree ---------- */

.search-box { position: relative; flex: 0 1 260px; min-width: 170px; }
.search-box .nav-icon { position: absolute; inset-inline-start: .6rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search-box input { padding-inline-start: 2rem; }

.tree-hint { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-bottom: .7rem; margin-bottom: .4rem; border-bottom: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.tree-hint b { font-weight: 600; flex-shrink: 0; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree ul { list-style: none; margin: 0; padding-inline-start: 20px; border-inline-start: 1px solid var(--line); margin-inline-start: 13px; }
.tree-row { display: flex; align-items: center; gap: .5rem; min-height: 38px; padding: .22rem .4rem; border-bottom: 1px solid var(--primary-softer); transition: background .12s; }
.tree-row:hover, .tree-row:focus-within { background: var(--row-hover); }
.tree-toggle { display: grid; place-items: center; width: 24px; height: 24px; flex: 0 0 24px; border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; border-radius: 6px; }
.tree-toggle:hover { background: var(--primary-soft); color: var(--primary); }
.tree-toggle.leaf { visibility: hidden; }
.tree-toggle .nav-chev { transition: transform .15s; opacity: 1; }
li.collapsed > .tree-row > .tree-toggle .nav-chev { transform: rotate(-90deg); }
[dir="rtl"] li.collapsed > .tree-row > .tree-toggle .nav-chev { transform: rotate(90deg); }
li.collapsed > ul { display: none; }
.tree-kind { display: inline-flex; color: var(--muted); }
.tree-kind .nav-icon { width: 17px; height: 17px; }
.tree-group > .tree-row > .tree-kind { color: var(--accent-dark); }
.tree-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-group > .tree-row .tree-name { font-weight: 600; }
.tree-row .code { color: var(--muted); font-size: .86rem; }
.tree > li > .tree-row { background: var(--primary-softer); margin-top: .35rem; border-radius: 8px; border-bottom: 0; }
.tree > li > .tree-row .tree-name { font-weight: 700; }
.tree > li > .tree-row:hover { background: var(--primary-soft); }
.tree-inactive .tree-name { text-decoration: line-through; color: var(--muted); }
.lvl { font-size: .7rem; font-weight: 700; padding: .05rem .4rem; border-radius: 6px; white-space: nowrap; background: var(--primary-soft); color: var(--primary-dark); }
.lvl-1 { background: var(--primary); color: #fff; }
.lvl-2 { background: #5a9be0; color: #fff; }
.lvl-3 { background: #a9cdf1; color: #173a70; }
.lvl-5 { background: var(--chip-muted); color: var(--muted); }
.tag { font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--warn-soft); color: var(--warn); white-space: nowrap; }
.tag-post { background: var(--ok-soft); color: var(--ok); }
.tree-actions { display: flex; gap: 4px; opacity: 0; margin-inline-start: auto; transition: opacity .12s; }
.tree-row:hover .tree-actions, .tree-row:focus-within .tree-actions { opacity: 1; }
.tree-actions .btn { --bs-btn-padding-y: .1rem; --bs-btn-padding-x: .45rem; --bs-btn-font-size: .76rem; background: var(--surface); }
.tree-balance { min-width: 110px; font-weight: 600; }
@media (hover: none) { .tree-actions { opacity: 1; } }
@media (max-width: 767.98px) {
    .tree-row { flex-wrap: wrap; }
    .tree-name { flex-basis: 55%; white-space: normal; }
    .tree-actions { margin-inline-start: 0; order: 5; flex-basis: 100%; flex-wrap: wrap; }
    .tree-balance { margin-inline-start: auto; min-width: 0; }
    .tree ul { padding-inline-start: 10px; margin-inline-start: 6px; }
}

/* ---------- Searchable select ---------- */

.combo { position: relative; }
.combo-list { position: absolute; z-index: 1060; inset-inline: 0; top: calc(100% + 2px); max-height: 240px; min-width: 260px; overflow-y: auto; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 14px 30px rgba(13, 27, 56, .2); display: none; padding: .25rem; }
.combo.open .combo-list { display: block; }
.combo-item { padding: .35rem .6rem; cursor: pointer; font-size: .9rem; border-radius: 6px; }
.combo-item.hi, .combo-item:hover { background: var(--primary-soft); }

/* ---------- Line editors ---------- */

.lines-table td { padding: .3rem !important; }
.lines-table input.form-control, .lines-table select.form-select { font-size: .9rem; padding: .3rem .5rem; }
.lines-table .amount { min-width: 96px; }
.totals { margin-inline-start: auto; max-width: 340px; }
.totals div { display: flex; justify-content: space-between; padding: .2rem 0; }
.totals .grand { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--ink); margin-top: .3rem; padding-top: .45rem; }
.diff-ok { color: var(--ok); font-weight: 600; }
.diff-bad { color: var(--bad); font-weight: 600; }

/* ---------- Sign-in ---------- */

.auth-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(160deg, var(--primary-softer), var(--primary-soft)); }
.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--page); }
.login-hero {
    position: relative; overflow: hidden; color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 3rem 3.5rem 2rem;
    background: radial-gradient(circle at 15% 15%, rgba(140, 200, 240, .35), transparent 45%), radial-gradient(circle at 85% 90%, rgba(79, 154, 216, .45), transparent 50%), linear-gradient(150deg, #1d4f96 0%, #2a3f6e 55%, #1a2440 100%);
}
:root[data-theme="dark"] .login-hero { background: radial-gradient(circle at 15% 15%, rgba(140, 200, 240, .18), transparent 45%), radial-gradient(circle at 85% 90%, rgba(79, 154, 216, .25), transparent 50%), linear-gradient(150deg, #13366a 0%, #172645 55%, #0b1428 100%); }
.login-hero::before, .login-hero::after { content: ""; position: absolute; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .10); }
.login-hero::before { width: 520px; height: 520px; top: -180px; left: -160px; }
.login-hero::after { width: 380px; height: 380px; bottom: -140px; right: -120px; }
.login-hero-inner { position: relative; z-index: 1; max-width: 460px; margin-inline: auto; width: 100%; }
.login-hero-logo { width: 104px; height: 104px; border-radius: 26px; background: #fff; display: grid; place-items: center; box-shadow: 0 18px 40px rgba(0, 0, 0, .25); margin-bottom: 1.4rem; }
.login-hero-logo img { width: 74px; height: auto; }
.login-hero h1 { margin: 0; font-size: 2.4rem; font-weight: 800; line-height: 1.2; color: #fff; }
.login-hero-tag { margin: .8rem 0 0; font-size: 1.05rem; line-height: 1.8; color: rgba(255, 255, 255, .85); }
.login-pulse { width: 100%; height: 56px; margin: 1.4rem 0 1.2rem; }
.login-pulse path { fill: none; stroke: #8cc8f0; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; stroke-dasharray: 700; stroke-dashoffset: 700; animation: login-pulse 3.6s ease-in-out infinite; filter: drop-shadow(0 0 6px rgba(140, 200, 240, .7)); }
@keyframes login-pulse { 0% { stroke-dashoffset: 700; } 55% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -700; } }
@media (prefers-reduced-motion: reduce) { .login-pulse path { animation: none; stroke-dasharray: none; stroke-dashoffset: 0; } .mega-panel, .user-panel, .lang-panel { animation: none; } }
.login-features { list-style: none; margin: 0; padding: 0; display: grid; gap: .65rem; }
.login-features li { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; border-radius: 12px; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .12); backdrop-filter: blur(4px); }
.login-features span { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: rgba(255, 255, 255, .14); flex: none; }
.login-hero-foot { position: relative; z-index: 1; margin-top: 2rem; text-align: center; color: rgba(255, 255, 255, .6); }
.login-panel { display: flex; flex-direction: column; padding: 1.25rem 1.5rem 2rem; }
.login-top { display: flex; justify-content: flex-end; align-items: center; gap: .5rem; }
.login-home { display: inline-flex; align-items: center; gap: .4rem; margin-inline-end: auto; color: var(--muted); font-weight: 600; }
.login-home:hover { color: var(--primary); text-decoration: none; }
.login-card { width: min(420px, 100%); margin: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 2.25rem 2rem 2rem; box-shadow: 0 24px 60px rgba(29, 79, 150, .12); }
:root[data-theme="dark"] .login-card { box-shadow: 0 24px 60px rgba(0, 0, 0, .45); }
.login-card h2 { margin: 0 0 .3rem; font-size: 1.6rem; font-weight: 700; }
.login-sub { margin: 0 0 1.4rem; }
.login-card .form-control { padding: .7rem .9rem; border-radius: 10px; }
.btn-login { padding: .75rem; font-size: 1.05rem; border-radius: 10px; margin-top: .4rem; background: linear-gradient(135deg, #2f7bd0, #1d4f96); border: 0; box-shadow: 0 10px 22px rgba(47, 123, 208, .3); }
.btn-login:hover { filter: brightness(1.08); background: linear-gradient(135deg, #2f7bd0, #1d4f96); }
@media (max-width: 900px) {
    .login-page { grid-template-columns: 1fr; grid-auto-rows: min-content; }
    .login-hero { padding: 1.5rem 1.25rem 1.25rem; }
    .login-hero-logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: .7rem; }
    .login-hero-logo img { width: 46px; }
    .login-hero h1 { font-size: 1.6rem; }
    .login-hero-tag { margin-top: .3rem; font-size: .92rem; }
    .login-features, .login-hero-foot { display: none; }
    .login-pulse { margin: .6rem 0 0; height: 36px; }
    .login-panel { padding: 1rem 1rem 2rem; }
    .login-card { margin: 1rem auto 0; padding: 1.6rem 1.25rem; }
}
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 2rem 1.75rem; box-shadow: 0 10px 30px rgba(29, 79, 150, .08); }

/* ---------- Printing ---------- */

.print-only { display: none; }

@media print {
    .appbar, .crumbs, .no-print, .filter-bar { display: none !important; }
    .print-only { display: block; }
    body, .panel { background: #fff; border: 0; box-shadow: none; }
    .content { padding: 0; max-width: none; }
    .panel { padding: 0; }
    .panel > .table-wrap { margin: 0; }
    .table thead th, .table tfoot td, .table tfoot th, .table .row-group td { background: none; }
    a { color: inherit; }
}
