@font-face {
  font-family: Overpass; src: url(fonts/overpass-cyrillic.woff2) format('woff2');
  font-weight: 400 800; font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: Overpass; src: url(fonts/overpass-latin.woff2) format('woff2');
  font-weight: 400 800; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --asphalt: #2A2D31;
  --asphalt-2: #3A3E44;
  --line-yellow: #F5C400;
  --concrete: #E9EAE6;
  --paper: #FFFFFF;
  --ink: #17191C;
  --muted: #5C6168;
  --rule: #D3D5D0;
  --green: #0E6B4A;
  --blue: #1B5FAA;
  --red: #B92D1B;
  --red-soft: #FBE9E5;
  --amber-soft: #FFF5CC;
  --r-plate: 8px;
  --r-field: 5px;
  --rail: 228px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--concrete); color: var(--ink);
  font: 400 16px/1.45 Overpass, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 19px; font-weight: 700; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Каркас: слева полоса асфальта с осевой разметкой */
.shell { min-height: 100vh; min-height: 100dvh; }
.rail {
  position: fixed; inset: 0 auto 0 0; width: var(--rail); background: var(--asphalt); color: #fff;
  display: flex; flex-direction: column; padding: 18px 12px; z-index: 5;
}
.rail::after {
  content: ''; position: absolute; top: 0; bottom: 0; right: 0; width: 4px;
  background: repeating-linear-gradient(to bottom, var(--line-yellow) 0 34px, transparent 34px 62px);
}
.brand { font-weight: 800; font-size: 21px; padding: 2px 10px 18px; text-decoration: none; display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 10px; text-decoration: none;
  border-radius: var(--r-field); color: #D8DADB; font-weight: 600;
}
.nav a:hover { background: var(--asphalt-2); }
.nav a[aria-current=page] { background: #fff; color: var(--ink); }
.nav svg { width: 21px; height: 21px; flex: none; }
.who { font-size: 14px; color: #C3C6C8; padding: 10px; border-top: 1px solid var(--asphalt-2); margin-right: 6px; }
.who strong { display: block; color: #fff; font-weight: 600; }
.who button { background: none; border: 0; padding: 4px 0 0; color: #C3C6C8; text-decoration: underline; cursor: pointer; }
.main { margin-left: var(--rail); padding: 26px 32px 60px; max-width: calc(var(--rail) + 1180px); }

.head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.head h1 { flex: 1; min-width: 200px; }
.back { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 8px; font-weight: 600; }
.back:hover { color: var(--ink); }

/* Таблички: фирменный элемент. Двойная кромка как у дорожного указателя. */
.plates { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.plate {
  --bg: var(--blue); --fg: #fff; --edge: #fff;
  display: flex; flex-direction: column; justify-content: space-between; gap: 18px; min-height: 124px;
  padding: 16px 18px; background: var(--bg); color: var(--fg); text-decoration: none;
  border-radius: var(--r-plate); box-shadow: inset 0 0 0 4px var(--bg), inset 0 0 0 6px var(--edge);
  font-size: 21px; font-weight: 800; line-height: 1.1;
}
.plate:hover { filter: brightness(1.07); }
.plate:active { transform: translateY(1px); }
.plate svg { width: 42px; height: 42px; }
.plate small { display: block; font-size: 14px; font-weight: 500; margin-top: 5px; opacity: .92; }
.t-purchase { --bg: var(--green); }
.t-issue { --bg: var(--line-yellow); --fg: var(--ink); --edge: var(--ink); }
.t-transfer { --bg: var(--blue); }
.t-return { --bg: var(--paper); --fg: var(--ink); --edge: var(--ink); }
.t-writeoff { --bg: var(--red); }
.t-inventory { --bg: var(--asphalt); }
.minor-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 26px; }

.tag {
  --bg: var(--blue); --fg: #fff; --edge: #fff;
  display: inline-block; padding: 3px 9px 2px; border-radius: 4px; font-size: 13px; font-weight: 700;
  background: var(--bg); color: var(--fg); white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--bg), inset 0 0 0 2px var(--edge);
}

/* Панели и таблицы */
.columns { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { background: var(--paper); border-radius: var(--r-plate); padding: 16px 18px; }
.panel + .panel { margin-top: 16px; }
.panel > h2 { margin-bottom: 10px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 14px; font-weight: 600; color: var(--muted); padding: 7px 10px; border-bottom: 2px solid var(--ink); vertical-align: bottom; }
td { padding: 9px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th.n, td.n { text-align: right; white-space: nowrap; }
tr.cat td { font-weight: 800; padding-top: 16px; border-bottom: 2px solid var(--rule); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #F4F5F2; }
tr.sub td { background: #F4F5F2; font-size: 15px; color: var(--muted); padding-left: 24px; }
tr.total td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom: 0; }
.neg { color: var(--red); font-weight: 700; }
.over { color: var(--red); font-weight: 700; }
.ok { color: var(--green); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.doc-row {
  display: grid; grid-template-columns: 124px minmax(0, 1fr) auto; gap: 4px 14px; align-items: start;
  padding: 11px 4px; border-bottom: 1px solid var(--rule); text-decoration: none;
}
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: #F4F5F2; }
.doc-row .route { font-weight: 600; overflow-wrap: anywhere; }
.doc-row .sum { text-align: right; font-weight: 700; white-space: nowrap; }
.doc-row.cancelled .route, .doc-row.cancelled .sum { text-decoration: line-through; color: var(--muted); }

.sites { list-style: none; margin: 0; padding: 0; }
.sites a { display: flex; justify-content: space-between; gap: 12px; padding: 9px 4px; border-bottom: 1px solid var(--rule); text-decoration: none; }
.sites li:last-child a { border-bottom: 0; }
.sites a:hover { background: #F4F5F2; }
.sites span:last-child { white-space: nowrap; font-weight: 700; }

/* Фильтры */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--rule); background: var(--paper); border-radius: 999px; padding: 7px 14px 5px; cursor: pointer; font-weight: 600; font-size: 15px; }
.chip[aria-pressed=true] { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs { display: flex; gap: 22px; border-bottom: 2px solid var(--rule); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 8px 0; text-decoration: none; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a[aria-current=page] { color: var(--ink); border-color: var(--line-yellow); }

/* Формы */
.field { display: block; margin-bottom: 14px; }
.field > span, .label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px 8px; background: var(--paper);
  border: 1.5px solid #9EA3A8; border-radius: var(--r-field);
}
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; flex: none; margin: 0; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: 2px solid var(--blue); outline-offset: 0; }
.form { max-width: 760px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.static { min-height: 46px; display: flex; align-items: center; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px;
  padding: 10px 18px 8px; border-radius: var(--r-field); border: 1.5px solid var(--ink);
  background: var(--paper); font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #F4F5F2; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #33373C; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.link { border-color: transparent; background: none; padding-inline: 8px; text-decoration: underline; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.submit-bar { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.submit-bar .total-line { flex: 1; font-weight: 800; font-size: 18px; }

.top-actions { margin-bottom: 12px; }
.top-actions:empty { display: none; }
.lines { border-top: 2px solid var(--ink); margin-bottom: 12px; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) 150px 150px 40px; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--rule); align-items: start; }
.line.no-third { grid-template-columns: minmax(0, 1fr) 170px 40px; }
.line .nm { font-weight: 700; padding-top: 11px; overflow-wrap: anywhere; }
.line .hint { font-size: 14px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.line label > span { font-size: 13px; color: var(--muted); display: block; margin-bottom: 2px; }
.line .all { background: none; border: 0; padding: 3px 0 0; font-size: 14px; text-decoration: underline; cursor: pointer; color: var(--blue); }
.line .x { width: 40px; height: 46px; margin-top: 20px; border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; }
.line .warn { grid-column: 1 / -1; background: var(--amber-soft); padding: 7px 10px 5px; border-radius: 4px; font-size: 15px; }
.error-box { background: var(--red-soft); color: var(--red); border-left: 4px solid var(--red); padding: 10px 14px 8px; margin: 12px 0; font-weight: 600; }
.notice { background: var(--amber-soft); border-left: 4px solid var(--line-yellow); padding: 10px 14px 8px; margin-bottom: 16px; }
.empty { padding: 30px 8px; color: var(--muted); }
.check-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; max-height: 240px; overflow: auto; padding: 8px; border: 1.5px solid #9EA3A8; border-radius: var(--r-field); }
.check { display: flex; gap: 9px; align-items: flex-start; font-size: 15px; }

/* Диалоги */
dialog { border: 0; border-radius: var(--r-plate); padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); color: var(--ink); }
dialog::backdrop { background: rgba(23, 25, 28, .6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 8px; }
.dlg-close { border: 0; background: none; font-size: 26px; cursor: pointer; line-height: 1; padding: 4px 8px; }
.dlg-body { padding: 4px 18px 18px; }
.pick-list { height: min(56dvh, 460px); overflow-y: auto; margin-top: 10px; }
.pick-list h3 { font-size: 14px; color: var(--muted); padding: 12px 4px 4px; font-weight: 700; position: sticky; top: 0; background: var(--paper); }
.pick { display: flex; justify-content: space-between; gap: 12px; width: 100%; min-height: 46px; padding: 10px 6px 8px; background: none; border: 0; border-bottom: 1px solid var(--rule); cursor: pointer; text-align: left; font-weight: 600; }
.pick:hover, .pick:focus-visible { background: #F4F5F2; }
.pick span:last-child { font-weight: 400; color: var(--muted); white-space: nowrap; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 11px 18px 9px; border-radius: var(--r-field); font-weight: 700; transition: .18s; z-index: 50; max-width: 90vw;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Вход: дорога с разметкой и табличка */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--asphalt); position: relative; overflow: hidden;
}
.login::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 10px; margin-left: -5px;
  background: repeating-linear-gradient(to bottom, #fff 0 70px, transparent 70px 130px);
}
.login form {
  position: relative; width: min(380px, 100%); background: var(--blue); color: #fff; padding: 26px 26px 22px;
  border-radius: 10px; box-shadow: inset 0 0 0 5px var(--blue), inset 0 0 0 8px #fff;
}
.login h1 { font-size: 30px; margin-bottom: 18px; }
.login .field > span { color: #fff; }
.login input { border-color: #fff; color: var(--ink); }
.login .btn { background: var(--line-yellow); border-color: var(--line-yellow); color: var(--ink); width: 100%; margin-top: 4px; }
.login .error-box { background: #fff; }

@media (max-width: 1040px) {
  .columns { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .rail {
    inset: auto 0 0 0; width: auto; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .rail::after {
    top: 0; bottom: auto; left: 0; right: 0; width: auto; height: 3px;
    background: repeating-linear-gradient(to right, var(--line-yellow) 0 26px, transparent 26px 46px);
  }
  .brand, .who { display: none; }
  .nav { flex-direction: row; justify-content: space-around; gap: 0; }
  .nav a { flex: 1; min-width: 0; flex-direction: column; gap: 1px; padding: 8px 2px 3px; font-size: 12px; text-align: center; }
  .nav a[aria-current=page] { background: none; color: var(--line-yellow); }
  .main { margin: 0; padding: 16px 16px calc(92px + env(safe-area-inset-bottom)); }
  h1 { font-size: 23px; }
  .plates { grid-template-columns: 1fr 1fr; gap: 10px; }
  .plate { min-height: 108px; font-size: 19px; padding: 14px 15px; }
  .plate svg { width: 34px; height: 34px; }
  .panel { padding: 12px 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .line, .line.no-third { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px; }
  .line .nm { grid-column: 1 / -2; grid-row: 1; padding-top: 2px; }
  .line .x { grid-column: 3; grid-row: 1; margin-top: 0; width: 36px; height: 30px; }
  .line.no-third label:not(.keep) { grid-column: 1 / -1; }
  .doc-row { grid-template-columns: minmax(0, 1fr) auto; }
  .doc-row .tag-cell { grid-column: 1; }
  .doc-row .sum { grid-column: 2; grid-row: 1; }
  .doc-row .route { grid-column: 1 / -1; }
  .check-list { grid-template-columns: 1fr; }
  .submit-bar .btn.primary { width: 100%; }
  th, td { padding-inline: 6px; }
  .hide-sm { display: none; }
  #toast { bottom: 88px; }
}
@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
@media print {
  .rail, .no-print { display: none !important; }
  .main { margin: 0; padding: 0; }
  body { background: #fff; }
}

/* Загрузка счёта: пунктир как прерывистая разметка */
.drop { background: var(--paper); border: 3px dashed var(--line-yellow); border-radius: var(--r-plate); padding: 14px 16px; margin-bottom: 16px; }
.drop.over { background: var(--amber-soft); }
.drop-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.file-input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; }
.file-input:focus-visible + .drop-row .btn { outline: 3px solid var(--blue); outline-offset: 2px; }
.drop-row label.btn { cursor: pointer; }
.invoice-state:not(:empty) { margin-top: 12px; }
.invoice-state p { margin: 6px 0; }
.invoice-state .warn { background: var(--amber-soft); padding: 7px 10px 5px; border-radius: 4px; font-size: 15px; margin: 6px 0; }
.invoice-state .error-box { margin: 6px 0; }
.line.unmatched { grid-template-columns: minmax(0, 1fr) auto 40px; background: var(--amber-soft); padding-inline: 8px; }
.line.unmatched .btn { margin-top: 4px; }
.line.unmatched .x { margin-top: 4px; }
@media (max-width: 820px) {
  .line.unmatched { grid-template-columns: minmax(0, 1fr) 36px; }
  .line.unmatched .nm { grid-column: 1; }
  .line.unmatched .btn { grid-column: 1 / -1; grid-row: 2; }
  .line.unmatched .x { grid-column: 2; grid-row: 1; }
}
