/* Navi — экран сбора поездки.
   Язык формы взят с самой дороги: зелень указателей, жёлтый баннер oversize,
   асфальт, сигнальный красный. Шрифт Overpass нарисован по дорожным знакам США. */
:root {
  --sign: #00684A;
  --sign-ink: #FFFFFF;
  --banner: #FFC400;
  --banner-ink: #2A2100;
  --stop: #B8241B;
  --page: #ECEEEA;
  --panel: #FFFFFF;
  --ink: #15181A;
  --ink-2: #4E565B;
  --ink-3: #7C858A;
  --line: #D5D9D3;
  --ok-bg: #DDEFE7;
  --warn-bg: #FFF0BF;
  --warn: #6B5200;
  --stop-bg: #F7DCDA;
  --radius: 10px;
  --tap: 52px;
  /* Светлая тема — та, что по умолчанию: системную тёмную многие держат
     круглые сутки, а днём в кабине на солнце тёмный экран бликует и читается
     хуже. Ночная включается выбором водителя в «Настройках». */
  color-scheme: light;
}
/* Тёмная тема. Ставится атрибутом на <html> (static/theme.js) — и при прямом
   выборе «ночная», и при «как в телефоне», когда в телефоне ночь. Стилям
   поэтому хватает одного блока, а без скриптов остаётся день. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #101314;
  --panel: #1A1E20;
  --ink: #F1F3F0;
  --ink-2: #B3BBBF;
  --ink-3: #838C91;
  --line: #2C3235;
  --ok-bg: #12382C;
  --warn-bg: #3F3400;
  --warn: #F0C650;
  --stop-bg: #3A1512;
  --sign: #0A7D5A;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Overpass", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header.top {
  padding: 18px 18px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.top-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-logo { width: 34px; height: 34px; border-radius: 8px; flex: none; }
header.top h1 { font-size: 28px; font-weight: 800; margin: 0; letter-spacing: -0.01em; }
header.top a { color: var(--ink-2); font-size: 15px; text-decoration: none; white-space: nowrap; }

main { flex: 1; padding: 0 12px 16px; }
section { background: var(--panel); border-radius: var(--radius); margin-top: 12px; overflow: hidden; }
section > h2 { font-size: 15px; font-weight: 600; color: var(--ink-2); margin: 0; padding: 14px 16px 4px; }
.hint { font-size: 13px; color: var(--ink-3); margin: 0; padding: 0 16px 14px; }
.empty { padding: 6px 16px 0; color: var(--ink-2); font-size: 15px; margin: 0; }
.inline-error {
  margin: 0 16px 14px; padding: 10px 12px; border-radius: 8px;
  background: var(--stop-bg); color: var(--ink); font-size: 15px;
}
/* Строка внизу главной — только предупреждения; текст ошибки сервера бывает
   длиннее экрана, поэтому переносим принудительно, иначе он растягивает
   страницу и правый столбец кнопок уезжает за край. */
.health {
  color: var(--ink-3); font-size: 13px; text-align: center; margin: 14px 4px 0;
  overflow-wrap: anywhere;
}
.health.warn { color: var(--stop); font-weight: 600; }

/* Вход в обычную навигацию: строка поиска, ведущая на /go. */
.go-entry {
  display: flex; align-items: center; gap: 12px;
  margin-top: 12px; padding: 12px 16px;
  min-height: 64px;
  background: var(--panel); border-radius: var(--radius);
  color: inherit; text-decoration: none;
  border: 2px solid var(--sign);
}
.go-entry:active { background: var(--page); }
.go-entry > svg { width: 24px; height: 24px; color: var(--sign); flex: none; }
.go-entry-text { min-width: 0; }
.go-entry b { display: block; font-size: 19px; font-weight: 800; }
.go-entry small { display: block; font-size: 13px; color: var(--ink-2); margin-top: 2px; }

