:root,
html[data-theme="dark"] {
    --bg: #09131f;
    --bg-soft: #102033;
    --panel: rgba(14, 27, 43, 0.88);
    --panel-strong: rgba(11, 24, 39, 0.96);
    --border: rgba(148, 173, 196, 0.16);
    --text: #edf5ff;
    --muted: #93a6bd;
    --accent: #47d1c5;
    --accent-strong: #2f87d7;
    --accent-warm: #f4b860;
    --accent-red: #ff6b6b;
    --shadow: 0 30px 70px rgba(0, 0, 0, 0.32);
    --radius: 24px;
    --page-background:
        radial-gradient(circle at top left, rgba(71, 209, 197, 0.12), transparent 24%),
        radial-gradient(circle at right 20%, rgba(244, 184, 96, 0.12), transparent 22%),
        linear-gradient(160deg, #07101a 0%, #0a1522 48%, #08111c 100%);
    --sidebar-background: rgba(5, 12, 21, 0.74);
    --surface: rgba(255, 255, 255, 0.03);
    --surface-strong: rgba(255, 255, 255, 0.06);
    --input-background: rgba(6, 14, 24, 0.8);
    --theme-toggle-background: rgba(255, 255, 255, 0.05);
    --theme-toggle-hover: rgba(255, 255, 255, 0.09);
    --backdrop: rgba(2, 7, 13, 0.72);
}

html[data-theme="light"] {
    --bg: #eef4fa;
    --bg-soft: #dce6f2;
    --panel: rgba(255, 255, 255, 0.84);
    --panel-strong: rgba(255, 255, 255, 0.96);
    --border: rgba(44, 76, 103, 0.14);
    --text: #122235;
    --muted: #60748a;
    --accent: #0ca6a0;
    --accent-strong: #266dc8;
    --accent-warm: #e59e32;
    --accent-red: #d65252;
    --shadow: 0 24px 60px rgba(72, 96, 122, 0.16);
    --page-background:
        radial-gradient(circle at top left, rgba(12, 166, 160, 0.12), transparent 24%),
        radial-gradient(circle at right 20%, rgba(229, 158, 50, 0.12), transparent 22%),
        linear-gradient(160deg, #f6fbff 0%, #edf4fb 48%, #e7eff7 100%);
    --sidebar-background: rgba(248, 251, 255, 0.82);
    --surface: rgba(18, 34, 53, 0.03);
    --surface-strong: rgba(18, 34, 53, 0.08);
    --input-background: rgba(255, 255, 255, 0.92);
    --theme-toggle-background: rgba(18, 34, 53, 0.05);
    --theme-toggle-hover: rgba(18, 34, 53, 0.09);
    --backdrop: rgba(16, 24, 36, 0.3);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Manrope", sans-serif;
    background: var(--page-background);
    color: var(--text);
    transition: background 180ms ease, color 180ms ease;
}

.shell {
    display: grid;
    grid-template-columns: 288px 1fr;
    min-height: 100vh;
}

.sidebar {
    padding: 28px;
    border-right: 1px solid var(--border);
    background: var(--sidebar-background);
    backdrop-filter: blur(18px);
}

.brand,
.topbar,
.panel-head,
.filter-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-mark {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #041019;
    font-weight: 800;
    margin-right: 14px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 11px;
}

.brand h1,
.topbar h2,
.panel-head h3 {
    margin: 0;
}

.nav {
    display: grid;
    gap: 10px;
    margin: 34px 0;
}

.nav-link {
    padding: 13px 16px;
    border-radius: 16px;
    color: var(--muted);
    text-decoration: none;
    background: var(--surface);
    transition: 160ms ease;
}

.nav-link:hover,
.nav-link.is-active {
    color: var(--text);
    background: rgba(71, 209, 197, 0.12);
    transform: translateX(4px);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-toggle {
    min-height: 44px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--theme-toggle-background);
    color: var(--text);
    padding: 0 16px;
    font: inherit;
    cursor: pointer;
    transition: 160ms ease;
}

.theme-toggle:hover {
    background: var(--theme-toggle-hover);
    transform: translateY(-1px);
}

.sidebar-card,
.filters-panel,
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.sidebar-card {
    padding: 20px;
}

.sidebar-card h3,
.sidebar-card p {
    margin: 0;
}

.sidebar-card p:last-child {
    margin-top: 12px;
    color: var(--muted);
    line-height: 1.5;
}

.content {
    padding: 28px;
}

.topbar-chip {
    padding: 12px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    background: var(--surface);
}

.filters-panel {
    margin-top: 24px;
    padding: 18px;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

label span {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
}

input,
select,
.button {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--input-background);
    color: var(--text);
    padding: 0 14px;
    font: inherit;
}

.button {
    cursor: pointer;
    transition: 160ms ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #041019;
    font-weight: 800;
}

.page-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-top: 20px;
}

.panel {
    padding: 20px;
    overflow: hidden;
}

.section-span {
    grid-column: span 3;
}

.section-span-2 {
    grid-column: span 2;
}

.section-span-3 {
    grid-column: span 3;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px;
}

.kpi-card {
    padding: 18px;
    border-radius: 20px;
    background: linear-gradient(180deg, var(--surface-strong), var(--surface));
    border: 1px solid var(--surface-strong);
}

.kpi-card h3 {
    margin: 0 0 8px;
    font-size: 14px;
    color: var(--muted);
}

.kpi-value,
.hero-number {
    font-size: 34px;
    font-weight: 800;
}

.hero-number {
    margin-top: 18px;
}

.chart {
    width: 100%;
    height: 340px;
}

#topCounterparties,
#receivablesManagers,
#receivablesCounterparties,
.rule-list,
.alerts-list,
.detail-stack {
    display: grid;
    gap: 12px;
}

.list-card,
.alert-card,
.rule-card,
.detail-card,
.spotlight-card,
.formula-card {
    padding: 16px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--surface-strong);
}

