:root {
  --bg: #f3f4f7; --surface: #fff; --surface-2: #f8f9fb; --ink: #17202e; --muted: #667085; --line: #e3e7ee;
  --accent: #3355d1; --accent-ink: #fff; --accent-soft: #eaeefb;
  --nt: #d43b2d; --extra: #2b6fd6; --util: #dd6b12; --checks: #b98507; --ok: #16803c; --ok-soft: #eaf6ee;
  --err: #c5221f; --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131a; --surface: #161c25; --surface-2: #1b222d; --ink: #e7eaf0; --muted: #96a2b5; --line: #29323f;
    --accent: #7d97f5; --accent-ink: #0e131a; --accent-soft: #1d2740;
    --nt: #f0705f; --extra: #6ea3f2; --util: #f09448; --checks: #e0b341; --ok: #4cc27a; --ok-soft: #15281d;
    --err: #f28b82; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .93em; letter-spacing: .01em; }
.muted { color: var(--muted); }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1120px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 650; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.topbar .spacer { flex: 1; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 20px 64px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.section-title { font-size: 13px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  margin: 28px 0 10px; display: flex; align-items: center; gap: 12px; }
.section-title .spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  border-radius: 9px; border: 1px solid transparent; background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(1.06); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-small { min-height: 32px; padding: 0 12px; font-size: 13.5px; font-weight: 550; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- загрузка --- */
.upload { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.drop { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 16px; min-height: 92px;
  border: 1.5px dashed var(--line); border-radius: 10px; background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.filled { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.drop b { font-weight: 600; }
.drop span { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.field { flex: 1; min-width: 200px; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--ink); font: inherit; }
.field::placeholder { color: var(--muted); }

/* --- список авто --- */
.cars { display: flex; flex-direction: column; }
.car { display: grid; grid-template-columns: minmax(150px, 1.1fr) minmax(170px, 1.4fr) minmax(190px, 1.3fr) 24px;
  gap: 16px; align-items: center; padding: 14px 20px; color: var(--ink); border-top: 1px solid var(--line); }
.car:first-child { border-top: 0; }
.car:hover { background: var(--surface-2); text-decoration: none; }
.car-donor { font-size: 17px; font-weight: 650; }
.car-sub { color: var(--muted); font-size: 13.5px; }
.car-loss { text-align: right; }
.car-loss b { font-size: 17px; font-weight: 650; }
.car .chev { color: var(--muted); font-size: 18px; text-align: right; }
.bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px;
  font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.chip-run { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.chip-err { color: var(--err); border-color: var(--err); background: transparent; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

/* --- страница авто --- */
.back { display: inline-block; margin-bottom: 14px; font-size: 14px; }
.head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head h1 { font-size: 26px; line-height: 1.2; font-weight: 680; }
.head-meta { margin-top: 6px; color: var(--muted); display: flex; gap: 6px 14px; flex-wrap: wrap; font-size: 14px; }
.head .spacer { flex: 1; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.tab { text-align: left; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; cursor: pointer; box-shadow: var(--shadow); border-top: 3px solid var(--c); }
.tab:hover { background: var(--surface-2); }
.tab[aria-selected="true"] { border-color: var(--c); background: var(--surface); box-shadow: 0 0 0 1px var(--c), var(--shadow); }
.tab-name { display: block; font-size: 13.5px; color: var(--muted); font-weight: 550; }
.tab-count { display: block; font-size: 24px; font-weight: 680; line-height: 1.25; }
.tab-sub { display: block; font-size: 12.5px; color: var(--muted); min-height: 18px; }
.t-nt { --c: var(--nt); } .t-extra { --c: var(--extra); } .t-util { --c: var(--util); } .t-checks { --c: var(--checks); }

.panel-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; font-weight: 650; }
.panel-head .spacer { flex: 1; }
.panel-hint { color: var(--muted); font-size: 13.5px; }

.rows { width: 100%; border-collapse: collapse; }
.rows th { text-align: left; font-size: 12.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.rows td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rows tr:last-child td { border-bottom: 0; }
.rows th:first-child, .rows td:first-child { padding-left: 20px; }
.rows th:last-child, .rows td:last-child { padding-right: 20px; }
.c-check { width: 46px; }
.c-name { width: 32%; }
.c-price { width: 120px; text-align: right !important; }
.r-name { font-weight: 600; }
.r-labels { margin-top: 3px; display: flex; gap: 4px 6px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.r-price { font-weight: 600; }
.r-comment { color: var(--ink); }
tr.checked { background: var(--ok-soft); }
tr.checkable { cursor: pointer; }
tr.checkable:hover { background: var(--surface-2); }
tr.checkable.checked:hover { background: var(--ok-soft); }
.rows input[type=checkbox] { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--ok); cursor: pointer; }

.total { position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px 28px; flex-wrap: wrap; padding: 14px 20px;
  background: var(--surface); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.total .spacer { flex: 1; }
.total-item span { display: block; font-size: 12.5px; color: var(--muted); }
.total-item b { font-size: 20px; font-weight: 680; }
.total-main b { color: var(--ok); font-size: 24px; }

/* --- ход сверки --- */
.progress { display: flex; gap: 14px; align-items: flex-start; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .9s linear infinite; flex: none; margin-top: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.log { margin-top: 8px; color: var(--muted); font-size: 13.5px; white-space: pre-wrap; }
.error { color: var(--err); font-weight: 600; }
.foot { margin-top: 18px; color: var(--muted); font-size: 13px; }
.feedback-card { margin-top: 20px; }
.feedback-card h2 { font-size: 18px; }
.feedback-card p { margin: 8px 0 12px; }
.feedback-text { display: block; width: 100%; height: auto; min-height: 120px; resize: vertical; padding: 12px; }
.feedback-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.feedback-actions[hidden] { display: none; }
.c-action { width: 130px; }
.removed-rows { border-top: 1px solid var(--line); }
.removed-rows summary { padding: 14px 20px; color: var(--muted); cursor: pointer; }
.removed-rows .rows { opacity: .8; }

/* --- вход, пользователи, права --- */
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.who { display: flex; align-items: center; gap: 12px; }
.who-name { color: var(--ink); font-weight: 600; text-align: right; line-height: 1.25; }
.who-name span { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.flash { margin-bottom: 16px; padding: 12px 16px; border-radius: 10px; background: var(--ok-soft); border: 1px solid var(--ok); }
.flash-error { background: transparent; border-color: var(--err); color: var(--err); font-weight: 600; }
.auth { max-width: 420px; margin: 32px auto 0; display: flex; flex-direction: column; gap: 14px; }
.auth h1 { font-size: 22px; }
.auth label, .user-new label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 14px; }
.auth label .muted, .user-new label .muted { font-weight: 400; font-size: 13px; overflow-wrap: anywhere; }
.auth .field, .user-new .field { flex: none; width: 100%; min-width: 0; font-weight: 400; }
select.field { appearance: auto; }
.user-new { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr auto; gap: 14px; align-items: end; }
.user-new-hint { grid-column: 1 / -1; font-size: 13.5px; }
.people { display: flex; flex-direction: column; gap: 12px; }
.person-off { opacity: .65; }
.person-head { display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.person-head > div:first-child { flex: 1; min-width: 220px; }
.person-name { width: 100%; max-width: 340px; font-weight: 650; font-size: 16px; margin-bottom: 4px; }
.inline { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.inline .field { flex: none; min-width: 0; width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14.5px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.perms { padding: 14px 20px; display: flex; gap: 12px 32px; flex-wrap: wrap; align-items: flex-start; }
.perms fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.perms legend { padding: 0; margin-bottom: 8px; font-size: 12.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.person-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 13.5px; }
.person-reset { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: -4px 0 8px; padding: 0 20px; }

@media (max-width: 760px) {
  .nav { margin-left: 0; }
  .who-name span { display: none; }
  .user-new { grid-template-columns: 1fr; }
  .wrap { padding: 16px 12px 48px; }
  .upload { grid-template-columns: 1fr; }
  .car { grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 14px; }
  .car .chev { display: none; }
  .car-vin { grid-column: 1 / -1; order: 3; }
  .tabs { grid-template-columns: 1fr 1fr; }
  .head h1 { font-size: 22px; }
  .rows thead { display: none; }
  .rows tr { display: grid; grid-template-columns: 34px 1fr auto; gap: 2px 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .rows tr.plain { grid-template-columns: 1fr auto; }
  .rows td { display: block; padding: 0 !important; border: 0; width: auto !important; }
  .rows td.c-check { grid-row: 1 / span 2; }
  .rows td.r-comment { grid-column: 2 / -1; color: var(--muted); font-size: 14px; }
  .rows tr.plain td.r-comment { grid-column: 1 / -1; }
  .rows tr.plain td.c-action { grid-column: 1 / -1; margin-top: 8px; }
  .panel-head, .total { padding: 12px 14px; }
  .total { position: static; }
}

.archive-row { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:12px; }
.expense-scroll { overflow-x:auto; margin-top:20px; }
.expense-table { width:100%; border-collapse:collapse; min-width:740px; }
.expense-table th, .expense-table td { padding:14px 16px; border-bottom:1px solid var(--line); text-align:left; }
.expense-table th { color:var(--muted); font-size:13px; }
