* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --bg: #f0f2f5;
    --card: #fff;
    --text: #1a1a2e;
    --text2: #667085;
    --text3: #98a2b3;
    --border: #e4e7ec;
    --border-light: #f2f4f7;
    --success: #12b76a;
    --danger: #f04438;
    --warning: #f79009;
    --sidebar-w: 240px;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    background: #1a1a2e;
    color: #fff;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform .25s;
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-header h2 { font-size: 20px; font-weight: 700; }
.sidebar-sub { font-size: 12px; color: rgba(255,255,255,.5); }

.sidebar-nav { list-style: none; padding: 12px 0; flex: 1; overflow-y: auto; }
.sidebar-nav li { margin: 0; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px;
    color: rgba(255,255,255,.65);
    text-decoration: none;
    font-size: 14px;
    transition: all .15s;
    cursor: pointer;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-item.active { color: #fff; background: rgba(59,130,246,.3); border-right: 3px solid var(--primary); }
.nav-icon { font-size: 16px; width: 22px; text-align: center; }
.nav-divider { height: 1px; background: rgba(255,255,255,.08); margin: 8px 16px; }

/* ── Mobile ── */
.mobile-header {
    display: none;
    position: fixed; top: 0; left: 0; right: 0;
    height: 56px;
    background: #1a1a2e;
    color: #fff;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    z-index: 90;
}
.mobile-header h2 { font-size: 18px; }
.menu-toggle { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99; }

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .mobile-header { display: flex; }
    .main-content { margin-left: 0 !important; padding-top: 72px !important; }
}

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-w);
    padding: 24px;
    min-height: 100vh;
}

.page { display: none; }
.page.active { display: block; }

.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.page-desc { font-size: 14px; color: var(--text2); }

/* ── Cards ── */
.card {
    background: var(--card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-title-sub { font-size: 12px; color: var(--text3); font-weight: 400; }

/* ── KPI ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.kpi-grid-sm { margin-bottom: 16px; }
.kpi-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
}
.kpi-sm { padding: 12px; }
.kpi-label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.kpi-value { display: block; font-size: 22px; font-weight: 700; color: var(--text); }
.kpi-sm .kpi-value { font-size: 16px; }

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text2);
}
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.empty-state p { margin-bottom: 20px; font-size: 14px; }

/* ── Drop Zone ── */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all .2s;
}
.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--primary);
    background: #eff6ff;
}
.drop-zone-icon { font-size: 48px; margin-bottom: 12px; }
.drop-zone-text { font-size: 16px; font-weight: 600; color: #344054; margin-bottom: 4px; }
.drop-zone-hint { font-size: 13px; color: var(--text3); }

/* ── Tabs ── */
.tabs {
    display: flex; gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    overflow-x: auto;
}
.tab {
    padding: 10px 16px;
    border: none; background: none;
    font-size: 13px; font-weight: 500;
    color: var(--text2);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ── Tables ── */
.table-wrapper { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.table-wrapper-lg { max-height: 600px; overflow-y: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table thead { position: sticky; top: 0; z-index: 1; }
.data-table th {
    background: #f9fafb;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: #344054;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}
.data-table tr:hover td { background: #f9fafb; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .subtotal td { background: #eff6ff; font-weight: 600; }
.data-table .total td { background: #eef2ff; font-weight: 700; }

.editable-table td[contenteditable="true"] {
    cursor: text;
    outline: none;
}
.editable-table td[contenteditable="true"]:focus {
    background: #fef9c3;
    box-shadow: inset 0 0 0 2px var(--primary);
}

/* ── Filter Bar ── */
.filter-bar {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
    min-width: 200px;
}

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px;
    border: none; border-radius: 8px;
    font-size: 14px; font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
    background: #fff; color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: #f9fafb; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #d92d20; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn:active { transform: scale(.98); }

/* ── Upload Result ── */
.upload-result-header {
    display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
}
.file-label { font-size: 14px; font-weight: 600; color: var(--text); }

.upload-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ── Badge ── */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.badge-success { background: #ecfdf3; color: #027a48; }
.badge-info { background: #eff6ff; color: #1d4ed8; }
.badge-danger { background: #fef3f2; color: #b42318; }

/* ── History ── */
.history-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: box-shadow .15s;
}
.history-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.history-info { flex: 1; }
.history-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.history-meta { font-size: 12px; color: var(--text2); display: flex; gap: 16px; flex-wrap: wrap; }
.history-actions { display: flex; gap: 6px; }

/* ── Settlement Grid ── */
.settlement-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.settlement-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.settlement-card-header {
    background: #f9fafb;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 14px;
    display: flex; justify-content: space-between; align-items: center;
}
.settlement-card-body { padding: 8px; }
.settlement-total {
    font-size: 18px; font-weight: 700; color: var(--primary);
}
.stl-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 8px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
}
.stl-row:last-child { border-bottom: none; }
.stl-row .stl-date { color: var(--text2); }
.stl-row .stl-amt { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Modal ── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
}
.modal-content {
    background: #fff;
    border-radius: 12px;
    width: 90%; max-width: 400px;
    box-shadow: 0 8px 32px rgba(0,0,0,.15);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 24px; color: var(--text3); cursor: pointer; }
.modal-body { padding: 20px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.input {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

/* ── Export ── */
.export-options { display: flex; flex-direction: column; gap: 10px; }
.checkbox-label {
    display: flex; align-items: center; gap: 8px;
    font-size: 14px; cursor: pointer;
}
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }

/* ── Loading ── */
.loading-overlay {
    position: fixed; inset: 0;
    background: rgba(255,255,255,.85);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 1000;
}
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadingText { font-size: 14px; color: var(--text2); }

/* ── Toast ── */
.toast-container {
    position: fixed; bottom: 24px; right: 24px;
    z-index: 300;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    background: #1a1a2e; color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    animation: slideIn .3s ease;
    max-width: 360px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }

/* ── Cashflow ── */
.kpi-income { color: var(--primary) !important; }
.kpi-expense { color: var(--danger) !important; }
.kpi-warning { color: var(--warning) !important; }

.cf-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 180px;
    padding: 16px 0;
    overflow-x: auto;
}
.cf-bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px;
    flex: 1;
}
.cf-bars {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 140px;
}
.cf-bar {
    width: 20px;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height .3s;
}
.cf-bar.income { background: var(--primary); }
.cf-bar.expense { background: var(--danger); }
.cf-bar-label {
    font-size: 11px;
    color: var(--text2);
    margin-top: 6px;
    white-space: nowrap;
}

.cf-row-income td { color: var(--primary); }
.cf-row-expense td { color: var(--danger); }
.cf-positive { color: var(--primary) !important; font-weight: 600; }
.cf-negative { color: var(--danger) !important; font-weight: 600; }

.stl-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.stl-status.completed { background: #ecfdf3; color: #027a48; }
.stl-status.expected { background: #fef9c3; color: #854d0e; }

.hidden { display: none !important; }
