:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #dde1e7;
  --accent: #3c6797;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #b86e00;
  --bad: #c62f2f;
  --ok-bg: #e6f4ec;
  --warn-bg: #fdf1dd;
  --bad-bg: #fbe7e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1f25;
    --surface-2: #222830;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --border: #2e3640;
    --accent: #4d72a3;
    --ok: #4cc27f;
    --warn: #e2a33c;
    --bad: #ef6b6b;
    --ok-bg: #173324;
    --warn-bg: #3a2c13;
    --bad-bg: #3d1c1c;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 2px 5px; border-radius: 5px; }
.hint { color: var(--muted); margin: 8px 0 0; }
.error { color: var(--bad); margin: 8px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover, .btn.ghost.active { background: var(--surface-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn:disabled { opacity: .55; cursor: default; }

input, select {
  height: 38px; padding: 0 12px; border-radius: 8px; width: 100%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label { display: grid; gap: 6px; font-weight: 500; }
label.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); cursor: pointer; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .04em; color: var(--text); text-decoration: none; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; font-size: 16px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 16px; }
.login-card .btn { justify-content: center; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; gap: 4px; }

.view.search, .view.settings { max-width: 1240px; margin: 0 auto; padding: 32px 24px 64px; }

/* Search */
.search-box { display: flex; gap: 8px; max-width: 760px; margin: 24px auto 0; }
.search-box .article-field { flex: 2; position: relative; }
.search-box #q-article { height: 46px; font-size: 16px; }
.history-menu {
  position: absolute; z-index: 10; top: calc(100% + 4px); left: 0; right: 0;
  margin: 0; padding: 4px; list-style: none; max-height: 320px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.history-menu .history-title { padding: 6px 10px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.history-menu li[role="option"] {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.history-menu li[role="option"].active, .history-menu li[role="option"]:hover { background: var(--surface-2); }
.history-menu .remove { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.history-menu .remove:hover { color: var(--bad); }
.search-box #q-brand { flex: 1; height: 46px; }
.search-box .btn { height: 46px; padding: 0 22px; }
.view.search > .hint { text-align: center; }

.supplier-strip { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 24px 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.running .dot, .chip.pending .dot { background: var(--accent); animation: pulse 1s infinite alternate; }
.chip.ok .dot { background: var(--ok); }
.chip.no_match .dot, .chip.ambiguous .dot, .chip.timeout .dot, .chip.circuit_open .dot { background: var(--warn); }
.chip.error .dot, .chip.blocked .dot, .chip.needs_login .dot { background: var(--bad); }
.chip small { color: var(--muted); }
@keyframes pulse { to { opacity: .3; } }

/* Under the search box without taking room: it overlays the gap below. */
.search-box { position: relative; }
.progress-bar { position: absolute; left: 0; right: 0; bottom: -9px; height: 3px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.progress-bar span { display: block; width: 30%; height: 100%; border-radius: 2px; background: var(--accent); animation: sweep 1.3s ease-in-out infinite; }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.btn.busy::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .progress-bar span { animation: none; width: 100%; opacity: .5; }
  .btn.busy::before { animation-duration: 2s; }
}

.clarify, .results { margin: 24px auto 0; }
.results { overflow-x: auto; }
.clarify { max-width: 900px; }
.clarify tbody tr { cursor: pointer; }
.clarify tbody tr:hover { background: var(--surface-2); }

.results-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.results-head h2 { margin: 0; }

.grid { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.grid th, .grid td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.grid th[data-sort] { cursor: pointer; user-select: none; }
.grid th[data-sort]:hover { color: var(--text); }
.grid th.sorted::after { content: " ↑"; }
.grid th.sorted.desc::after { content: " ↓"; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.grid td.nowrap { white-space: nowrap; }
.grid tr.group td { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.offers td a { color: inherit; }
.offers .name { color: var(--muted); max-width: 360px; }
.offers .price { font-weight: 600; }
.offers tr.best td.price { color: var(--ok); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.muted { background: var(--surface-2); color: var(--muted); }

/* Carts */
.btn .count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 12px; }
.cart-switch { position: relative; display: inline-flex; align-items: center; }
.cart-switch #nav-cart { padding-right: 6px; }
.active-cart-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.caret { padding: 0 8px; }
.menu {
  position: absolute; z-index: 20; top: calc(100% + 4px); right: 0; min-width: 240px; max-width: 340px;
  margin: 0; padding: 4px; list-style: none; max-height: 360px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / 15%);
}
.menu.floating { position: fixed; top: 0; right: auto; }
.menu .menu-title { padding: 6px 10px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.menu button {
  display: flex; width: 100%; justify-content: space-between; gap: 10px; align-items: center;
  padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu button .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.menu button .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.offers .add-col { width: 1%; white-space: nowrap; }
/* Cells align to the top (descriptions wrap); the controls, taller than a
   line of text, are pulled up so their middle sits on the first line. */
.add-cell { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin: -5px 0; }
.add-cell input, .qty-input { width: 64px; height: 30px; padding: 0 6px; text-align: right; }
.split { display: inline-flex; }
.split .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split .btn.caret { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgb(255 255 255 / 35%); padding: 0 7px; }
.in-cart { color: var(--ok); font-size: 12px; white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.view.cart { max-width: 1320px; margin: 0 auto; padding: 32px 24px 64px; }
.carts-layout { display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: start; }
.carts-aside { position: sticky; top: 72px; }
.carts-aside-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.carts-filters { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 10px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: var(--surface); color: var(--muted); padding: 5px 12px; font: inherit; cursor: pointer; }
.segmented button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.cart-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cart-list li { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.cart-list li:hover { border-color: var(--muted); }
.cart-list li.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cart-list .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.cart-list .row1 b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-list .sub { color: var(--muted); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-list li.archived { opacity: .7; }
.cart-list .empty { border: 0; background: none; cursor: default; }
.cart-detail { min-width: 0; }
.cart-detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.cart-detail-head h2 { font-size: 20px; margin: 0; display: flex; gap: 8px; align-items: center; }
.cart-detail-head .hint { margin-top: 4px; }
.cart-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cart-group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 0 8px; }
.cart-group-head h3 { margin: 0; font-size: 15px; }
.cart-group-head .sum { color: var(--muted); }
.cart-group-head .group-actions { margin-left: auto; display: flex; gap: 6px; align-self: center; }
.cart-group-head .group-actions a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.cart .grid td { vertical-align: middle; }
.cart-table { margin-top: 20px; overflow-x: auto; }
/* Ten columns share the cart area next to the cart list: tighter cells. */
.cart .grid th, .cart .grid td { padding-left: 8px; padding-right: 8px; }
.cart .grid tr.group-head td { background: var(--surface-2); padding: 10px 12px; }
.cart .grid tbody + tbody tr.group-head td { border-top: 1px solid var(--border); }
.cart .grid tr.group-head .cart-group-head { margin: 0; align-items: center; }
/* Long part numbers wrap here rather than push the actions out of view. */
.cart .grid td.nowrap { white-space: normal; overflow-wrap: anywhere; }
.cart .line-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.cart .move-select { height: 30px; width: auto; max-width: 150px; padding: 0 6px; font-size: 13px; }
.cart .remove-line { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0 6px; }
.cart .remove-line:hover { color: var(--bad); }
.cart .was { color: var(--muted); text-decoration: line-through; font-weight: 400; margin-right: 6px; }
.cart-totals { margin-top: 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 15px; }
.cart-totals b { font-size: 18px; }

/* Settings */
.settings-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.accounts { margin-top: 20px; }
.accounts td.actions { text-align: right; white-space: nowrap; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); width: min(460px, calc(100% - 32px)); box-shadow: 0 10px 40px rgb(0 0 0 / 25%); }
dialog::backdrop { background: rgb(0 0 0 / 35%); }
.dialog-form { display: grid; gap: 14px; padding: 22px; }
.dialog-form h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 20; }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  #nav-search { display: none; }
  .view.search, .view.settings, .view.cart { padding: 20px 16px 48px; }
  .carts-layout { grid-template-columns: 1fr; }
  .carts-aside { position: static; }
  .active-cart-name { max-width: 90px; }
  .search-box { flex-wrap: wrap; }
  .search-box .article-field, .search-box #q-brand { flex: 1 1 100%; }
  .search-box .btn { flex: 1; justify-content: center; }
  .results, .accounts, .clarify { overflow-x: auto; }
  .accounts { display: block; }
  .grid { min-width: 720px; }
  .settings-head { flex-wrap: wrap; }
}
