:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --sidebar: #0f172a;
    --sidebar-text: #cbd5e1;
    --green: #15803d;
    --green-bg: #dcfce7;
    --red: #b91c1c;
    --red-bg: #fee2e2;
    --amber: #b45309;
    --amber-bg: #fef3c7;
    --blue-bg: #dbeafe;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
}
body.modal-open { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand strong { display: block; color: #fff; font-size: 15px; }
.brand small { color: #94a3b8; font-size: 12px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 10px; background: var(--primary); color: #fff;
    display: grid; place-items: center; font-weight: 700; font-size: 18px; flex-shrink: 0;
}
.nav { padding: 14px 10px; flex: 1; overflow-y: auto; }
.nav a {
    display: block; padding: 10px 14px; margin-bottom: 3px; border-radius: 8px;
    color: var(--sidebar-text); font-weight: 500; border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(37,99,235,.22); color: #fff; border-left-color: #60a5fa; }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.who strong { display: block; color: #fff; font-size: 13.5px; }
.who small { color: #94a3b8; font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 28px;
    display: flex; align-items: center; gap: 14px;
}
.topbar h1 { font-size: 20px; flex: 1; }
.topbar-date { color: var(--muted); font-size: 13px; }
.menu-toggle { display: none; background: none; border: 0; font-size: 24px; cursor: pointer; color: var(--text); padding: 0 6px; }
.content { padding: 24px 28px 48px; max-width: 1280px; width: 100%; }

/* ---------- Cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; border-left: 4px solid var(--primary); }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 22px; font-weight: 700; word-break: break-word; }
.stat small { color: var(--muted); }
.stat.pos { border-left-color: #16a34a; }
.stat.neg { border-left-color: #dc2626; }
.stat.warn { border-left-color: #d97706; }
.pos .stat-value, .text-pos { color: var(--green); }
.neg .stat-value, .text-neg { color: var(--red); }
.section { margin-bottom: 24px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 20px; margin-bottom: 24px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; }
tfoot td { font-weight: 700; background: #f8fafc; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }
td.desc { max-width: 340px; color: var(--muted); word-break: break-word; }
.empty { padding: 34px 20px; text-align: center; color: var(--muted); }

/* ---------- Buttons & forms ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600;
    cursor: pointer; text-decoration: none; line-height: 1.2; transition: background .15s, border-color .15s;
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-light { background: #fff; color: var(--text); border-color: var(--border); }
.btn-light:hover { background: #f1f5f9; }
.btn-danger { background: #fff; color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: var(--red-bg); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,.35); border-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.toolbar .left, .toolbar .right-group { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search-form, .inline-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search-form input, .inline-filters input, .inline-filters select { width: auto; min-width: 150px; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 16px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tabs { display: inline-flex; background: #f1f5f9; border-radius: 8px; padding: 3px; gap: 2px; }
.tab { padding: 7px 14px; border-radius: 6px; font-weight: 600; color: var(--muted); font-size: 13.5px; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.period-nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.range-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.range-form label { margin: 0; display: flex; align-items: center; gap: 6px; }
.range-form input { width: auto; }
.period-strip { margin-bottom: 14px; padding: 10px 16px; background: var(--blue-bg); border-radius: 8px; color: #1e3a8a; font-weight: 500; display: flex; flex-wrap: wrap; gap: 6px 24px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px; color: var(--muted); }

/* ---------- Badges & alerts ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-income { background: var(--green-bg); color: var(--green); }
.badge-expense { background: var(--red-bg); color: var(--red); }
.badge-admin { background: var(--blue-bg); color: #1e40af; }
.badge-manager { background: var(--amber-bg); color: var(--amber); }
.badge-on { background: var(--green-bg); color: var(--green); }
.badge-off { background: #e2e8f0; color: #475569; }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: var(--green-bg); color: #14532d; border-color: #bbf7d0; }
.alert-error { background: var(--red-bg); color: #7f1d1d; border-color: #fecaca; }
.alert-info { background: var(--blue-bg); color: #1e3a8a; border-color: #bfdbfe; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; }
.modal-close { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: #f8fafc; border-radius: 0 0 12px 12px; }

/* ---------- Charts & bars ---------- */
.chart { display: flex; align-items: flex-end; gap: 18px; height: 190px; padding: 10px 6px 0; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 100%; width: 100%; justify-content: center; }
.bar-income, .bar-expense { width: 40%; max-width: 30px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-income { background: #22c55e; }
.bar-expense { background: #ef4444; }
.chart-label { font-size: 12px; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.meter { background: #e2e8f0; border-radius: 99px; height: 8px; min-width: 90px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--primary); }

/* ---------- Login / auth pages ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: linear-gradient(135deg, #0f172a, #1e3a8a); }
.auth-card { background: #fff; padding: 34px 32px; border-radius: 14px; width: 100%; max-width: 410px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card .brand-mark { margin-bottom: 14px; }
.auth-card .btn { width: 100%; padding: 11px; }
.auth-wide { max-width: 480px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar { position: fixed; left: -270px; top: 0; z-index: 90; transition: left .2s; width: 260px; }
    body.nav-open .sidebar { left: 0; }
    .menu-toggle { display: block; }
    .content { padding: 18px 14px 40px; }
    .topbar { padding: 12px 14px; }
    .topbar-date { display: none; }
    .grid-2 { grid-template-columns: 1fr; }
    .field-row { grid-template-columns: 1fr; }
}

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar .menu-toggle, .no-print, .btn, .modal { display: none !important; }
    .layout { display: block; }
    body { background: #fff; }
    .content { padding: 0; max-width: none; }
    .card { box-shadow: none; }
    td.actions, th.actions { display: none; }
}
