/* Цвета берутся из темы Telegram: их подставляет app.js в переменные ниже.
   Значения по умолчанию — на случай, если тема не пришла (браузер на Маке). */
:root {
  --bg: #ffffff;
  --text: #000000;
  --hint: #707579;
  --card: #f4f4f5;
  --line: #e4e4e7;
  --accent: #2481cc;
  --accent-text: #ffffff;

  /* Цвета состояний — одно место на весь дашборд. Ниже они переопределяются
     для тёмной темы: на тёмном фоне те же оттенки не читаются. */
  --held: #2f7fd0;      /* за водителем */
  --free: #3a9a4a;      /* свободна */
  --off: #8a8f98;       /* не на ходу */
  --warn: #b9770a;      /* скоро истекает */
  --bad: #d5342b;       /* просрочено */
  --good: #3a9a4a;
  --on-warn: #fff6e6;   /* подложка метки */
  --on-bad: #fdeceb;
  --on-held: #eaf2fb;
  --on-free: #ecf6ee;
  --on-off: #f1f2f4;
}

/* Тёмная тема приходит от Telegram: класс ставит app.js по его colorScheme. */
:root.dark {
  --held: #7cb6f0;
  --free: #74d18a;
  --off: #a8aeb8;
  --warn: #f0b64d;
  --bad: #ff8a80;
  --good: #74d18a;
  --on-warn: #3a2f16;
  --on-bad: #3a201e;
  --on-held: #1b2a3a;
  --on-free: #1b3323;
  --on-off: #2a2c31;
}

/* Если страницу открыли просто в браузере (Telegram цвета не прислал),
   идём за системной темой — иначе на тёмном экране она слепит белым. */
@media (prefers-color-scheme: dark) {
  :root:not(.light):not(.dark) {
    --bg: #17212b;
    --text: #f5f5f5;
    --hint: #8a9aa9;
    --card: #232e3c;
    --line: #2f3d4d;
    --accent: #5aa9e6;
    --accent-text: #ffffff;
    --held: #7cb6f0;
    --free: #74d18a;
    --off: #a8aeb8;
    --warn: #f0b64d;
    --bad: #ff8a80;
    --good: #74d18a;
    --on-warn: #3a2f16;
    --on-bad: #3a201e;
    --on-held: #1b2a3a;
    --on-free: #1b3323;
    --on-off: #2a2c31;
  }
}

* { box-sizing: border-box; }

/* -------------------------------------------------------------- иконки
   Набор Lucide (ISC), каждая иконка — свой файл в /icons. Красится она
   через currentColor: сама картинка работает маской, а цвет даёт текст,
   рядом с которым иконка стоит. */
