:root {
    --sidebar-w: 260px;
    --sidebar-bg: #16213e;
    --sidebar-bg-dark: #101a31;
    --sidebar-text: #9aa5c0;
    --sidebar-text-active: #ffffff;
    --accent: #3b82f6;
    --accent-rgb: 59, 130, 246;
    --content-bg: #f1f5f9;
    --topbar-h: 62px;
    --radius: 0.75rem;
}

* { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }

body {
    background: var(--content-bg);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

/* ---------- Sidebar ---------- */
.app-sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-dark));
    color: var(--sidebar-text);
    position: fixed; inset: 0 auto 0 0; z-index: 1040;
    display: flex; flex-direction: column;
    transition: transform .2s ease;
}

.sidebar-brand {
    display: flex; align-items: center; gap: .75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-icon {
    width: 40px; height: 40px; border-radius: .6rem;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: #fff; display: grid; place-items: center; font-size: 1.25rem;
    box-shadow: 0 4px 12px rgba(var(--accent-rgb), .35);
}
.brand-name { font-weight: 700; color: #fff; line-height: 1.1; font-size: 1.05rem; }
.brand-name span { color: #60a5fa; }
.brand-sub { font-size: .7rem; color: #7c88a5; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .65rem 1rem; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #5b6b8c; padding: .85rem .6rem .3rem; }

/* ---------- Collapsible sidebar sections ---------- */
.nav-group-wrap:first-child .nav-section--toggle { padding-top: .35rem; }
.nav-section--toggle {
    display: flex; align-items: center; width: 100%;
    background: none; border: 0; text-align: left; cursor: pointer; font: inherit;
}
.nav-section--toggle .nav-caret {
    margin-left: auto; font-size: .62rem; opacity: .55; transition: transform .15s ease;
}
.nav-section--toggle:hover { color: #93a3c4; }
.nav-group-wrap.is-collapsed .nav-section--toggle .nav-caret { transform: rotate(-90deg); }
.nav-group-wrap.is-collapsed .nav-group { display: none; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: .65rem;
    padding: .55rem .75rem; border-radius: .55rem;
    color: var(--sidebar-text); font-size: .92rem;
    margin-bottom: 2px; position: relative; text-decoration: none;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-nav .nav-link:hover { color: #fff; background: rgba(255,255,255,.05); }
.sidebar-nav .nav-link.active {
    color: #fff; background: linear-gradient(135deg, rgba(var(--accent-rgb), .35), rgba(var(--accent-rgb), .15));
    box-shadow: inset 3px 0 0 #60a5fa;
}
.nav-badge {
    margin-left: auto; background: #ef4444; color: #fff;
    font-size: .68rem; font-weight: 700; border-radius: 10px; padding: 1px 7px;
}

/* ---------- Collapsible sidebar sub-menu ---------- */
.sidebar-nav .nav-link.nav-parent .nav-caret { font-size: .78rem; transition: transform .15s ease; }
.sidebar-nav .nav-link.nav-parent[aria-expanded="true"] .nav-caret { transform: rotate(180deg); }
.nav-subsection {
    font-size: .6rem; text-transform: uppercase; letter-spacing: .07em;
    color: #4a5878; padding: .55rem .6rem .2rem 1.2rem;
}
.sidebar-nav .nav-link.nav-child { padding-left: 1.2rem; font-size: .84rem; }
.sidebar-nav .nav-link.nav-child i { font-size: .95rem; }

.sidebar-footer { padding: .8rem 1.25rem; border-top: 1px solid rgba(255,255,255,.06); }

/* ---------- Main / topbar ---------- */
.app-main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.app-topbar {
    height: var(--topbar-h);
    background: #fff; border-bottom: 1px solid #e2e8f0;
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.5rem; position: sticky; top: 0; z-index: 1020;
}
.app-content { flex: 1; padding: 1.5rem 2rem; width: 100%; min-width: 0; }

.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff;
    display: inline-grid; place-items: center; font-size: .82rem; font-weight: 700;
}

/* ---------- Cards / stats ---------- */
.card { border: 1px solid #e5e9f0; border-radius: var(--radius); }
.card-header { background: transparent; border-bottom-color: #edf0f5; font-weight: 600; }
.stat-card { border: none; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04); position: relative; overflow: hidden; }
.stat-card .card-body { padding: 1.1rem 1.25rem; }
.stat-icon {
    width: 46px; height: 46px; border-radius: .7rem;
    display: grid; place-items: center; font-size: 1.3rem;
}
.stat-label { font-size: .8rem; color: #64748b; font-weight: 500; }
.stat-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; }
.stat-trend { font-size: .75rem; }

/* ---------- Tables ---------- */
.table { --bs-table-hover-bg: #f8fafc; font-size: .9rem; margin-bottom: 0; }
.table thead th {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
    color: #64748b; font-weight: 600; border-bottom-width: 1px; white-space: nowrap;
}
.table td { vertical-align: middle; }
.table .product-name { font-weight: 600; color: #0f172a; }

/* ---------- Badges ---------- */
.badge-status { font-size: .72rem; font-weight: 600; padding: .3em .65em; }

/* ---------- Buttons / forms ---------- */
.btn { border-radius: .5rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: #2563eb; border-color: #2563eb; }
.form-control:focus, .form-select:focus { border-color: rgba(var(--accent-rgb), .5); box-shadow: 0 0 0 .2rem rgba(var(--accent-rgb), .12); }
.form-label { font-size: .82rem; font-weight: 500; color: #334155; }
.input-group-text { background: #f8fafc; }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-header h4 { font-weight: 700; margin: 0; }
.page-header .text-muted { font-size: .85rem; }

/* ---------- Invoice editor rows ---------- */
.item-row .form-control, .item-row .form-select { font-size: .85rem; }

/* ---------- Guest auth ---------- */
.guest-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 10% 10%, #1e3a8a 0%, #0f172a 55%, #020617 100%); }
.guest-wrap { width: 100%; max-width: 460px; padding: 1rem; }
.guest-card { border-radius: 1rem; }
.guest-logo {
    width: 56px; height: 56px; border-radius: 1rem;
    background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff;
    display: grid; place-items: center; font-size: 1.6rem;
    box-shadow: 0 8px 24px rgba(var(--accent-rgb), .35);
}

/* ---------- Invoice show / print ---------- */
.invoice-sheet { background: #fff; border: 1px solid #e5e9f0; border-radius: .5rem; }
.invoice-sheet .inv-header { border-bottom: 2px solid #0f172a; padding-bottom: 1rem; }
.vat-box-total {
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: .6rem;
}
.amount-big { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }

/* ---------- Sidebar toggle (mobile) ---------- */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(2,6,23,.5); z-index: 1035; }
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
    .sidebar-backdrop.open { display: block; }
    .app-main { margin-left: 0; }
    .app-content { padding: 1rem; }
}

/* ---------- Print ---------- */
@media print {
    .app-topbar, .page-header .btn, .app-sidebar, .sidebar-backdrop, .no-print { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0; max-width: 100%; }
    .card { border: none; box-shadow: none; }
}

/* Invoice template picker */
.cursor-pointer { cursor: pointer; }
.template-card {
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: .75rem;
    padding: .65rem;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.template-card:hover { border-color: #94a3b8; }
.template-card.selected { border-color: #4f46e5; box-shadow: 0 0 0 1px #4f46e5; }

.template-block.selected { box-shadow: 0 0 0 1px #4f46e5 inset; }

/* Mini invoice thumbnail */
.template-preview {
    height: 110px;
    border: 1px solid #e2e8f0;
    border-radius: .5rem;
    background: #fff;
    position: relative;
    overflow: hidden;
}
.template-preview::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 14px;
    background: #94a3b8;
}
.template-preview.classic::before { background: #16213e; }
.template-preview.modern::before { background: #4f46e5; }
.template-preview.minimal::before { background: #111827; }
.template-preview.executive::before { background: #0f766e; }
.template-preview::after {
    content: '';
    position: absolute;
    left: 10px; right: 10px; top: 22px;
    height: 3px;
    border-radius: 2px;
    background: #eef2f7;
    box-shadow: 0 9px 0 #f4f7fa, 0 18px 0 #f4f7fa, 0 27px 0 #f4f7fa, 0 36px 0 #f4f7fa, 0 45px 0 #f4f7fa, 0 54px 0 #f4f7fa;
}
.template-preview.modern::after {
    background: #eef2ff;
    box-shadow: 0 9px 0 #f8faff, 0 18px 0 #f8faff, 0 27px 0 #f8faff, 0 36px 0 #f8faff, 0 45px 0 #f8faff, 0 54px 0 #f8faff;
}
.template-preview.minimal::after {
    border-top: 1px solid #e5e7eb;
    background: transparent;
    box-shadow: 0 9px 0 #f3f4f6, 0 18px 0 #f3f4f6, 0 27px 0 #f3f4f6, 0 36px 0 #f3f4f6, 0 45px 0 #f3f4f6, 0 54px 0 #f3f4f6;
}

/* ---------- Full-bleed editor pages ---------- */
.app-content--wide { max-width: none; padding: 0; }
.app-content--wide > .alert { margin: 1rem 2rem -0.25rem; }

/* ---------- Invoice editor (create / edit) ---------- */
.inv-editor {
    --rail-w: 380px;
    display: flex; flex-direction: column;
    min-height: calc(100vh - var(--topbar-h));
    background: #f4f6fa;
}
.inv-editor.is-submitting { opacity: .65; pointer-events: none; }

.inv-hero {
    background: #fff; border-bottom: 1px solid #e5e9f0;
    padding: 1.15rem 2rem;
    display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.inv-hero__eyebrow { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); font-weight: 800; }
.inv-hero h1 { font-size: 1.55rem; font-weight: 800; letter-spacing: -.025em; margin: .2rem 0 0; color: #0f172a; }
.inv-hero p { margin: .25rem 0 0; color: #64748b; font-size: .88rem; }

.inv-editor__grid {
    flex: 1;
    display: grid; grid-template-columns: minmax(0, 1fr) var(--rail-w);
    gap: 1.5rem; align-items: start;
    padding: 1.5rem 2rem 6.5rem;
}
.inv-editor__main { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }
.inv-editor__side { position: sticky; top: calc(var(--topbar-h) + 1.25rem); display: flex; flex-direction: column; gap: 1.25rem; }

.inv-panel {
    background: #fff; border: 1px solid #e7ebf2; border-radius: 1rem;
    box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 20px 40px -32px rgba(15,23,42,.35);
    overflow: hidden;
}
.inv-panel__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem .75rem; padding: .95rem 1.25rem; border-bottom: 1px solid #eef1f6; flex-wrap: wrap; }
.inv-panel__title { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: .96rem; color: #0f172a; }
.inv-panel__title .step {
    display: inline-grid; place-items: center; width: 27px; height: 27px; border-radius: 9px;
    background: linear-gradient(135deg, rgba(var(--accent-rgb),.18), rgba(var(--accent-rgb),.07));
    color: var(--accent); font-weight: 800; font-size: .78rem;
}
.inv-panel__body { padding: 1.25rem; }
.inv-panel__body .form-control, .inv-panel__body .form-select { border-radius: .6rem; border-color: #e2e8f0; }

/* payment type toggles */
.inv-flag-field { display: flex; gap: .6rem; }
.inv-flag { flex: 1; position: relative; }
.inv-flag input { position: absolute; opacity: 0; pointer-events: none; }
.inv-flag label {
    display: flex; flex-direction: column; align-items: center; gap: .3rem;
    padding: .75rem .5rem; border: 1.5px solid #e5e9f0; border-radius: .8rem;
    font-weight: 600; font-size: .84rem; color: #475569; cursor: pointer; transition: .15s;
    background: #f8fafc; text-align: center;
}
.inv-flag label i { font-size: 1.2rem; }
.inv-flag input:checked + label { border-color: var(--accent); background: rgba(var(--accent-rgb),.08); color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.inv-flag input:disabled + label { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* items grid */
.inv-items-table { margin: 0; }
.inv-items-table thead th {
    background: #f8fafc; color: #64748b; font-size: .68rem; text-transform: uppercase;
    letter-spacing: .05em; font-weight: 700; border-bottom: 1.5px solid #e5e9f0; padding: .55rem .5rem;
}
.inv-items-table tbody td { padding: .5rem; vertical-align: middle; border-bottom: 1px solid #f1f4f9; }
.inv-items-table tbody tr:last-child td { border-bottom: 0; }
.inv-items-table .form-control, .inv-items-table .form-select { font-size: .86rem; border-radius: .55rem; border-color: #e2e8f0; }
.inv-items-table .item-amount { font-variant-numeric: tabular-nums; font-weight: 700; }
.inv-items-table .item-remove-btn {
    border: 0; background: transparent; color: #cbd5e1; width: 32px; height: 32px;
    border-radius: 8px; display: inline-grid; place-items: center; transition: .15s;
}
.inv-items-table .item-remove-btn:hover { background: #fee2e2; color: #ef4444; }
.inv-items-hint { display: flex; align-items: center; gap: .4rem; padding: .8rem 1.25rem; border-top: 1px solid #eef1f6; color: #64748b; font-size: .82rem; background: #fbfcfe; }

/* summary rail */
.inv-summary { background: linear-gradient(165deg, #fff, #f7f9fc); }
.inv-summary__row { display: flex; justify-content: space-between; padding: .4rem 0; color: #475569; font-size: .9rem; }
.inv-summary__row span:last-child { font-weight: 600; color: #0f172a; font-variant-numeric: tabular-nums; }
.inv-summary__grand { display: flex; justify-content: space-between; align-items: baseline; margin-top: .55rem; padding-top: .9rem; border-top: 1px dashed #cbd5e1; }
.inv-summary__grand .label { font-weight: 700; color: #0f172a; }
.inv-summary__grand .amount { font-size: 1.75rem; font-weight: 800; letter-spacing: -.025em; color: var(--accent); font-variant-numeric: tabular-nums; }
.inv-ccy { font-size: .9rem; font-weight: 700; color: #94a3b8; margin-right: .15rem; }

/* sticky action bar */
.inv-actionbar {
    position: sticky; bottom: 0; z-index: 15; margin-top: auto;
    background: rgba(255,255,255,.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid #e5e9f0;
    padding: .8rem 2rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.inv-actionbar__total { font-size: .82rem; color: #64748b; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.inv-actionbar__total strong { display: block; font-size: 1.35rem; color: #0f172a; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.inv-actionbar__btns { display: flex; gap: .55rem; flex-wrap: wrap; }
.inv-actionbar .btn { border-radius: .6rem; font-weight: 600; padding: .55rem 1.15rem; }
.inv-actionbar .btn-primary { box-shadow: 0 8px 20px -8px rgba(var(--accent-rgb), .6); }

@media (max-width: 1100px) {
    .inv-editor__grid { grid-template-columns: 1fr; padding: 1.25rem 1.25rem 9rem; }
    .inv-editor__side { position: static; }
    .inv-hero { padding-left: 1.25rem; padding-right: 1.25rem; }
    .app-content--wide > .alert { margin-left: 1.25rem; margin-right: 1.25rem; }

    .inv-actionbar { display: block; padding: .8rem 1.25rem; }
    .inv-actionbar__total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .6rem; }
    .inv-actionbar__total strong { display: inline; font-size: 1.15rem; }
    .inv-actionbar__btns { display: flex; flex-wrap: wrap-reverse; gap: .5rem; }
    .inv-actionbar__btns .btn { flex: 1 1 calc(50% - .3rem); }
    .inv-actionbar__btns .btn:last-child { flex-basis: 100%; }
}

/* ---------- Tom Select (searchable customer + product dropdowns) ---------- */
.ts-wrapper.form-select { padding: 0; height: auto; background-image: none; }
.ts-wrapper .ts-control {
    border: 1px solid #dce1ea;
    border-radius: var(--radius);
    min-height: 38px;
}
.ts-wrapper.focus .ts-control {
    border-color: rgba(var(--accent-rgb), .55);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .14);
}
.ts-dropdown {
    border-color: #dce1ea;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .10);
    min-width: 220px;
}
.ts-dropdown .active { background: rgba(var(--accent-rgb), .12); color: inherit; }
.ts-dropdown .option { white-space: nowrap; }

/* compact variant inside the invoice item grid */
.inv-items-table td:first-child { min-width: 240px; }
.inv-items-table .ts-wrapper { min-width: 220px; }
.inv-items-table .ts-control { min-height: 34px; }

/* Wide Product + Description, narrow Qty + Rate */
.inv-items-table th:nth-child(1), .inv-items-table td:nth-child(1) { min-width: 240px; }
.inv-items-table th:nth-child(2), .inv-items-table td:nth-child(2) { min-width: 340px; }
.inv-items-table th:nth-child(3), .inv-items-table td:nth-child(3) { width: 64px; min-width: 64px; }
.inv-items-table th:nth-child(4), .inv-items-table td:nth-child(4) { width: 92px; min-width: 92px; }
.inv-items-table .item-qty { width: 56px; min-width: 56px; padding-left: .4rem; padding-right: .4rem; }
.inv-items-table .item-rate { width: 84px; min-width: 84px; padding-left: .4rem; padding-right: .4rem; }
.inv-items-table .item-description { min-width: 320px; }

/* ---------- Listing pages (KPIs + filter pills + data table) ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.kpi {
    background: #fff; border: 1px solid #e7ebf2; border-radius: 1rem;
    padding: 1.05rem 1.2rem; box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 16px 34px -30px rgba(15,23,42,.3);
}
.kpi__top { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.kpi__label { font-size: .78rem; color: #64748b; font-weight: 600; }
.kpi__ico { width: 34px; height: 34px; border-radius: .6rem; display: grid; place-items: center; font-size: 1rem; flex: none; }
.kpi__value { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; margin-top: .45rem; color: #0f172a; font-variant-numeric: tabular-nums; }
.kpi__sub { font-size: .75rem; color: #94a3b8; margin-top: .1rem; }
@media (max-width: 900px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .kpi-row { grid-template-columns: 1fr; } }

.filter-pills { display: flex; flex-wrap: wrap; gap: .4rem; }
.filter-pill {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .38rem .8rem; border-radius: 999px; font-size: .82rem; font-weight: 600;
    color: #475569; background: #f1f5f9; border: 1px solid transparent; text-decoration: none; transition: .12s;
}
.filter-pill:hover { background: #e2e8f0; color: #0f172a; }
.filter-pill.is-active { background: var(--accent); color: #fff; box-shadow: 0 6px 16px -8px rgba(var(--accent-rgb), .7); }
.filter-pill .n { font-size: .7rem; line-height: 1; background: rgba(15,23,42,.09); padding: .18rem .4rem; border-radius: 999px; }
.filter-pill.is-active .n { background: rgba(255,255,255,.25); }

.adv-filters {
    background: #f8fafc; border: 1px solid #eef1f6; border-radius: .8rem;
    padding: 1rem; margin-bottom: .85rem;
}
.adv-filters__grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; }
.adv-filters label { font-size: .75rem; font-weight: 600; color: #64748b; margin-bottom: .15rem; display: block; }
.adv-filters .form-control, .adv-filters .form-select { font-size: .86rem; }
@media (max-width: 992px) { .adv-filters__grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .adv-filters__grid { grid-template-columns: 1fr; } }

.filter-summary {
    display: flex; flex-wrap: wrap; gap: .35rem .9rem; align-items: baseline;
    font-size: .82rem; color: #64748b; margin-bottom: .6rem;
    padding: .5rem .75rem; background: rgba(var(--accent-rgb), .06); border-radius: .55rem;
}
.filter-summary strong { color: #0f172a; font-variant-numeric: tabular-nums; }

.data-table { margin: 0; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table th, .data-table td { padding-top: .7rem; padding-bottom: .7rem; white-space: nowrap; }
.data-table .cell-amt { font-variant-numeric: tabular-nums; }
.cust-avatar {
    width: 34px; height: 34px; border-radius: 10px; flex: none;
    display: inline-grid; place-items: center; font-weight: 700; font-size: .8rem;
    background: linear-gradient(135deg, #e0e7ff, #eef2ff); color: #4f46e5;
}

/* ==================== Dashboard v2 ==================== */
.dash-hero {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
    flex-wrap: wrap; margin-bottom: 1.4rem;
}
.dash-hero__greeting { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; color: #0f172a; margin: 0; }
.dash-hero__greeting .wave { display: inline-block; animation: wave 2.2s ease-in-out 1; transform-origin: 70% 70%; }
@keyframes wave { 0%,60%,100%{transform:rotate(0)} 15%{transform:rotate(16deg)} 30%{transform:rotate(-8deg)} 45%{transform:rotate(12deg)} }
.dash-hero__sub { color: #64748b; font-size: .9rem; margin-top: .2rem; }
.dash-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.dash-actions .btn { border-radius: .65rem; font-weight: 600; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.1rem; }
@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-tile {
    position: relative; overflow: hidden;
    background: #fff; border: 1px solid #e8ecf3; border-radius: 1rem;
    padding: 1.05rem 1.15rem 0;
    box-shadow: 0 1px 2px rgba(15,23,42,.04);
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
    display: flex; flex-direction: column;
}
.kpi-tile:hover { transform: translateY(-3px); box-shadow: 0 14px 32px -12px rgba(15,23,42,.18); border-color: #dbe2ee; }
.kpi-tile::before {
    content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
    background: var(--kpi-accent, var(--accent));
}
.kpi-tile__top { display: flex; align-items: center; gap: .6rem; }
.kpi-tile__icon {
    width: 38px; height: 38px; border-radius: .7rem; flex: none;
    display: grid; place-items: center; font-size: 1.05rem;
    color: var(--kpi-accent, var(--accent));
    background: #eef4ff;
    background: color-mix(in srgb, var(--kpi-accent, var(--accent)) 12%, #fff);
}
.kpi-tile__label { font-size: .78rem; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: .04em; }
.kpi-tile__value { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; color: #0f172a; margin: .55rem 0 .15rem; font-variant-numeric: tabular-nums; }
.kpi-tile__value .ccy { font-size: .8rem; font-weight: 600; color: #94a3b8; margin-right: .25rem; }
.kpi-tile__meta { font-size: .78rem; color: #64748b; min-height: 1.1rem; margin-bottom: .8rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.kpi-delta { display: inline-flex; align-items: center; gap: .2rem; font-weight: 700; font-size: .74rem; padding: .1rem .4rem; border-radius: .5rem; }
.kpi-delta.up { color: #047857; background: #d1fae5; }
.kpi-delta.down { color: #b91c1c; background: #fee2e2; }
.kpi-delta.flat { color: #475569; background: #eef2f7; }
.kpi-tile__spark { height: 42px; margin: 0 -1.15rem; }
.kpi-tile__spark canvas { display: block; }

.dash-card { border: 1px solid #e8ecf3; border-radius: 1rem; box-shadow: 0 1px 2px rgba(15,23,42,.04); background: #fff; }
.dash-card > .card-header {
    background: transparent; border-bottom: 1px solid #eef1f6;
    font-weight: 700; font-size: .95rem; padding: .95rem 1.15rem;
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
}
.dash-card > .card-header .hdr-link { font-size: .8rem; font-weight: 600; text-decoration: none; }
.dash-card > .card-body { padding: 1.1rem 1.15rem; }

.chart-legend { display: flex; gap: 1rem; font-size: .78rem; color: #64748b; }
.chart-legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: .35rem; vertical-align: middle; }

/* aging */
.aging-total { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; color: #0f172a; }
.aging-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: #f1f5f9; margin: .7rem 0 1rem; }
.aging-bar span { display: block; }
.aging-legend { display: flex; flex-direction: column; gap: .55rem; }
.aging-legend__row { display: flex; align-items: center; gap: .6rem; font-size: .84rem; }
.aging-legend__row .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.aging-legend__row .amt { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; color: #0f172a; }
.aging-legend__row .lbl { color: #64748b; }

/* clean lists */
.dash-list { list-style: none; margin: 0; padding: 0; }
.dash-list li { display: flex; align-items: center; gap: .75rem; padding: .7rem 1.15rem; border-top: 1px solid #f1f4f9; }
.dash-list li:first-child { border-top: 0; }
.dash-list .di-ic {
    width: 34px; height: 34px; border-radius: .6rem; flex: none;
    display: grid; place-items: center; font-size: .95rem;
    background: #eef2ff; color: #4f46e5;
}
.dash-list .di-ic.green { background: #dcfce7; color: #16a34a; }
.dash-list .di-main { min-width: 0; flex: 1; }
.dash-list .di-title { font-weight: 600; color: #0f172a; font-size: .88rem; }
.dash-list .di-sub { font-size: .76rem; color: #94a3b8; }
.dash-list .di-amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.debtor-row { display: flex; align-items: center; gap: .7rem; padding: .55rem 0; }
.debtor-row + .debtor-row { border-top: 1px solid #f1f4f9; }
.debtor-row .amt { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: .5rem; }
.debtor-row .min-w-0 { min-width: 0; }
.debtor-bar { height: 5px; border-radius: 3px; background: #e2e8f0; margin-top: .3rem; overflow: hidden; }
.debtor-bar span { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #3b82f6); }

.empty-state { text-align: center; color: #94a3b8; padding: 2rem 1rem; }
.empty-state i { font-size: 1.8rem; display: block; margin-bottom: .4rem; }

@media (prefers-reduced-motion: reduce) {
    .kpi-tile, .dash-hero__greeting .wave { transition: none; animation: none; }
}

/* ==================== Toasts ==================== */
.toast-stack {
    position: fixed; bottom: 5.25rem; right: 1.25rem;
    z-index: 1090; display: flex; flex-direction: column-reverse; gap: .6rem;
    max-width: min(380px, calc(100vw - 2rem)); pointer-events: none;
}
.toast-stack .toast { pointer-events: auto; }
.app-toast {
    border: 1px solid #e2e8f0; border-left: 4px solid #94a3b8;
    border-radius: .7rem; box-shadow: 0 12px 32px -12px rgba(15,23,42,.35);
    background: #fff;
}
.app-toast .toast-body { display: flex; align-items: flex-start; gap: .6rem; font-size: .88rem; color: #1e293b; }
.app-toast .toast-body > .bi { font-size: 1.05rem; line-height: 1.35; flex: none; }
.app-toast .btn-close { font-size: .7rem; margin-top: .15rem; }
.app-toast.toast--success { border-left-color: #16a34a; }
.app-toast.toast--success .toast-body > .bi { color: #16a34a; }
.app-toast.toast--error   { border-left-color: #dc2626; }
.app-toast.toast--error   .toast-body > .bi { color: #dc2626; }
.app-toast.toast--warning { border-left-color: #d97706; }
.app-toast.toast--warning .toast-body > .bi { color: #d97706; }
.app-toast.toast--info    { border-left-color: #2563eb; }
.app-toast.toast--info    .toast-body > .bi { color: #2563eb; }
@media (max-width: 575.98px) {
    .toast-stack { left: 1rem; right: 1rem; bottom: 1rem; max-width: none; }
}

/* ==================== AI Assistant — floating widget ==================== */
/* The FAB is draggable: `left`/`top` are set inline by assistant-widget.js and
   persisted per browser. `right`/`bottom` here are only the first-run position. */
.aw { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 1095; touch-action: none; }
.aw.aw--moved { right: auto; bottom: auto; }
.aw-fab {
    width: 56px; height: 56px; border-radius: 50%; border: none;
    background: var(--accent); color: #fff; font-size: 1.4rem;
    box-shadow: 0 10px 28px -6px rgba(var(--accent-rgb), .6);
    display: grid; place-items: center; cursor: grab; transition: transform .15s ease;
    margin-left: auto; touch-action: none;
}
.aw-fab:hover { transform: translateY(-2px); }
.aw-fab:active { cursor: grabbing; }
.aw.is-dragging .aw-fab { transform: scale(1.06); transition: none; }
.aw-fab__close { display: none; }
.aw.is-open .aw-fab__open { display: none; }
.aw.is-open .aw-fab__close { display: block; }

.aw-panel {
    /* position (left/top) is computed from the FAB by assistant-widget.js each
       time it opens, then clamped on screen. */
    position: fixed; right: 1.25rem; bottom: 68px;
    width: min(370px, calc(100vw - 2.5rem)); height: min(520px, calc(100vh - 8rem));
    background: #fff; border: 1px solid #e2e8f0; border-radius: 1rem;
    box-shadow: 0 24px 60px -12px rgba(15, 23, 42, .35);
    display: flex; flex-direction: column; overflow: hidden;
}
.aw-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem .9rem; border-bottom: 1px solid #eef1f6; font-weight: 600; font-size: .9rem;
    background: #f8fafc;
}
.aw-head__actions { display: flex; gap: .8rem; }
.aw-head__actions a { color: #94a3b8; text-decoration: none; font-size: .95rem; }
.aw-head__actions a:hover { color: #475569; }

.aw-thread { flex: 1; overflow-y: auto; padding: .85rem; display: flex; flex-direction: column; gap: .6rem; }
.aw-hint { margin: auto; text-align: center; color: #94a3b8; font-size: .82rem; padding: 1rem; }
.aw-msg { display: flex; }
.aw-msg.is-user { justify-content: flex-end; }
.aw-bubble { max-width: 84%; padding: .5rem .75rem; border-radius: .8rem; font-size: .87rem; line-height: 1.5; }
.aw-bubble code { background: rgba(15,23,42,.08); padding: .05rem .3rem; border-radius: .3rem; font-size: .85em; }
.aw-msg.is-user .aw-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: .25rem; }
.aw-msg.is-bot .aw-bubble { background: #f1f5f9; color: #1e293b; border-bottom-left-radius: .25rem; }
.aw-bubble--error { background: #fef2f2 !important; color: #b91c1c !important; }
.aw-lookup { font-size: .72rem; color: #94a3b8; display: flex; align-items: center; gap: .3rem; }
.aw-action { border: 1px solid #e2e8f0; border-radius: .7rem; overflow: hidden; font-size: .84rem; }
.aw-action__b { padding: .55rem .7rem; color: #334155; }
.aw-action__btns { display: flex; gap: .4rem; padding: 0 .7rem .6rem; }
.aw-action.is-pending { border-color: #fde68a; }
.aw-action.is-pending .aw-action__b { background: #fffbeb; }
.aw-action.is-done .aw-action__b { background: #f0fdf4; color: #15803d; }
.aw-action.is-failed .aw-action__b { background: #fef2f2; }
.aw-typing { display: inline-flex; gap: 4px; }
.aw-typing span { width: 5px; height: 5px; border-radius: 50%; background: #94a3b8; animation: asstBlink 1.2s infinite ease-in-out; }
.aw-typing span:nth-child(2) { animation-delay: .2s; }
.aw-typing span:nth-child(3) { animation-delay: .4s; }

.aw-composer { display: flex; gap: .4rem; align-items: flex-end; padding: .6rem; border-top: 1px solid #eef1f6; }
.aw-composer textarea {
    flex: 1; resize: none; border: 1px solid #dce1ea; border-radius: .6rem;
    padding: .45rem .6rem; font: inherit; font-size: .87rem; max-height: 120px; outline: none;
}
.aw-composer textarea:focus { border-color: rgba(var(--accent-rgb), .5); }
.aw-composer .btn { border-radius: .6rem; }

@media print { .aw { display: none; } }

:root[data-bs-theme="dark"] .aw-panel { background: var(--surface); border-color: var(--border-soft); }
:root[data-bs-theme="dark"] .aw-head { background: var(--surface-2); border-bottom-color: var(--border-soft); }
:root[data-bs-theme="dark"] .aw-msg.is-bot .aw-bubble { background: var(--surface-3); color: var(--body-text); }
:root[data-bs-theme="dark"] .aw-bubble--error { background: rgba(185,28,28,.16) !important; color: #fca5a5 !important; }
:root[data-bs-theme="dark"] .aw-action { border-color: var(--border-soft); }
:root[data-bs-theme="dark"] .aw-action__b { color: var(--body-text); }
:root[data-bs-theme="dark"] .aw-action.is-pending .aw-action__b { background: rgba(180,120,10,.15); }
:root[data-bs-theme="dark"] .aw-action.is-done .aw-action__b { background: rgba(21,128,61,.16); }
:root[data-bs-theme="dark"] .aw-composer { border-top-color: var(--border-soft); }
:root[data-bs-theme="dark"] .aw-composer textarea { background: var(--surface-2); border-color: var(--border-soft); color: var(--heading); }

/* ==================== AI Assistant ==================== */
.asst { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - var(--topbar-h)); }
.asst-rail { border-right: 1px solid #e5e9f0; padding: 1rem .75rem; background: #fbfcfe; display: flex; flex-direction: column; }
.asst-convos { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.asst-convo { display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem; border-radius: .5rem; color: #475569; text-decoration: none; font-size: .86rem; white-space: nowrap; overflow: hidden; }
.asst-convo span { overflow: hidden; text-overflow: ellipsis; }
.asst-convo:hover { background: #eef2f7; color: #0f172a; }
.asst-convo.is-active { background: rgba(var(--accent-rgb), .12); color: var(--accent); font-weight: 600; }

.asst-main { display: flex; flex-direction: column; min-width: 0; }
.asst-thread { flex: 1; overflow-y: auto; padding: 1.5rem 1.25rem; display: flex; flex-direction: column; gap: .85rem; }
.asst-hint, .asst-empty { margin: auto; text-align: center; color: #94a3b8; }
.asst-empty i { font-size: 2.2rem; display: block; margin-bottom: .5rem; }
.asst-empty { padding: 3rem 1rem; }

.asst-msg { display: flex; }
.asst-msg.is-user { justify-content: flex-end; }
.asst-bubble { max-width: 680px; padding: .7rem .95rem; border-radius: .9rem; font-size: .92rem; line-height: 1.55; }
.asst-bubble p { margin: 0 0 .5rem; }
.asst-bubble p:last-child { margin-bottom: 0; }
.asst-bubble code { background: rgba(15,23,42,.08); padding: .05rem .3rem; border-radius: .3rem; font-size: .85em; }
.asst-msg.is-user .asst-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: .3rem; }
.asst-msg.is-user .asst-bubble code { background: rgba(255,255,255,.2); }
.asst-msg.is-bot .asst-bubble { background: #f1f5f9; color: #1e293b; border-bottom-left-radius: .3rem; }

.asst-lookup { align-self: flex-start; font-size: .76rem; color: #94a3b8; display: flex; align-items: center; gap: .35rem; padding-left: .3rem; }

.asst-action { align-self: flex-start; max-width: 520px; border: 1px solid #e2e8f0; border-radius: .8rem; overflow: hidden; background: #fff; }
.asst-action__head { display: flex; align-items: center; gap: .5rem; padding: .6rem .85rem; font-weight: 600; font-size: .85rem; background: #f8fafc; border-bottom: 1px solid #eef1f6; }
.asst-action__body { padding: .7rem .85rem; font-size: .88rem; color: #334155; }
.asst-action__btns { display: flex; gap: .5rem; padding: 0 .85rem .8rem; }
.asst-action.is-pending .asst-action__head { color: #b45309; background: #fffbeb; border-bottom-color: #fef3c7; }
.asst-action.is-done .asst-action__head { color: #15803d; background: #f0fdf4; border-bottom-color: #dcfce7; }
.asst-action.is-failed .asst-action__head { color: #b91c1c; background: #fef2f2; border-bottom-color: #fee2e2; }

.asst-typing { display: inline-flex; gap: 4px; padding: .8rem 1rem; }
.asst-typing span { width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; animation: asstBlink 1.2s infinite ease-in-out; }
.asst-typing span:nth-child(2) { animation-delay: .2s; }
.asst-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes asstBlink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.asst-composer { display: flex; gap: .5rem; align-items: flex-end; padding: .8rem 1.25rem; border-top: 1px solid #e5e9f0; }
.asst-composer textarea { flex: 1; resize: none; border: 1px solid #dce1ea; border-radius: .7rem; padding: .6rem .8rem; font: inherit; font-size: .92rem; max-height: 160px; outline: none; }
.asst-composer textarea:focus { border-color: rgba(var(--accent-rgb), .5); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .12); }
.asst-composer .btn { border-radius: .7rem; padding: .55rem .9rem; }
.asst-foot { display: flex; gap: 1rem; flex-wrap: wrap; padding: 0 1.25rem .7rem; font-size: .74rem; color: #94a3b8; }

@media (max-width: 767.98px) {
    .asst { grid-template-columns: 1fr; }
    .asst-rail { display: none; }
}

:root[data-bs-theme="dark"] .asst-rail { background: var(--surface-2); border-right-color: var(--border-soft); }
:root[data-bs-theme="dark"] .asst-convo:hover { background: var(--surface-3); color: var(--heading); }
:root[data-bs-theme="dark"] .asst-thread { }
.asst-bubble--error { background: #fef2f2 !important; color: #b91c1c !important; border: 1px solid #fee2e2; }

:root[data-bs-theme="dark"] .asst-msg.is-bot .asst-bubble { background: var(--surface-3); color: var(--body-text); }
:root[data-bs-theme="dark"] .asst-bubble--error { background: rgba(185,28,28,.15) !important; color: #fca5a5 !important; border-color: rgba(185,28,28,.3); }
:root[data-bs-theme="dark"] .asst-action { background: var(--surface); border-color: var(--border-soft); }
:root[data-bs-theme="dark"] .asst-action__head { background: var(--surface-2); border-bottom-color: var(--border-soft); }
:root[data-bs-theme="dark"] .asst-action__body { color: var(--body-text); }
:root[data-bs-theme="dark"] .asst-action.is-pending .asst-action__head { background: rgba(180,120,10,.15); }
:root[data-bs-theme="dark"] .asst-action.is-done .asst-action__head { background: rgba(21,128,61,.16); }
:root[data-bs-theme="dark"] .asst-action.is-failed .asst-action__head { background: rgba(185,28,28,.16); }
:root[data-bs-theme="dark"] .asst-composer { border-top-color: var(--border-soft); }
:root[data-bs-theme="dark"] .asst-composer textarea { background: var(--surface-2); border-color: var(--border-soft); color: var(--heading); }

/* ==================== Command palette (Ctrl-K search) ==================== */
.cmdk-trigger {
    display: inline-flex; align-items: center; gap: .5rem;
    height: 36px; padding: 0 .7rem; border-radius: .55rem;
    border: 1px solid #e2e8f0; background: #f8fafc; color: #64748b;
    font-size: .85rem; max-width: 260px; width: 100%;
}
.cmdk-trigger:hover { border-color: #cbd5e1; color: #475569; }
.cmdk-trigger kbd {
    margin-left: auto; font-size: .68rem; background: #fff; border: 1px solid #e2e8f0;
    border-radius: .3rem; padding: .1rem .35rem; color: #94a3b8;
}
@media (max-width: 575.98px) { .cmdk-trigger { width: auto; max-width: none; } }

.cmdk-overlay {
    position: fixed; inset: 0; z-index: 1085;
    background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 12vh 1rem 1rem;
}
.cmdk-panel {
    width: 100%; max-width: 560px; background: #fff;
    border: 1px solid #e2e8f0; border-radius: .85rem;
    box-shadow: 0 24px 60px -12px rgba(15, 23, 42, .4);
    overflow: hidden; display: flex; flex-direction: column; max-height: 66vh;
}
.cmdk-input { display: flex; align-items: center; gap: .6rem; padding: .85rem 1rem; border-bottom: 1px solid #eef1f6; }
.cmdk-input > .bi { color: #94a3b8; font-size: 1.05rem; }
.cmdk-input input { flex: 1; border: 0; outline: 0; font-size: .98rem; background: transparent; color: #0f172a; }
.cmdk-input kbd { font-size: .68rem; background: #f1f5f9; border-radius: .3rem; padding: .12rem .4rem; color: #94a3b8; }
.cmdk-results { overflow-y: auto; padding: .35rem; }
.cmdk-hint { padding: 1.4rem 1rem; text-align: center; color: #94a3b8; font-size: .85rem; }
.cmdk-group-label {
    display: flex; align-items: center; gap: .45rem;
    font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
    color: #94a3b8; padding: .6rem .75rem .3rem;
}
.cmdk-item {
    display: flex; align-items: baseline; gap: .6rem;
    padding: .5rem .75rem; border-radius: .5rem; text-decoration: none; color: #1e293b;
}
.cmdk-item.is-active { background: rgba(var(--accent-rgb), .12); }
.cmdk-item__title { font-weight: 600; font-size: .9rem; white-space: nowrap; }
.cmdk-item__sub { color: #64748b; font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item__meta { margin-left: auto; color: #94a3b8; font-size: .8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

:root[data-bs-theme="dark"] .cmdk-trigger { background: var(--surface-2); border-color: var(--border-soft); color: var(--muted-text); }
:root[data-bs-theme="dark"] .cmdk-trigger kbd { background: var(--surface-3); border-color: var(--border-soft); }
:root[data-bs-theme="dark"] .cmdk-panel { background: var(--surface); border-color: var(--border-soft); }
:root[data-bs-theme="dark"] .cmdk-input { border-bottom-color: var(--border-soft); }
:root[data-bs-theme="dark"] .cmdk-input input { color: var(--heading); }
:root[data-bs-theme="dark"] .cmdk-input kbd { background: var(--surface-3); }
:root[data-bs-theme="dark"] .cmdk-item { color: var(--body-text); }

/* ==================== Bulk action bar (list pages) ==================== */
.bulk-cell { width: 34px; text-align: center; }
.bulk-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    background: rgba(var(--accent-rgb), .08);
    border: 1px solid rgba(var(--accent-rgb), .25);
    border-radius: .6rem; padding: .5rem .85rem; margin-bottom: .75rem;
}
.bulk-bar__count { font-size: .85rem; color: #334155; }
.bulk-bar__count strong { font-variant-numeric: tabular-nums; }
.bulk-bar__actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
:root[data-bs-theme="dark"] .bulk-bar { background: rgba(var(--accent-rgb), .14); border-color: rgba(var(--accent-rgb), .35); }
:root[data-bs-theme="dark"] .bulk-bar__count { color: var(--body-text); }

/* ==================== Internal notes (invoice list) ==================== */
.inote-btn { position: relative; }
.inote-btn.has-notes { color: var(--accent); border-color: rgba(var(--accent-rgb), .4); }
.inote-count {
    display: inline-block; margin-left: .3rem; min-width: 1.1em; padding: 0 .25em;
    font-size: .7rem; font-weight: 700; line-height: 1.4; border-radius: .7rem;
    background: var(--accent); color: #fff; vertical-align: text-top;
}
.inote-list { display: flex; flex-direction: column; gap: .6rem; }
.inote-item { border: 1px solid #e2e8f0; border-radius: .6rem; padding: .5rem .65rem; background: #f8fafc; }
.inote-meta { display: flex; align-items: center; gap: .5rem; font-size: .75rem; color: #64748b; margin-bottom: .2rem; }
.inote-author { font-weight: 600; color: #334155; }
.inote-time { margin-right: auto; }
.inote-body { font-size: .88rem; color: #1e293b; white-space: pre-wrap; word-break: break-word; }
:root[data-bs-theme="dark"] .inote-item { background: var(--surface-2); border-color: var(--border-soft); }
:root[data-bs-theme="dark"] .inote-author { color: var(--heading); }
:root[data-bs-theme="dark"] .inote-body { color: var(--body-text); }
:root[data-bs-theme="dark"] .inote-meta { color: var(--muted-text); }

/* ==================== Theme toggle button ==================== */
.theme-toggle { display: inline-grid; place-items: center; line-height: 1; }
.theme-toggle .bi { font-size: 1rem; }
:root[data-bs-theme="light"] .theme-toggle__light { display: none; }
:root[data-bs-theme="dark"]  .theme-toggle__dark  { display: none; }

/* ==================== Dark theme ==================== */
:root[data-bs-theme="dark"] {
    --sidebar-bg: #131d33;
    --sidebar-bg-dark: #0c1425;
    --content-bg: #0b1220;

    --surface: #131d33;        /* cards, panels, topbar */
    --surface-2: #0f1728;      /* subtle inset areas */
    --surface-3: #1b2740;      /* hover / raised */
    --border-soft: #27334d;
    --heading: #f1f5f9;
    --body-text: #cbd5e1;
    --muted-text: #8b97b0;
}

:root[data-bs-theme="dark"] * { scrollbar-color: #3a4a6b transparent; }

:root[data-bs-theme="dark"] .app-topbar {
    background: var(--surface);
    border-bottom-color: var(--border-soft);
}

/* Cards & generic surfaces */
:root[data-bs-theme="dark"] .card,
:root[data-bs-theme="dark"] .dash-card,
:root[data-bs-theme="dark"] .kpi,
:root[data-bs-theme="dark"] .kpi-tile,
:root[data-bs-theme="dark"] .inv-panel,
:root[data-bs-theme="dark"] .invoice-sheet,
:root[data-bs-theme="dark"] .template-preview {
    background: var(--surface);
    border-color: var(--border-soft);
}
:root[data-bs-theme="dark"] .card-header,
:root[data-bs-theme="dark"] .dash-card > .card-header,
:root[data-bs-theme="dark"] .inv-panel__head,
:root[data-bs-theme="dark"] .inv-summary__grand,
:root[data-bs-theme="dark"] .dash-list li,
:root[data-bs-theme="dark"] .dash-list li:first-child,
:root[data-bs-theme="dark"] .debtor-row + .debtor-row { border-color: var(--border-soft); }

/* Headings / dark text that must flip light */
:root[data-bs-theme="dark"] .table .product-name,
:root[data-bs-theme="dark"] .inv-hero h1,
:root[data-bs-theme="dark"] .inv-panel__title,
:root[data-bs-theme="dark"] .inv-summary__row span:last-child,
:root[data-bs-theme="dark"] .inv-summary__grand .label,
:root[data-bs-theme="dark"] .inv-actionbar__total strong,
:root[data-bs-theme="dark"] .kpi__value,
:root[data-bs-theme="dark"] .kpi-tile__value,
:root[data-bs-theme="dark"] .filter-summary strong,
:root[data-bs-theme="dark"] .filter-pill:hover,
:root[data-bs-theme="dark"] .dash-hero__greeting,
:root[data-bs-theme="dark"] .aging-total,
:root[data-bs-theme="dark"] .aging-legend__row .amt,
:root[data-bs-theme="dark"] .dash-list .di-title { color: var(--heading); }

:root[data-bs-theme="dark"] .form-label { color: var(--body-text); }
:root[data-bs-theme="dark"] .stat-label,
:root[data-bs-theme="dark"] .kpi__sub,
:root[data-bs-theme="dark"] .dash-list .di-sub { color: var(--muted-text); }

/* Tables */
:root[data-bs-theme="dark"] .table { --bs-table-hover-bg: var(--surface-3); }
:root[data-bs-theme="dark"] .data-table tbody tr:hover,
:root[data-bs-theme="dark"] .table-hover > tbody > tr:hover > * { background: var(--surface-3); }
:root[data-bs-theme="dark"] .inv-items-table tbody td { border-color: var(--border-soft); }

/* Inset / muted blocks */
:root[data-bs-theme="dark"] .adv-filters,
:root[data-bs-theme="dark"] .vat-box-total,
:root[data-bs-theme="dark"] .inv-flag label,
:root[data-bs-theme="dark"] .inv-items-table thead th,
:root[data-bs-theme="dark"] .inv-items-hint,
:root[data-bs-theme="dark"] .input-group-text {
    background: var(--surface-2);
    border-color: var(--border-soft);
    color: var(--body-text);
}

/* Editors */
:root[data-bs-theme="dark"] .inv-editor { background: var(--content-bg); }
:root[data-bs-theme="dark"] .inv-hero { background: var(--surface); border-bottom-color: var(--border-soft); }
:root[data-bs-theme="dark"] .inv-hero p { color: var(--muted-text); }
:root[data-bs-theme="dark"] .inv-summary { background: linear-gradient(165deg, var(--surface), var(--surface-2)); }
:root[data-bs-theme="dark"] .inv-summary__row { color: var(--body-text); }
:root[data-bs-theme="dark"] .inv-actionbar {
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border-top-color: var(--border-soft);
}

/* Filter pills */
:root[data-bs-theme="dark"] .filter-pill { background: var(--surface-3); color: var(--body-text); }
:root[data-bs-theme="dark"] .filter-pill:hover { background: #2a3856; }
:root[data-bs-theme="dark"] .filter-pill .n { background: rgba(255,255,255,.12); }
:root[data-bs-theme="dark"] .filter-summary { background: rgba(var(--accent-rgb), .12); }

/* Dashboard accents that assumed a white base */
:root[data-bs-theme="dark"] .kpi-tile__icon,
:root[data-bs-theme="dark"] .dash-list .di-ic {
    background: color-mix(in srgb, var(--kpi-accent, var(--accent)) 22%, transparent);
}
:root[data-bs-theme="dark"] .kpi-tile:hover { border-color: #33436a; }
:root[data-bs-theme="dark"] .aging-bar,
:root[data-bs-theme="dark"] .debtor-bar { background: var(--surface-3); }

/* Tom Select */
:root[data-bs-theme="dark"] .ts-wrapper .ts-control { background: var(--surface-2); border-color: var(--border-soft); }
/* Tom Select paints its text in a near-black default that vanishes on the dark
   surface — force the control text, selected items and search input light. */
:root[data-bs-theme="dark"] .ts-wrapper .ts-control,
:root[data-bs-theme="dark"] .ts-wrapper .ts-control .item,
:root[data-bs-theme="dark"] .ts-wrapper .ts-control > input { color: var(--body-text); }
:root[data-bs-theme="dark"] .ts-wrapper .ts-control > input::placeholder { color: var(--muted-text); opacity: 1; }
:root[data-bs-theme="dark"] .ts-wrapper.plugin-remove_button .item .remove { border-left-color: var(--border-soft); }
:root[data-bs-theme="dark"] .ts-dropdown {
    background: var(--surface); border-color: var(--border-soft); color: var(--body-text);
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
:root[data-bs-theme="dark"] .ts-dropdown .active { background: rgba(var(--accent-rgb), .28); }
:root[data-bs-theme="dark"] .ts-dropdown .option:hover { background: var(--surface-3); }
:root[data-bs-theme="dark"] .ts-dropdown .optgroup-header { background: var(--surface-2); color: var(--muted-text); }

/* Form-control borders in the invoice editor were hardcoded to a near-white
   (#e2e8f0) — glaring on the dark theme. Match the panel borders instead. */
:root[data-bs-theme="dark"] .inv-panel__body .form-control,
:root[data-bs-theme="dark"] .inv-panel__body .form-select,
:root[data-bs-theme="dark"] .inv-items-table .form-control,
:root[data-bs-theme="dark"] .inv-items-table .form-select { border-color: var(--border-soft); }

/* Invoice print sheet header rule */
:root[data-bs-theme="dark"] .invoice-sheet .inv-header { border-bottom-color: var(--heading); }

/* Template picker */
:root[data-bs-theme="dark"] .template-card { border-color: var(--border-soft); }
:root[data-bs-theme="dark"] .template-card:hover { border-color: #4b5b80; }
:root[data-bs-theme="dark"] .template-block { background: var(--surface); border-color: var(--border-soft); }
/* The mini thumbnail's faux "rows" are hardcoded pale greys — dim them for dark. */
:root[data-bs-theme="dark"] .template-preview::after {
    background: var(--surface-3);
    box-shadow: 0 9px 0 var(--surface-3), 0 18px 0 var(--surface-3), 0 27px 0 var(--surface-3),
                0 36px 0 var(--surface-3), 0 45px 0 var(--surface-3), 0 54px 0 var(--surface-3);
}
:root[data-bs-theme="dark"] .template-preview.minimal::after {
    border-top-color: var(--border-soft); background: transparent;
}

/* Bootstrap's fixed-light utilities read as glaring panels on the dark theme.
   Re-point them at the dark surfaces (used ~90 places, incl. invoice customization). */
:root[data-bs-theme="dark"] .bg-light { background-color: var(--surface-2) !important; }
:root[data-bs-theme="dark"] .bg-white { background-color: var(--surface) !important; }
:root[data-bs-theme="dark"] .text-dark { color: var(--body-text) !important; }
:root[data-bs-theme="dark"] .alert-light {
    background-color: var(--surface-2); border-color: var(--border-soft); color: var(--body-text);
}
:root[data-bs-theme="dark"] .table-light {
    --bs-table-bg: var(--surface-2); --bs-table-color: var(--body-text);
    --bs-table-border-color: var(--border-soft);
}
:root[data-bs-theme="dark"] .offcanvas { background-color: var(--surface); color: var(--body-text); }
:root[data-bs-theme="dark"] .offcanvas .offcanvas-header { border-bottom-color: var(--border-soft); }

/* Toasts */
:root[data-bs-theme="dark"] .app-toast {
    background: var(--surface-3); border-color: var(--border-soft);
    box-shadow: 0 12px 32px -10px rgba(0,0,0,.6);
}
:root[data-bs-theme="dark"] .app-toast .toast-body { color: var(--body-text); }

