/* Arb Hub — dark-first design system. Hand-written, no frameworks. */

/* The hidden attribute must always win: author display rules (.panel etc.)
   otherwise override the UA's [hidden] { display: none }. */
[hidden] { display: none !important; }

:root {
  --bg-0: #0e1116;   /* page */
  --bg-1: #151a21;   /* surface */
  --bg-2: #1b222b;   /* raised surface */
  --bg-3: #222b36;   /* hover / controls */
  --border: #28313d;
  --border-soft: #1f2731;
  --text: #d8dee7;
  --text-dim: #8b95a3;
  --text-faint: #5d6773;
  --accent: #6ea1d8;
  --accent-strong: #4c86c8;
  --accent-dim: rgba(110, 161, 216, 0.14);
  --green: #46b878;
  --amber: #d9a03f;
  --red: #d96459;
  --violet: #a687e0;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text);
  font: 500 13px/1.45 var(--sans);
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }

/* ---------- layout: fixed sidebar + main ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 188px;
  background: var(--bg-1); border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; padding: 14px 10px; gap: 2px;
}
.sidebar .brand {
  padding: 2px 10px 14px; font-weight: 600; font-size: 14px; letter-spacing: 0.02em;
}
.sidebar .brand small { display: block; color: var(--text-faint); font-weight: 500; font-size: 11px; }
.sidebar a.nav-link {
  display: block; padding: 7px 10px; border-radius: 6px; color: var(--text-dim);
  font-weight: 500; border-left: 2px solid transparent;
}
.sidebar a.nav-link:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
.sidebar a.nav-link.active {
  background: var(--accent-dim); color: var(--accent); border-left-color: var(--accent); font-weight: 600;
}
.sidebar .nav-spacer { flex: 1; }
.sidebar .nav-foot { padding: 6px 10px; color: var(--text-faint); font-size: 11px; }

.main {
  margin-left: 188px; height: 100vh;
  display: flex; flex-direction: column; min-width: 0;
}

/* ---------- toolbar ---------- */
.toolbar {
  flex: none; padding: 10px 16px 8px; background: var(--bg-0);
  border-bottom: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 8px;
}
/* wrap, never clip: the merge added the source switch + spreadsheet picker to
   this row on top of the six list tabs; a single non-wrapping flex row would
   overflow and (under body{overflow:hidden}) push the right-most tabs off the
   clipped edge where they can't be clicked. Wrapping keeps every control
   reachable on any width. */
.toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; row-gap: 8px; min-height: 26px; }
.toolbar-row .spacer { flex: 1; }
.page-title { font-size: 15px; font-weight: 600; margin: 0; }
.meta { color: var(--text-faint); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusline { color: var(--text-dim); font-size: 12px; }
.kbd-hint { color: var(--text-faint); font-size: 11px; }
.kbd-hint b { color: var(--text-dim); font-weight: 600; font-family: var(--mono); }

/* tabs (segmented control) — flex:none so a crowded toolbar-row wraps the whole
   control to the next line intact rather than shrinking/clipping its buttons.
   max-width + overflow-x: on viewports narrower than the strip itself it
   clamps and scrolls internally instead of overflowing the clipped body. */
.tabs { display: inline-flex; flex: none; max-width: 100%; overflow-x: auto; background: var(--bg-2); border: 1px solid var(--border); border-radius: 7px; padding: 2px; gap: 2px; }
.tabs button {
  border: 0; background: transparent; color: var(--text-dim); font: 500 12.5px var(--sans);
  padding: 4px 12px; border-radius: 5px; cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--bg-3); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }

/* ---------- leads toolbar control groups (source switch + pickers) ---------- */
/* JS toggles these between display:none and their shown flex here, so a
   `style.display = ""` reset falls back to a properly aligned inline-flex. */
/* 0 1 auto + min-width:0 (not flex:none): the picker group must be able to
   shrink — toolbar wrap can't rescue a single item wider than the row. */
