:root {
  --bg: #edf0f4; --surface: #ffffff; --ink: #172033; --muted: #5b6779; --line: #d4dae3;
  --accent: #1e4ed8; --accent-ink: #ffffff; --cheaper: #157347; --pricier: #b42318; --warn: #a15c00;
  --radius: 6px; --font: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); font-variant-numeric: tabular-nums; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: center; justify-content: space-between; height: 52px; padding: 0 20px; background: var(--ink); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.mark { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(30,78,216,.35); }
.status { color: #b9c2d0; font-size: 13px; }

.app { display: grid; grid-template-columns: 340px 1fr; height: calc(100% - 52px); }
.panel { background: var(--surface); border-right: 1px solid var(--line); padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; }
.block label { display: block; font-weight: 600; margin-bottom: 6px; }
.block label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.cell .rank { font-size: 11.5px; color: var(--muted); }
.hint { margin: 0 0 8px; color: var(--muted); font-size: 12.5px; }
.hint code { background: var(--bg); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
textarea { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); resize: vertical; background: #fbfcfd; }
.row-between { display: flex; align-items: baseline; justify-content: space-between; }
.mini-actions button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0 4px; font-size: 13px; }
.competitors { display: flex; flex-direction: column; gap: 10px; }
.competitors .group { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.competitors .group h3 { margin: 0; padding: 7px 10px; font-size: 12.5px; font-weight: 600; color: var(--muted); background: #f5f7fa; border-bottom: 1px solid var(--line); }
.competitors label { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-weight: 400; margin: 0; cursor: pointer; }
.competitors label + label { border-top: 1px solid #eef1f5; }
.competitors .tag { margin-inline-start: auto; font-size: 11px; color: var(--muted); }
input[type=range] { width: 100%; accent-color: var(--accent); }
output { font-weight: 400; color: var(--muted); margin-inline-start: 6px; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--radius); padding: 11px 16px; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: .55; cursor: progress; }
.ghost { display: inline-block; border: 1px solid var(--ink); border-radius: var(--radius); padding: 8px 14px; text-decoration: none; color: var(--ink); font-weight: 500; }
.err { color: var(--pricier); margin: 0; }

.results { padding: 20px 24px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.results-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.results h1 { margin: 0; font-size: 20px; font-weight: 600; }
.sub { margin: 4px 0 0; color: var(--muted); }
.progress { height: 6px; background: #dfe4ec; border-radius: 3px; overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.grid-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.grid { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.grid th, .grid td { padding: 8px 12px; border-bottom: 1px solid var(--line); border-inline-end: 1px solid #eef1f5; vertical-align: top; white-space: nowrap; }
.grid th { position: sticky; top: 0; background: #f5f7fa; font-weight: 600; text-align: start; z-index: 2; }
.grid th.site { min-width: 130px; }
.grid td.product { white-space: normal; min-width: 260px; max-width: 360px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.grid td.product .sku { font-weight: 600; }
.grid td.product .t { color: var(--muted); font-size: 12.5px; }
.grid td.ours { font-weight: 600; background: #f8f9fc; }
.cell { display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.cell .p { font-weight: 600; }
.cell .d { font-size: 12px; }
.cell.cheaper .d { color: var(--cheaper); }
.cell.pricier .d { color: var(--pricier); }
.cell .conf { font-size: 11px; color: var(--muted); }
.cell.lowest .p::after { content: " lowest"; font-size: 10.5px; color: var(--cheaper); font-weight: 500; }
.state { color: var(--muted); font-size: 12.5px; }
.state.blocked, .state.error { color: var(--warn); }
.state.pending::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-inline-end: 6px; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .state.pending::before { animation: none; } .bar { transition: none; } }

.log summary { cursor: pointer; color: var(--muted); }
.log pre { font-size: 12px; background: var(--surface); border: 1px solid var(--line); padding: 10px; border-radius: var(--radius); max-height: 220px; overflow: auto; }

.drawer { position: fixed; top: 52px; inset-inline-end: 0; bottom: 0; width: 440px; max-width: 100%; background: var(--surface); border-inline-start: 1px solid var(--line); box-shadow: -8px 0 24px rgba(23,32,51,.12); padding: 18px; overflow: auto; z-index: 5; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.drawer-head button { background: none; border: 0; font-size: 22px; cursor: pointer; }
.drawer .alt { padding: 10px 0; border-bottom: 1px solid var(--line); }
.drawer .alt a { color: var(--accent); text-decoration: none; }
.drawer .alt .m { display: flex; gap: 12px; color: var(--muted); font-size: 12.5px; margin-top: 2px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .grid td.product { position: static; }
}
