:root {
  --bg: #f5f5f9;
  --card: #ffffff;
  --text: #566a7f;
  --title: #384551;
  --muted: #a1acb8;
  --primary: #696cff;
  --primary-soft: #e7e7ff;
  --success: #71dd37;
  --success-soft: #e8fadf;
  --danger: #ff3e1d;
  --danger-soft: #ffe0db;
  --warning: #ffab00;
  --line: #d9dee3;
  --shadow: 0 2px 6px rgba(67, 89, 113, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

.card, .bottom-nav, .app-header {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: auto;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 'Public Sans', system-ui, sans-serif;
  min-height: 100%;
  min-height: 100dvh;
  min-height: var(--tg-viewport-stable-height, 100dvh);
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 96px;
  overflow-x: hidden;
  width: 100%;
}

.loading {
  min-height: 70vh;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.logo-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border-radius: 20px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 34px;
}

.loading b {
  font-size: 30px;
  color: var(--title);
}

.back-btn {
  margin-bottom: 12px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  margin: 0;
  color: var(--title);
}

h2 {
  font-size: 18px;
  margin: 0 0 12px;
  color: var(--title);
}

.badge, .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

.pill.on { background: var(--success-soft); color: #3b7a1d; }
.pill.off { background: var(--danger-soft); color: var(--danger); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}

.hero-card {
  background: linear-gradient(135deg, #696cff 0%, #8f93ff 100%);
  color: #fff;
  border: 0;
}

.hero-card h2, .hero-card p { color: #fff; }
.hero-card .hint { color: rgba(255,255,255,.85); }

.order-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.status {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-align: right;
}

.priority-card {
  border-color: #e6b800;
  background: linear-gradient(180deg, #fffbeb 0%, #fff 48%);
  box-shadow: 0 8px 24px rgba(230, 184, 0, .14);
}

.priority-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff3bf;
  color: #8a6d00;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}

.route { margin: 12px 0; line-height: 1.55; }
.route span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.route b { color: var(--title); font-weight: 600; }

.details {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

button, .primary {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: .15s ease;
}

button:active { transform: scale(.98); }

.primary {
  color: #fff;
  background: var(--primary);
  width: 100%;
}

.secondary { background: var(--primary-soft); color: var(--primary); }
.danger { background: var(--danger-soft); color: var(--danger); }
.ghost { background: transparent; color: var(--primary); padding: 0; }
.light { background: #fff; color: var(--title); border: 1px solid var(--line); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  max-width: 100%;
}
.actions button {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.rating-block {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  background: var(--primary-soft);
  border: 1px solid #d8d8ff;
}
.rating-block .hint {
  margin: 0 0 10px;
  color: var(--title);
  font-weight: 600;
}
.rating-row {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}
.rating-btn {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 10px 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.rating-btn:active {
  transform: scale(.96);
  background: var(--primary-soft);
}
.rating-done {
  margin-top: 10px;
  font-weight: 600;
  color: var(--title);
}
.admin-actions {
  flex-direction: column;
}
.admin-actions button {
  flex: none;
  width: 100%;
}

.form { display: grid; gap: 12px; }
.form label { font-size: 13px; font-weight: 500; color: var(--title); }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--title);
  padding: 12px 14px;
  font: inherit;
  /* iOS иначе зумит страницу при фокусе, если меньше 16px */
  font-size: 16px;
  margin-top: 6px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(105, 108, 255, .15);
}

textarea { resize: vertical; min-height: 80px; }

.hint { color: var(--muted); font-size: 13px; margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 28px; }

.error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
}

.success-box {
  color: #3b7a1d;
  background: var(--success-soft);
  padding: 12px 14px;
  border-radius: 12px;
}

.stop { display: flex; gap: 8px; align-items: flex-start; }
.stop .field { flex: 1; }
.stop button { padding: 10px 12px; margin-top: 6px; }

.route-points { display: grid; gap: 10px; }
.route-point {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.route-point.is-dragging {
  opacity: .72;
  border-color: var(--primary);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .08);
}
.route-point-main { min-width: 0; }
.route-point-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 2px;
}
.drag-handle {
  touch-action: none;
  user-select: none;
  cursor: grab;
  width: 36px;
  min-height: 44px;
  margin-top: 18px;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f6f6fb;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: -2px;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.route-point-remove {
  margin-top: 18px;
  padding: 10px 12px;
}
.waiting-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f7f8ff 0%, #fff 100%);
}
.waiting-box.waiting-paid {
  border-color: #f0b429;
  background: linear-gradient(180deg, #fff8e8 0%, #fff 100%);
}
.waiting-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.waiting-timer {
  font-size: 16px;
  font-weight: 600;
  color: var(--title);
  margin-bottom: 4px;
}
.waiting-timer b {
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.waiting-box.waiting-driver {
  margin-top: 10px;
  margin-bottom: 4px;
  border-color: var(--primary);
  background: linear-gradient(180deg, #eef0ff 0%, #fff 100%);
}
.waiting-box.waiting-driver .waiting-timer {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}
.waiting-box .details {
  margin-top: 8px;
}

.quick-row, .choice-row, .stats-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-row button, .choice-row button {
  flex: 1;
  min-width: 140px;
  background: #fff;
  color: var(--title);
  border: 1px solid var(--line);
}

.quick-row button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.suggest-wrap { position: relative; z-index: 1; }
.suggest-wrap:focus-within { z-index: 40; }

.suggest-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  max-height: 180px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 4px 16px rgba(67, 89, 113, 0.18);
}

.suggest-list button {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 0;
  background: #fff;
  color: var(--title);
  font-weight: 500;
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid #eef0f3;
}

.tabs, .bottom-nav {
  display: flex;
  gap: 6px;
}

.tabs { margin-bottom: 12px; }
.tabs button {
  flex: 1;
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--line);
}

.tabs button.active, .filter-row button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  max-width: 100vw;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.bottom-nav button {
  flex: 1 1 0;
  min-width: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.15;
  padding: 8px 2px;
  white-space: normal;
  overflow-wrap: anywhere;
  touch-action: manipulation;
  cursor: pointer;
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.bottom-nav button.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.auth-card {
  max-width: 460px;
  margin: 4vh auto 0;
}

.auth-card .logo-mark { margin-bottom: 8px; }

.login-widget {
  display: flex;
  justify-content: center;
  margin: 18px 0;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin: 16px 0;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.info-text {
  white-space: pre-line;
  color: var(--text);
  line-height: 1.65;
}

.stats-row .stat {
  flex: 1;
  min-width: 120px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.stats-row .stat b {
  display: block;
  font-size: 22px;
  color: var(--title);
}

.filter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.filter-row button {
  background: #fff;
  color: var(--title);
  border: 1px solid var(--line);
  font-size: 13px;
  padding: 8px 12px;
}

.shift-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.shift-bar button { flex: 1; }

.role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.role-card {
  text-align: left;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.role-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.role-card b { display: block; color: var(--title); margin-bottom: 4px; }

.active-order-card {
  border-color: var(--primary);
  background: linear-gradient(180deg, #f7f7ff 0%, #fff 100%);
}

.active-order-badge {
  display: inline-flex;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 6px 10px;
  border-radius: 999px;
}

.active-status { color: #3b7a1d; }

.client-block {
  margin: 12px 0;
  padding: 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.client-block span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.client-block b { color: var(--title); }

.phone-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.map-links {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.map-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-width: 140px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  text-align: center;
}

.map-link.route-link {
  background: var(--primary);
  color: #fff;
}

.compact-card { margin: 8px 0; }

.compact-card .actions button { font-size: 14px; }

.order-map-wrap { margin-top: 12px; }

.order-map {
  width: 100%;
  height: 220px;
  min-height: 220px;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
  z-index: 1;
  background: #e8ecf0;
}

.order-map .leaflet-container {
  width: 100% !important;
  height: 100% !important;
  z-index: 1 !important;
  background: #e8ecf0;
  /* iOS Safari: pan-x/pan-y без pinch-zoom блокирует pinch на карте.
     none — жесты отдаём Leaflet (как в дефолте библиотеки). */
  touch-action: none;
}

.admin-drivers-map .leaflet-container {
  width: 100% !important;
  height: 100% !important;
  z-index: 1 !important;
  background: #e8ecf0;
  touch-action: none;
}

.order-map .leaflet-control-zoom {
  border: 0 !important;
  box-shadow: var(--shadow);
}

.order-map .leaflet-control-zoom a {
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  color: var(--title) !important;
}

.location-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.location-warn {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  background: var(--warning-soft, #fff4de);
  border: 1px solid #ffd58a;
}
.location-warn .hint {
  margin: 0;
  color: var(--title);
}
.location-warn .hint + .hint {
  margin-top: 6px;
  font-weight: 400;
  color: var(--text);
}
.location-warn .actions {
  margin-top: 10px;
}

.admin-drivers-map {
  width: 100%;
  height: 320px;
  min-height: 280px;
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
  z-index: 1;
  background: #e8ecf0;
}

.admin-driver-tooltip {
  background: rgba(20, 24, 32, 0.88);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.25;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-driver-tooltip::before {
  border-top-color: rgba(20, 24, 32, 0.88);
}

.notify-banner {
  border-color: #8f93ff;
  background: linear-gradient(180deg, #f2f2ff 0%, #fff 100%);
}

.impersonation-banner {
  border-color: #ffb020;
  background: linear-gradient(180deg, #fff8e8 0%, #fff 100%);
  margin-bottom: 12px;
}

.impersonation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.impersonation-row .hint {
  margin: 4px 0 0;
}

.impersonation-row button {
  flex-shrink: 0;
}

.notify-banner h2 { margin-bottom: 8px; }

.notify-steps {
  margin: 10px 0 0;
  padding-left: 1.2em;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.notify-steps li { margin: 4px 0; }
.notify-steps b { color: var(--title); font-weight: 600; }

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  margin: 0 0 16px;
  padding: 0;
  box-sizing: border-box;
}

.admin-tile {
  min-height: 72px;
  width: 100%;
  max-width: 100%;
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--title);
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.admin-item { cursor: pointer; }

.admin-back {
  min-width: 44px;
  flex-shrink: 0;
  padding: 8px 12px;
}

.admin-info-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.admin-info-row:last-of-type { border-bottom: 0; }
.admin-info-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.admin-info-row b {
  color: var(--title);
  font-weight: 600;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 380px) {
  .admin-grid { grid-template-columns: 1fr; }
}

@media (min-width: 700px) {
  .bottom-nav {
    max-width: 680px;
    margin: 0 auto;
    border-radius: 18px 18px 0 0;
  }
}
