:root {
  --accent: #ffd400;
  --accent-ink: #1a1a1a;
  --accent-soft: #fff6c2;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b66;
  --line: #e4e3dd;
  --ok: #1f9d55;
  --ok-soft: #e3f5ea;
  --warn: #b7791f;
  --warn-soft: #fdf1dc;
  --danger: #d63c3c;
  --danger-soft: #fdecec;
  --info: #2b6cb0;
  --info-soft: #e6effa;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.4; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ── Верхняя панель ── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: relative; z-index: 1000;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; text-decoration: none; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; font-size: 17px;
}
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.conn.on { background: var(--ok); }

/* ── Раскладка «панель + карта» ── */
.app { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; height: calc(100dvh - 53px); }
.panel { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; background: var(--bg); }
.map { position: relative; min-height: 300px; background: #e8e6df; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 42dvh auto; height: auto; }
  .map { order: -1; }
  .panel { overflow: visible; }
}
.map-offline { display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); }

/* ── Карточки и элементы ── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 26px; font-weight: 800; }
.grow { flex: 1; min-width: 0; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font-size: 15px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea.input { resize: vertical; min-height: 60px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  font-weight: 600; background: #ecebe6; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--ink); color: #fff; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; }

.seg { display: flex; background: #ecebe6; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 10%); }

.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #ecebe6; white-space: nowrap; }
.badge.searching { background: var(--warn-soft); color: var(--warn); }
.badge.accepted, .badge.arrived { background: var(--info-soft); color: var(--info); }
.badge.in_progress { background: var(--accent-soft); color: #7a6400; }
.badge.completed, .badge.online { background: var(--ok-soft); color: var(--ok); }
.badge.cancelled { background: var(--danger-soft); color: var(--danger); }
.badge.busy { background: var(--info-soft); color: var(--info); }
.badge.offline { background: #ecebe6; color: var(--muted); }

/* Адресная строка */
.addr { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: center; }
.addr .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #fff; cursor: pointer; border: 2px solid transparent; }
.addr .dot.a { background: var(--ok); }
.addr .dot.b { background: var(--danger); }
.addr .dot.picking { border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent); }
.hint { font-size: 13px; color: var(--muted); background: var(--accent-soft); border-radius: 10px; padding: 8px 10px; }
.cad-box { border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; gap: 6px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* Тарифы */
.tariffs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tariff { border: 2px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; background: var(--surface); text-align: left; display: flex; flex-direction: column; gap: 2px; }
.tariff.active { border-color: var(--ink); background: var(--accent-soft); }
.tariff .t-name { font-weight: 700; font-size: 14px; }
.tariff .t-price { font-weight: 800; font-size: 17px; }
.tariff .t-eta { font-size: 12px; color: var(--muted); }

/* Водитель/машина */
.car-plate { display: inline-block; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-weight: 700; letter-spacing: 1px; border: 2px solid var(--ink); border-radius: 6px; padding: 2px 8px; background: #fff; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 18px; flex: none; }

.stars { display: flex; gap: 4px; }
.stars button { font-size: 30px; line-height: 1; background: none; border: 0; cursor: pointer; color: #d5d3cb; padding: 0; }
.stars button.on { color: #f5b301; }

.status-head { display: flex; align-items: center; gap: 12px; }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--warn); animation: pulse 1.4s infinite; flex: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(183 121 31 / 50%); } 70% { box-shadow: 0 0 0 12px rgb(183 121 31 / 0%); } 100% { box-shadow: 0 0 0 0 rgb(183 121 31 / 0%); } }

.route { display: grid; grid-template-columns: 14px 1fr; gap: 4px 10px; font-size: 14px; }
.route .ra, .route .rb { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.route .ra { background: var(--ok); }
.route .rb { background: var(--danger); }

.list { display: flex; flex-direction: column; gap: 10px; }
.offer { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--surface); }
.offer.new { animation: flash 1.5s; }
@keyframes flash { from { background: var(--accent-soft); } to { background: var(--surface); } }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.stat .v { font-size: 20px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); }

/* Переключатель «на линии» */
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d5d3cb; border-radius: 999px; transition: 0.2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 3px rgb(0 0 0 / 30%); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(22px); }

