/* ABC Brands · Supply Chain Intelligence */
:root, [data-theme="dark"] {
  --bg: #0b1220; --bg2: #0f1a2e; --panel: #131f36; --panel2: #18263f; --line: #24344f; --line2: #2e4262;
  --fg: #e7edf7; --fg2: #a9b7cc; --fg3: #7b8aa3;
  --acc: #2ec4b6; --acc2: #3a86ff; --ok: #2fbf71; --warn: #f4a259; --bad: #ef476f; --info: #4cc9f0;
  --s1: #3a86ff; --s2: #2ec4b6; --s3: #f4a259; --s4: #b388eb; --s5: #ef476f;
  --grid: rgba(255,255,255,.06); --shadow: 0 8px 28px rgba(0,0,0,.35);
  --heat0: #ef476f; --heat1: #f4a259; --heat2: #e9c46a; --heat3: #2a9d8f; --heat4: #1f6f6a;
}
[data-theme="light"] {
  --bg: #f3f6fb; --bg2: #e9eef7; --panel: #ffffff; --panel2: #f6f8fc; --line: #dbe3ef; --line2: #c8d3e3;
  --fg: #142033; --fg2: #46566e; --fg3: #6f7f97;
  --acc: #0f9488; --acc2: #2563eb; --ok: #15803d; --warn: #c2620a; --bad: #c8204b; --info: #0e7490;
  --s1: #2563eb; --s2: #0f9488; --s3: #d97706; --s4: #7c3aed; --s5: #c8204b;
  --grid: rgba(15,30,60,.08); --shadow: 0 6px 22px rgba(20,40,80,.12);
  --heat0: #e5486e; --heat1: #f59e4b; --heat2: #f3d36b; --heat3: #4fb3a6; --heat4: #2f7f78;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif; }
a { color: var(--acc2); }
button, input, select, textarea { font: inherit; color: inherit; }
select, input[type=text], input:not([type]), input[type=password] { background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; padding: 5px 9px; }
select option { background: var(--panel); color: var(--fg); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--fg3); } .ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(1200px 600px at 10% 10%, rgba(46,196,182,.18), transparent 60%),
  radial-gradient(900px 500px at 90% 90%, rgba(58,134,255,.18), transparent 60%), var(--bg); }
