/* Haxna CRM design system — light + dark, driven by html[data-theme].
   Loaded AFTER MudBlazor.min.css so the dark [data-theme] overrides of --mud-palette-* win by specificity.
   Light mode is driven by the custom MudTheme in MainLayout; here we only add app-level tokens for light
   and override MudBlazor's palette for dark. */

:root {
    color-scheme: light;

    /* Brand (haxna.com — blue node accent) */
    --brand: #3b82f6;
    --brand-strong: #2f6fe0;
    --brand-soft: rgba(59, 130, 246, 0.12);
    --on-brand: #ffffff;

    /* Surfaces / text / lines */
    --app-bg: #f5f6fb;
    --surface: #ffffff;
    --surface-2: #f2f3f8;
    --text: #1a1d26;
    --text-muted: #667085;
    --border: #e6e8ef;

    /* Shell */
    --sidebar-bg: #ffffff;
    --sidebar-text: #4a4f60;
    --sidebar-active-bg: var(--brand-soft);
    --sidebar-active-text: var(--brand);
    --sidebar-border: var(--border);
    --topbar-bg: rgba(255, 255, 255, 0.82);
    --topbar-border: var(--border);

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.10);
    --radius: 12px;
    --radius-sm: 8px;
    --topbar-h: 60px;
    --sidebar-w: 250px;
}

html[data-theme="dark"] {
    color-scheme: dark;

    --brand: #5c9bff;
    --brand-strong: #3b82f6;
    --brand-soft: rgba(92, 155, 255, 0.16);
    --on-brand: #ffffff;

    --app-bg: #0b0d11;
    --surface: #14171e;
    --surface-2: #1b1f27;
    --text: #e6e8ee;
    --text-muted: #9aa4b2;
    --border: #262b36;

    --sidebar-bg: #0e1015;
    --sidebar-text: #b7bec9;
    --sidebar-active-bg: rgba(92, 155, 255, 0.18);
    --sidebar-active-text: #a9c9ff;
    --sidebar-border: #20242e;
    --topbar-bg: rgba(12, 14, 18, 0.82);
    --topbar-border: #20242e;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.5);

    /* ---- MudBlazor palette overrides (dark) ---- */
    --mud-palette-primary: #5c9bff;
    --mud-palette-primary-rgb: 92, 155, 255;
    --mud-palette-primary-text: #ffffff;
    --mud-palette-primary-hover: rgba(92, 155, 255, 0.12);
    --mud-palette-secondary: #a9c9ff;

    --mud-palette-black: #08090c;
    --mud-palette-background: #0b0d11;
    --mud-palette-background-gray: #08090c;
    --mud-palette-surface: #14171e;

    --mud-palette-text-primary: rgba(255, 255, 255, 0.87);
    --mud-palette-text-secondary: rgba(255, 255, 255, 0.60);
    --mud-palette-text-disabled: rgba(255, 255, 255, 0.38);

    --mud-palette-action-default: rgba(255, 255, 255, 0.80);
    --mud-palette-action-default-hover: rgba(255, 255, 255, 0.08);
    --mud-palette-action-disabled: rgba(255, 255, 255, 0.26);
    --mud-palette-action-disabled-background: rgba(255, 255, 255, 0.12);

    --mud-palette-divider: rgba(255, 255, 255, 0.12);
    --mud-palette-divider-light: rgba(255, 255, 255, 0.06);
    --mud-palette-lines-default: rgba(255, 255, 255, 0.12);
    --mud-palette-lines-inputs: rgba(255, 255, 255, 0.30);
    --mud-palette-table-lines: rgba(255, 255, 255, 0.12);
    --mud-palette-table-striped: rgba(255, 255, 255, 0.02);
    --mud-palette-table-hover: rgba(255, 255, 255, 0.04);

    --mud-palette-drawer-background: #0e1015;
    --mud-palette-drawer-text: rgba(255, 255, 255, 0.80);
    --mud-palette-drawer-icon: rgba(255, 255, 255, 0.80);
    --mud-palette-appbar-background: #14171e;
    --mud-palette-appbar-text: rgba(255, 255, 255, 0.87);

    --mud-palette-surface-rgb: 20, 23, 30;
    --mud-palette-gray-light: #2a2f3a;
    --mud-palette-gray-lighter: #21252f;
}

/* Base */
html, body {
    background-color: var(--app-bg);
    color: var(--text);
}

/* Smooth (but quick) transition when toggling theme */
body, .mud-paper, .mud-card, .card, .table, .form-control, .form-select, .sidebar, .app-topbar {
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

::selection {
    background: var(--brand-soft);
}

/* ---------------- Sidebar nav (global: NavLink is a child component) ---------------- */
.sidebar .nav-menu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0.75rem 0.6rem;
    overflow-y: auto;
    flex: 1 1 auto;
}

.sidebar .nav-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 0.7rem;
    border-radius: 9px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

.sidebar .nav-row:hover {
    background: var(--surface-2);
    color: var(--text);
}

.sidebar .nav-row.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}

.sidebar .nav-ico {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    opacity: 0.9;
}

/* ---------------- Links / bootstrap forms / tables in both themes ---------------- */
a, .btn-link {
    color: var(--brand);
}

.form-control,
.form-select {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.form-control:focus,
.form-select:focus {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem var(--brand-soft);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* light dropdown arrow for selects in dark mode */
html[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%239aa4b2' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

.table {
    --bs-table-color: var(--text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--border);
    color: var(--text);
}

.table > :not(caption) > * > * {
    background-color: transparent;
    color: var(--text);
    border-bottom-color: var(--border);
}

.table thead th {
    color: var(--text-muted);
    font-weight: 600;
}

/* wrapper for horizontally-scrollable tables on small screens */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* subtle card polish for MudPaper/MudCard */
.mud-paper {
    border: 1px solid var(--border);
}

/* ---------------- Dashboard ---------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.9rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 0.15rem;
}

.stat-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.9rem;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.kpi-value {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: 0.15rem;
}

.kpi-value.pos {
    color: #16a34a;
}

.kpi-value.neg {
    color: #ef4444;
}

.kpi-cur {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
}

/* vertical grouped bars (monthly income vs expense) */
.bars {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 170px;
    padding-top: 0.5rem;
}

.bar-col {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.bar-stack {
    height: 140px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
    width: 100%;
}

.bar {
    width: 9px;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
}

.bar-inc { background: #22c55e; }
.bar-exp { background: #ef4444; }

.bar-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

.chart-legend {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

.lg {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    margin-right: 0.35rem;
}

.lg-inc { background: #22c55e; }
.lg-exp { background: #ef4444; }

.cur-tab {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    text-decoration: none;
    color: var(--text-muted);
    border: 1px solid var(--border);
    margin-right: 0.35rem;
}

.cur-tab.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

/* status stacked bar + legend */
.stack-bar {
    display: flex;
    height: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface-2);
}

.stack-seg {
    height: 100%;
}

.legend-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
}

.legend-item .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-count {
    font-weight: 700;
}

/* horizontal bars (categories, top clients) */
.hbar-row {
    display: grid;
    grid-template-columns: 110px 1fr auto;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}

.hbar-label {
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hbar-track {
    height: 8px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.hbar-fill {
    height: 100%;
    border-radius: 999px;
    min-width: 2px;
}

.hbar-fill.inc { background: var(--brand); }
.hbar-fill.exp { background: #f59e0b; }

.hbar-value {
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
}

