:root {
  --bg: #0b0e13;
  --bg-2: #10141b;
  --panel: #141922;
  --panel-2: #1a202b;
  --line: #252d3a;
  --line-2: #323c4d;
  --text: #e6ebf2;
  --muted: #8592a6;
  --dim: #5b6779;
  --accent: #c6ff3d;
  --accent-ink: #0b0e13;
  --accent-glow: rgba(198, 255, 61, .18);
  --cyan: #4fd6ff;
  --amber: #ffb547;
  --red: #ff5d6c;
  --green: #3ddc97;
  --radius: 10px;
  --display: 'Chakra Petch', ui-monospace, monospace;
  --body: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 85% -10%, rgba(79, 214, 255, .07), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(198, 255, 61, .05), transparent 60%),
    linear-gradient(var(--bg-2) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-2) 1px, transparent 1px);
  background-size: auto, auto, 28px 28px, 28px 28px;
  color: var(--text);
  font: 14px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.show-sm { display: none; }
@media (max-width: 760px) { .show-sm { display: inline; } }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 28px;
  padding: 22px 14px;
  background: linear-gradient(180deg, rgba(20, 25, 34, .92), rgba(11, 14, 19, .92));
  border-right: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.brand strong { font: 700 17px/1 var(--display); letter-spacing: .14em; display: block; }
.brand small { color: var(--dim); font: 500 10px/1.6 var(--mono); letter-spacing: .2em; text-transform: uppercase; }
.chip-logo {
  width: 30px; height: 30px; border: 2px solid var(--accent); border-radius: 5px; position: relative;
  box-shadow: 0 0 16px var(--accent-glow);
}
.chip-logo::after { content: ''; position: absolute; inset: 7px; background: var(--accent); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none;
  font: 600 13px/1 var(--display); letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid transparent; transition: .15s;
}
nav a .k { font: 500 10px var(--mono); color: var(--dim); }
nav a:hover { color: var(--text); background: var(--panel); }
nav a.active { color: var(--accent); background: var(--panel); border-color: var(--line); box-shadow: inset 2px 0 0 var(--accent); }
nav a em { margin-left: auto; font: 600 10px/1 var(--mono); font-style: normal; color: var(--accent-ink); background: var(--amber); border-radius: 99px; padding: 3px 6px; }
nav a em:empty { display: none; }
.rail-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; padding: 0 10px; color: var(--dim); font: 11px var(--mono); }
.led { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2.4s infinite; }
.led.off { background: var(--red); box-shadow: 0 0 8px var(--red); }
@keyframes pulse { 50% { opacity: .45; } }

main { padding: 22px 26px 60px; min-width: 0; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi {
  position: relative; padding: 14px 16px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); overflow: hidden;
  animation: rise .45s both;
}
.kpi::before { content: ''; position: absolute; left: 0; top: 0; width: 28px; height: 2px; background: var(--c, var(--accent)); }
.kpi label { display: block; color: var(--muted); font: 600 10px/1 var(--display); letter-spacing: .14em; text-transform: uppercase; }
.kpi b { display: block; margin-top: 10px; font: 600 22px/1 var(--mono); letter-spacing: -.02em; }
.kpi small { color: var(--dim); font: 11px var(--mono); }
.kpi:nth-child(2) { animation-delay: .05s } .kpi:nth-child(3) { animation-delay: .1s } .kpi:nth-child(4) { animation-delay: .15s } .kpi:nth-child(5) { animation-delay: .2s }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- generic ---------- */
.view { animation: rise .3s both; }
.head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
h1 { margin: 0; font: 700 26px/1 var(--display); letter-spacing: .04em; text-transform: uppercase; }
h1 span { color: var(--dim); font: 500 12px var(--mono); letter-spacing: .1em; margin-left: 10px; vertical-align: middle; }
h2 { margin: 0 0 12px; font: 600 13px/1 var(--display); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.card { background: rgba(20, 25, 34, .86); border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  font: 600 12px/1 var(--display); letter-spacing: .08em; text-transform: uppercase; transition: .15s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 0 0 0 var(--accent-glow); }
.btn.primary:hover { box-shadow: 0 0 0 5px var(--accent-glow); }
.btn.warn { color: var(--amber); border-color: rgba(255, 181, 71, .4); }
.btn.danger { color: var(--red); border-color: rgba(255, 93, 108, .35); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 11px; }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }

