/* =========================================================
   Кабинет водителя — мобильный интерфейс в стиле приложения.
   Масштабируется от узких телефонов (320px) до раскладушек
   и планшетов: на широком экране главная делится на 2 колонки.
   ========================================================= */
:root {
  --bg: #0f1012;
  --surface: #191b1f;
  --surface-2: #23262b;
  --line: #2c3036;
  --text: #f3f4f6;
  --muted: #9aa1a9;
  --accent: #fcd535;
  --accent-text: #111214;
  --ok: #3ecf6e;
  --warn: #ffb020;
  --bad: #ff5d5d;

  --radius: 20px;
  --gap: clamp(10px, 3vw, 16px);
  --pad: clamp(14px, 4.5vw, 22px);
  --content-max: 560px;
  --appbar-h: 64px;
  --tabbar-h: 64px;

  --fs-body: clamp(15px, 4.2vw, 17px);
  --fs-title: clamp(20px, 6vw, 26px);
  --fs-hero: clamp(22px, 7vw, 30px);
}

@media (min-width: 720px) {
  :root { --content-max: 960px; }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  color: var(--text);
  font: var(--fs-body)/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: .86em; }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Кнопки и поля ---------- */
.btn {
  min-height: 54px; padding: 0 20px; border: 0; border-radius: 16px;
  font-size: 1.05em; font-weight: 700; cursor: pointer;
  transition: transform .08s ease, opacity .15s ease, background .15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
.btn-xl { min-height: 72px; font-size: 1.2em; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: .86em; color: var(--muted); }
input {
  width: 100%; padding: 16px 18px;
  font-size: max(16px, 1.15em); /* ≥16px — иначе iOS увеличивает страницу при фокусе */
  background: var(--surface-2); color: var(--text);
  border: 2px solid transparent; border-radius: 16px; outline: none;
}
input:focus { border-color: var(--accent); }
.code-input { text-align: center; letter-spacing: .6em; font-size: 2em; font-weight: 800; padding-left: calc(18px + .6em); }

.error { color: var(--bad); min-height: 1.3em; margin: 0; font-size: .9em; }

/* ---------- Экраны входа ---------- */
.auth {
  min-height: 100dvh;
  max-width: 440px; margin: 0 auto;
  padding: calc(var(--pad) + env(safe-area-inset-top)) var(--pad) calc(var(--pad) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; justify-content: space-between; gap: 24px;
}
.auth-hero { padding-top: 12vh; position: relative; }
.auth-hero h1 { font-size: var(--fs-title); margin: 18px 0 8px; }
.logo {
  width: 72px; height: 72px; border-radius: 22px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 32px; font-weight: 900;
}
.back {
  position: absolute; top: 0; left: -6px;
  width: 48px; height: 48px; border: 0; border-radius: 14px;
  background: var(--surface); font-size: 22px; cursor: pointer;
}
.auth-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Вход звонком ---------- */
.call-number {
  text-align: center; font-size: clamp(24px, 8vw, 32px); font-weight: 900; letter-spacing: .02em;
  background: var(--surface); border-radius: var(--radius); padding: 22px 12px;
}
.call-btn { display: flex; align-items: center; justify-content: center; text-decoration: none; min-height: 64px; font-size: 1.2em; }
.call-status { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); min-height: 28px; }
.call-status.done { color: var(--ok); font-weight: 700; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
.call-status.done .spinner, .call-status.stopped .spinner { display: none; }

/* ---------- Оболочка приложения ---------- */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }

.appbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: var(--content-max); margin: 0 auto; height: var(--appbar-h);
  padding: 0 var(--pad);
  display: flex; align-items: center; justify-content: space-between;
}
.appbar-title { font-size: 1.2em; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 46px; height: 46px; flex: none; border: 0; border-radius: 14px;
  background: var(--surface); font-size: 22px; cursor: pointer;
}
.icon-btn.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.content {
  flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto;
  padding: var(--pad) var(--pad) calc(var(--tabbar-h) + var(--pad) + env(safe-area-inset-bottom));
}
.tab { display: flex; flex-direction: column; gap: var(--gap); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner { max-width: var(--content-max); margin: 0 auto; height: var(--tabbar-h); display: flex; }
.tab-btn {
  flex: 1; border: 0; background: none; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .78em; font-weight: 600;
}
.tab-btn .tab-ico { font-size: 1.5em; line-height: 1; }
.tab-btn.active { color: var(--accent); }

/* ---------- Карточки ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: var(--pad); }
.card-title { font-weight: 800; font-size: 1.05em; }
.notice { border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent); }

.home-grid { display: grid; gap: var(--gap); }
.actions { display: flex; flex-direction: column; gap: var(--gap); }
@media (min-width: 720px) {
  .home-grid { grid-template-columns: 1fr 1fr; align-items: start; }
  .home-grid > .hero { grid-column: 1; grid-row: 1; }
  .home-grid > .today { grid-column: 1; grid-row: 2; }
  .home-grid > .actions { grid-column: 2; grid-row: 1 / span 2; }
}

/* ---------- Текущий заказ и снятие ---------- */
.btn-danger-solid { background: var(--bad); color: #fff; }
.order-card { border: 1px solid var(--line); }
.order-route-big { display: flex; flex-direction: column; gap: 10px; font-weight: 700; }
.route-point { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.route-point span:last-child { min-width: 0; overflow-wrap: anywhere; }
.route-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; margin-top: .35em; }
.route-dot.a { background: var(--accent); }
.route-dot.b { background: var(--text); }
.cancel-note { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.cancel-note.warn { color: var(--warn); }
.cancel-note.ok { color: var(--ok); }
.cancel-note.bad { color: var(--bad); }
.cancel-note .note-sub { display: block; color: var(--muted); font-weight: 500; font-size: .9em; margin-top: 2px; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .6); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 10px var(--pad) calc(var(--pad) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
  animation: sheet-up .2s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 6px 0 0; font-size: 1.35em; }
.sheet p { margin: 0; }
.sheet-handle { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.reasons { display: flex; flex-direction: column; gap: 8px; }
.reason {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 14px;
  background: var(--surface-2); border: 2px solid transparent; border-radius: 14px;
  font-weight: 600; text-align: left; cursor: pointer;
}
.reason::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.reason.selected { border-color: var(--bad); }
.reason.selected::before { border-color: var(--bad); background: radial-gradient(var(--bad) 45%, transparent 50%); }
textarea {
  width: 100%; padding: 12px 14px; font: inherit; font-size: max(16px, 1em);
  background: var(--surface-2); color: var(--text); border: 2px solid transparent; border-radius: 14px; outline: none; resize: vertical;
}
textarea:focus { border-color: var(--accent); }

/* ---------- Где работать ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--pad) * -1); padding: 0 var(--pad); }
.chips::-webkit-scrollbar { display: none; }
.chip-btn {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 700; font-size: .9em;
}
.chip-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip-btn.tariff.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.where-hero { display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 14%, var(--surface)), var(--surface) 70%); }
.where-title { font-size: var(--fs-title); font-weight: 900; line-height: 1.15; }
.where-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi-val { font-size: 1.15em; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-lbl { color: var(--muted); font-size: .75em; }
.where-best:empty { display: none; }

.map-card { padding: 0; overflow: hidden; position: relative; }
.where-map { height: clamp(300px, 70vw, 460px); width: 100%; background: #1c1f24; }
.map-top { position: absolute; top: 10px; left: 56px; right: 56px; z-index: 500; display: flex; gap: 6px; flex-wrap: wrap; }
.map-chip {
  min-height: 34px; padding: 0 12px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: .8em;
  border: 1px solid rgba(255,255,255,.18); background: rgba(15,16,18,.82); color: var(--muted);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.map-chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.map-btn {
  position: absolute; top: 10px; right: 10px; z-index: 500; width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.18); background: rgba(15,16,18,.85); color: var(--text); font-size: 18px; font-weight: 800;
}
.map-legend {
  position: absolute; left: 10px; bottom: 22px; z-index: 500; display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 10px; background: rgba(15,16,18,.82); font-size: .72em; color: var(--muted);
}
.map-legend i { width: 70px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #2c6e9b, #fcd535, #ff8a3d, #ff3b30); }
.map-note {
  position: absolute; left: 10px; right: 10px; bottom: 56px; z-index: 500; padding: 8px 10px; border-radius: 10px;
  background: rgba(15,16,18,.9); color: var(--muted); font-size: .78em; text-align: center;
}
.map-card.map-full {
  position: fixed; inset: 0; z-index: 60; border-radius: 0;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); background: var(--bg);
}
.map-card.map-full .where-map { height: 100%; }
.map-card.map-full .map-btn { top: calc(10px + env(safe-area-inset-top)); }
.map-card.map-full .map-top { top: calc(10px + env(safe-area-inset-top)); }
body.no-scroll { overflow: hidden; }
.leaflet-tooltip.rank-tip {
  background: transparent; border: 0; box-shadow: none; padding: 0; color: #111214; font-weight: 900; font-size: 12px;
}
.leaflet-tooltip.rank-tip::before { display: none; }
.pop { display: flex; flex-direction: column; gap: 4px; }
.pop .btn-go { align-self: flex-start; margin-top: 4px; }
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-2); color: var(--text); }
.leaflet-popup-content { margin: 10px 12px; line-height: 1.35; }
.leaflet-control-attribution { font-size: 9px; }

.places { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.place { display: grid; grid-template-columns: 30px 1fr; gap: 2px 10px; padding: 14px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.place:last-child { border-bottom: 0; }
.place-rank { grid-row: span 3; align-self: start; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 900; font-size: .9em; }
.place:first-child .place-rank { background: var(--accent); color: var(--accent-text); }
.place-name { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.place-meta { color: var(--muted); font-size: .84em; }
.place-actions { grid-column: 2; display: flex; gap: 8px; margin-top: 6px; }
.btn-go, .btn-mini {
  display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 0 14px;
  border-radius: 10px; font-weight: 800; font-size: .85em; text-decoration: none; cursor: pointer; border: 0;
}
.btn-go { background: var(--accent); color: var(--accent-text) !important; }
.btn-go-big { min-height: 44px; padding: 0 18px; font-size: .95em; flex: none; }
.btn-mini { background: var(--surface-2); color: var(--text); }
.best-line { min-width: 0; }
.where-best { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.place-meta b { color: var(--text); }

.hours-bars { height: 120px; gap: 2px; }
.hours-bars .bar-col.best { background: var(--ok); }
.hours-bars .bar-col.off { background: var(--surface-2); opacity: .5; }

/* ---------- «Где работать сейчас» на главной ---------- */
.now-card { display: flex; flex-direction: column; gap: 10px; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.now-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.now-place { font-size: 1.15em; font-weight: 800; overflow-wrap: anywhere; }
.now-meta { color: var(--muted); font-size: .88em; }
.now-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.now-actions .btn-go, .now-actions .btn-mini { min-height: 46px; font-size: .95em; }

/* ---------- Сводка «Сегодня» на главной ---------- */
.today { border: 0; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 14px; width: 100%; }
.today:active { transform: scale(.99); }
.today-head { display: flex; justify-content: space-between; align-items: baseline; }
.today-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.today-val { font-size: 1.25em; font-weight: 900; white-space: nowrap; }

/* ---------- Статистика ---------- */
.stack-gap { display: flex; flex-direction: column; gap: var(--gap); }
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

.periods {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  background: var(--surface); border-radius: 16px; padding: 4px;
  position: sticky; top: calc(var(--appbar-h) + env(safe-area-inset-top) + 8px); z-index: 5;
}
.period {
  border: 0; background: none; min-height: 44px; border-radius: 12px;
  font-weight: 700; font-size: .92em; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.period.active { background: var(--accent); color: var(--accent-text); }

.earn { display: flex; flex-direction: column; gap: 6px;
        background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 16%, var(--surface)), var(--surface) 75%); }
.earn-val { font-size: clamp(32px, 11vw, 46px); font-weight: 900; line-height: 1.1; letter-spacing: -.01em; }
.earn-sub { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: .92em; }
.earn-sub b { color: var(--text); }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(6, 1fr); } }
.tile { background: var(--surface); border-radius: 16px; padding: 14px 10px; text-align: center; min-width: 0; }
.tile-val { font-size: 1.2em; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-lbl { color: var(--muted); font-size: .76em; margin-top: 2px; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding-top: 18px; }
.bar { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.bar-col { width: 100%; max-width: 44px; border-radius: 8px 8px 4px 4px; background: var(--surface-2); position: relative; min-height: 4px; }
.bar-col.has { background: var(--accent); }
.bar-col.today-bar { background: var(--ok); }
.bar-val { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: .68em; font-weight: 700; white-space: nowrap; color: var(--muted); }
.bar-lbl { font-size: .7em; color: var(--muted); white-space: nowrap; }
.bars.dense .bar-val { display: none; }
.bars.dense .bar-lbl:not(.show) { visibility: hidden; }

.breakdown { display: flex; flex-direction: column; }
.bd-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.bd-row:last-child { border-bottom: 0; }
.bd-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bd-amount { font-weight: 800; white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

.orders { display: flex; flex-direction: column; }
.order { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.order:last-child { border-bottom: 0; }
.order-route { min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-price { font-weight: 900; white-space: nowrap; text-align: right; }
.order-meta { color: var(--muted); font-size: .82em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-status { font-size: .78em; font-weight: 700; text-align: right; white-space: nowrap; }
.order.cancelled .order-price { color: var(--muted); text-decoration: line-through; }
.empty-note { color: var(--muted); text-align: center; padding: 18px 0; }

.skeleton .earn-val, .skeleton .tile-val, .skeleton .today-val { color: transparent; background: var(--surface-2); border-radius: 8px; }

.hero { display: flex; flex-direction: column; gap: 22px; min-height: 180px; justify-content: space-between; }
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hero-state { display: flex; align-items: center; gap: 16px; }
.hero-title { font-size: var(--fs-hero); font-weight: 900; line-height: 1.15; }
.hero-sub { color: var(--muted); margin-top: 4px; }
.hero.state-ok { background: linear-gradient(160deg, color-mix(in srgb, var(--ok) 18%, var(--surface)), var(--surface) 70%); }
.hero.state-warn { background: linear-gradient(160deg, color-mix(in srgb, var(--warn) 20%, var(--surface)), var(--surface) 70%); }
.hero.state-bad { background: linear-gradient(160deg, color-mix(in srgb, var(--bad) 18%, var(--surface)), var(--surface) 70%); }

.chip { padding: 5px 12px; border-radius: 999px; background: var(--surface-2); font-size: .82em; font-weight: 700; }
.dot { width: 20px; height: 20px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 7px color-mix(in srgb, var(--ok) 20%, transparent); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 7px color-mix(in srgb, var(--warn) 20%, transparent); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 7px color-mix(in srgb, var(--bad) 20%, transparent); }

.pause-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 10px; }
.pause-btn {
  min-height: 84px; padding: 8px 4px; background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.pause-btn b { font-size: 1.7em; line-height: 1; font-weight: 900; }
.pause-btn small { font-size: .78em; color: var(--muted); font-weight: 600; }
.list-row > :last-child { text-align: right; white-space: nowrap; }

/* ---------- Профиль ---------- */
.profile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding-top: 28px; padding-bottom: 28px; }
.avatar {
  width: 80px; height: 80px; border-radius: 50%; margin-bottom: 8px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 30px; font-weight: 900;
}
.profile-name { font-size: 1.3em; font-weight: 800; }
.list { padding-top: 6px; padding-bottom: 6px; }
.list-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; }

/* ---------- Прочее ---------- */
.toast {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg);
  padding: 14px 18px; border-radius: 14px; font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.loading { opacity: .55; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
