:root {
  --bg: #f4f5f4;
  --card: #ffffff;
  --text: #17201d;
  --muted: #66716d;
  --line: #e2e6e4;
  --accent: #0f6d5c;
  --accent-soft: #e2f1ed;
  --ok: #1d7a3e;
  --ok-soft: #e1f3e6;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101413;
    --card: #1a201e;
    --text: #e8eeeb;
    --muted: #94a19c;
    --line: #2a3330;
    --accent: #4cc3a8;
    --accent-soft: #173a32;
    --ok: #6fd18f;
    --ok-soft: #173322;
    --warn: #f0b45a;
    --warn-soft: #3a2a10;
    --bad: #ff8a80;
    --bad-soft: #3d1a17;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent); color: #fff;
}
.top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top button { background: none; border: 0; color: inherit; font: inherit; padding: 4px 6px; }
.top .back { font-size: 30px; line-height: 1; padding: 0 8px 4px 0; }

main { padding: 12px 16px; max-width: 720px; margin: 0 auto; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: 12px;
}
.tabs a span { font-size: 20px; }
.tabs a.active { color: var(--accent); font-weight: 600; }

input[type=search], input[type=text], input[type=password] {
  width: 100%; padding: 14px 16px; font-size: 17px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); }
.vin-input { text-transform: uppercase; letter-spacing: 1px; font-family: ui-monospace, Menlo, Consolas, monospace; }

button.primary {
  width: 100%; margin-top: 10px; padding: 14px; font-size: 17px; font-weight: 600;
  border: 0; border-radius: var(--radius); background: var(--accent); color: #fff;
}
button.primary:disabled { opacity: .5; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin: 10px 0; border: 1px solid var(--line);
}
a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { background: var(--accent-soft); }

