:root {
  --bg: #f4f6fb; --panel: #ffffff; --panel-2: #f8fafc; --border: #e4e8f0; --text: #0f172a; --muted: #64748b;
  --primary: #4f46e5; --primary-2: #4338ca; --primary-soft: #eef2ff;
  --green: #16a34a; --green-soft: #dcfce7; --red: #dc2626; --red-soft: #fee2e2;
  --amber: #d97706; --amber-soft: #fef3c7; --blue: #2563eb; --blue-soft: #dbeafe;
  --side: #111827; --side-text: #cbd5e1; --side-active: #1f2937;
  --radius: 12px; --shadow: 0 1px 2px rgba(15,23,42,.04), 0 2px 8px rgba(15,23,42,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --panel: #121a2e; --panel-2: #0f1628; --border: #222c45; --text: #e5e7eb; --muted: #94a3b8;
    --primary-soft: #1e1b4b; --green-soft: #052e16; --red-soft: #450a0a; --amber-soft: #451a03; --blue-soft: #172554;
    --side: #070b16; --side-active: #141c31;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --panel: #121a2e; --panel-2: #0f1628; --border: #222c45; --text: #e5e7eb; --muted: #94a3b8;
  --primary-soft: #1e1b4b; --green-soft: #052e16; --red-soft: #450a0a; --amber-soft: #451a03; --blue-soft: #172554;
  --side: #070b16; --side-active: #141c31;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.pos { color: var(--green); } .neg { color: var(--red); } .warn { color: var(--amber); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* Layout */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 17px; }
.brand b { display: block; font-size: 14px; } .brand span { font-size: 11px; color: #94a3b8; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--side-text); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--side-active); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; padding: 14px 12px 6px; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; padding: 12px; font-size: 12px; color: #94a3b8; border-top: 1px solid #1f2937; }
.side-foot button { margin-top: 8px; width: 100%; }
.main { min-width: 0; }
.topbar { display: none; }
.content { padding: 24px 28px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Components */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .v { font-size: 21px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); } .badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); } .badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.purple { background: var(--primary-soft); color: var(--primary); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-2); white-space: nowrap; }
tbody tr:hover { background: var(--panel-2); }
tfoot td { font-weight: 700; background: var(--panel-2); }
tr.clickable { cursor: pointer; }
td.act { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
table.report td, table.report th { padding: 7px 8px; font-size: 13px; }
table.report tr.group td { font-weight: 700; background: var(--panel-2); }
table.report td:first-child { white-space: nowrap; }
table.report tr.total td { font-weight: 700; border-top: 2px solid var(--text); }

/* Forms */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters .f { display: flex; flex-direction: column; gap: 4px; }
.filters label { font-size: 11px; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--primary); border-color: var(--primary); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 620px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 1000px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-b { padding: 20px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--panel-2); border-radius: 0 0 14px 14px; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.items-table input, .items-table select { width: 100%; padding: 6px 8px; }
.items-table td { padding: 5px 4px; }
.totals { margin-left: auto; width: 320px; max-width: 100%; margin-top: 12px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }

/* Toast & alerts */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 9px; box-shadow: var(--shadow); max-width: 360px; animation: up .2s ease; }
.toast.err { background: var(--red); color: #fff; }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; font-size: 13px; }
.alert.red { background: var(--red-soft); color: var(--red); } .alert.amber { background: var(--amber-soft); color: var(--amber); }
.alert.green { background: var(--green-soft); color: var(--green); } .alert.blue { background: var(--blue-soft); color: var(--blue); }
.alert b { color: inherit; }
.demo-bar { background: var(--amber-soft); color: var(--amber); padding: 8px 16px; text-align: center; font-size: 13px; font-weight: 500; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #4f46e5 0%, #111827 100%); }
.auth .card { width: 100%; max-width: 420px; padding: 28px; }
.auth h1 { margin-bottom: 4px; }
.auth .form { grid-template-columns: 1fr; margin-top: 18px; }
.auth .btn { justify-content: center; width: 100%; padding: 11px; }

/* Lists */
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.bar { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.acc-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.acc-card { cursor: pointer; transition: transform .1s; }
.acc-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 230px; }

/* Mobile */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .content { padding: 16px 16px 60px; }
  .g2, .g3, .g-2-1 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .modal-bg { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
}
@media print {
  .side, .topbar, .page-head .actions, .filters, .no-print, .demo-bar { display: none !important; }
  .layout { display: block; } .content { padding: 0; } body { background: #fff; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
