/* «Лоция» — внешний вид всего сайта.
 * Каркас страницы: .app (панель .app__side слева + рабочая область .app__main).
 * Панель, крошки и шаги дорисовывает assets/shell.js; разметку см. в merge/index.html.
 * Шрифты — assets/fonts.css (подключается отдельной ссылкой перед этим файлом). */

:root {
  color-scheme: light;

  --depth: #0f2a3b;     /* панель, заголовки */
  --depth-2: #183a4f;   /* подложка переключателя в панели */
  --water: #eaf1f2;     /* фон рабочей области */
  --surface: #ffffff;   /* карточки, списки, полоса действия */
  --line: #cfdde2;      /* рамки и разделители */
  --ink: #10202a;       /* основной текст */
  --muted: #52646e;     /* второстепенный текст */
  --accent: #a8126a;    /* главное действие, текущий шаг, фокус */
  --accent-h: #8c0e58;  /* наведение на главное */
  --accent-t: #f6e3ee;  /* фон зоны при перетаскивании */
  --sea: #2f6f8a;       /* полосы в дашбордах, ссылки второго плана */
  --error: #b42318;
  --error-bg: #fdecea;
  --warn: #7a5207;
  --warn-bg: #fbf1dc;

  --drop-line: #6e97a8; /* пунктир зоны для файлов */
  --tint: #f4f8f9;      /* шапки таблиц, итоговые строки */
  --side-text: #d5e3ea;
  --side-muted: #9fbccb;

  --font-ui: "Onest", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius: 10px;
  --radius-btn: 8px;
}

* {
  box-sizing: border-box;
}

/* Атрибут hidden должен побеждать display у классов (.btn — inline-flex и т. п.):
 * страницы прячут кнопки «Скачать» и блоки именно через hidden. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--water);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.5;
}

a {
  color: var(--sea);
}

h2 {
  font-size: 22px;
  line-height: 1.25;
  margin: 32px 0 12px;
  color: var(--depth);
}

h3 {
  font-size: 19px;
  line-height: 1.3;
  margin: 24px 0 10px;
  color: var(--depth);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ───────────── Каркас: панель + рабочая область ───────────── */

.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

.app__side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 16px 20px;
  background: var(--depth);
  color: var(--side-text);
  overflow: hidden;
}

/* Изобаты — тонкие линии глубин внизу панели, как на морской карте. */
.app__side::after {
  content: "";
  position: absolute;
  left: -20px;
  right: -20px;
  bottom: -10px;
  height: 170px;
  opacity: 0.22;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='170' fill='none' stroke='%237FB3C8' stroke-width='1'%3E%3Cpath d='M0 40 C58 18 116 64 174 40 S276 20 320 36'/%3E%3Cpath d='M0 66 C64 46 122 90 180 64 S280 46 320 62'/%3E%3Cpath d='M0 92 C70 72 128 116 186 90 S284 72 320 88'/%3E%3Cpath d='M0 118 C76 98 134 142 192 116 S288 98 320 114'/%3E%3Cpath d='M0 144 C82 124 140 168 198 142 S292 124 320 140'/%3E%3C/svg%3E")
    center bottom / 320px 170px repeat-x;
}

.app__side :focus-visible {
  outline-color: #ffffff;
}

.app__main {
  min-width: 0;
  width: 100%;
  /* Не уже 1240: таблица «Результат» склейки (имя файла + три колонки веса
     «18 360 789,626 KGS») требует ~920 px и при 1000 уходила в прокрутку. */
  max-width: 1240px;
  padding: 32px 40px 40px;
}

/* Панель (разметку рисует shell.js) */

.side__brand {
  display: block;
  color: #ffffff;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  border-radius: 6px;
}

.side__brand-sub {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--side-muted);
}

.side__safe {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  color: var(--side-muted);
}

.side__tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--depth-2);
  border-radius: var(--radius);
}

.side__tab {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--side-muted);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.side__tab:hover {
  color: #ffffff;
}

.side__tab[aria-selected="true"] {
  background: #ffffff;
  color: var(--depth);
}

.side__tab[aria-selected="true"]:focus-visible {
  outline-offset: -3px;
  outline-color: var(--accent);
}

.side__menu-btn {
  display: none;
}

.side__nav {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -6px;
  padding: 0 6px 120px; /* низ — под изобатами, чтобы последний пункт не лёг на линии */
}

.side__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.side__link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: var(--radius-btn);
  color: var(--side-text);
  font-size: 15px;
  line-height: 1.3;
  text-decoration: none;
}

.side__link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.side__link[aria-current="page"] {
  background: #ffffff;
  color: var(--depth);
  font-weight: 600;
}

.side__link[aria-current="page"]:focus-visible {
  outline-color: var(--accent);
  outline-offset: -3px;
}

