:root {
  --canvas: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f7f8fa;
  --ink: #16181d;
  --ink-muted: #5b6270;
  --ink-faint: #8b93a1;
  --line: #e3e6ec;
  --red: #e11927;
  --violet: #635bff;
  --violet-soft: #eeecff;
  --green: #00c853;
  --green-soft: #e6f9ee;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .05), 0 4px 14px rgba(16, 20, 30, .06);
  --shadow-lg: 0 2px 6px rgba(16, 20, 30, .07), 0 12px 34px rgba(16, 20, 30, .10);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ------------------------------------------------------------------ header */

header {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 16px; }
.brand .mark { width: 4px; height: 20px; background: var(--red); border-radius: 2px; align-self: center; }
.brand span { color: var(--ink-faint); font-size: 12px; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--surface-alt); color: var(--ink-muted);
  border: 1px solid var(--line);
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); }
.pill.ok { background: var(--green-soft); color: #0a6b35; border-color: #b7ecca; }
.pill.ok .dot { background: var(--green); }
.pill.bad { background: #fdeaec; color: #9b1520; border-color: #f6c6cb; }
.pill.bad .dot { background: var(--red); }

/* -------------------------------------------------------------------- tabs */

nav.tabs { display: flex; gap: 2px; padding: 0 28px; border-bottom: 1px solid var(--line); background: var(--surface); }
nav.tabs button {
  background: none; border: none; cursor: pointer;
  padding: 12px 16px; font-size: 13.5px; font-weight: 500;
  color: var(--ink-muted); border-bottom: 2px solid transparent;
}
nav.tabs button:hover { color: var(--ink); }
nav.tabs button.active { color: var(--ink); border-bottom-color: var(--red); }

main { padding: 22px 28px 60px; max-width: 1560px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ------------------------------------------------------------------- cards */

.grid { display: grid; gap: 18px; }
.grid.three { grid-template-columns: 320px minmax(0, 1fr) 340px; align-items: start; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 1280px) { .grid.three { grid-template-columns: 1fr; } .grid.two { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card > header {
  position: static; padding: 12px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; background: var(--surface);
}
.card > header h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); }
.card > header .spacer { margin-left: auto; }
.card .body { padding: 16px; }
.card .body.tight { padding: 0; }

/* ------------------------------------------------------------------ inputs */

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; font-weight: 500; color: var(--ink-muted); margin-bottom: 5px; }

input[type=text], input[type=number], input[type=email], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--violet); box-shadow: 0 0 0 3px var(--violet-soft); }
textarea { resize: vertical; min-height: 62px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 500; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-alt); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #524aeb; }
.btn.danger { color: var(--red); border-color: #f3c9cd; }
.btn.danger:hover:not(:disabled) { background: #fdeaec; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- PO list */

.po-search { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.po-list { max-height: 560px; overflow-y: auto; }
.po-item {
  padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; gap: 10px; align-items: baseline;
}
.po-item:hover { background: var(--surface-alt); }
.po-item.selected { background: var(--violet-soft); box-shadow: inset 3px 0 0 var(--violet); }
.po-item .po-id { font-weight: 600; font-variant-numeric: tabular-nums; }
.po-item .po-sup { color: var(--ink-muted); font-size: 12.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.po-item .po-date { color: var(--ink-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- scenarios */

.scenario-group + .scenario-group { margin-top: 18px; }
.scenario-group > h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--violet); margin-bottom: 8px; font-weight: 600;
}
.scenario {
  border: 1px solid var(--line); border-radius: 6px;
  padding: 10px 12px; margin-bottom: 8px; background: var(--surface);
}
.scenario.on { border-color: var(--violet); background: #fbfaff; }
.scenario .head { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; }
.scenario .head input { margin: 3px 0 0; flex-shrink: 0; }
.scenario .head .label { font-weight: 500; }
.scenario .desc { font-size: 12px; color: var(--ink-muted); margin-top: 3px; }
.scenario .params { display: none; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.scenario.on .params { display: flex; }
.scenario .params label.field { margin: 0; flex: 1 1 130px; min-width: 120px; }

/* ------------------------------------------------------------------ tables */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-muted); font-weight: 600;
  padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--surface-alt);
  position: sticky; top: 0;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: var(--surface-alt); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ------------------------------------------------------------------ result */

.result {
  border: 1px solid var(--line); border-left: 3px solid var(--green);
  border-radius: 6px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface);
}
.result.warn { border-left-color: var(--amber); }
.result .top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.result .top .num-label { font-weight: 600; }
.result .top .amt { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.result ul { margin: 8px 0 0; padding-left: 18px; color: var(--ink-muted); font-size: 12.5px; }
.result .outcome { font-size: 12.5px; color: var(--ink-muted); margin-top: 6px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500; background: var(--violet-soft); color: #40389c;
  margin: 0 4px 4px 0;
}
.tag.clean { background: var(--green-soft); color: #0a6b35; }
.tag.warn { background: var(--amber-soft); color: var(--amber); }

.empty { padding: 34px 20px; text-align: center; color: var(--ink-faint); font-size: 13px; }
.muted { color: var(--ink-muted); }
.small { font-size: 12px; }
.spinner {
  width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 100;
  background: var(--ink); color: #fff; padding: 11px 16px;
  border-radius: 6px; box-shadow: var(--shadow-lg); max-width: 420px;
  opacity: 0; transform: translateY(8px); transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--red); }

pre.crib {
  background: var(--surface-alt); border: 1px solid var(--line); border-radius: 6px;
  padding: 14px; font-size: 12px; line-height: 1.55; overflow-x: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre-wrap;
}

.batch-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; font-size: 12.5px;
}
.batch-item .po { font-weight: 600; }
.batch-item .tags { flex: 1; }

/* ------------------------------------------------------- initials / tagging */

.initials-box {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 4px 3px 10px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface-alt);
}
.initials-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-faint); font-weight: 600;
}
.initials-box input {
  width: 52px; padding: 3px 7px; text-align: center;
  text-transform: uppercase; font-weight: 600; letter-spacing: .04em;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.initials-preview {
  font-size: 11.5px; color: var(--ink-muted); padding-right: 7px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ------------------------------------------------------------ type-ahead */

.combo { position: relative; }
.combo-list {
  display: none; position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; box-shadow: var(--shadow-lg);
}
.combo-list.open { display: block; }
.combo-opt { padding: 8px 11px; cursor: pointer; border-bottom: 1px solid var(--line); }
.combo-opt:last-child { border-bottom: none; }
.combo-opt:hover, .combo-opt.active { background: var(--violet-soft); }
.combo-opt .name { font-weight: 500; }
.combo-opt .meta { font-size: 11.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.combo-opt.note { color: var(--ink-faint); cursor: default; font-size: 12.5px; }
.combo-opt.note:hover { background: none; }

.combo-chosen { display: none; margin-top: 7px; align-items: center; gap: 8px; }
.combo-chosen.on { display: flex; }
.combo-chosen .who { font-size: 12.5px; }
.combo-chosen .who strong { font-weight: 600; }
.combo-chosen .code {
  font-size: 11px; color: #40389c; background: var(--violet-soft);
  padding: 2px 7px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
