/* TMS — стиль по макетам: IBM Plex, светлый фон, синий акцент. */
:root {
  --bg: #F5F5F2; --surface: #FFFFFF; --surface-2: #FAFAF8; --ink: #1B1D1F; --muted: #5B6066; --muted-2: #4A4F55;
  --line: #DCDDD8; --line-2: #EEEFEC; --accent: #1F5FBF; --accent-ink: #163F80; --accent-bg: #E3ECF9;
  --green-bg: #E4F2E8; --green: #24643E; --orange-bg: #FFF1DF; --orange: #8A4A0F; --red-bg: #FBE6E4; --red: #9E2219;
  --grey-bg: #EEEFEC; --violet-bg: #E4DDF4; --violet: #45337A; --repair-bg: #F3E3D0; --repair: #6E4214;
  --header: #1B1D1F; --radius: 10px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
h1 { margin: 0; font-size: 22px; font-weight: 600; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
h3 { margin: 0; font-size: 14px; font-weight: 600; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* Шапка */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; padding: 10px 24px; background: var(--header); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; font-size: 16px; }
.brand-version { font-size: 11px; font-weight: 400; color: rgba(255,255,255,.6); white-space: nowrap; }
.brand-mark { width: 28px; height: 28px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; font-size: 13px; }
.topbar .role { font-size: 13px; color: #C9CCD0; }
.topbar .spacer { flex: 1 1 200px; display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; align-items: center; }
.topbar input[type=search] { flex: 0 1 340px; min-width: 180px; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid #3A3D41; background: #2A2D31; color: #fff; font: inherit; }
.topbar a.icon { color: #fff; text-decoration: none; position: relative; padding: 8px; }
.topbar .badge-count { position: absolute; top: 0; right: -2px; background: #D33; color: #fff; border-radius: 9px; font-size: 11px; padding: 0 5px; }
.topbar form { margin: 0; }
.linkbtn { background: none; border: 0; color: #C9CCD0; font: inherit; cursor: pointer; padding: 8px; }

/* Раскладка */
.layout { display: flex; flex-wrap: wrap; align-items: flex-start; }
.sidenav { flex: 1 1 200px; max-width: 230px; padding: 20px 12px; display: flex; flex-direction: column; gap: 2px; }
.sidenav a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.sidenav a.active { background: var(--accent-bg); color: var(--accent-ink); font-weight: 600; }
.sidenav .group { margin: 14px 12px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sidenav .hint { margin-top: 16px; padding: 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.main { flex: 999 1 560px; min-width: 0; padding: 20px 24px 48px; display: flex; flex-direction: column; gap: 22px; }
.narrow { max-width: 1280px; margin: 0 auto; width: 100%; }
.section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; }

/* Кнопки и фильтры */
.btn { display: inline-flex; align-items: center; justify-content: center; height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #B9BBB5; color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-ink); color: #fff; }
.btn-danger { color: var(--red); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; height: 48px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: 13px; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .n { margin-left: 6px; color: inherit; opacity: .7; }

/* Таблицы и карточки */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-pad { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; color: var(--muted); background: var(--surface-2); font-weight: 500; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data .sub { font-size: 12px; color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--grey-bg); color: var(--muted-2); }
.badge.blue { background: var(--accent-bg); color: #1A4F9E; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.red { background: var(--red-bg); color: var(--red); }
dl.kv { margin: 0; display: grid; grid-template-columns: 170px 1fr; gap: 8px 12px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
dl.sum { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13px; }
dl.sum dt { color: var(--muted); }
dl.sum dd { margin: 0; text-align: right; white-space: nowrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; }

/* Сетка загрузки парка */
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.fleet { min-width: 1040px; display: grid; grid-template-columns: 200px repeat(7, minmax(0, 1fr)); font-size: 12px; }
.fleet > div { border-bottom: 1px solid var(--line-2); }
.fleet .h { padding: 10px 8px; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); text-align: center; }
.fleet .h.today { color: var(--accent-ink); font-weight: 600; }
.fleet .veh { padding: 10px 12px; }
.fleet .day { padding: 6px 4px; display: flex; }
.cell { flex: 1; min-height: 36px; padding: 4px 6px; border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; line-height: 1.25; gap: 2px; }
.cell a { color: inherit; }
.cell.trip { background: #CFE0F7; color: var(--accent-ink); }
.cell.free { background: #fff; color: var(--green); border: 1px solid #9CC9AC; }
.cell.other { background: var(--violet-bg); color: var(--violet); }
.cell.repair { background: var(--repair-bg); color: var(--repair); }
.cell.off { background: #E6E7E3; color: var(--muted-2); }
.cell .free-tail { color: var(--green); font-size: 11px; }

/* Шаги статуса */
.steps { list-style: none; margin: 0; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.steps li { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.steps li .dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid #9EA2A6; flex: none; }
.steps li.done { color: var(--ink); }
.steps li.done .dot { background: #2E7D4F; border-color: #2E7D4F; }
.steps li.now { background: var(--accent-bg); color: var(--accent-ink); font-weight: 600; }
.steps li.now .dot { background: var(--accent); border-color: var(--accent); }
.steps .t { font-size: 12px; color: var(--muted); font-weight: 400; }

/* Формы */
.form { display: flex; flex-direction: column; gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .field .label { font-size: 13px; font-weight: 500; color: var(--muted-2); }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea, .inline-table input:not([type=checkbox]), .inline-table select {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid #C9CBC5; border-radius: 8px; background: #fff; font: inherit; color: var(--ink); }
.field textarea { min-height: 64px; }
.field.check { display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: center; align-self: end;
  column-gap: 10px; row-gap: 2px; min-height: 44px; }
.field.check .help, .field.check .err { grid-column: 2; }
.field.check label { font-size: 14px; color: var(--ink); }
/* Все галочки одного размера и вида (#16): квадрат 20 px не сжимается, даже если рядом длинная подпись. */
input[type=checkbox] { width: 20px; height: 20px; flex: none; margin: 0; accent-color: var(--accent); }
/* Блок галочек карточки (форма задаёт check_groups): группы с заголовком, галочки столбцом, подписи справа. */
.check-groups { display: flex; flex-wrap: wrap; gap: 16px 48px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.check-group { display: flex; flex-direction: column; gap: 4px; min-width: 200px; max-width: 320px; }
.check-group > .label { font-size: 13px; font-weight: 500; color: var(--muted-2); margin-bottom: 2px; }
.check-group .field.check { min-height: 32px; align-self: stretch; }
.field .help { font-size: 12px; color: var(--muted); }
.field .err, .errorlist { color: var(--red); font-size: 12px; margin: 0; padding: 0; list-style: none; }
.field.has-error input, .field.has-error select { border-color: var(--red); }
.radio-row { display: flex; gap: 4px; padding: 4px; background: var(--grey-bg); border-radius: 10px; }
.radio-row label { flex: 1; display: flex; align-items: center; justify-content: center; height: 40px; border-radius: 8px; cursor: pointer; color: var(--muted-2); font-weight: 400; }
.radio-row input { position: absolute; opacity: 0; pointer-events: none; }
.radio-row label:has(input:checked) { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.radio-row label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.inline-table { width: 100%; border-collapse: collapse; }
/* Поля во вложенных таблицах не сжимаются до обрезанных: если не влезает, таблица прокручивается вбок. */
.inline-table input:not([type=checkbox]) { min-width: 110px; }
.inline-table input[type=date] { min-width: 140px; }
.inline-table input[type=datetime-local] { min-width: 190px; }
.inline-table select { min-width: 130px; }
.inline-table input[type=date], .inline-table input[type=datetime-local] { font-size: 14px; padding-inline: 8px; }
.inline-table th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 4px 6px; }
.inline-table td { padding: 4px 6px; vertical-align: top; }
.inline-table input[type=checkbox] { min-height: 0; margin: 12px 0 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .block-title { font-weight: 600; font-size: 16px; margin: 0 0 10px; }
/* Заголовки вложенных блоков форм справочников — обычный заголовок, а не legend: Safari рисует legend
   на рамке, как бы его ни оформляли (#16). */
/* Заголовок раздела внутри карточки: по умолчанию браузер рисует legend поверх верхней рамки.
   float убирает его из этой роли — он становится обычным блоком внутри отступов карточки. */
fieldset.card > legend { float: left; width: 100%; padding: 0; margin: 0; }

/* Сообщения */
.messages { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.msg { padding: 10px 14px; border-radius: 8px; font-size: 13px; border: 1px solid var(--line); background: #fff; }
.msg.success { background: var(--green-bg); border-color: #BCDCC6; color: var(--green); }
.msg.warning { background: var(--orange-bg); border-color: #F1D3AE; color: var(--orange); }
.msg.error { background: var(--red-bg); border-color: #F0C2BD; color: var(--red); }

/* Мобильный экран (быстрые действия) */
.mobile { max-width: 520px; margin: 0 auto; width: 100%; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--grey-bg); border-radius: 10px; }
.seg a, .seg label { height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 8px; color: var(--muted-2); text-decoration: none; }
.seg a.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.car { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.car .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.car .plate { font-family: var(--mono); font-size: 16px; }
.car .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.car .actions .btn { height: 44px; }
.bottomnav { display: none; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .topbar .role { display: none; }
  .brand-version { font-size: 10px; }
  .topbar input[type=search], .topbar .btn-primary { display: none; }
  .sidenav { display: none; }
  .main { padding: 16px 16px 88px; }
  dl.kv { grid-template-columns: 1fr; gap: 2px; }
  dl.kv dd { margin-bottom: 8px; }
  .bottomnav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); z-index: 10; }
  .bottomnav a { height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--muted-2); text-decoration: none; }
  .bottomnav a.active { color: var(--accent); font-weight: 600; }
  .mobile { padding: 0 0 88px; }
}

/* Вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; }