.side__fmt,
.fmt {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.side__fmt {
  color: #7fa3b6;
}

.side__link[aria-current="page"] .side__fmt {
  color: var(--accent);
}

/* Узкое окно: панель превращается в верхнюю полосу */

@media (max-width: 899.98px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .app__side {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand menu"
      "tabs tabs"
      "safe safe"
      "nav nav";
    align-items: center;
    gap: 12px;
    padding: 12px 16px 0;
    overflow: visible;
  }

  .app__side::after {
    display: none;
  }

  .side__brand {
    grid-area: brand;
    font-size: 18px;
  }

  .side__brand-sub {
    display: none;
  }

  .side__menu-btn {
    grid-area: menu;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: var(--radius-btn);
    background: transparent;
    color: #ffffff;
    font: inherit;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
  }

  .side__menu-btn[aria-expanded="true"] {
    background: #ffffff;
    color: var(--depth);
  }

  .side__tabs {
    grid-area: tabs;
  }

  .side__nav {
    grid-area: nav;
    display: none;
    margin: 0;
    padding: 0;
    max-height: 60vh;
  }

  .app__side.is-open .side__nav {
    display: block;
    padding-bottom: 12px;
  }

  .side__safe {
    grid-area: safe;
    margin: 0 -16px;
    padding: 10px 16px;
    background: var(--depth-2);
    font-size: 15px;
  }

  .app__main {
    padding: 20px 16px 32px;
  }
}

/* ───────────── Заголовок страницы, крошки ───────────── */

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.crumbs a {
  color: var(--muted);
  text-decoration: none;
  border-radius: 4px;
}

.crumbs a:hover {
  color: var(--depth);
  text-decoration: underline;
}

.page__title {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--depth);
}

.page__subtitle {
  margin: 0 0 24px;
  font-size: 18px;
  color: var(--muted);
}

/* ───────────── Шаги 1 → 2 → 3 ───────────── */

.steps {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0 0 24px;
  padding: 0;
  color: var(--muted);
  font-size: 17px;
}

.steps li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.steps li + li::before {
  content: "";
  width: 28px;
  border-top: 2px solid var(--line);
}

.steps__num {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.steps li.is-done .steps__num {
  background: var(--depth);
  border-color: var(--depth);
  color: #ffffff;
}

.steps li.is-current {
  color: var(--ink);
  font-weight: 600;
}

.steps li.is-current .steps__num {
  border-color: var(--accent);
  color: var(--accent);
}

/* ───────────── Кнопки ───────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 24px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-btn);
  background: var(--accent);
  color: #ffffff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  background: var(--accent-h);
  border-color: var(--accent-h);
}

.btn:disabled {
  background: #d9e4e8;
  border-color: #d9e4e8;
  color: var(--muted);
  cursor: not-allowed;
}

.btn--secondary {
  background: var(--surface);
  border-color: #9dbac5;
  color: var(--depth);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--depth);
  color: var(--depth);
}

.btn--secondary:disabled {
  background: var(--surface);
  border-color: var(--line);
}

/* ───────────── Зона для файлов и список ───────────── */

.dropzone {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 28px 24px;
  border: 2px dashed var(--drop-line);
  border-radius: var(--radius);
  background: #f7fafb;
  color: var(--muted);
  text-align: center;
}

.dropzone__text {
  margin: 0;
}

.dropzone__hint {
  flex-basis: 100%;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--muted);
}

.dropzone.dropzone--active {
  border-color: var(--accent);
  background: var(--accent-t);
  color: var(--accent);
}

.file-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.file-list:empty {
  display: none;
}

.file-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  min-height: 52px;
  padding: 4px 6px 4px 16px;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.file-list li:last-child {
  border-bottom: 0;
}

.file-list li[draggable="true"] {
  cursor: grab;
}

.file-list li.is-dragging {
  opacity: 0.45;
}

.file-list li.is-drop-target {
  box-shadow: inset 0 3px 0 var(--accent);
}

