:root {
  --alu: #E7EAEE;          /* фон: корпус диска */
  --surface: #FFFFFF;
  --ink: #1F2328;
  --muted: #5E6672;
  --faint: #8A929D;
  --line: #CED4DB;
  --line-soft: #E2E6EA;
  --cobalt: #2346C8;       /* действия и «Отобрано» */
  --cobalt-soft: #E6EBFB;
  --go: #1D7444;           /* подходит, выгода */
  --go-soft: #E2F2E8;
  --amber: #8F5B00;        /* нужно проверить */
  --amber-soft: #FFF1CF;
  --teal: #0E6767;         /* куплено */
  --teal-soft: #DDF0EF;
  --stop: #A3312A;
  --stop-soft: #FBE7E5;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --sans: "Onest", system-ui, "Segoe UI", sans-serif;
  --r-s: 4px;
  --r-m: 8px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--alu);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--cobalt); }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.code { font-family: var(--mono); font-weight: 500; letter-spacing: .01em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* --- шапка --- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand svg { flex: none; }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 12px; border-radius: var(--r-s);
  color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap;
}
.nav a:hover { color: var(--ink); background: var(--alu); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--alu); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.who { color: var(--muted); white-space: nowrap; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--cobalt); cursor: pointer; }

/* --- обновление --- */
.refresh { display: flex; align-items: center; gap: 12px; }
.refresh-info { text-align: right; font-size: 13px; line-height: 1.3; color: var(--muted); white-space: nowrap; }
.refresh-info b { color: var(--ink); font-weight: 600; }
.progress {
  height: 3px; background: var(--line-soft); position: absolute; left: 0; right: 0; bottom: -1px; overflow: hidden;
}
.progress i { display: block; height: 100%; background: var(--cobalt); transition: width .4s ease; }
.alert {
  margin: 16px 24px 0; padding: 12px 16px; border-radius: var(--r-m);
  background: var(--amber-soft); color: #5A3A00; border: 1px solid #F0D58F;
}
.alert.stop { background: var(--stop-soft); color: #6E1D18; border-color: #F0BDB8; }

/* --- кнопки и поля --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--r-s);
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.btn.primary:hover { background: #1B39A8; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.small { height: 32px; padding: 0 12px; font-size: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input {
  height: 38px; padding: 0 12px; border-radius: var(--r-s);
  border: 1px solid var(--line); background: var(--surface); min-width: 0;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--cobalt); outline: none; box-shadow: 0 0 0 3px var(--cobalt-soft); }

/* --- страница --- */
.page { padding: 24px; max-width: 1480px; margin: 0 auto; }
.page h1 { margin: 0 0 4px; font-size: 24px; line-height: 1.25; font-weight: 700; }
.page .lead { margin: 0 0 20px; color: var(--muted); max-width: 70ch; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); }

/* --- вкладки статусов --- */
.tabs { display: flex; gap: 2px; margin-bottom: -1px; overflow-x: auto; }
.tab {
  display: flex; align-items: baseline; gap: 8px;
  padding: 10px 16px; border: 1px solid transparent; border-bottom: 0;
  border-radius: var(--r-m) var(--r-m) 0 0;
  background: none; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap;
}
.tab .n { font-weight: 500; color: var(--faint); }
.tab[aria-selected="true"] { background: var(--surface); border-color: var(--line); color: var(--ink); }
.tab[aria-selected="true"] .n { color: var(--muted); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
}
.toolbar .input[type="search"] { flex: 1 1 240px; max-width: 360px; }
.check { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); cursor: pointer; white-space: nowrap; }
.check input { width: 16px; height: 16px; accent-color: var(--cobalt); }

