:root {
  --bg: #f3f1ef;
  --panel: #ffffff;
  --border: #e6e1dd;
  --text: #201c1b;
  --muted: #746e6a;
  --accent: #e5220d;
  --accent-dark: #b81a09;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #b3261e;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен скрывать элемент всегда. Без этого правила form.stack { display:flex }
   перебивал hidden — например, форма "Сохранить машину этому водителю" была видна сразу. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg) url("/static/img/mesh-bg.jpg") center top / cover fixed no-repeat;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 3px solid var(--accent);
}

.brand { display: flex; align-items: center; text-decoration: none; }
.brand-logo { height: 52px; width: auto; display: block; }

.topbar nav { display: flex; align-items: center; gap: 14px; }
#whoami { color: var(--muted); font-size: 14px; }
#logout-link { color: var(--accent); display: inline-flex; align-items: center; text-decoration: none; }
#logout-link:hover { color: var(--accent-dark); }

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(32, 28, 27, 0.06);
}

h1 { margin-top: 0; color: var(--text); }
h2, h3 {
  margin-top: 0;
  padding-left: 11px;
  border-left: 4px solid var(--accent);
}

form.stack { display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
/* div.stack раньше не имел стилей вовсе — подписи и поля шли одной строкой вперемешку
   (форма "Оформить и выдать груз" в карточке заявки). */
.stack { display: flex; flex-direction: column; gap: 10px; flex-wrap: wrap; }
.stack > * { min-width: 0; }

label { font-size: 13px; color: var(--muted); }

input, select, textarea, button {
  font: inherit;
  max-width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

button:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: var(--bg); border-color: #cfc8c3; }
button.danger { background: var(--danger); }
button.danger:hover { background: #8f1d17; }
button.ok { background: var(--ok); }
button.ok:hover { background: #12833b; }

/* minmax(0, 1fr), а не 1fr: иначе колонка растягивается по самому широкому содержимому
   (таблица, строка кнопок) и на телефоне страница уезжает вбок. */
.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.order-list { display: flex; flex-direction: column; gap: 10px; }

.order-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  background: #fff;
  cursor: grab;
}
.order-row > div:first-child { flex: 1 1 260px; min-width: 0; }
.order-row > div:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
  justify-content: flex-end;
}

/* Заголовок + статусные бейджи заявки — отдельной строкой, чтобы бейдж не разрывался
   пополам при переносе (был баг: "От" и "водителя" оказывались на разных строках). */
.order-title-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 4px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.free { background: #dcfce7; color: var(--ok); }
.badge.busy { background: #fee2e2; color: var(--danger); }
.badge.queued { background: #fef3c7; color: var(--warn); }
.badge.progress { background: #fde2de; color: var(--accent); }
.badge.adhoc { background: #201c1b; color: #fff; margin-left: 0; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters button { background: #fff; color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.filters button:hover { background: var(--bg); }
.filters button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

#map { width: 100%; height: 420px; border-radius: var(--radius); border: 1px solid var(--border); }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; }
.success { color: var(--ok); font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(32, 28, 27, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }
body.modal-open { overflow: hidden; }

.modal-box {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 640px;
  width: 100%;
  position: relative;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); background: none; }

.badge.offer { background: #ede9fe; color: #6d28d9; }

.price-offer-box {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 12px;
  font-size: 16px;
  color: var(--muted);
}
.price-offer-box b { font-size: 22px; color: var(--text); }

/* Баннер-предложение включить уведомления — запрос разрешения браузер показывает как
   полноценный попап только по клику пользователя (жест), а не при автозапросе на загрузке
   страницы, поэтому вместо автозапроса даём кнопку. */
.notif-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 1000;
  max-width: 420px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(32, 28, 27, 0.18);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.notif-banner p { margin: 0; flex: 1 1 220px; font-size: 14px; }
.notif-banner .row { display: flex; gap: 8px; }

/* Картинка маршрута из Static API в карточке заявки */
.route-map { display: block; width: 100%; max-width: 600px; height: auto; border-radius: var(--radius); border: 1px solid var(--border); }

/* Выпадающие подсказки адресов (ymaps.SuggestView) должны быть поверх модальных окон */
ymaps[class*="-search__suggest"], ymaps[class*="-suggest"] { z-index: 10000 !important; }

/* Форма машины из СТС: две колонки на широком экране, одна — на телефоне */
.sts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 12px; }
.sts-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.sts-field input, .sts-field select { width: 100%; }
.sts-missing input, .sts-missing select { border-color: var(--danger); background: #fff5f5; }
.file-button { display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; border-radius: var(--radius); background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; }
.file-button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.file-button input { display: none; }
.doc-editor { border: 1px dashed var(--border); border-radius: var(--radius); padding: 12px; margin-top: 12px; }
.doc-editor img { max-width: 160px; max-height: 120px; border-radius: 6px; float: right; margin-left: 10px; }
.warn-list { margin: 8px 0; padding-left: 18px; color: var(--danger); }

/* Отмена/удаление заявки — внизу карточки, визуально отделены от основных действий */
.danger-zone { border-color: #f1c8c4; }

/* Кнопки ↑/↓ для очереди погрузки — на телефонах перетаскивание не работает */
.queue-move { display: inline-flex; gap: 4px; }
.queue-move button { padding: 4px 10px; line-height: 1; }

/* Телефоны */
@media (max-width: 600px) {
  .container { padding: 12px; }
  .card { padding: 14px; }
  h1 { font-size: 24px; }
  .topbar { padding: 8px 12px; }
  .brand-logo { height: 40px; }
  #whoami { max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .modal-overlay { padding: 12px 8px; }
  .modal-box { padding: 16px; }
  .order-row > div:last-child { justify-content: flex-start; }
  #map { height: 320px; }
  th, td { padding: 6px 8px; font-size: 13px; }
}