.file-list__meta {
  font-family: var(--font-mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.file-list__meta--error {
  font-family: var(--font-ui);
  white-space: normal;
  color: var(--error);
}

.file-list__remove {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}

.file-list__remove:hover {
  background: var(--water);
  color: var(--ink);
}

.hint {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--muted);
}

/* ───────────── Параметры: тумблер ───────────── */

.options {
  margin: 24px 0 0;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  cursor: pointer;
}

.switch__input {
  position: absolute;
  opacity: 0;
  width: 44px;
  height: 26px;
  margin: 0;
}

.switch__track {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: #a9bcc4;
  transition: background 0.15s ease;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s ease;
}

.switch__input:checked + .switch__track {
  background: var(--depth);
}

.switch__input:checked + .switch__track::after {
  transform: translateX(18px);
}

.switch__input:focus-visible + .switch__track {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ───────────── Полоса действия ───────────── */

.action-bar {
  position: sticky;
  bottom: 12px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 28px;
  padding: 10px 10px 10px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.action-bar__info {
  flex: 1 1 220px;
  margin: 0;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.action-bar__hint {
  font-size: 15px;
  color: var(--muted);
}

.action-bar__hint:empty {
  display: none;
}

/* ───────────── Результат ───────────── */

.result {
  margin-top: 32px;
}

.result__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.result__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  flex: 1 1 auto;
}

.result__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.stat {
  min-width: 150px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat__value {
  display: block;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--depth);
  white-space: nowrap;
}

.stat__label {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  color: var(--muted);
}

.table-scroll {
  overflow-x: auto;
  margin-bottom: 16px;
}

/* На Mac полоса прокрутки по умолчанию прячется, пока не начнёшь листать, —
   широкая таблица в узком окне выглядела обрезанной. Своя полоса видна всегда. */
.table-scroll::-webkit-scrollbar {
  height: 10px;
}

.table-scroll::-webkit-scrollbar-track {
  background: var(--line);
  border-radius: 5px;
}

.table-scroll::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 5px;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: var(--tint);
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table .num {
  font-family: var(--font-mono);
  font-size: 15px; /* моноширинный шире Onest: при 17 px три колонки веса не влезали в 1280 px */
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.data-table tr.is-total td {
  background: var(--tint);
  font-weight: 600;
}

/* ───────────── Сообщения ───────────── */

.error-message,
.warning-message {
  margin: 16px 0;
  padding: 14px 16px;
  border: 1px solid;
  border-left-width: 4px;
  border-radius: var(--radius-btn);
}

.error-message {
  background: var(--error-bg);
  border-color: #f1c1bb;
  border-left-color: var(--error);
  color: var(--error);
}

.warning-message {
  background: var(--warn-bg);
  border-color: #ecd6a6;
  border-left-color: var(--warn);
  color: var(--warn);
}

/* Вложенные строки/списки (заголовок предупреждений, ошибки нескольких архивов) —
 * без браузерных полей, иначе блок выше, чем нужно. */
:is(.error-message, .warning-message) :is(p, ul) {
  margin: 0;
}

:is(.error-message, .warning-message) ul {
  padding-left: 1.25em;
}

/* ───────────── Главная: маршрут и карточки ───────────── */

.route {
  margin: 0 0 24px;
  padding: 20px 20px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.route__title {
  margin: 0 0 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.route__stops {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--stops, 5), minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.route__stops::before {
  content: "";
  position: absolute;
  top: 8px;
  left: calc(50% / var(--stops, 5));
  right: calc(50% / var(--stops, 5));
  border-top: 2px dashed var(--accent);
  opacity: 0.55;
}

.route__stop {
  position: relative;
  text-align: center;
}

.route__link {
  display: block;
  padding: 0 6px 4px;
  border-radius: var(--radius-btn);
  color: var(--ink);
  text-decoration: none;
}

.route__link::before {
  content: "";
  display: block;
  width: 16px;
  height: 16px;
  margin: 1px auto 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
}

.route__link:hover .route__name {
  color: var(--accent);
  text-decoration: underline;
}

.route__name {
  display: block;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
}

.route__stop .fmt {
  color: var(--muted);
}

.tool-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}

.tool-card:hover {
  border-color: var(--accent);
}

.tool-card__title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--depth);
}

.tool-card__description {
  margin: 0;
  font-size: 17px;
  color: var(--muted);
}

.tool-card .fmt {
  align-self: flex-start;
  margin-top: 4px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
}

.tool-empty {
  color: var(--muted);
}

@media (max-width: 699.98px) {
  .route__stops {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .route__stops::before {
    top: 10px;
    bottom: 10px;
    left: 8px;
    right: auto;
    border-top: 0;
    border-left: 2px dashed var(--accent);
  }

  .route__stop {
    text-align: left;
  }

  .route__link {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 0;
  }

  .route__link::before {
    flex: none;
    margin: 0;
    transform: translateY(3px);
  }
}

/* ───────────── Общие блоки страниц инструментов ─────────────
 * Дашборды (секция .dashboard-block, строки итогов, полоса веса порта) и поля
 * ввода (Итоговый отчёт: позывной, дата прибытия, терминал). Таблицы внутри
 * .dashboard-block на страницах .app оформляет .data-table. */

.dashboard-block {
  margin-bottom: 32px;
}

.dashboard-row--port-total td {
  font-weight: 600;
  background: var(--tint);
}

.dashboard-row--grand-total td {
  font-weight: 700;
  background: var(--water);
}

/* Порожние контейнеры того же типа — отдельная строка, заметно другая на
 * вид, но не как жёлтый/голубой у расхождений в других инструментах
 * (dg-check, order-check, template-check): тут не ошибка, а факт. */
.dashboard-row--empty td {
  background: var(--water);
  color: var(--muted);
  font-style: italic;
}

.port-bar {
  height: 6px;
  width: 100%;
  max-width: 240px;
  margin-top: 4px;
  background: var(--line);
  border-radius: 3px;
}

.port-bar__fill {
  height: 100%;
  background: var(--sea);
  border-radius: 3px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 17px;
  color: var(--muted);
}

.field input {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid #9dbac5;
  border-radius: var(--radius-btn);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 17px;
}

.field input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}