.input, select.input, textarea.input {
  height: 36px; padding: 0 11px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line-2); outline: none; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: 70px; padding: 9px 11px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.input.search { width: 240px; padding-left: 32px; background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%235b6779' stroke-width='2'%3E%3Ccircle cx='6' cy='6' r='4.5'/%3E%3Cpath d='m9.5 9.5 3 3'/%3E%3C/svg%3E") no-repeat 11px 50%; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font: 600 10px/1 var(--display); letter-spacing: .14em; text-transform: uppercase; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.seg { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--bg); border: 1px solid var(--line-2); }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font: 600 11px/1 var(--display); letter-spacing: .08em; text-transform: uppercase; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 11px 14px; color: var(--dim); font: 600 10px/1 var(--display); letter-spacing: .14em; text-transform: uppercase; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid rgba(37, 45, 58, .6); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(26, 32, 43, .7); }
tr.clickable { cursor: pointer; }
td.r, th.r { text-align: right; }
.item-name b { display: block; font-weight: 600; }
.item-name small { color: var(--dim); font: 11px var(--mono); }
.empty { padding: 40px; text-align: center; color: var(--dim); font: 12px var(--mono); }

.tag { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 5px; font: 600 10px/1.2 var(--mono); letter-spacing: .04em; white-space: nowrap; border: 1px solid; }
.tag.ours { color: var(--cyan); border-color: rgba(79, 214, 255, .3); background: rgba(79, 214, 255, .06); }
.tag.tp { color: var(--amber); border-color: rgba(255, 181, 71, .3); background: rgba(255, 181, 71, .06); }
.tag.paid { color: var(--green); border-color: rgba(61, 220, 151, .3); background: rgba(61, 220, 151, .06); }
.tag.cat { color: var(--muted); border-color: var(--line-2); }
.stock-n { font: 600 13px var(--mono); }
.stock-n.low { color: var(--amber); } .stock-n.zero { color: var(--red); }

/* ---------- sell ---------- */
.sell { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; background: var(--bg); }
.stepper button { width: 30px; height: 30px; border: 0; background: none; cursor: pointer; color: var(--muted); font: 600 16px/1 var(--mono); }
.stepper button:hover:not(:disabled) { color: var(--accent); background: var(--panel-2); }
.stepper button:disabled { opacity: .3; cursor: not-allowed; }
.stepper output { width: 30px; text-align: center; font: 600 13px var(--mono); }
tr.picked { background: linear-gradient(90deg, rgba(198, 255, 61, .07), transparent 70%); }
tr.picked td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
tr.out { opacity: .45; }
.price-in { width: 96px; height: 30px; text-align: right; font-family: var(--mono); }
.money-in { position: relative; display: inline-block; }
.money-in::before { content: '$'; position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--dim); font: 12px var(--mono); pointer-events: none; }
.money-in .input { padding-left: 20px; }

.panel { position: sticky; top: 22px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.panel .lines { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow: auto; }
.panel .line { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 8px 10px; border-radius: 7px; background: var(--bg); border: 1px solid var(--line); }
.panel .line span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel .line .num { color: var(--muted); white-space: nowrap; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; border-top: 1px dashed var(--line-2); }
.total-row span { color: var(--muted); font: 600 11px var(--display); letter-spacing: .14em; text-transform: uppercase; }
.total-row b { font: 600 28px/1 var(--mono); color: var(--accent); text-shadow: 0 0 22px var(--accent-glow); }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(255, 181, 71, .3); background: rgba(255, 181, 71, .05); cursor: pointer; }
.check input { accent-color: var(--amber); margin-top: 2px; }
.check small { display: block; color: var(--muted); font-size: 12px; }