.list-card strong,
.spotlight-card strong {
    font-size: 18px;
}

.muted,
.list-card p,
.alert-card p,
.detail-card p,
.rule-card p,
.spotlight-card p,
.formula-card p,
.empty-state {
    color: var(--muted);
    line-height: 1.5;
}

.alert-card.warning {
    border-color: rgba(244, 184, 96, 0.25);
}

.alert-card.critical {
    border-color: rgba(255, 107, 107, 0.32);
}

.drawer {
    position: fixed;
    inset: 0;
    z-index: 20;
}

.drawer.hidden {
    display: none;
}

.drawer-backdrop {
    position: absolute;
    inset: 0;
    background: var(--backdrop);
}

.drawer-panel {
    position: absolute;
    top: 24px;
    right: 24px;
    bottom: 24px;
    width: min(720px, calc(100vw - 48px));
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 28px;
    padding: 24px;
    box-shadow: var(--shadow);
    overflow: auto;
}

.drawer-close {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 0;
    background: var(--theme-toggle-background);
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
}

.tabulator {
    background: transparent;
    border: 0;
    color: var(--text);
}

.tabulator .tabulator-tableholder,
.tabulator .tabulator-tableholder .tabulator-table,
.tabulator .tabulator-header,
.tabulator .tabulator-row {
    background: transparent !important;
}

.tabulator .tabulator-header {
    border-bottom: 1px solid var(--border);
}

.tabulator .tabulator-col,
.tabulator .tabulator-cell,
.tabulator .tabulator-footer,
.tabulator .tabulator-header .tabulator-col {
    border-color: var(--border) !important;
}

.tabulator .tabulator-header .tabulator-col,
.tabulator .tabulator-row .tabulator-cell {
    background: transparent !important;
    color: var(--text) !important;
}

.tabulator .tabulator-row:hover {
    background: var(--surface) !important;
}

.tabulator .tabulator-row.tabulator-selected {
    background: rgba(71, 209, 197, 0.14) !important;
}

@media (max-width: 1280px) {
    .shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .filters-grid,
    .page-grid,
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .section-span,
    .section-span-2,
    .section-span-3 {
        grid-column: span 2;
    }
}

@media (max-width: 760px) {
    .content,
    .sidebar {
        padding: 18px;
    }

    .filters-grid,
    .page-grid,
    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .section-span,
    .section-span-2,
    .section-span-3 {
        grid-column: span 1;
    }

    .topbar {
        display: block;
    }

    .topbar-actions {
        margin-top: 12px;
        flex-wrap: wrap;
    }

    .topbar-chip {
        margin-top: 0;
    }
}