/* Уведомления */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 5000; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: rise 0.2s; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* Маркеры карты */
.pin { display: grid; place-items: center; border-radius: 50%; font-weight: 800; color: #fff; border: 3px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 35%); font-size: 13px; }
.pin-from { background: var(--ok); }
.pin-to { background: var(--danger); }
.pin-car, .pin-me { background: var(--accent); font-size: 18px; }
.pin-me { box-shadow: 0 0 0 4px rgb(255 212 0 / 45%), 0 2px 6px rgb(0 0 0 / 35%); }
.pin-free { background: #fff; font-size: 14px; border-width: 2px; border-color: var(--accent); }
.pin-busy { background: var(--info); font-size: 14px; }
.pin-offline { background: #b8b6ae; font-size: 14px; }
.pin-wait { background: var(--warn); font-size: 12px; }

/* ── Страница входа ── */
.auth-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, var(--accent) 0 34%, var(--bg) 34%); }
.auth-box { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.auth-title { display: flex; align-items: center; gap: 12px; }
.auth-title .logo-mark { width: 48px; height: 48px; font-size: 28px; border-radius: 12px; background: #fff; }
.auth-title h1 { font-size: 30px; }
.error { color: var(--danger); font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ── Диспетчерская ── */
.admin { padding: 16px; display: flex; flex-direction: column; gap: 16px; max-width: 1400px; margin: 0 auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.admin-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .admin-grid { grid-template-columns: 1fr; } }
.admin .map { height: 460px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .input { padding: 6px 8px; width: 90px; }

/* Подпись источника данных карты (ODbL): минимальная, но читаемая и видимая без нажатий */
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib {
  margin: 0 4px 4px 0;
  padding: 0 5px;
  font-size: 10px;
  line-height: 16px;
  background: rgb(255 255 255 / 55%);
  border-radius: 4px;
}
.maplibregl-ctrl-attrib a { color: #555; text-decoration: none; }

/* Подпись источника карты в панели (вместо надписи поверх карты) */
.map-credit { font-size: 11px; color: var(--muted); }
.map-credit a { color: inherit; text-decoration: none; }
.map-credit a:hover { text-decoration: underline; }
.panel > .map-credit { margin-top: auto; padding-top: 4px; }
.admin .map-credit { text-align: right; }
@media (max-width: 820px) {
  /* на телефоне карта сверху, панель под ней — подпись первой строкой, сразу под картой */
  .panel > .map-credit { order: -1; margin: -8px 0 -6px; text-align: right; }
}

/* Подсказки адресов */
.ac { position: relative; min-width: 0; }
.ac-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 14%); max-height: 320px; overflow-y: auto; padding: 4px 0;
}
.ac-head { padding: 8px 12px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.ac-item { padding: 8px 12px; cursor: pointer; }
.ac-item.active, .ac-item:hover { background: var(--accent-soft); }
.ac-item .t { font-weight: 600; font-size: 14px; }
.ac-item .d { font-size: 12px; color: var(--muted); margin-top: 1px; }
.ac-empty { padding: 10px 12px; font-size: 13px; color: var(--muted); }

/* «Моё местоположение» */
.map-locate { display: grid; place-items: center; color: var(--ink); }
.map-locate svg { display: block; }
@media (pointer: coarse) { .maplibregl-ctrl-group .map-locate { width: 44px; height: 44px; } }
.pin-user { background: var(--info); box-shadow: 0 0 0 6px rgb(43 108 176 / 25%), 0 1px 4px rgb(0 0 0 / 30%); }
.ac-foot { padding: 8px 12px 6px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; }

/* Свои адреса в диспетчерской */
.pin-addr { background: #7c3aed; font-size: 13px; }
.pin-pick { background: var(--ink); font-size: 18px; }
label.field .ac { width: 100%; }

/* Адаптивная диспетчерская. */
#tabs { flex-wrap: wrap; }
.admin-grid > * { min-width: 0; }
#tabs button { min-width: 76px; }
#tabs button:not(.active) { color: #656560; }
.admin .badge.online { color: #13713c; }
@media (min-width: 1001px) { .admin-grid > .stack { position: sticky; top: 16px; } }
@media (max-width: 820px) { .admin .map-credit { flex-basis: 100%; min-width: max-content; } }