/* ---------- categories chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 10px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--bg); font: 500 12px var(--body); }
.chip .n { color: var(--dim); font: 11px var(--mono); }
.chip button { border: 0; background: none; color: var(--dim); cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.chip button:hover { color: var(--text); background: var(--panel-2); }

.stack { display: flex; flex-direction: column; gap: 16px; }
.sup-tot { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.sup-card { padding: 12px 14px; }
.sup-card b { display: block; font: 600 14px var(--display); letter-spacing: .04em; margin-bottom: 6px; }
.sup-card .row { display: flex; justify-content: space-between; font: 12px var(--mono); color: var(--muted); }
.sup-card .row .o { color: var(--amber); } .sup-card .row .p { color: var(--green); }

/* ---------- modal ---------- */
dialog {
  width: min(560px, calc(100vw - 32px)); padding: 0; border-radius: 14px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
dialog.wide { width: min(780px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 7, 10, .7); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.m-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.m-head h3 { margin: 0; font: 700 16px var(--display); letter-spacing: .08em; text-transform: uppercase; }
.m-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.err { color: var(--red); font-size: 13px; min-height: 0; }
.err:empty { display: none; }
.inline-add { display: flex; gap: 6px; }
.inline-add .input { flex: 1; }
.meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.meta div { padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
.meta label { display: block; color: var(--dim); font: 600 9px var(--display); letter-spacing: .14em; text-transform: uppercase; margin-bottom: 4px; }

/* toast */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { padding: 11px 14px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line-2); box-shadow: 0 10px 30px rgba(0, 0, 0, .5); font-size: 13px; animation: rise .2s both; max-width: 340px; }
.toast.ok { border-color: rgba(198, 255, 61, .5); } .toast.ok::before { content: '✓ '; color: var(--accent); }
.toast.bad { border-color: rgba(255, 93, 108, .5); } .toast.bad::before { content: '! '; color: var(--red); font-weight: 700; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 980px) {
  .sell { grid-template-columns: 1fr; }
  .panel { position: static; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: sticky; top: 0; height: auto; z-index: 10; flex-direction: row; align-items: center; gap: 10px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand small, .rail-foot { display: none; }
  nav { flex-direction: row; }
  nav a { padding: 8px 10px; white-space: nowrap; }
  nav a .k { display: none; }
  main { padding: 16px 16px 60px; }
  .kpis { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px 18px; padding: 0 16px; scrollbar-width: none; }
  .kpi { flex: 0 0 62%; scroll-snap-align: start; }
  .kpi b { font-size: 18px; }
  .input.search { width: 100%; }
  .toolbar { width: 100%; }
  .grid2, .grid3, .meta { grid-template-columns: 1fr; }
  .hide-sm { display: none !important; }
  td, th { padding: 10px 10px; }

  /* tables become stacked cards on phones */
  .cards table, .cards tbody { display: block; }
  .cards thead { display: none; }
  .cards tbody tr { display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .cards tbody tr:last-child { border-bottom: 0; }
  .cards td { padding: 0; border: 0; text-align: left; }
  .cards td.full { grid-column: 1 / -1; }
  .cards td.r, .cards td.rs { text-align: right; }
  .cards td.sl { text-align: left; }
  .cards td.first { order: -1; }
  .cards td[data-l]::before { content: attr(data-l) ' '; color: var(--dim); font: 600 10px var(--display); letter-spacing: .12em; text-transform: uppercase; }
  .cards tfoot { display: block; padding: 12px 14px; text-align: right; }
  .cards tfoot tr { display: block; }
  .cards tfoot td { display: inline; padding: 0; border: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }
@media print {
  .rail, .kpis, #toasts, .m-foot, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
}