.row { display: flex; align-items: flex-start; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.name { font-weight: 600; word-wrap: break-word; }
.sub { color: var(--muted); font-size: 14px; margin-top: 2px; word-wrap: break-word; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.price { font-weight: 700; white-space: nowrap; text-align: right; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.none { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

.hero { text-align: center; padding: 6px 0 2px; }
.hero .big { font-size: 30px; font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 12px; }

h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 20px 0 6px; }

details.card summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "›"; transform: rotate(90deg); color: var(--muted); font-size: 22px; transition: transform .15s; }
details.card[open] summary::after { transform: rotate(-90deg); }
details .part { padding: 10px 0; border-top: 1px solid var(--line); }
details .part:first-of-type { margin-top: 10px; }
.part a { color: inherit; text-decoration: none; }

pre.text { white-space: pre-wrap; font: inherit; font-size: 14px; margin: 10px 0 0; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.note { font-size: 13px; color: var(--muted); text-align: center; margin-top: 16px; }
.alert { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; font-size: 14px; }
.error { color: var(--bad); margin-top: 10px; text-align: center; }

.tabs a { position: relative; }
.tabs .dot { position: absolute; top: 6px; left: 50%; margin-left: 8px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.top #topAction button { background: rgba(255,255,255,.15); border-radius: 10px; padding: 6px 10px; font-size: 14px; }

/* миниатюры и фото */
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--line); flex: none; }
.thumb.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 22px; }
.gallery { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; scroll-snap-type: x mandatory; }
.gallery img { height: 160px; border-radius: 12px; scroll-snap-align: start; flex: none; }
.add-photo { height: 160px; min-width: 120px; border: 2px dashed var(--line); border-radius: 12px; background: none;
  color: var(--muted); font: inherit; font-size: 14px; flex: none; }
.viewer img { width: 100%; border-radius: 12px; }

/* кнопки */
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
button.secondary {
  flex: 1; padding: 12px; font: inherit; font-weight: 600; border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--card); color: var(--accent);
}
button.small, a.small {
  display: inline-block; padding: 6px 12px; font: inherit; font-size: 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
button.danger { color: var(--bad); border-color: var(--bad-soft); }
button.link { background: none; border: 0; color: var(--accent); font: inherit; padding: 0; }

/* строки документа (продажа/приход) */
.line { padding: 12px 0; border-top: 1px solid var(--line); }
.line:first-child { border-top: 0; padding-top: 0; }
.line-controls { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 40px; height: 40px; border: 0; background: var(--bg); color: var(--text); font-size: 20px; }
.stepper input { width: 52px; height: 40px; border: 0; text-align: center; font-size: 16px; background: var(--card); color: var(--text); }
.field { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.field input { width: 100px; padding: 9px 10px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); }
.field.wide input { width: 100%; }
.remove { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 22px; padding: 4px 8px; }
.total { display: flex; justify-content: space-between; align-items: baseline; font-size: 22px; font-weight: 700; margin: 6px 0; }
.form-row { margin-top: 10px; }
.form-row input, .form-row textarea { width: 100%; padding: 12px 14px; font: inherit; font-size: 16px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); color: var(--text); }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-top: 10px; }
.segmented button { flex: 1; padding: 12px 4px; border: 0; background: var(--card); color: var(--text); font: inherit; font-size: 15px; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.on { background: var(--accent); color: #fff; font-weight: 600; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip button { background: none; border: 0; color: inherit; font-size: 18px; padding: 0; line-height: 1; }

.picker-results { margin-top: 4px; }
.pick { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; font: inherit; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 6px; }

/* группы */
.crumbs { font-size: 14px; color: var(--muted); margin: 2px 0 8px; }
.crumbs a { color: var(--accent); text-decoration: none; }
.group-row { display: flex; align-items: center; gap: 12px; }
.group-row .icon { font-size: 22px; }
.group-row .gphoto { width: 52px; height: 52px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.gphoto.big { display: block; max-width: 100%; max-height: 320px; object-fit: contain; margin: 8px 0; border-radius: 10px; background: #fff; }
.check { width: 24px; height: 24px; flex: none; accent-color: var(--accent); }
.selectbar { position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 6;
  display: flex; gap: 8px; align-items: center; padding: 10px 16px; background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0,0,0,.08); }
.selectbar .grow { font-weight: 600; }
.selectbar button.primary { width: auto; margin: 0; padding: 10px 16px; }
.tree-item { display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0;
  border-bottom: 1px solid var(--line); padding: 12px 4px; }
.tree-item.current { color: var(--accent); font-weight: 700; }

/* выезжающий лист и уведомление */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 18px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; text-align: center; font-weight: 600; }
.toast.bad { background: var(--bad); color: #fff; }

.menu-list a { display: flex; align-items: center; gap: 12px; }
.menu-list .icon { font-size: 22px; }
.cancelled { opacity: .55; }

.login { max-width: 380px; margin: 40px auto 0; }
.login input { margin-top: 10px; }
.login .logo { text-align: center; font-size: 48px; }

/* результат подбора */
.car-card .car-title { font-size: 20px; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip-sm { padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 6px; font: inherit; font-size: 22px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); }
.tile span { font-size: 14px; font-weight: 600; }
.tile:active { background: var(--accent-soft); }
.rich { white-space: pre-wrap; font-size: 14px; line-height: 1.55; margin-top: 10px; }
.rich .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--accent-soft); padding: 0 4px; border-radius: 4px; }
.send-text { width: 100%; margin-top: 10px; padding: 12px; font: inherit; font-size: 14px; line-height: 1.45; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); color: var(--text); resize: vertical; }

