:root{
  --bg:#f5f6fa; --surface:#ffffff; --surface-2:#f8f9fc; --border:#e4e7ef; --border-strong:#cfd5e2;
  --text:#141a2e; --text-2:#4a5470; --muted:#7a839c;
  --primary:#4f46e5; --primary-600:#4338ca; --primary-50:#eef0ff; --primary-100:#e0e3ff;
  --green:#0f9d6b; --green-50:#e6f7f0; --red:#d93f4c; --red-50:#fdecee; --amber:#c27c0e; --amber-50:#fdf4e3; --blue:#2563eb; --blue-50:#e8f0fe;
  --sidebar:#0f1530; --sidebar-2:#1a2246; --sidebar-text:#aeb6d3; --sidebar-active:#ffffff;
  --radius:12px; --radius-sm:8px; --shadow:0 1px 2px rgba(16,24,40,.05),0 1px 3px rgba(16,24,40,.06);
  --shadow-lg:0 12px 32px rgba(16,24,40,.14),0 2px 6px rgba(16,24,40,.06);
  --font:"Inter",system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
}
:root[data-theme="dark"]{
  --bg:#0b1020; --surface:#121933; --surface-2:#18203d; --border:#252f52; --border-strong:#34406a;
  --text:#e8ecf8; --text-2:#b4bdd8; --muted:#8089a8;
  --primary:#7c74ff; --primary-600:#6d64f5; --primary-50:#1e2152; --primary-100:#272b66;
  --green:#34c28f; --green-50:#0f2e26; --red:#f06571; --red-50:#3a1720; --amber:#e6a23c; --amber-50:#33270f; --blue:#5b8cff; --blue-50:#14244a;
  --sidebar:#080c1a; --sidebar-2:#121933;
  --shadow:0 1px 2px rgba(0,0,0,.3); --shadow-lg:0 12px 32px rgba(0,0,0,.5);
}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{font-family:var(--font);background:var(--bg);color:var(--text);font-size:14px;line-height:1.45;-webkit-font-smoothing:antialiased}
button,input,select,textarea{font:inherit;color:inherit}
a{color:var(--primary);text-decoration:none}
.boot{height:100vh;display:grid;place-items:center;align-content:center;gap:12px;color:var(--muted)}
.spinner{width:34px;height:34px;border:3px solid var(--primary-100);border-top-color:var(--primary);border-radius:50%;animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* ---------- Layout ---------- */
.layout{display:grid;grid-template-columns:248px 1fr;min-height:100vh}
.sidebar{background:var(--sidebar);color:var(--sidebar-text);display:flex;flex-direction:column;position:sticky;top:0;height:100vh;overflow:auto}
.brand{display:flex;align-items:center;gap:10px;padding:20px 18px 16px}
.brand-logo{width:36px;height:36px;border-radius:10px;background:linear-gradient(135deg,#6366f1,#22c1a4);display:grid;place-items:center;color:#fff;font-weight:700}
.brand b{color:#fff;font-size:15px;display:block}
.brand small{font-size:11.5px;color:#8a93b8}
.nav{padding:6px 10px;display:flex;flex-direction:column;gap:2px;flex:1}
.nav-label{font-size:10.5px;letter-spacing:.08em;text-transform:uppercase;color:#636c92;padding:14px 10px 6px}
.nav a{display:flex;align-items:center;gap:11px;padding:9px 10px;border-radius:9px;color:var(--sidebar-text);font-weight:500;font-size:13.5px}
.nav a:hover{background:var(--sidebar-2);color:#fff}
.nav a.active{background:linear-gradient(90deg,rgba(99,102,241,.35),rgba(99,102,241,.12));color:var(--sidebar-active)}
.nav svg{width:18px;height:18px;flex:none;opacity:.9}
.sidebar-foot{padding:14px;border-top:1px solid rgba(255,255,255,.06);font-size:12px}
.main{min-width:0;display:flex;flex-direction:column}
.topbar{height:62px;display:flex;align-items:center;gap:12px;padding:0 26px;background:var(--surface);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:20}
.topbar h1{font-size:17px;margin:0;font-weight:650;letter-spacing:-.01em}
.topbar .crumb{color:var(--muted);font-size:12.5px}
.topbar .spacer{flex:1}
.menu-btn{display:none}
.content{padding:24px 26px 60px;max-width:1500px;width:100%}
.user-chip{display:flex;align-items:center;gap:9px;padding:5px 10px 5px 5px;border:1px solid var(--border);border-radius:99px;background:var(--surface-2);cursor:pointer}
.avatar{width:28px;height:28px;border-radius:50%;background:var(--primary);color:#fff;display:grid;place-items:center;font-weight:600;font-size:12px}
.user-chip svg{width:16px;height:16px;color:var(--muted)}
.user-chip small{display:block;color:var(--muted);font-size:11px;line-height:1.1}
.demo-banner{background:var(--amber-50);color:var(--amber);border-bottom:1px solid var(--border);padding:7px 26px;font-size:12.5px}

/* ---------- Components ---------- */
.card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow)}
.card-h{display:flex;align-items:center;gap:10px;padding:14px 18px;border-bottom:1px solid var(--border)}
.card-h h3{margin:0;font-size:14.5px;font-weight:600}
.card-b{padding:16px 18px}
.grid{display:grid;gap:16px}
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:14px;margin-bottom:18px}
.kpi{padding:16px 18px}
.kpi .lbl{color:var(--muted);font-size:12.5px;font-weight:500;display:flex;align-items:center;gap:7px}
.kpi .val{font-size:clamp(18px,1.6vw,23px);white-space:nowrap;font-weight:700;margin-top:6px;letter-spacing:-.02em;font-variant-numeric:tabular-nums}
.kpi .sub{font-size:12px;color:var(--muted);margin-top:2px}
.dot{width:8px;height:8px;border-radius:50%;display:inline-block}
.btn{display:inline-flex;align-items:center;justify-content:center;gap:7px;height:36px;padding:0 14px;border-radius:9px;border:1px solid var(--border-strong);background:var(--surface);font-weight:550;font-size:13px;cursor:pointer;white-space:nowrap;transition:background .12s,border-color .12s,box-shadow .12s}
.btn:hover{background:var(--surface-2)}
.btn:focus-visible,.input:focus,.select:focus,textarea:focus{outline:none;box-shadow:0 0 0 3px var(--primary-100);border-color:var(--primary)}
.btn svg{width:16px;height:16px}
.btn.primary{background:var(--primary);border-color:var(--primary);color:#fff}
.btn.primary:hover{background:var(--primary-600)}
.btn.danger{color:var(--red);border-color:color-mix(in srgb,var(--red) 35%,transparent)}
.btn.danger:hover{background:var(--red-50)}
.btn.ghost{border-color:transparent;background:transparent}
.btn.ghost:hover{background:var(--surface-2)}
.btn.sm{height:30px;padding:0 10px;font-size:12.5px;border-radius:8px}
.btn.icon{width:32px;padding:0;height:32px}
.btn[disabled]{opacity:.5;pointer-events:none}
.toolbar{display:flex;flex-wrap:wrap;gap:10px;align-items:flex-end;margin-bottom:16px}
.toolbar .grow{flex:1}
.field{display:flex;flex-direction:column;gap:5px;min-width:0}
.field label{font-size:12px;font-weight:550;color:var(--text-2)}
.field .hint{font-size:11.5px;color:var(--muted)}
.input,.select,textarea{height:36px;border:1px solid var(--border-strong);background:var(--surface);border-radius:9px;padding:0 11px;min-width:0;width:100%}
textarea{height:auto;padding:9px 11px;resize:vertical;min-height:64px}
.input[readonly]{background:var(--surface-2);color:var(--text-2)}
.chips{display:flex;gap:6px;flex-wrap:wrap}
.chip{height:30px;padding:0 11px;border-radius:99px;border:1px solid var(--border);background:var(--surface);font-size:12.5px;cursor:pointer;font-weight:500;color:var(--text-2)}
.chip.on{background:var(--primary-50);border-color:var(--primary);color:var(--primary)}
.badge{display:inline-flex;align-items:center;height:22px;padding:0 8px;border-radius:99px;font-size:11.5px;font-weight:600;background:var(--surface-2);color:var(--text-2);border:1px solid var(--border)}
.badge.green{background:var(--green-50);color:var(--green);border-color:transparent}
.badge.red{background:var(--red-50);color:var(--red);border-color:transparent}
.badge.amber{background:var(--amber-50);color:var(--amber);border-color:transparent}
.badge.blue{background:var(--blue-50);color:var(--blue);border-color:transparent}
.badge.violet{background:var(--primary-50);color:var(--primary);border-color:transparent}
.pos{color:var(--green)} .neg{color:var(--red)} .muted{color:var(--muted)}
.num{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}

/* ---------- Tables ---------- */
.table-wrap{overflow:auto;max-height:calc(100vh - 290px);border-radius:0 0 var(--radius) var(--radius)}
table.t{border-collapse:separate;border-spacing:0;width:100%;font-size:13px}
.t th{position:sticky;top:0;background:var(--surface-2);text-align:left;font-weight:600;color:var(--text-2);font-size:11.5px;text-transform:uppercase;letter-spacing:.03em;padding:10px 12px;border-bottom:1px solid var(--border);white-space:nowrap;z-index:1}
.t td{padding:9px 12px;border-bottom:1px solid var(--border);white-space:nowrap}
.t tbody tr:hover td{background:var(--surface-2)}
.t tr.clickable{cursor:pointer}
.t tfoot td{position:sticky;bottom:0;background:var(--surface);font-weight:700;border-top:2px solid var(--border-strong);border-bottom:none}
.t td.wrap{white-space:normal;min-width:180px;max-width:340px}
.t .actions{display:flex;gap:4px;justify-content:flex-end}
.t tr.sub td{background:var(--surface-2);font-weight:600}
.empty{padding:48px 20px;text-align:center;color:var(--muted)}
.empty svg{width:40px;height:40px;opacity:.5}
.tbl-meta{display:flex;gap:14px;align-items:center;padding:10px 18px;border-bottom:1px solid var(--border);font-size:12.5px;color:var(--muted);flex-wrap:wrap}
.tbl-meta b{color:var(--text)}

/* ---------- Modal ---------- */
.modal-bg{position:fixed;inset:0;background:rgba(10,14,30,.45);backdrop-filter:blur(2px);display:flex;align-items:flex-start;justify-content:center;padding:5vh 16px;z-index:100;overflow:auto;animation:fade .15s}
.modal{background:var(--surface);border-radius:16px;box-shadow:var(--shadow-lg);width:100%;max-width:720px;animation:pop .16s ease-out}
.modal.wide{max-width:1040px}
.modal.small{max-width:440px}
.modal-h{display:flex;align-items:center;padding:16px 20px;border-bottom:1px solid var(--border)}
.modal-h h3{margin:0;font-size:16px;flex:1}
.modal-b{padding:18px 20px;max-height:70vh;overflow:auto}
.modal-f{display:flex;gap:10px;justify-content:flex-end;padding:14px 20px;border-top:1px solid var(--border);background:var(--surface-2);border-radius:0 0 16px 16px}
.form-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:14px}
.form-grid .span2{grid-column:span 2}
.form-grid .span3{grid-column:1/-1}
.calc-box{background:var(--primary-50);border:1px dashed var(--primary-100);border-radius:10px;padding:12px 14px;display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:10px;grid-column:1/-1}
.calc-box div small{display:block;color:var(--text-2);font-size:11.5px}
.calc-box div b{font-variant-numeric:tabular-nums;font-size:15px}
@keyframes fade{from{opacity:0}}
@keyframes pop{from{transform:translateY(8px) scale(.98);opacity:0}}

/* ---------- Toast ---------- */
#toast-root{position:fixed;bottom:20px;right:20px;display:flex;flex-direction:column;gap:8px;z-index:200}
.toast{background:var(--text);color:var(--surface);padding:11px 16px;border-radius:10px;box-shadow:var(--shadow-lg);font-size:13px;max-width:380px;animation:pop .2s}
.toast.err{background:var(--red);color:#fff}
.toast.ok{background:#0f7a55;color:#fff}

/* ---------- Login ---------- */
.login{min-height:100vh;display:grid;grid-template-columns:1.1fr 1fr}
.login-art{background:radial-gradient(1200px 600px at 10% 10%,#4f46e5 0,#1b1f5e 50%,#0b1020 100%);color:#fff;padding:56px;display:flex;flex-direction:column;justify-content:space-between}
.login-art h2{font-size:34px;line-height:1.15;margin:0 0 12px;letter-spacing:-.02em}
.login-art p{color:#c6cbf0;max-width:440px}
.login-art .feat{display:grid;grid-template-columns:1fr 1fr;gap:12px;max-width:480px}
.login-art .feat div{background:rgba(255,255,255,.07);border:1px solid rgba(255,255,255,.12);border-radius:12px;padding:12px 14px;font-size:13px}
.login-form{display:grid;place-items:center;padding:30px;background:var(--surface)}
.login-form form{width:100%;max-width:360px;display:flex;flex-direction:column;gap:14px}
.login-form h3{font-size:22px;margin:0}

/* ---------- Charts ---------- */
.bars{display:flex;align-items:flex-end;gap:8px;height:200px;padding:6px 4px 0}
.bars .col{flex:1;display:flex;flex-direction:column;align-items:center;gap:6px;min-width:0;height:100%;justify-content:flex-end}
.bars .pair{display:flex;gap:3px;align-items:flex-end;height:100%;width:100%;justify-content:center}
.bars .b{width:42%;max-width:18px;border-radius:4px 4px 0 0;min-height:2px}
.bars .lbl{font-size:10.5px;color:var(--muted)}
.legend{display:flex;gap:14px;font-size:12px;color:var(--text-2)}
.legend span{display:flex;align-items:center;gap:6px}
.list-row{display:flex;align-items:center;gap:10px;padding:10px 0;border-bottom:1px solid var(--border)}
.list-row:last-child{border-bottom:none}
.list-row .grow{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.progress{height:8px;background:var(--surface-2);border-radius:99px;overflow:hidden;border:1px solid var(--border)}
.progress i{display:block;height:100%;background:var(--primary);transition:width .2s}
.tabs{display:flex;gap:4px;border-bottom:1px solid var(--border);margin-bottom:16px}
.tabs button{border:none;background:none;padding:10px 14px;font-weight:550;color:var(--muted);cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px}
.tabs button.on{color:var(--primary);border-bottom-color:var(--primary)}
.perm-table td,.perm-table th{padding:7px 10px}
.items-table input{height:32px}
.inv-preview{background:#fff;color:#111;border:1px solid var(--border);border-radius:10px;padding:26px;font-size:12.5px}
.inv-preview table{width:100%;border-collapse:collapse}
.inv-preview td,.inv-preview th{border:1px solid #999;padding:6px 8px}

@media (max-width: 980px){
  .layout{grid-template-columns:1fr}
  .sidebar{position:fixed;left:0;top:0;bottom:0;width:260px;z-index:60;transform:translateX(-100%);transition:transform .2s}
  .sidebar.open{transform:none;box-shadow:var(--shadow-lg)}
  .menu-btn{display:inline-flex}
  .content{padding:16px}
  .topbar{padding:0 16px}
  .form-grid{grid-template-columns:1fr 1fr}
  .login{grid-template-columns:1fr}
  .login-art{display:none}
  .user-chip small,.user-chip .nm{display:none}
}
@media (max-width: 560px){ .form-grid{grid-template-columns:1fr} .form-grid .span2{grid-column:auto} }
.items-table th,.items-table tfoot td{position:static}
@media (max-width:560px){.kpis{grid-template-columns:1fr 1fr;gap:10px}.kpi{padding:12px}}
