/* ====== FinFlow KG — Современный дизайн ====== */
:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #eef2ff;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --info: #06b6d4;
    --info-light: #cffafe;
    --sidebar-bg: #0f172a;
    --sidebar-bg-2: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #6366f1;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
    --shadow: 0 4px 6px -1px rgba(15,23,42,.08), 0 2px 4px -2px rgba(15,23,42,.04);
    --shadow-lg: 0 10px 25px -5px rgba(15,23,42,.10), 0 8px 10px -6px rgba(15,23,42,.06);
    --radius: 14px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============ SIDEBAR ============ */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 260px;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    z-index: 1000;
    box-shadow: 4px 0 16px rgba(15,23,42,.08);
    transition: transform .25s ease;
}
.sidebar-brand {
    padding: 22px 20px;
    display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-logo {
    width: 42px; height: 42px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 22px;
    box-shadow: 0 4px 12px rgba(99,102,241,.4);
}
.brand-title { color: white; font-weight: 800; font-size: 18px; letter-spacing: -.3px; }
.brand-title span { background: linear-gradient(90deg,#6366f1,#ec4899); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sub { font-size: 11px; color: #94a3b8; margin-top: 1px; letter-spacing: .5px; }
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px;
    color: var(--sidebar-text); text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500; font-size: 14px;
    transition: all .15s ease;
    margin-bottom: 2px;
}
.sidebar-nav .nav-link:hover {
    background: rgba(99,102,241,.12);
    color: white;
}
.sidebar-nav .nav-link.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    box-shadow: 0 4px 12px rgba(99,102,241,.4);
}
.sidebar-nav .nav-link i { font-size: 18px; width: 22px; text-align: center; }
.nav-divider {
    font-size: 11px; text-transform: uppercase;
    letter-spacing: 1px; color: #64748b;
    margin: 18px 14px 8px;
    font-weight: 600;
}
.sidebar-footer {
    padding: 14px;
    border-top: 1px solid rgba(255,255,255,.06);
    background: rgba(0,0,0,.15);
}
.user-card {
    display: flex; align-items: center; gap: 10px;
    padding: 8px;
    margin-bottom: 12px;
}
.user-avatar {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, #ec4899, #f97316);
    color: white; font-weight: 700;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    text-transform: uppercase;
}
.user-info { flex: 1; min-width: 0; }
.user-name { color: white; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: #94a3b8; font-size: 11px; }

/* ============ MAIN ============ */
.main-content {
    margin-left: 260px;
    min-height: 100vh;
    display: flex; flex-direction: column;
}
.topbar {
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky; top: 0; z-index: 50;
}
.page-title {
    margin: 0;
    font-size: 20px; font-weight: 700;
    color: var(--text);
    letter-spacing: -.3px;
    flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-date { color: var(--text-muted); font-size: 13px; }
.org-badge {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(99,102,241,.10), rgba(139,92,246,.10));
    border: 1px solid rgba(99,102,241,.25);
    color: var(--primary-dark);
    font-weight: 600;
    font-size: 13px;
    max-width: 360px;
}
.org-badge i { font-size: 14px; }
.org-badge .org-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-badge .org-switch {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: white;
    color: var(--primary);
    text-decoration: none;
    transition: all .15s;
}
.org-badge .org-switch:hover { background: var(--primary); color: white; }
[data-theme="dark"] .org-badge { background: rgba(99,102,241,.18); color: #c7d2fe; border-color: rgba(99,102,241,.4); }
[data-theme="dark"] .org-badge .org-switch { background: var(--surface); color: #c7d2fe; }
.btn-icon {
    background: transparent; border: 1px solid var(--border);
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: var(--text);
}
.content-wrapper { padding: 28px; flex: 1; }

/* ============ CARDS ============ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 18px 20px;
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h5, .card-header h6 { margin: 0; font-weight: 700; }
.card-body { padding: 20px; }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all .2s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-card .kpi-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; font-weight: 600; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 800; margin: 8px 0 4px; letter-spacing: -.5px; }
.kpi-card .kpi-meta { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.kpi-card .kpi-icon {
    position: absolute; top: 18px; right: 18px;
    width: 44px; height: 44px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.kpi-card.kpi-income .kpi-value { color: var(--success); }
.kpi-card.kpi-income .kpi-icon { background: var(--success-light); color: var(--success); }
.kpi-card.kpi-expense .kpi-value { color: var(--danger); }
.kpi-card.kpi-expense .kpi-icon { background: var(--danger-light); color: var(--danger); }
.kpi-card.kpi-profit .kpi-value { color: var(--primary); }
.kpi-card.kpi-profit .kpi-icon { background: var(--primary-light); color: var(--primary); }
.kpi-card.kpi-balance .kpi-value { color: #0891b2; }
.kpi-card.kpi-balance .kpi-icon { background: var(--info-light); color: var(--info); }

.delta-up { color: var(--success); font-weight: 600; }
.delta-down { color: var(--danger); font-weight: 600; }

/* ============ TABLES ============ */
.table {
    margin: 0;
    color: var(--text);
}
.table > :not(caption) > * > * {
    padding: 12px 16px;
    border-bottom-color: var(--border);
}
.table thead th {
    background: #f8fafc;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .8px;
    font-weight: 700;
    border-top: 1px solid var(--border);
}
.table tbody tr:hover { background: #f8fafc; }
.table-card { padding: 0 !important; }
.table-card .table { border-radius: var(--radius); overflow: hidden; }

/* Category chip */
.cat-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px; font-weight: 600;
    background: rgba(99,102,241,.1);
    color: var(--primary);
}
.cat-chip i { font-size: 13px; }

.amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-income { color: var(--success); }
.amount-expense { color: var(--danger); }

.badge-soft {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.badge-soft.income { background: var(--success-light); color: #047857; }
.badge-soft.expense { background: var(--danger-light); color: #b91c1c; }
.badge-soft.transfer { background: var(--info-light); color: #0e7490; }
.badge-soft.client { background: #dbeafe; color: #1e40af; }
.badge-soft.supplier { background: #fef3c7; color: #92400e; }
.badge-soft.other { background: #e2e8f0; color: #475569; }
.badge-soft.admin { background: #fce7f3; color: #be185d; }
.badge-soft.user { background: #e0e7ff; color: #4338ca; }
.badge-soft.cash { background: #dcfce7; color: #166534; }
.badge-soft.bank { background: #dbeafe; color: #1e40af; }
.badge-soft.card { background: #f3e8ff; color: #6b21a8; }
.badge-soft.active { background: var(--success-light); color: #047857; }
.badge-soft.inactive { background: #f1f5f9; color: var(--text-muted); }

/* ============ BUTTONS ============ */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    padding: 8px 16px;
    transition: all .15s;
    border: 1px solid transparent;
}
.btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-color: transparent;
    color: white;
    box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(99,102,241,.45); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-outline-secondary { color: var(--text); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--bg); color: var(--text); border-color: var(--text-muted); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ============ FORMS ============ */
.form-control, .form-select {
    border-color: var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 14px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-label { font-weight: 600; font-size: 13px; color: var(--text); margin-bottom: 6px; }

/* ============ ALERT ============ */
.alert {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
}
.alert-success { background: var(--success-light); border-color: #6ee7b7; color: #065f46; }
.alert-danger { background: var(--danger-light); border-color: #fca5a5; color: #991b1b; }
.alert-warning { background: var(--warning-light); border-color: #fcd34d; color: #92400e; }
.alert-info { background: var(--info-light); border-color: #67e8f9; color: #155e75; }

/* ============ LOGIN ============ */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    padding: 20px;
    position: relative;
    overflow: hidden;
}
.login-page::before, .login-page::after {
    content: ''; position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: .35;
}
.login-page::before { width: 400px; height: 400px; background: #f59e0b; top: -100px; left: -100px; }
.login-page::after { width: 500px; height: 500px; background: #06b6d4; bottom: -150px; right: -150px; }
.login-card {
    background: white;
    border-radius: 24px;
    padding: 40px;
    width: 100%; max-width: 440px;
    box-shadow: 0 25px 70px rgba(0,0,0,.3);
    position: relative; z-index: 2;
}
.login-logo {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 30px;
    margin: 0 auto 16px;
    box-shadow: 0 8px 24px rgba(99,102,241,.4);
}
.login-card h1 { font-size: 24px; font-weight: 800; text-align: center; margin: 0; letter-spacing: -.5px; }
.login-card .subtitle { color: var(--text-muted); text-align: center; margin: 8px 0 28px; font-size: 14px; }
.login-card .form-control { padding: 12px 14px; }
.login-card .btn-primary { width: 100%; padding: 12px; font-size: 15px; }
.login-hint {
    margin-top: 18px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}
.login-hint code { background: var(--primary-light); color: var(--primary-dark); padding: 1px 6px; border-radius: 4px; font-weight: 600; }

/* ============ MISC ============ */
.section-title {
    font-size: 16px; font-weight: 700;
    margin: 0 0 14px;
    color: var(--text);
    letter-spacing: -.2px;
}

.progress {
    height: 8px;
    background: #e2e8f0;
    border-radius: 6px;
}
.progress-bar { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.progress-bar.bg-warning { background: linear-gradient(90deg, #f59e0b, #ef4444) !important; }
.progress-bar.bg-danger { background: linear-gradient(90deg, #dc2626, #991b1b) !important; }
.progress-bar.bg-success { background: linear-gradient(90deg, #10b981, #059669) !important; }

.icon-circle {
    width: 36px; height: 36px;
    border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 48px; opacity: .4; margin-bottom: 12px; display: block; }

.modal-content { border-radius: var(--radius); border: none; }
.modal-header { border-bottom: 1px solid var(--border); padding: 18px 20px; }
.modal-body { padding: 20px; }
.modal-title { font-weight: 700; }

/* Charts wrapper */
.chart-box { position: relative; }
.chart-canvas { width: 100% !important; }

/* Filter bar */
.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 18px;
    display: grid;
    grid-template-columns: repeat(6, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.text-muted-soft { color: var(--text-muted); font-size: 12px; }

.metric-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.metric-row:last-child { border-bottom: none; }

/* Responsive */
@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 575px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .content-wrapper { padding: 16px; }
    .topbar { padding: 0 16px; }
}

/* ============ DARK THEME ============ */
[data-theme="dark"] {
    --bg: #0b1120;
    --surface: #131c2e;
    --border: #1f2a3f;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --primary-light: #1e1b4b;
    --success-light: #052e21;
    --danger-light: #3b1212;
    --warning-light: #3a2810;
    --info-light: #0c2832;
    --sidebar-bg: #060c1a;
    --sidebar-bg-2: #0c1426;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 4px 6px -1px rgba(0,0,0,.5);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.6);
}
[data-theme="dark"] body { background: var(--bg); color: var(--text); }
[data-theme="dark"] .topbar { background: var(--surface); }
[data-theme="dark"] .table thead th { background: #0f172a; color: var(--text-muted); }
[data-theme="dark"] .table tbody tr:hover { background: #182238; }
[data-theme="dark"] .table > :not(caption) > * > * { border-bottom-color: var(--border); }
[data-theme="dark"] .table thead th { border-top: 1px solid var(--border); }
[data-theme="dark"] .form-control, [data-theme="dark"] .form-select {
    background: #0f172a; border-color: var(--border); color: var(--text);
}
[data-theme="dark"] .form-control:focus, [data-theme="dark"] .form-select:focus {
    background: #0f172a; color: var(--text);
}
[data-theme="dark"] .input-group-text { background: #0f172a !important; border-color: var(--border); color: var(--text); }
[data-theme="dark"] .modal-content { background: var(--surface); color: var(--text); }
[data-theme="dark"] .btn-close { filter: invert(1); }
[data-theme="dark"] .btn-outline-secondary { color: var(--text); border-color: var(--border); }
[data-theme="dark"] .btn-outline-secondary:hover { background: var(--bg); color: var(--text); }
[data-theme="dark"] code { background: #0f172a; color: #a5b4fc; padding: 2px 6px; border-radius: 4px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