/* отчёты */
:root { --chart-cost: #9fd3c6; --chart-profit: #0f6d5c; --chart-grid: #e2e6e4; }
@media (prefers-color-scheme: dark) { :root { --chart-cost: #24584d; --chart-profit: #5fd1b6; --chart-grid: #2a3330; } }
.period-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.period-row button { flex: none; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-size: 14px; }
.period-row button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 6px 0; }
@media (min-width: 560px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.kpi span { display: block; color: var(--muted); font-size: 13px; }
.kpi b { display: block; font-size: 20px; margin: 2px 0; }
.delta { font-size: 13px; color: var(--muted); }
.delta.up { color: var(--ok); }
.delta.down { color: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 6px 0 4px; font-size: 13px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-cost { background: var(--chart-cost); }
.sw-profit { background: var(--chart-profit); }
.chart { position: relative; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .bar-cost { fill: var(--chart-cost); }
.chart .bar-profit { fill: var(--chart-profit); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit.on { fill: var(--text); fill-opacity: .06; }
.chart .tip { position: absolute; top: 0; width: 160px; padding: 8px 10px; border-radius: 10px; font-size: 13px; line-height: 1.4;
  background: var(--text); color: var(--bg); pointer-events: none; }
.rank { display: flex !important; align-items: center; gap: 10px; }
.rank-n { width: 24px; text-align: center; color: var(--muted); font-weight: 700; flex: none; }
.grp-row { padding: 8px 0; border-top: 1px solid var(--line); }
.grp-row:first-child { border-top: 0; padding-top: 0; }
.bar-track { height: 8px; background: var(--line); border-radius: 4px; margin: 6px 0 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--chart-profit); border-radius: 4px; }
.tbl { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.tbl th, .tbl td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th { color: var(--muted); font-weight: 600; }

.ptype { font-weight: 700; margin-top: 14px; padding-bottom: 2px; }
details > summary + .ptype { margin-top: 10px; }
.ptype + .part { border-top: 0; padding-top: 4px; }

.btns .small.on-chip { background: var(--accent); color: #fff; border-color: var(--accent); }
.form-row textarea { width: 100%; padding: 12px 14px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); }
.field.form-row input { width: 100%; padding: 12px 14px; }

/* фото комплектов */
.kit-card { display: flex !important; gap: 12px; align-items: flex-start; }
.kit-card img { width: 88px; height: 88px; border-radius: 10px; object-fit: cover; flex: none; }
.kit-item { font-size: 14px; line-height: 1.35; }
.gallery.big img { height: 260px; }

/* отметки продажи */
.marks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.mark-btn { display: flex; align-items: center; gap: 6px; text-align: left; padding: 10px; border-radius: 12px; font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.mark-btn.off { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.mark-btn.on { border-color: var(--ok-soft); background: var(--ok-soft); color: var(--ok); }
.mark small { display: block; font-size: 11px; opacity: .8; font-weight: 400; }
.mark.on { font-weight: 600; }

.pos { color: var(--muted); font-weight: 700; margin-right: 6px; min-width: 22px; }

a.secondary { flex: 1; display: block; padding: 12px; font-weight: 600; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--card); color: var(--accent); }

/* чаты */
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.chat-row { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; }
.chat-row.unread .name { font-weight: 700; }
.chat-ava { position: relative; flex: none; width: 46px; height: 46px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; }
.chat-ava img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.chat-ava span { position: absolute; right: -4px; bottom: -4px; font-size: 14px; }
.chat-unread { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff;
  font-size: 12px; line-height: 20px; text-align: center; }
.chat-head .chat-product { display: block; margin-top: 6px; color: var(--accent); text-decoration: none; font-size: 14px; }
.chat-msgs { display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; }
.chat-day { align-self: center; margin: 8px 0 2px; font-size: 12px; color: var(--muted); }
.chat-system { align-self: center; max-width: 90%; font-size: 13px; color: var(--muted); text-align: center; }
.bubble { max-width: 82%; padding: 8px 10px 4px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.bubble.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--accent-soft); border-color: transparent; border-bottom-right-radius: 4px; }
.bubble img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 4px; }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-time { text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.composer { position: sticky; bottom: 0; display: flex; gap: 6px; align-items: flex-end; margin: 0 -16px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; min-width: 0; resize: none; padding: 10px 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 18px; background: var(--card); color: var(--text); max-height: 140px; }
.composer button { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--card); font-size: 20px; }
.composer button.send { background: var(--accent); color: #fff; }
body.chat-open { padding-bottom: 0; }
body.chat-open .tabs { display: none; }
.bubble-text a { color: var(--accent); word-break: break-all; }
.chat-menu-btn { position: fixed; right: 12px; bottom: 76px; z-index: 5; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,.25); font-size: 18px; }
