:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #687082;
  --line: #e2e5eb;
  --accent: #2457d6;
  --accent-soft: #e8eefc;
  --best: #dff3e4;
  --best-text: #17663a;
  --warn: #fff4d6;
  --warn-text: #7a5600;
  --error: #fde5e5;
  --error-text: #a12020;
  --fact: #e6effd;
  --estimate: #f3e8fc;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --card: #1d2129; --text: #e7e9ee; --muted: #9aa2b2; --line: #2e3440;
    --accent: #7aa2ff; --accent-soft: #24304d; --best: #1d3b29; --best-text: #8fe0aa;
    --warn: #3b3218; --warn-text: #f0d48a; --error: #3e1f1f; --error-text: #ffaaaa;
    --fact: #1f2e47; --estimate: #35243f;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "Arial Hebrew", Arial, sans-serif; font-size: 15px; line-height: 1.5;
}
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

.topbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.logout { margin: 0; }
.nopass { background: var(--warn); color: var(--warn-text); text-align: center; padding: 6px 16px; font-size: .9em; }
.nopass code { direction: ltr; unicode-bidi: isolate; }
.login { max-width: 400px; margin: 8vh auto 0; text-align: center; }
.login .field { text-align: start; }
.login-icon { font-size: 2.6rem; }
.btn.wide { width: 100%; }
.budget { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .9em; color: var(--muted); margin: 0 0 14px; }
.budget b { color: var(--text); font-variant-numeric: tabular-nums; }
.budget.blocked { color: var(--error-text); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }

/* ---------- form ---------- */
.field { display: block; margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus, .drop:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input.num { max-width: 120px; }
.row { display: flex; gap: 24px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; padding: 8px 16px; }
.seg input:checked + span { background: var(--accent); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }

.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center;
  cursor: pointer; background: var(--bg); transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { font-size: 1.8rem; }
.drop img { max-height: 160px; max-width: 100%; border-radius: 8px; display: block; margin: 0 auto 8px; }

.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px;
  padding: 9px 18px; font: inherit; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 4px 10px; font-size: .9em; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }

.alert { border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.alert.error { background: var(--error); color: var(--error-text); }
.alert.warn { background: var(--warn); color: var(--warn-text); }
.alert.info { background: var(--accent-soft); }

/* ---------- history ---------- */
.history { display: grid; gap: 8px; }
.hist-item {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; text-decoration: none; color: inherit;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px;
}
.hist-item:hover { border-color: var(--accent); }
.hist-title { font-weight: 600; }
.badge { display: inline-block; font-size: .78em; padding: 1px 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--best); color: var(--best-text); border-color: transparent; }
.badge.run { background: var(--accent-soft); border-color: transparent; }
.badge.bad { background: var(--error); color: var(--error-text); border-color: transparent; }
.badge.demo { background: var(--warn); color: var(--warn-text); border-color: transparent; }

/* ---------- progress ---------- */
.head { display: flex; gap: 16px; align-items: center; }
.head img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.head h1 { margin: 0 0 4px; }
.progress-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.steps { list-style: none; padding: 0; margin: 4px 0 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.steps li { padding: 4px 12px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); font-size: .9em; }
.steps li.done { background: var(--best); color: var(--best-text); border-color: transparent; }
.steps li.done::before { content: "✓ "; }
.steps li.current { background: var(--accent); color: #fff; border-color: transparent; }
.now { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
.now.waiting .spinner { animation: none; border-color: var(--warn-text); }
@keyframes spin { to { transform: rotate(360deg); } }
.events { list-style: none; padding: 0; margin: 8px 0 0; font-size: .9em; max-height: 320px; overflow: auto; }
.events li { padding: 2px 0; border-bottom: 1px dashed var(--line); }
.events .t { color: var(--muted); margin-left: 8px; font-variant-numeric: tabular-nums; }
.events .warning { color: var(--warn-text); }
.events .error { color: var(--error-text); }
.log { white-space: pre-wrap; font-size: .8em; max-height: 360px; overflow: auto; direction: ltr; text-align: left; background: var(--bg); padding: 10px; border-radius: 8px; }
summary { cursor: pointer; font-weight: 600; }

/* ---------- approvals ---------- */
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-bottom: 14px; }
.option { border: 2px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer; display: block; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option input { margin-left: 6px; }
.conf { font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.matches { display: grid; gap: 4px; margin: 0 0 14px; padding: 0; list-style: none; font-size: .9em; }
.lens-list { list-style: none; padding: 0; margin: 8px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.lens-list li { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: .9em; min-width: 0; }
.lens-list li > div { min-width: 0; overflow-wrap: anywhere; }
.lens-list img, .thumb-empty { width: 56px; height: 56px; object-fit: contain; border-radius: 6px; background: var(--bg); flex: none; }
.feat-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.feat-table th, .feat-table td { padding: 6px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
.feat-table input, .feat-table select { padding: 6px 8px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- result table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.cmp { border-collapse: collapse; width: 100%; min-width: 640px; background: var(--card); }
table.cmp th, table.cmp td { border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); padding: 8px 10px; text-align: start; vertical-align: top; }
table.cmp thead th { background: var(--bg); position: sticky; top: 0; }
table.cmp td, table.cmp thead th:not(.feat) { min-width: 160px; }
table.cmp th.feat { background: var(--bg); min-width: 130px; position: sticky; right: 0; z-index: 1; }
table.cmp tr.price-row td, table.cmp tr.price-row th { border-bottom: 2px solid var(--text); }
table.cmp td.best { background: var(--best); color: var(--best-text); font-weight: 600; }
.prod-name { font-weight: 700; }
.from-image { display: inline-block; font-size: .75em; background: var(--accent); color: #fff; border-radius: 99px; padding: 0 8px; }
.nf { color: var(--muted); font-style: italic; }
.src { font-size: .72em; vertical-align: super; margin-right: 2px; text-decoration: none; }
.offer { white-space: nowrap; }
.offer + .offer { margin-top: 4px; }
.via { font-size: .75em; color: var(--muted); font-weight: 400; }
.toolbar { padding: 12px 16px; }
a.btn { display: inline-block; text-decoration: none; }
.src-group { margin-bottom: 6px; }
.src-list { list-style: none; padding: 0; margin: 6px 0 10px; display: grid; gap: 4px; font-size: .9em; }
.src-list li { overflow-wrap: anywhere; }
.ils { color: var(--muted); font-size: .9em; }
.conflict { font-size: .9em; }
.conflict-title { color: var(--warn-text); font-size: .85em; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .85em; color: var(--muted); margin-top: 10px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--best); vertical-align: middle; margin-left: 4px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.pcard { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.pcard ul { margin: 4px 0 10px; padding-inline-start: 18px; }
.pcard li { margin-bottom: 3px; }
.tag { display: inline-block; font-size: .72em; border-radius: 4px; padding: 0 6px; margin-inline-start: 4px; vertical-align: 1px; }
.tag.fact { background: var(--fact); }
.tag.estimate { background: var(--estimate); }
.ref { font-size: .8em; color: var(--muted); }
.summary-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.summary-list li { border-inline-start: 4px solid var(--accent); padding: 4px 12px; }
.costs { display: flex; gap: 24px; flex-wrap: wrap; }
.cost-num { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .wrap { padding: 10px; }
  .card { padding: 14px; }
  .head { flex-direction: column; align-items: flex-start; }
}
