:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #18202b;
  --muted: #677385;
  --line: #e2e6ec;
  --accent: #0d6b5f;
  --accent-ink: #ffffff;
  --accent-soft: #e3f2ef;
  --good: #11804a;
  --good-soft: #e2f5ea;
  --warn: #9a6200;
  --warn-soft: #fdf1d8;
  --bad: #b3261e;
  --bad-soft: #fbe7e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* шапка */
.top {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 13px; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 15px;
}
.who { display: flex; gap: 8px; align-items: center; color: var(--muted); }

.layout { display: grid; grid-template-columns: 280px 1fr; height: calc(100% - 56px); }

/* список клиентов */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.client-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.client-list li {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; display: grid; gap: 1px;
}
.client-list li:hover { background: var(--bg); }
.client-list li.active { background: var(--accent-soft); }
.client-list .name { font-weight: 600; }
.client-list .sub { color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; gap: 8px; }
.client-list .empty { color: var(--muted); cursor: default; }
.plate {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px;
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; background: #fff; color: var(--ink);
}

/* основная часть */
main { overflow-y: auto; padding: 20px 24px 90px; position: relative; }
.main-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: #e8ebef; padding: 3px; border-radius: 9px; }
.tabs button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 7px;
  font: inherit; color: var(--muted); cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.count { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
.count:empty { display: none; }

/* форма */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px 18px; margin: 0 0 14px; box-shadow: var(--shadow); min-width: 0;
}
.card.inner { box-shadow: none; background: #fafbfc; margin-top: 12px; }
legend { font-weight: 700; font-size: 15px; padding: 0 6px; margin-left: -6px; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; }
.f { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12.5px; }
.f.w2 { grid-column: span 2; }
.f.w4 { grid-column: span 4; }
input, select {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #cfd5dd; border-radius: 7px; padding: 7px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.invalid, select.invalid { border-color: var(--bad); background: var(--bad-soft); }
.with-btn { display: flex; gap: 8px; }
.with-btn input { flex: 1; text-transform: uppercase; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; margin-top: 4px; }
.check input { width: auto; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.f .hint { margin: 0; }
.driver-head { display: flex; justify-content: space-between; margin-bottom: 10px; }
.row-btns { display: flex; gap: 8px; margin-top: 12px; }
.search { margin: 0; }

/* кнопки */
.btn {
  font: inherit; border: 1px solid #cfd5dd; background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 7px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #e8ebef; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.link.remove { color: var(--bad); }

/* нижняя панель действий */
.actionbar {
  position: fixed; left: 280px; right: 0; bottom: 0; display: flex; gap: 8px; align-items: center;
  padding: 12px 24px; background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.spacer { flex: 1; }
.missing { color: var(--bad); font-size: 13px; cursor: pointer; }
.missing:empty { display: none; }

/* предложения */
.platform-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 14px; }
.pcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); display: grid; gap: 4px;
}
.pcard .pname { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.pcard .pstatus { font-size: 12.5px; color: var(--muted); }
.pcard .pstatus.ok { color: var(--good); }
.pcard .pstatus.err { color: var(--bad); }
.pcard a { font-size: 12.5px; color: var(--accent); text-decoration: none; }
.chip { font-size: 11px; font-weight: 600; border-radius: 5px; padding: 1px 6px; text-transform: uppercase; letter-spacing: .02em; }
.chip.api { background: var(--good-soft); color: var(--good); }
.chip.demo { background: var(--warn-soft); color: var(--warn); }
.chip.manual { background: #eceff3; color: var(--muted); }
.spin {
  display: inline-block; width: 11px; height: 11px; border: 2px solid #c8cfd8; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; margin-right: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.note {
  background: var(--warn-soft); color: #6b4700; border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px; font-size: 13px;
}
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.summary:empty { display: none; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 22px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12.5px; color: var(--muted); }

.manual {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px dashed #c3cad4; border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px;
}
.manual .txt { flex: 1; min-width: 240px; }

.table-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 10px; }
.seg { display: flex; background: #e8ebef; padding: 3px; border-radius: 8px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; font: inherit; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.matrix { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.matrix th, .matrix td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.matrix th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.matrix td:first-child { font-weight: 600; }
.matrix tr:last-child td { border-bottom: 0; }
.matrix .price { font-weight: 600; }
.matrix .kv { font-size: 12px; color: var(--muted); }
.matrix td.best { background: var(--good-soft); }
.matrix td.best .kv { color: var(--good); font-weight: 600; }
.matrix td.na { color: #b5bcc6; }
.matrix td.declined { color: var(--muted); font-size: 12.5px; }
.matrix tr.cheapest td:first-child::after {
  content: "лучшая цена"; margin-left: 8px; font-size: 11px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft); border-radius: 5px; padding: 1px 6px;
}
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }

.toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .f.w4 { grid-column: span 2; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 260px; }
  main { padding: 16px 16px 140px; }
  .actionbar { left: 0; flex-wrap: wrap; padding: 10px 16px; }
  .grid { grid-template-columns: 1fr; }
  .f.w2, .f.w4 { grid-column: span 1; }
  .summary { grid-template-columns: 1fr; }
  .brand small { display: none; }
}
a.btn { text-decoration: none; display: inline-block; }
.chip.manual { padding: 1px 6px; }

/* настройки */
.top-right { display: flex; align-items: center; gap: 14px; }
.dlg { border: 0; border-radius: 14px; padding: 22px 24px; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 60px rgba(20, 30, 45, .3); color: var(--ink); }
.dlg::backdrop { background: rgba(20, 30, 45, .45); }
.dlg h2 { font-size: 18px; margin-bottom: 4px; }
.srow { padding: 12px 14px; }
.srow-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.srow-head select { width: auto; }
.srow .grid { margin-top: 10px; }
.sresult { font-size: 12.5px; grid-column: span 4; }
.sresult.ok { color: var(--good); }
.sresult.err { color: var(--bad); }
.sresult:empty { display: none; }
.urow { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto auto; gap: 8px; align-items: end; margin: 8px 0; }
.urow .btn { padding-left: 10px; padding-right: 10px; }
@media (max-width: 700px) { .urow { grid-template-columns: 1fr 1fr; } }
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.login-card .muted { margin: -6px 0 0; }
.login-error { color: var(--bad); font-size: 13px; min-height: 1em; }
.login-error:empty { display: none; }
.who b { color: var(--ink); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 1100px) { .sresult { grid-column: span 2; } }
@media (max-width: 760px) { .sresult { grid-column: span 1; } .top-right { gap: 6px; } .who { font-size: 0; } .who select { font-size: 14px; } }

/* собственник = водитель */
.checks { display: flex; flex-direction: column; gap: 6px; }
.check .small { margin-left: 4px; }
.linked-note { display: none; }
.driver.linked .linked-note { display: inline; }
.driver.linked .remove { display: none; }
.driver.linked input[readonly] { background: var(--bg); color: var(--muted); }
.driver-head { align-items: baseline; gap: 12px; }
.driver-head .ocr-license { margin-left: auto; }

/* подсказки адресов */
.addr-wrap { position: relative; display: block; }
.suggest {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20, 30, 45, .14); max-height: 280px; overflow-y: auto;
}
.suggest li { padding: 7px 10px; border-radius: 6px; cursor: pointer; color: var(--ink); font-size: 13.5px; }
.suggest li.active, .suggest li:hover { background: var(--accent-soft); }
.hint.addr-ok { color: var(--good); }
.hint.addr-warn { color: var(--warn); }

/* заполнение по фото документов */
.doc-upload { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.doc-upload .btn { border: 1px dashed #b9c2cd; background: var(--bg); }
.ocr-status { margin: 0; }
.driver .ocr-status:not(:empty) { margin: -4px 0 10px; }
.ocr-status.ok { color: var(--good); }
.ocr-status.warn { color: var(--warn); }
.ocr-status.err { color: var(--bad); }
input.ocr-filled, select.ocr-filled { background: #fff8db; border-color: #e0b84a; }
.card.drop-hover { outline: 2px dashed var(--accent); outline-offset: -6px; background: var(--accent-soft); }
.checks .check { flex-wrap: wrap; row-gap: 0; }
.checks .check .small { flex-basis: 100%; margin-left: 24px; }
.driver-head { flex-wrap: wrap; }
.driver-no { white-space: nowrap; }

.ocr-text { max-height: 50vh; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font: 12.5px/1.5 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre-wrap; margin: 10px 0 0; }
.ocr-status .link { margin-left: 6px; font-size: inherit; }
