:root {
  --brick: #C4451C; --brick-light: #E8673A; --brick-bg: rgba(196,69,28,0.14);
  --gold: #D4A853;
  --bg: #17171B; --surface: #202026; --surface2: #2A2A31; --surface3: #33333B;
  --border: rgba(255,255,255,0.08); --border2: rgba(255,255,255,0.14);
  --text1: #F0EDE8; --text2: #A9A6AB; --text3: #75737A;
  --green: #2DD4A0; --green-bg: rgba(45,212,160,0.12);
  --blue: #60A5FA; --blue-bg: rgba(96,165,250,0.12);
  --amber: #FBBF24; --amber-bg: rgba(251,191,36,0.12);
  --red: #F87171; --red-bg: rgba(248,113,113,0.12);
  --purple: #A78BFA; --purple-bg: rgba(167,139,250,0.12);
  --radius: 14px; --radius-sm: 9px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: 'Outfit', system-ui, sans-serif; background: var(--bg); color: var(--text1); font-size: 15px; line-height: 1.45; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brick-light); }
.muted { color: var(--text2); }
.dim { color: var(--text3); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  background: rgba(23,23,27,0.88); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.logo { font-weight: 800; font-size: 20px; letter-spacing: -.02em; text-decoration: none;
  background: linear-gradient(135deg, var(--brick-light), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo small { font-size: 11px; font-weight: 600; color: var(--text3); -webkit-text-fill-color: var(--text3); margin-left: 4px; }
.spacer { flex: 1; }
.live { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text2); white-space: nowrap; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(45,212,160,.6); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(45,212,160,.55); } 70% { box-shadow: 0 0 0 8px rgba(45,212,160,0); } 100% { box-shadow: 0 0 0 0 rgba(45,212,160,0); } }
.who { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

/* ---------- Layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 20px 60px; }
.demo-note { font-size: 12.5px; color: var(--text3); background: var(--surface); border: 1px dashed var(--border2); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 20px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; padding: 9px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--text2); font-weight: 500; font-size: 14px; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text1); }
.tab.active { background: var(--brick); color: #fff; }
.tab .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: rgba(255,255,255,0.18); font-size: 11.5px; text-align: center; }
h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
h3 { font-size: 16px; font-weight: 600; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.section-head p { font-size: 13.5px; color: var(--text2); }
.section + .section { margin-top: 28px; }

/* ---------- Cards / grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.grid { display: grid; gap: 14px; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 20px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.kpi .card .lbl { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--text3); font-weight: 600; }
.kpi .card .val { font-size: 26px; font-weight: 700; font-family: var(--mono); margin-top: 4px; }
.kpi .card .sub { font-size: 12.5px; color: var(--text2); }

/* Stock card (customer) */
.stock-card { display: flex; flex-direction: column; gap: 10px; }
.stock-card .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.stock-card .type { font-weight: 700; font-size: 16.5px; }
.stock-card .hi { font-size: 12.5px; color: var(--text3); }
.stock-card .dealer { font-size: 13.5px; color: var(--text2); }
.stock-card .avail { font-family: var(--mono); font-size: 28px; font-weight: 700; color: var(--green); line-height: 1.1; border-radius: 6px; transition: background .3s; }
.stock-card .avail.out { color: var(--red); font-size: 20px; }
.stock-card .row { display: flex; justify-content: space-between; font-size: 13.5px; gap: 8px; }
.stock-card .row span:last-child { text-align: right; }
.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { background: rgba(251,191,36,0.45); } 100% { background: transparent; } }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-green { background: var(--green-bg); color: var(--green); }
.b-blue { background: var(--blue-bg); color: var(--blue); }
.b-amber { background: var(--amber-bg); color: var(--amber); }
.b-red { background: var(--red-bg); color: var(--red); }
.b-purple { background: var(--purple-bg); color: var(--purple); }
.b-grey { background: var(--surface3); color: var(--text2); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 15px; border-radius: 10px; border: 1px solid var(--border2);
  background: var(--surface2); color: var(--text1); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: rgba(255,255,255,0.28); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brick); border-color: var(--brick); color: #fff; }
.btn.primary:hover { background: var(--brick-light); border-color: var(--brick-light); }
.btn.green { background: #138a67; border-color: #138a67; color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Filters / forms ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12.5px; color: var(--text2); font-weight: 500; }
.input, select.input, textarea.input { width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border2); background: var(--bg); color: var(--text1); outline: none; min-height: 40px; }
.input:focus { border-color: var(--brick-light); box-shadow: 0 0 0 3px var(--brick-bg); }
textarea.input { min-height: 64px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 6px 0; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--brick); }
.check .amt { margin-left: auto; color: var(--text2); font-size: 13px; }
.hint { font-size: 12.5px; color: var(--text3); }
.error { color: var(--red); font-size: 13px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text3); font-weight: 600; background: var(--surface2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--mono); }
td.actions { text-align: right; }
td.wrap { white-space: normal; min-width: 160px; }
.empty { padding: 28px; text-align: center; color: var(--text3); }

/* ---------- Orders ---------- */
.order { display: flex; flex-direction: column; gap: 12px; }
.order .head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.order .title { font-weight: 700; font-size: 16px; }
.order .meta { font-size: 13.5px; color: var(--text2); }
.order .total { font-family: var(--mono); font-size: 20px; font-weight: 700; }
.steps { display: flex; gap: 4px; }
.steps .s { flex: 1; height: 5px; border-radius: 3px; background: var(--surface3); }
.steps .s.done { background: var(--green); }
.steps-l { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text3); margin-top: 4px; }
.breakdown { width: 100%; font-size: 13.5px; }
.breakdown td { padding: 4px 0; border: 0; white-space: normal; }
.breakdown td:last-child { text-align: right; font-family: var(--mono); white-space: nowrap; }
.breakdown tr.total td { border-top: 1px solid var(--border2); padding-top: 8px; font-weight: 700; font-size: 15px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--text3); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- Login ---------- */
.login { max-width: 900px; margin: 40px auto; padding: 0 20px; }
.login h1 { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.login .grid { grid-template-columns: 1fr 1fr; margin-top: 22px; }
.login .card { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.login .role { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }

/* ---------- Dialog ---------- */
dialog { margin: auto; border: 1px solid var(--border2); border-radius: 16px; background: var(--surface); color: var(--text1); padding: 0; width: min(620px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(3px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.x { background: none; border: 0; color: var(--text2); font-size: 22px; cursor: pointer; line-height: 1; padding: 2px 6px; }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: calc(100% - 32px); max-width: 420px; }
.toast { background: var(--surface3); border: 1px solid var(--border2); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.4); animation: tin .25s ease-out; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 720px) {
  .wrap { padding: 16px 16px 60px; }
  .topbar { padding: 10px 16px; gap: 8px; }
  .who { display: none; }
  .login .grid, .two-col, .form-grid { grid-template-columns: 1fr; }
  .grid.kpi { grid-template-columns: 1fr 1fr; }
  .kpi .card .val { font-size: 21px; }
  .live .txt { display: none; }
}
td.actions .btn-row { flex-wrap: nowrap; }