/* --- таблица объявлений --- */
table.grid { width: 100%; border-collapse: collapse; }
.grid th {
  text-align: left; font-size: 13px; font-weight: 500; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
.grid td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.grid tr:last-child td { border-bottom: 0; }
.grid th.num, .grid td.num { text-align: right; }
.grid tbody tr.row { cursor: pointer; }
.grid tbody tr.row:hover td { background: #F6F7F9; }
.grid tbody tr.row.open td { background: var(--cobalt-soft); }
.grid tbody tr.gone td { color: var(--faint); }
.t-title { display: block; max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-sub { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.cap { font-weight: 700; font-size: 16px; white-space: nowrap; }
.price { font-weight: 600; white-space: nowrap; }
.prev { display: block; font-size: 13px; color: var(--faint); text-decoration: line-through; }
.gain { color: var(--go); font-weight: 600; white-space: nowrap; }
.gain .pct { display: block; font-size: 13px; font-weight: 500; }
.star { color: #C98A00; }
.fresh {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 3px;
  background: var(--cobalt); color: #fff; font-size: 11px; font-weight: 600; vertical-align: 2px;
}

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-candidate { background: var(--go-soft); color: var(--go); }
.b-check { background: var(--amber-soft); color: var(--amber); }
.b-excluded { background: var(--line-soft); color: var(--muted); }
.b-review { background: var(--amber-soft); color: var(--amber); }
.b-selected { background: var(--cobalt-soft); color: var(--cobalt); }
.b-bought { background: var(--teal-soft); color: var(--teal); }
.b-rejected { background: var(--line-soft); color: var(--muted); }
.who-did { display: block; font-size: 12px; color: var(--faint); margin-top: 3px; white-space: nowrap; }

.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty h2 { margin: 0 0 6px; font-size: 18px; color: var(--ink); }
.empty p { margin: 0 auto 16px; max-width: 52ch; }

/* --- карточка объявления (наклейка диска) --- */
.scrim { position: fixed; inset: 0; background: rgba(31, 35, 40, .28); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(560px, 100%); overflow-y: auto;
  background: var(--alu); border-left: 1px solid var(--line);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } .progress i { transition: none; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; }
.drawer-head .x { width: 36px; height: 36px; border: 0; background: none; border-radius: var(--r-s); cursor: pointer; font-size: 22px; line-height: 1; color: var(--muted); }
.drawer-head .x:hover { background: var(--surface); }
.drawer-body { padding: 0 20px 32px; display: grid; gap: 16px; }

.label {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, #FFFFFF 0%, #F4F6F8 100%);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 20px 14px;
}
.label::after { /* скруглённый вырез, как у наклейки на корпусе */
  content: ""; position: absolute; right: -14px; top: 50%; width: 28px; height: 28px; margin-top: -14px;
  border-radius: 50%; background: var(--alu); border: 1px solid var(--line);
}
.label-brand { font-weight: 600; color: var(--muted); }
.label-cap { font-size: 56px; line-height: 1; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 4px; }
.label-cap small { font-size: 24px; font-weight: 600; margin-left: 4px; letter-spacing: 0; }
.label-model { font-family: var(--mono); font-size: 18px; font-weight: 600; }
.label-title { margin-top: 8px; color: var(--muted); }
.label-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-top: 14px; }
.barcode { display: flex; align-items: flex-end; gap: 1px; height: 30px; }
.barcode i { display: block; height: 100%; background: var(--ink); }
.label-id { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 3px; }

.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 16px; }
.block h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.figure .k { font-size: 13px; color: var(--muted); }
.figure .v { font-size: 18px; font-weight: 600; }
.figure .v.go { color: var(--go); }
.todo { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.todo li { display: grid; grid-template-columns: 18px 1fr; gap: 8px; }
.todo li::before { content: ""; width: 14px; height: 14px; margin-top: 3px; border: 1.5px solid var(--faint); border-radius: 3px; }
.todo li.warn::before { border-color: var(--amber); background: var(--amber-soft); }
.todo li.warn { color: #5A3A00; font-weight: 500; }
dl.kv { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; max-height: 240px; overflow-y: auto; }

.statuses { display: flex; flex-wrap: wrap; gap: 8px; }
.st-btn {
  height: 36px; padding: 0 14px; border-radius: var(--r-s); border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer;
}
.st-btn:hover { border-color: var(--faint); }
.st-btn[aria-pressed="true"].review { background: var(--amber-soft); border-color: #E9C46A; color: var(--amber); }
.st-btn[aria-pressed="true"].selected { background: var(--cobalt-soft); border-color: #9FB0EC; color: var(--cobalt); }
.st-btn[aria-pressed="true"].bought { background: var(--teal-soft); border-color: #8FC8C5; color: var(--teal); }
.st-btn[aria-pressed="true"].rejected { background: var(--line-soft); border-color: var(--faint); color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.history { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 14px; }
.history time { color: var(--faint); margin-right: 8px; }

/* --- справочник, настройки, пользователи --- */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-row .field { flex: 1 1 140px; }
.cell-input { width: 110px; height: 32px; padding: 0 8px; text-align: right; }
.cell-wide { width: 100%; min-width: 140px; height: 32px; padding: 0 8px; }
.switch { width: 18px; height: 18px; accent-color: var(--cobalt); }
.settings { display: grid; gap: 0; }
.set-h { font-size: 17px; font-weight: 600; margin: 24px 0 10px; }
.setting {
  display: grid; grid-template-columns: 1fr 180px; gap: 24px; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--line-soft);
}
.setting:last-child { border-bottom: 0; }
.setting b { display: block; font-weight: 600; }
.setting span { color: var(--muted); font-size: 14px; }
.setting .input { width: 100%; text-align: right; }
.actions-bar { display: flex; gap: 12px; margin-top: 16px; align-items: center; }

/* --- вход --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 28px; display: grid; gap: 16px;
}
.login h1 { margin: 0; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.err { color: var(--stop); font-size: 14px; margin: 0; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--r-m);
  font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: calc(100% - 32px);
}
#toast.on { opacity: 1; }

/* --- телефоны и узкие окна --- */
@media (max-width: 1100px) {
  .top { gap: 12px; padding: 0 16px; }
  .who { display: none; }
  .refresh-info { display: none; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .top { height: auto; flex-wrap: wrap; padding: 10px 16px; row-gap: 8px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .page { padding: 16px; }
  .alert { margin: 12px 16px 0; }
  .cols { grid-template-columns: 1fr; }
  .figures { grid-template-columns: 1fr 1fr; }
  .setting { grid-template-columns: 1fr; gap: 8px; padding: 14px 16px; }
  .label-cap { font-size: 44px; }
  /* таблица объявлений превращается в список карточек */
  table.grid.listings thead { display: none; }
  table.grid.listings, .grid.listings tbody, .grid.listings tr, .grid.listings td { display: block; }
  .grid.listings tr.row {
    display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
    padding: 12px 16px; border-bottom: 1px solid var(--line-soft);
  }
  .grid.listings td { padding: 0; border: 0; }
  .grid.listings td.num { text-align: left; }
  .grid.listings td[data-label]::before {
    content: attr(data-label); display: block; font-size: 12px; color: var(--faint); font-weight: 500;
  }
  .grid.listings tr.row { grid-template-columns: repeat(2, 1fr); }
  .grid.listings td[data-k="model"] + td, .grid.listings td[data-label] { padding-top: 6px; }
  .grid.listings td[data-k="model"] { grid-column: 1 / -1; }
  .grid.listings td[data-k="date"] { display: none; }
  .t-title { max-width: 100%; white-space: normal; }
  .table-scroll { overflow-x: auto; }
}

.t-sub.warn { color: var(--stop); font-weight: 600; }

/* --- агенты --- */
.agents-dot { font-size: 13px; color: var(--muted); text-decoration: none; }
.agents-dot::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--faint); }
.agents-dot.on::before { background: var(--go); }
.agents-dot.off { color: var(--stop); }
.agents-dot.off::before { background: var(--stop); }
.pair { padding: 16px 20px; margin-bottom: 16px; }
.pair ol { margin: 0 0 12px; padding-left: 20px; display: grid; gap: 8px; }
.pair-code { font-size: 32px; font-weight: 600; letter-spacing: 0.08em; margin: 4px 0 8px; }