/* Строка пермита */
.permit {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 12px;
  align-items: center; padding: 12px 16px; border-top: 1px solid var(--line);
}
.permit:first-of-type { border-top: 0; }
.state {
  width: 46px; height: 46px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
  background: var(--page); color: var(--ink-2);
}
.permit[data-status="ready"] .state { background: var(--sign); color: var(--sign-ink); }
.permit[data-status="review"] .state { background: var(--banner); color: var(--banner-ink); }
.permit[data-status="error"] .state { background: var(--stop); color: #fff; }
.permit .num { font-weight: 600; font-size: 16px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.permit .meta { font-size: 14px; color: var(--ink-2); margin: 2px 0 0; }
/* Ошибка разбора бывает в несколько строк — в строке хватит начала, остальное в панели. */
.permit .meta.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.permit[data-status="review"] .meta, .permit[data-status="error"] .meta { color: var(--ink); }
.permit .cell { min-width: 0; }
.permit .actions { display: flex; align-items: center; gap: 4px; }

.bar { height: 5px; border-radius: 3px; background: var(--page); margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 35%; background: var(--sign); border-radius: 3px; animation: read 1.2s ease-in-out infinite alternate; }
@keyframes read { from { transform: translateX(-40%); } to { transform: translateX(230%); } }
@media (prefers-reduced-motion: reduce) { .bar i { animation: none; width: 60%; } }
/* Сборка доложила «участок 3 из 12» — полоса перестаёт бегать и показывает долю.
   Ширину ставит разметка: строка списка перерисовывается целиком каждый опрос. */
.bar.step i { animation: none; width: 0; }
/* Пауза во внешней карте: тише основной строки — это не новость, а объяснение. */
.permit .meta.wait { color: var(--ink-2); opacity: .8; }

/* Серый прямоугольник, который Chrome сам рисует по тапу, живёт дольше самого
   нажатия и выглядит как «кнопка включена». Подсветку рисуем сами — :active. */
a, button, label, .tile { -webkit-tap-highlight-color: transparent; }

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible,
.switch input:focus-visible + span { outline: 3px solid var(--banner); outline-offset: 2px; }
.btn {
  min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1.5px solid var(--ink);
  background: transparent; font-weight: 600; font-size: 15px; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; color: inherit;
}
.btn.quiet { border-color: var(--line); color: var(--ink-2); font-weight: 400; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; color: var(--ink-3); border-radius: 8px; font-size: 22px; line-height: 1; }

/* Панель проверки шага */
.review { grid-column: 1 / -1; background: var(--warn-bg); border-radius: 8px; padding: 12px; }
.permit[data-status="error"] .review { background: var(--stop-bg); }
.review p { margin: 0 0 4px; font-size: 14px; }
.review .raw { font-weight: 600; font-size: 16px; margin: 2px 0 10px; }
.review .why { color: var(--ink-2); }
.review .item { border-top: 1px solid rgba(0, 0, 0, .12); padding-top: 10px; margin-top: 10px; }
.review .item:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.review .choices { display: grid; gap: 8px; margin-top: 10px; }
.review .btn { background: var(--panel); min-height: var(--tap); }

/* Добавление пермита */
.add { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 16px 10px; }
.add label {
  min-height: 72px; border: 2px dashed var(--ink-3); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-weight: 600; font-size: 15px; cursor: pointer; text-align: center; padding: 8px;
}
.add label:active { background: var(--page); }
.add label svg { width: 26px; height: 26px; }
.add input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.add label:focus-within { outline: 3px solid var(--banner); outline-offset: 2px; }
.add.busy { opacity: .6; pointer-events: none; }

/* Лента поездки: по сегменту на пермит, ширина — по милям */
.ribbon-wrap { padding: 8px 16px 16px; }
.ribbon { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--page); gap: 2px; }
.ribbon span { display: block; min-width: 10px; }
.ribbon .ready { background: var(--sign); }
.ribbon .review { background: var(--banner); }
.ribbon .error { background: var(--stop); }
.ribbon .reading { background: repeating-linear-gradient(90deg, var(--ink-3) 0 6px, transparent 6px 12px); }
.ribbon-labels { display: flex; gap: 2px; margin-top: 6px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.ribbon-labels span { min-width: 10px; text-align: center; white-space: nowrap; overflow: hidden; }
.totals { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 15px; }
.totals > div { flex: 1 1 0; min-width: 0; }
.totals b { font-weight: 800; font-size: 20px; display: block; line-height: 1.15; }
.totals div:last-child { text-align: right; }
/* «Часы движения» приезжают из пермита целой фразой — уменьшаем и режем по трём строкам. */
.totals .small b {
  font-size: 14px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* Настройки */
.opt { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: var(--tap); padding: 8px 16px; border-top: 1px solid var(--line); }
/* Подпись ужимается первой: названия систем единиц режутся до «Метры ▾», а
   длинную подпись слева перенести по словам ничего не стоит. */
.opt > div { min-width: 0; }
.opt > span { flex: none; }
.opt:first-of-type { border-top: 0; }
.opt .t { font-size: 16px; margin: 0; }
.opt .s { font-size: 14px; color: var(--ink-2); margin: 2px 0 0; }
select {
  font: inherit; color: var(--ink); background: var(--page); border: 1px solid var(--line);
  border-radius: 8px; min-height: 40px; padding: 0 10px; max-width: 55%;
}
/* Смена пароля в настройках: два поля в столбик внутри обычной строки `.opt`.
   Кладём их сюда, а не на отдельный экран, — ходят за ними раз в год. */
/* Кнопка справа не ужимается: длинная почта переносила «Выйти» на две строки. */
.opt > button { flex: none; white-space: nowrap; }
.account-form { align-items: flex-start; }
.account-fields { display: grid; gap: 8px; margin: 8px 0 2px; }
.account-fields input {
  font: inherit; color: var(--ink); background: var(--page);
  border: 1px solid var(--line); border-radius: 8px; min-height: 40px; padding: 0 10px;
}

.switch { position: relative; display: inline-block; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--ink-3); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--sign); }
.switch input:checked + span::after { transform: translateX(20px); }
@media (prefers-reduced-motion: reduce) { .switch span, .switch span::after { transition: none; } }

/* Низ экрана. Кнопка старта — единственный громкий элемент: дорожный указатель. */
footer.go {
  position: sticky; bottom: 0;
  background: var(--page);
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.notice { display: none; background: var(--warn-bg); color: var(--ink); border-radius: 8px; padding: 10px 12px; font-size: 15px; margin-bottom: 8px; }
.notice.show { display: block; }
.start {
  width: 100%; min-height: 64px;
  background: var(--sign); color: var(--sign-ink);
  border: 4px solid var(--sign); border-radius: 14px;
  box-shadow: inset 0 0 0 2.5px var(--sign-ink);
  font-weight: 800; font-size: 24px; letter-spacing: 0.01em;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  text-decoration: none;
}
.start svg { width: 26px; height: 26px; }
.start[data-state="blocked"] { background: var(--ink-3); border-color: var(--ink-3); }
.start:active { transform: scale(0.99); }
.legal { font-size: 13px; color: var(--ink-2); text-align: center; margin: 8px 0 0; }

/* Переключатель языка: один и тот же на всех экранах (static/i18n.js). */
.top-actions { display: flex; align-items: center; gap: 12px; }
.lang-select {
  /* Общий для селектов потолок в процентах здесь врал: внутри flex-строки он
     считается от ширины, которая сама зависит от селектора, — и «Русский» с
     «Метры и кг» обрывались на «Рус ▾» и «Метры ▾». Ширину задаёт содержимое,
     а ужимается подпись слева. */
  max-width: none; flex: none;
  appearance: none;
  background: var(--panel) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0h10L5 6z' fill='%23767676'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink-2); font: inherit; font-size: 15px;
  padding: 7px 26px 7px 10px; min-height: 38px;
}

/* Поездка целиком: склейка маршрутов пермитов со стыками между ними. */
.trip-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 16px 10px; }
.trip-actions .btn { flex: 1 1 auto; text-align: center; text-decoration: none; }
.notes { list-style: none; margin: 0; padding: 0 16px 10px; }
.notes li {
  font-size: 13px; color: var(--ink-2); line-height: 1.45;
  padding: 6px 0 6px 12px; border-left: 2px solid var(--line);
}
.notes li.muted { color: var(--ink-3); }
.totals .small b { font-size: 15px; }

/* Габариты: значения из пермита и правки водителя рядом. */
.dims { padding: 4px 16px 6px; }
.dim {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 12px;
  align-items: center; padding: 9px 0; border-top: 1px solid var(--line);
}
.dim:first-child { border-top: 0; }
.dim-name { color: var(--ink-2); font-size: 15px; }
.dim-value { font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums; }
.dim-input {
  font: inherit; font-size: 17px; text-align: right;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-height: var(--tap); width: 9.5em;
  background: var(--page); color: var(--ink);
}
.dim-marks { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 12px; font-weight: 600; border-radius: 999px;
  padding: 2px 8px; background: var(--page); color: var(--ink-2);
}
.tag.over { background: var(--warn-bg); color: var(--warn); }
.tag.manual { background: var(--sign); color: var(--sign-ink); }
.dims-actions {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 6px 16px 10px;
}
.dims-actions .s { color: var(--ink-3); font-size: 13px; }

/* Назад в меню: одна и та же стрелка на всех внутренних экранах. */
.top-back {
  width: 40px; height: 40px; margin-left: -8px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1; color: var(--ink-2); text-decoration: none;
}

/* Готовые источники габаритов: пермиты и поездки, уже разобранные сервером. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 16px 10px; }
.chip {
  border: 1.5px solid var(--line); background: var(--page); color: var(--ink);
  border-radius: 999px; padding: 0 14px; min-height: 40px;
  font-size: 15px; font-weight: 600;
}
.chip[aria-pressed="true"] { border-color: var(--sign); background: var(--ok-bg); }

.hint.warn { color: var(--stop); font-weight: 600; }
.start[disabled] { opacity: .7; cursor: default; }