.spreadsheet-pick { display: inline-flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0; }
.spreadsheet-pick select { max-width: min(240px, 50vw); }
.scanfile { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.viewbar { flex: none; }
/* the "Upload new…" path into /upload, always visible beside the picker in
   Spreadsheets mode so there is a clear way to add a supplier sheet. */
#spreadsheet-upload { white-space: nowrap; }

/* ---------- buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  font: 500 12.5px var(--sans); padding: 5px 12px; border-radius: 6px; cursor: pointer;
}
.btn:hover { border-color: var(--text-faint); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-danger { color: var(--red); border-color: rgba(217, 100, 89, 0.4); background: transparent; }
.btn-danger:hover { background: rgba(217, 100, 89, 0.12); border-color: var(--red); }
.btn-sm { padding: 2px 9px; font-size: 11.5px; border-radius: 5px; }

input[type="text"], input[type="number"], input[type="password"], select {
  background: var(--bg-1); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px; font: 500 12.5px var(--sans); min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent-strong); }
input::placeholder { color: var(--text-faint); }
input[type="checkbox"] { accent-color: var(--accent-strong); }
label.field { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--text-dim); }
label.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; }

/* ---------- chips & badges ---------- */
.chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; line-height: 16px; border: 1px solid transparent; white-space: nowrap;
}
.chip-ok      { color: var(--green);  background: rgba(70, 184, 120, 0.12); border-color: rgba(70, 184, 120, 0.3); }
.chip-bad     { color: #e08881;       background: rgba(217, 100, 89, 0.12); border-color: rgba(217, 100, 89, 0.3); }
.chip-warn    { color: var(--amber);  background: rgba(217, 160, 63, 0.12); border-color: rgba(217, 160, 63, 0.3); }
.chip-violet  { color: var(--violet); background: rgba(166, 135, 224, 0.12); border-color: rgba(166, 135, 224, 0.3); }
.chip-neutral { color: var(--text-dim); background: var(--bg-3); border-color: var(--border); }
.chip-accent  { color: var(--accent); background: var(--accent-dim); border-color: rgba(110, 161, 216, 0.35); }

.badge-amz {
  display: inline-block; padding: 0 6px; border-radius: 4px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; line-height: 16px;
  color: #e08881; background: rgba(217, 100, 89, 0.16); border: 1px solid rgba(217, 100, 89, 0.35);
}
.badge-zero {
  display: inline-block; padding: 0 6px; border-radius: 4px;
  font-size: 10.5px; font-weight: 700; line-height: 16px;
  color: var(--violet); background: rgba(166, 135, 224, 0.14); border: 1px solid rgba(166, 135, 224, 0.35);
}

.roi-good { color: var(--green); font-weight: 600; }
.roi-mid  { color: var(--amber); font-weight: 600; }
.roi-bad  { color: var(--red);   font-weight: 600; }
.roi-flat { color: var(--text); }
.subtext { display: block; color: var(--text-faint); font-size: 10.5px; line-height: 1.2; }
.faint { color: var(--text-faint); }

.link-mini {
  font-family: var(--mono); font-size: 11px; padding: 0 5px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--text-dim); background: var(--bg-2);
}
.link-mini:hover { color: var(--accent); border-color: var(--accent-strong); text-decoration: none; }

/* ---------- grid host ---------- */
.grid-wrap { flex: 1; min-height: 0; padding: 0 16px 12px; display: flex; }
#grid { flex: 1; min-height: 0; }