.icon {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  flex: none;
  vertical-align: -0.18em;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.icon-truck { --icon: url("/icons/truck.svg"); }
.icon-user { --icon: url("/icons/user.svg"); }
.icon-wrench { --icon: url("/icons/wrench.svg"); }
.icon-warning { --icon: url("/icons/triangle-alert.svg"); }
.icon-fuel { --icon: url("/icons/fuel.svg"); }
.icon-document { --icon: url("/icons/file-text.svg"); }
.icon-calendar { --icon: url("/icons/calendar.svg"); }
.icon-chart { --icon: url("/icons/chart-column.svg"); }
.icon-up { --icon: url("/icons/arrow-up.svg"); }
.icon-down { --icon: url("/icons/arrow-down.svg"); }
.icon-back { --icon: url("/icons/arrow-left.svg"); }
.icon-compare { --icon: url("/icons/arrow-up-down.svg"); }
.icon-check { --icon: url("/icons/check.svg"); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.head-inner { max-width: 1100px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.brand img { height: 28px; width: auto; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: .2px; }
.head {
  padding: 16px 16px 0;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.hello { font-size: 20px; font-weight: 600; margin: 0 0 2px; }
.company { color: var(--hint); margin: 0 0 12px; font-size: 14px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: none; color: var(--hint); font: inherit;
  padding: 8px 10px; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.page { max-width: 1100px; margin: 0 auto; padding: 14px 16px 32px; }

.state { padding: 24px 0; text-align: center; }
.state-text { color: var(--hint); margin: 0 0 14px; white-space: pre-line; }

.button {
  border: 0; border-radius: 10px; padding: 9px 16px; font: inherit;
  background: var(--accent); color: var(--accent-text); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.button[disabled] { opacity: .5; cursor: default; }
.button-quiet { background: var(--card); color: var(--text); }

h2 {
  font-size: 15px; font-weight: 600; margin: 22px 0 8px;
  display: flex; align-items: center; gap: 7px;
}
h2:first-child { margin-top: 0; }
h2 .icon { color: var(--hint); }

/* -------------------------------------------------------------- плитки */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { background: var(--card); border-radius: 12px; padding: 12px 10px; text-align: center; }
.tile-value { font-size: 24px; font-weight: 600; line-height: 1.1; }
.tile-label {
  color: var(--hint); font-size: 12px; margin-top: 4px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.tile-total .icon { color: var(--text); }
.tile-held .icon { color: var(--held); }
.tile-free .icon { color: var(--free); }
.tile-off .icon { color: var(--off); }

/* -------------------------------------------------------------- списки */
.rows { display: flex; flex-direction: column; gap: 6px; }
.row {
  background: var(--card); border-radius: 10px; padding: 10px 12px;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.row-main { font-weight: 500; display: flex; align-items: center; gap: 7px; }
.row-side { color: var(--hint); font-size: 13px; text-align: right; white-space: nowrap; }
.row-note { color: var(--hint); font-size: 13px; }
.soon { color: var(--warn); }
.late { color: var(--bad); font-weight: 600; }
.ok { color: var(--good); }
.empty { color: var(--hint); padding: 8px 0; }

/* Метка состояния: кружок цвета плюс подпись. Цвета — из переменных выше,
   и только оттуда: второго места, где они заданы, нет. */
.mark {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: 13px; white-space: nowrap;
}
.mark::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex: none;
}
.mark-held { color: var(--held); background: var(--on-held); }
.mark-free { color: var(--free); background: var(--on-free); }
.mark-off_road { color: var(--off); background: var(--on-off); }
.mark-soon { color: var(--warn); background: var(--on-warn); }
.mark-late { color: var(--bad); background: var(--on-bad); }

/* -------------------------------------------------------------- таблицы */
.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.tools input, .tools select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
}
.tools label { display: inline-flex; gap: 6px; align-items: center; color: var(--hint); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--hint); font-weight: 500; cursor: pointer; white-space: nowrap; }
th .icon { opacity: .75; margin-left: 4px; }
td.num, th.num {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--card); }

/* На телефоне таблица не читается — каждая строка становится карточкой. */
.cards { display: none; flex-direction: column; gap: 8px; }
.card {
  background: var(--card); border-radius: 12px; padding: 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
}
.card-head {
  display: flex; justify-content: space-between; gap: 8px; font-weight: 600;
  align-items: center;
}
.card-head .icon { color: var(--hint); }
.card-line { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.card-line span:first-child { color: var(--hint); }

@media (max-width: 720px) {
  .table-wrap { display: none; }
  .cards { display: flex; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

/* На узком экране строка «слева название, справа срок» не помещается —
   кладём срок под названием, а не ломаем слова пополам. */
@media (max-width: 520px) {
  .row { flex-direction: column; align-items: stretch; gap: 2px; }
  .row-side { text-align: left; white-space: normal; }
  .facts { grid-template-columns: 1fr; gap: 0 0; }
  .facts dt { margin-top: 8px; }
}

/* --------------------------------------------------------------- графики */
.chart-box { position: relative; height: 260px; margin-top: 8px; }
@media (max-width: 720px) { .chart-box { height: 220px; } }

/* -------------------------------------------------------------- карточка */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.facts dt { color: var(--hint); }
.facts dd { margin: 0; }

.summary-head { margin-right: auto; }
.summary-day { font-weight: 600; }
.row-open { cursor: pointer; }
.row-open:hover { outline: 1px solid var(--line); }

.pick { display: flex; align-items: center; gap: 8px; }
.pick input { width: 16px; height: 16px; }