.login form { width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; font-size: 20px; } .login p { margin: 0 0 6px; color: var(--fg2); }
.login input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel2); }
.login .err { color: var(--bad); min-height: 18px; font-size: 13px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 800; letter-spacing: -.5px;
  color: #fff; background: linear-gradient(135deg, var(--acc2), var(--acc)); font-size: 13px; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--bg2); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column;
  gap: 4px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side .brand { padding: 4px 8px 14px; }
.side .brand b { display: block; font-size: 13px; } .side .brand small { color: var(--fg3); font-size: 11px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--fg2);
  cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.nav:hover { background: var(--panel); color: var(--fg); }
.nav.on { background: var(--panel2); color: var(--fg); box-shadow: inset 3px 0 0 var(--acc); }
.nav svg { width: 17px; height: 17px; flex: none; }
.nav .pill { margin-left: auto; }
.side .sp { flex: 1; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 22px; border-bottom: 1px solid var(--line);
  background: var(--bg); position: sticky; top: 0; z-index: 20; }
.top h2 { margin: 0; font-size: 18px; } .top .sub { color: var(--fg3); font-size: 12px; }
.top .grow { flex: 1; }
.btn { border: 1px solid var(--line2); background: var(--panel); padding: 7px 12px; border-radius: 9px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--acc); }
.btn.pri { background: linear-gradient(135deg, var(--acc2), var(--acc)); border: 0; color: #fff; font-weight: 600; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.content { padding: 18px 22px 40px; display: flex; flex-direction: column; gap: 16px; }

/* ---------- cards */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; min-width: 0; }
.card h3 { margin: 0 0 2px; font-size: 14px; } .card .hint { color: var(--fg3); font-size: 12px; margin: 0 0 10px; }
.card .head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card .head .grow { flex: 1; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; inset: auto -30px -40px auto; width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--k, var(--acc)) 22%, transparent), transparent 70%); }
.kpi .l { color: var(--fg3); font-size: 12px; } .kpi .v { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .n { font-size: 12px; color: var(--fg2); margin-top: 2px; }
.kpi.click { cursor: pointer; } .kpi.click:hover { border-color: var(--k, var(--acc)); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent; }
.p-shortage, .p-macfail, .p-critical, .p-late { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.p-at_risk, .p-warning, .p-hold { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.p-ok, .p-released, .p-received { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.p-info, .p-open, .p-confirmed, .p-in_transit { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }

/* ---------- tables */
.tw { overflow: auto; max-height: 560px; border-radius: 10px; border: 1px solid var(--line); }
table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.t th { position: sticky; top: 0; z-index: 2; background: var(--panel2); color: var(--fg2); text-align: left; font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--line2); white-space: nowrap; cursor: default; }
.t th[data-k] { cursor: pointer; } .t th[data-k]:hover { color: var(--fg); }
.t td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td.r, .t th.r { text-align: right; font-variant-numeric: tabular-nums; }
.t tr.click { cursor: pointer; } .t tr.click:hover td { background: var(--panel2); }
.t td.wrap { white-space: normal; min-width: 240px; }
.bar-in { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; min-width: 60px; }
.bar-in i { display: block; height: 100%; background: var(--acc); }

/* ---------- filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line2); background: var(--panel); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 11px; cursor: pointer; color: var(--fg2); }
.seg button.on { background: var(--acc); color: #fff; }

/* ---------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--fg3); font-size: 11px; }
.chart .val { fill: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .gl { stroke: var(--grid); } .chart .ax { stroke: var(--line2); }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line2); border-radius: 9px;
  padding: 7px 10px; font-size: 12px; box-shadow: var(--shadow); z-index: 10; white-space: nowrap; }
.tip b { display: block; margin-bottom: 2px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--fg2); margin: 4px 0 8px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.heat { display: grid; gap: 2px; font-size: 11px; }
.heat .c { height: 22px; border-radius: 4px; display: grid; place-items: center; color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; }
.heat .lab { color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 6px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.heat .wk { color: var(--fg3); text-align: center; }

/* ---------- alerts */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 9px 11px; border-radius: 10px; background: var(--panel2);
  border: 1px solid var(--line); font-size: 13px; cursor: default; }
.alert.click { cursor: pointer; } .alert.click:hover { border-color: var(--acc); }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.d-critical { background: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 20%, transparent); }
.d-warning { background: var(--warn); } .d-info { background: var(--info); }

/* ---------- modal */
.modal-bg { position: fixed; inset: 0; background: rgba(5,10,20,.55); z-index: 50; display: flex; justify-content: flex-end; }
.drawer { width: min(860px, 100vw); height: 100vh; overflow: auto; background: var(--bg); border-left: 1px solid var(--line);
  padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer .x { margin-left: auto; }

/* ---------- sliders */
.ctl { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.ctl label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--fg2); }
.ctl input[type=range] { accent-color: var(--acc); width: 100%; }
.ctl select { padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line2); background: var(--panel2); }
.ctl output { font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }

/* ---------- AI */
.ai-fab { position: fixed; right: 22px; bottom: 22px; z-index: 40; border-radius: 999px; padding: 11px 16px; box-shadow: var(--shadow); }
.ai { position: fixed; right: 22px; bottom: 22px; width: min(460px, calc(100vw - 30px)); height: min(680px, calc(100vh - 40px));
  background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; box-shadow: var(--shadow); z-index: 45;
  display: flex; flex-direction: column; overflow: hidden; }
.ai header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.ai header b { flex: 1; }
.ai .msgs { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ai .m { padding: 9px 12px; border-radius: 12px; max-width: 92%; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.ai .m.u { align-self: flex-end; background: color-mix(in srgb, var(--acc2) 22%, var(--panel)); }
.ai .m.a { align-self: flex-start; background: var(--panel2); border: 1px solid var(--line); }
.ai .m.a table { border-collapse: collapse; margin: 6px 0; font-size: 12px; }
.ai .m.a td, .ai .m.a th { border: 1px solid var(--line2); padding: 3px 6px; }
.ai .m.a h3, .ai .m.a h4 { margin: 8px 0 4px; font-size: 13px; }
.ai .m.a p { margin: 4px 0; } .ai .m.a ul { margin: 4px 0; padding-left: 18px; }
.ai .tools { font-size: 11px; color: var(--fg3); display: flex; flex-direction: column; gap: 2px; }
.ai .chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.ai .chips button { border: 1px solid var(--line2); background: var(--panel2); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.ai .chips button:hover { border-color: var(--acc); }
.ai form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.ai textarea { flex: 1; resize: none; height: 40px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel2); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line2); border-top-color: var(--acc); border-radius: 50%; animation: sp 1s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }

.note { font-size: 12px; color: var(--fg3); }
.empty { padding: 24px; text-align: center; color: var(--fg3); }
.loading { padding: 40px; text-align: center; color: var(--fg3); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; overflow-x: auto; }
  .side .brand, .side .sp { display: none; }
  .nav span { display: none; }
  .g2 { grid-template-columns: 1fr; }
}