/* ---------- Tabulator (midnight) overrides ---------- */
.tabulator {
  background: var(--bg-1); border: 1px solid var(--border-soft); border-radius: 8px;
  font: 500 12.5px var(--sans);
}
.tabulator .tabulator-header {
  background: var(--bg-2); border-bottom: 1px solid var(--border); color: var(--text-dim);
}
.tabulator .tabulator-header .tabulator-col {
  background: var(--bg-2); border-right: 1px solid var(--border-soft);
}
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 6px 8px; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title { font-weight: 600; font-size: 11.5px; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover { background: var(--bg-3); }
.tabulator .tabulator-header .tabulator-header-filter input,
.tabulator .tabulator-header .tabulator-header-filter select {
  background: var(--bg-0); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 6px; font-size: 11.5px;
}
.tabulator-row {
  background: var(--bg-1); border-bottom: 1px solid var(--border-soft); color: var(--text);
  min-height: 0;
}
.tabulator-row.tabulator-row-even { background: var(--bg-1); }
.tabulator-row.tabulator-selectable:hover { background: var(--bg-2); }
.tabulator-row.tabulator-selected,
.tabulator-row.tabulator-selected:hover { background: var(--accent-dim); }
.tabulator-row.row-active { box-shadow: inset 3px 0 0 var(--accent); background: var(--bg-2); }
.tabulator-row.row-active.tabulator-selected { background: var(--accent-dim); }
.tabulator-row .tabulator-cell { border-right: 1px solid var(--border-soft); padding: 4px 8px; }
.tabulator-row .tabulator-cell.tabulator-frozen { background: inherit; }
.tabulator .tabulator-placeholder .tabulator-placeholder-contents { color: var(--text-faint); }
.tabulator .tabulator-alert { background: rgba(14, 17, 22, 0.6); }
.tabulator .tabulator-alert .tabulator-alert-msg {
  background: var(--bg-2); color: var(--text-dim); border: 1px solid var(--border); border-radius: 8px;
}
.tabulator-edit-list { background: var(--bg-2); border: 1px solid var(--border); }
.tabulator-edit-list .tabulator-edit-list-item { color: var(--text); }
.tabulator-edit-list .tabulator-edit-list-item.active,
.tabulator-edit-list .tabulator-edit-list-item:hover { background: var(--accent-dim); color: var(--text); }

.cell-product { line-height: 1.25; overflow: hidden; }
.cell-product .p-brand { color: var(--text-dim); font-weight: 600; margin-right: 6px; }
.cell-product .p-title { font-weight: 500; }
.cell-product .p-ids { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }

/* ---------- bulk bar ---------- */
.bulkbar { display: none; align-items: center; gap: 8px; }
.bulkbar.visible { display: inline-flex; }
.bulkbar .sel-count { color: var(--accent); font-weight: 600; font-size: 12px; }
.bulkbar input[type="text"] { width: 160px; padding: 3px 8px; font-size: 11.5px; }

/* ---------- toast ---------- */
#toast-host { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast {
  background: var(--bg-2); border: 1px solid var(--border); border-left: 3px solid var(--red);
  color: var(--text); border-radius: 7px; padding: 8px 14px; font-size: 12.5px;
  max-width: 380px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.toast.toast-ok { border-left-color: var(--green); }
.toast.toast-warn { border-left-color: var(--amber); }

/* ---------- jobs page ---------- */
.jobs-layout { flex: 1; min-height: 0; display: flex; gap: 14px; padding: 12px 16px; overflow: hidden; }
.jobs-forms { flex: none; width: 300px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.jobs-runs { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
.card {
  background: var(--bg-1); border: 1px solid var(--border-soft); border-radius: 8px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 9px;
}
.card h2 { margin: 0; font-size: 13px; font-weight: 600; }
.card .row2 { display: flex; gap: 8px; }
.card .row2 > * { flex: 1; }

.runs-scroll { flex: 1; min-height: 0; overflow-y: auto; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--bg-1); }
table.runs { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.runs th {
  position: sticky; top: 0; z-index: 2; background: var(--bg-2); color: var(--text-dim);
  text-align: left; font-size: 11.5px; font-weight: 600; padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}
table.runs td { padding: 6px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.runs td.num { text-align: right; }
table.runs .args-summary {
  font-family: var(--mono); font-size: 11px; color: var(--text-faint);
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;
}
tr.log-row > td { padding: 0 10px 10px; background: var(--bg-1); }
.log-pane {
  background: #0a0d11; border: 1px solid var(--border-soft); border-radius: 6px;
  font-family: var(--mono); font-size: 11px; line-height: 1.5; color: var(--text-dim);
  padding: 8px 10px; margin: 0; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-all;
}

.status-chip { text-transform: none; }
.st-queued    { color: var(--text-dim); background: var(--bg-3); border-color: var(--border); }
.st-running   { color: var(--accent); background: var(--accent-dim); border-color: rgba(110, 161, 216, 0.4); animation: pulse 1.6s ease-in-out infinite; }
.st-succeeded { color: var(--green); background: rgba(70, 184, 120, 0.12); border-color: rgba(70, 184, 120, 0.3); }
.st-failed    { color: #e08881; background: rgba(217, 100, 89, 0.12); border-color: rgba(217, 100, 89, 0.3); }
.st-cancelled { color: var(--amber); background: rgba(217, 160, 63, 0.12); border-color: rgba(217, 160, 63, 0.3); }
.st-empty     { color: var(--text-dim); background: var(--bg-3); border-color: var(--border); }
.st-orphaned  { color: var(--violet); background: rgba(166, 135, 224, 0.12); border-color: rgba(166, 135, 224, 0.3); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- login ---------- */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 320px; background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 28px 26px; display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 16px; font-weight: 600; }
.login-card p.sub { margin: -8px 0 0; color: var(--text-faint); font-size: 12px; }
.login-error {
  color: #e08881; background: rgba(217, 100, 89, 0.1); border: 1px solid rgba(217, 100, 89, 0.3);
  border-radius: 6px; padding: 7px 10px; font-size: 12px;
}

/* ---------- eligibility / velocity / drop chips (F1 / F5 / F6) ----------
   Verdict colors: BUY green (chip-ok), BUY (slow) teal, WATCH amber
   (chip-warn), RISKY orange, SKIP grey (chip-neutral). Eligibility: green /
   amber / red / grey via chip-ok / chip-warn / chip-bad / chip-neutral. */
.chip-teal   { color: #3fb8ab; background: rgba(63, 184, 171, 0.12); border-color: rgba(63, 184, 171, 0.3); }
.chip-orange { color: #e08a4d; background: rgba(224, 138, 77, 0.12); border-color: rgba(224, 138, 77, 0.32); }
.chip-hollow { color: var(--text-faint); background: transparent; border-color: var(--border); font-weight: 500; }
.chip-stale  { opacity: 0.55; filter: saturate(0.4); }
a.chip-link { cursor: pointer; }
a.chip-link:hover { text-decoration: none; border-color: currentColor; }
.track-btn {
  border: 0; background: transparent; color: var(--text-faint); cursor: pointer;
  font: 600 10px var(--sans); padding: 1px 5px; border-radius: 3px; margin-left: 2px;
}
.track-btn:hover { color: var(--accent); background: var(--bg-3); }
.flood-mark { color: var(--amber); font-weight: 700; margin-left: 4px; cursor: help; }

/* ---------- leads facet bar (eligibility / verdict / has-drop) ---------- */
.facetbar { flex-wrap: wrap; row-gap: 6px; }
.facet-label {
  color: var(--text-faint); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
}
.facet-group { display: inline-flex; gap: 4px; flex-wrap: wrap; }
button.facet-chip {
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text-dim);
  font: 600 11px var(--sans); line-height: 16px; padding: 1px 9px;
  border-radius: 999px; cursor: pointer;
}
button.facet-chip:hover { color: var(--text); border-color: var(--text-faint); }
button.facet-chip.active {
  color: var(--accent); background: var(--accent-dim); border-color: rgba(110, 161, 216, 0.35);
}
button.facet-chip .cnt {
  color: var(--text-faint); font-weight: 500; margin-left: 4px; font-variant-numeric: tabular-nums;
}
button.facet-chip.active .cnt { color: var(--accent); opacity: 0.75; }

/* ---------- confirm modal (Keepa token estimate) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(8, 10, 13, 0.62);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  width: 360px; max-width: calc(100vw - 40px);
  background: var(--bg-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px 20px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.modal h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.modal .m-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; color: var(--text-dim); }
.modal .m-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.modal .m-note { color: var(--text-faint); font-size: 11.5px; }
.modal .m-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 5px; border: 2px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* ---------- narrow viewports (phone / split-screen) ---------- */
/* The fixed 188px sidebar + margined .main assume desktop width — at 390px
   they left ~200px of content and no scroll path (body is overflow:hidden).
   Below 720px the sidebar becomes a wrapping top nav bar, the page stacks,
   and the jobs two-column layout goes vertical. */
@media (max-width: 720px) {
  body { display: flex; flex-direction: column; }
  .sidebar {
    position: static; inset: auto; width: auto; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 2px 4px; padding: 8px 10px;
    border-right: 0; border-bottom: 1px solid var(--border-soft);
  }
  .sidebar .brand { padding: 2px 8px; }
  .sidebar .brand small, .sidebar .nav-foot { display: none; }
  .sidebar .nav-spacer { flex: none; }
  .sidebar a.nav-link { padding: 5px 8px; border-left: 0; }
  /* bounded height (flex within the 100%-height body column) so the grid and
     .content keep their internal scroll containers */
  .main { margin-left: 0; height: auto; flex: 1 1 auto; min-height: 0; }
  .kbd-hint { display: none; } /* keyboard triage is meaningless on touch */

  .jobs-layout { flex-direction: column; overflow-y: auto; }
  .jobs-forms { width: auto; overflow-y: visible; }
  .jobs-runs { flex: none; min-height: 320px; overflow: visible; }
  .runs-scroll { min-height: 240px; }
}
