/* ───── Operator page ───── */
.op-page {
  display: flex; flex-direction: column;
  gap: 16px;
}

/* KPI row */
.op-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.op-kpi {
  background: #fff;
  border-radius: var(--radius-sm);
  border: 1px solid #e5e7eb;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 22px 1fr;
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-items: center;
  position: relative; overflow: hidden;
}
.op-kpi__icon {
  grid-row: 1 / span 2;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: rgba(255,193,7,0.1);
  border-radius: 6px;
}
.op-kpi__val { font-size: 14px; font-weight: 800; line-height: 1.05; color: var(--dark); }
.op-kpi__label { font-size: 8.5px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.2px; font-weight: 600; }
.op-kpi-online .op-kpi__icon { background: rgba(34,197,94,0.12); }
.op-kpi-busy .op-kpi__icon { background: rgba(239,68,68,0.12); }
.op-kpi-orders .op-kpi__icon { background: rgba(33,150,243,0.12); }
.op-kpi-warn .op-kpi__icon { background: rgba(245,158,11,0.12); }
.op-kpi-warn .op-kpi__val { color: #d97706; }

/* 2-column grid: большая карта слева + узкая колонка (заказы+водители) справа */
.op-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 14px;
  align-items: stretch;
}

.op-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.op-col-center { gap: 14px; }

/* Panels */
.op-panel {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid #e5e7eb;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.op-panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255,193,7,0.05), transparent);
  border-bottom: 1px solid #f3f4f6;
}
.op-panel__head h3 {
  margin: 0;
  font-size: 15px; font-weight: 800; color: var(--dark);
}
.op-select {
  padding: 5px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

/* Map — увеличена ~на 50% (480→720) под 3D-обзор */
.op-panel-map { flex: 1; min-height: 0; }
.op-map {
  width: 100%; height: 720px;
  background: #e8eaed;
  position: relative;
}
/* нативный MapLibre-канвас заполняет контейнер */
.op-map .maplibregl-canvas { outline: none; }
/* кнопка переключения 3D/2D наклона поверх карты */
.op-map-3dtoggle {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  background: rgba(17,24,39,0.82); color: #fff; border: 0;
  border-radius: 8px; padding: 7px 12px; font-weight: 700; font-size: 12.5px;
  cursor: pointer; font-family: inherit; letter-spacing: 0.3px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.op-map-3dtoggle:hover { background: var(--dark); }
.op-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 12px; color: #6b7280;
  align-items: center;
}
.op-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 4px; vertical-align: middle;
}
.op-dot-free { background: var(--green); }
.op-dot-busy { background: var(--red); }
.op-dot-order { background: var(--primary); }

/* Map markers */
.op-marker-driver, .op-marker-order {
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 14px;
  width: 32px; height: 32px;
  cursor: pointer;
}
.op-marker-order { width: 28px; height: 28px; font-size: 13px; }

/* Lists — заказы и водители теперь стопкой в правой колонке, каждый скроллится */
.op-orders-list, .op-drivers-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
.op-orders-list { max-height: 320px; }
.op-drivers-list { max-height: 360px; }
/* правая колонка панелей не должна растягиваться выше карты */
.op-col-right { max-height: 760px; }
.op-empty {
  padding: 20px; text-align: center;
  color: #9ca3af; font-style: italic; font-size: 13px;
}

/* Order item */
.op-order {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 6px;
  border: 1px solid transparent;
  transition: all 0.15s;
  background: #f9fafb;
}
.op-order:hover {
  background: #fff;
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.06);
}
.op-order-warn { background: #fef3c7; border-color: rgba(245,158,11,0.4); }
.op-order__head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
}
.op-order__id { font-weight: 800; color: var(--dark); font-size: 14px; }
.op-order__time { margin-left: auto; font-size: 11px; color: #9ca3af; }
.op-order__route { font-size: 12.5px; }
.op-order__from { color: var(--dark); font-weight: 500; }
.op-order__to { color: #6b7280; margin-top: 2px; }
.op-order__meta {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-top: 8px; padding-top: 6px;
  border-top: 1px dashed #e5e7eb;
  font-size: 11.5px; color: #6b7280;
}
.op-order__price { margin-left: auto; font-weight: 700; color: var(--dark); font-size: 13px; }
.op-status {
  padding: 2px 7px; border-radius: 5px;
  font-size: 10.5px; font-weight: 700;
}

/* Driver category tabs */
.op-driver-cat-tabs {
  display: flex; gap: 4px;
  padding: 8px 10px 0;
  border-bottom: 1px solid #f3f4f6;
}
.op-cat-tab {
  flex: 1; padding: 7px 8px;
  background: transparent;
  border: 0; border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px; font-weight: 600;
  color: #6b7280;
  transition: all 0.15s;
}
.op-cat-tab:hover { color: var(--dark); }
.op-cat-tab.active {
  color: var(--gold-deep);
  border-bottom-color: var(--primary);
}

/* Driver item */
.op-driver {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
}
.op-driver:hover { background: rgba(255,193,7,0.08); }
.op-presence {
  width: 12px; height: 12px; border-radius: 50%;
  flex-shrink: 0;
}
.op-presence-free {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34,197,94,0.6);
  animation: opPulse 1.6s ease-out infinite;
}
.op-presence-busy { background: var(--red); }
.op-presence-off { background: #d1d5db; }
@keyframes opPulse {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.7); }
  70% { box-shadow: 0 0 0 10px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
.op-driver__body { flex: 1; min-width: 0; }
.op-driver__name {
  font-weight: 700; font-size: 13.5px; color: var(--dark);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.op-driver__sub {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-top: 2px;
  font-size: 11px; color: #6b7280;
}
.op-chip {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: rgba(255,193,7,0.15); color: var(--gold-deep);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px;
}
.op-driver__status { color: #6b7280; }
.op-bal { font-weight: 700; color: var(--green-dark); margin-left: auto; }
.op-bal-low { color: #f59e0b; }
.op-bal-neg { color: var(--red); }

/* Create order form */
.op-create { padding: 14px 16px 16px; }
.op-form-row {
  display: grid; gap: 16px;
  margin-bottom: 10px;
}
.op-form-row:has(> :nth-child(3)) { grid-template-columns: 1.4fr 1fr 1fr; }
.op-form-row:has(> :nth-child(2):last-child) { grid-template-columns: 1fr 1fr; }
.op-field label {
  display: block;
  font-size: 11px; color: #6b7280;
  text-transform: uppercase; letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 4px;
}
.op-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
}
.op-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255,193,7,0.15);
}
.op-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 18px;
  border: 0; border-radius: 9px;
  font-family: inherit;
  font-weight: 700; font-size: 13.5px;
  cursor: pointer;
  transition: all 0.15s;
}
.op-btn-yellow { background: var(--primary); color: #000; }
.op-btn-yellow:hover {
  background: var(--gold-deep); color: #fff;
  box-shadow: 0 4px 12px rgba(255,193,7,0.4);
}

/* Адаптив для маленьких экранов */
/* Create-bar — форма создания заказа ОДНОЙ СТРОКОЙ под дашбордом */
.op-create-bar { padding: 8px 12px; }
.op-create-inline {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: nowrap;
}
.op-create-inline .op-field { margin: 0; min-width: 0; }
.op-create-inline .op-field-sm { flex: 0 0 132px; }
.op-create-inline .op-field-grow { flex: 1 1 0; position: relative; }
.op-create-inline label {
  display: block; font-size: 10px; color: #6b7280;
  text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; margin-bottom: 3px;
}
.op-create-inline .op-input { padding: 8px 10px; font-size: 13px; }
.op-create-inline .op-create-submit {
  flex: 0 0 auto; white-space: nowrap; padding: 9px 16px; height: 38px;
}
.op-create-inline .addr-suggestions { position: absolute; z-index: 20; left: 0; right: 0; }
/* Поле предзаказа (дата+время подачи) */
.op-create-inline .op-field-when { flex: 0 0 178px; }
.op-field-hint { text-transform: none; letter-spacing: 0; color: #9ca3af; font-weight: 500; }

/* Иконка-кнопка «✉ Сообщение» в строках водителя/заказа */
.op-icon-btn {
  flex-shrink: 0;
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; color: #6b7280;
  border: 1px solid #e5e7eb; border-radius: 8px;
  font-size: 14px; line-height: 1; cursor: pointer;
  transition: all 0.15s;
}
.op-icon-btn:hover {
  background: rgba(255,193,7,0.15); color: var(--gold-deep);
  border-color: var(--primary);
}
.op-icon-btn-sm { width: 24px; height: 24px; font-size: 12px; border-radius: 6px; }

/* ───── Мини-модалка ручного сообщения оператора ───── */
.op-msg__overlay {
  position: fixed; inset: 0; z-index: 4000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15,20,25,0.45);
  opacity: 0; transition: opacity 0.18s ease;
  padding: 16px;
}
.op-msg__overlay.show { opacity: 1; }
.op-msg__modal {
  width: 100%; max-width: 420px;
  background: #fff; border-radius: 14px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}
.op-msg__overlay.show .op-msg__modal { transform: none; }
.op-msg__title { margin: 0 0 4px; font-size: 16px; font-weight: 800; color: var(--dark); }
.op-msg__sub { font-size: 12.5px; color: #6b7280; margin-bottom: 12px; }
.op-msg__targets { display: flex; gap: 6px; margin-bottom: 12px; }
.op-msg__seg {
  flex: 1; padding: 7px 10px;
  background: #f3f4f6; color: #6b7280;
  border: 1px solid transparent; border-radius: 8px;
  font-family: inherit; font-size: 12.5px; font-weight: 700;
  cursor: pointer; transition: all 0.15s;
}
.op-msg__seg:hover { color: var(--dark); }
.op-msg__seg.active {
  background: rgba(255,193,7,0.18); color: var(--gold-deep);
  border-color: var(--primary);
}
.op-msg__ta {
  width: 100%; box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid #d1d5db; border-radius: 9px;
  font-family: inherit; font-size: 13.5px;
  resize: vertical; min-height: 72px;
}
.op-msg__ta:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255,193,7,0.15);
}
.op-msg__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.op-msg__btn {
  padding: 9px 16px; border: 0; border-radius: 9px;
  font-family: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
  transition: all 0.15s;
}
.op-msg__btn-ghost { background: #f3f4f6; color: #374151; }
.op-msg__btn-ghost:hover { background: #e5e7eb; }
.op-msg__btn-send { background: var(--primary); color: #000; }
.op-msg__btn-send:hover { background: var(--gold-deep); color: #fff; }
.op-msg__btn:disabled { opacity: 0.55; cursor: default; }

/* #8: мини-чат — история отправленных оператором сообщений (сессия) */
.op-msg__history {
  max-height: 220px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  margin: 10px 0;
}
.op-msg__history-empty {
  color: #94a3b8; font-size: 12px; text-align: center; padding: 8px 0;
}
.op-msg__bubble {
  align-self: flex-end; max-width: 85%;
  background: #eef2ff; border: 1px solid #c7d2fe;
  border-radius: 10px 10px 2px 10px; padding: 6px 10px;
}
.op-msg__bubble-text {
  font-size: 13px; color: #1e293b;
  white-space: pre-wrap; word-break: break-word;
}
.op-msg__bubble-meta {
  font-size: 10px; color: #64748b; text-align: right; margin-top: 2px;
}

/* #18: грузовой заказ — отдельный маркер и подпись «Груз» */
.op-marker-cargo {
  background: #8b5cf6 !important;
  border-radius: 8px;
  position: relative;
  overflow: visible;
}
.op-marker-cargo-label {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  margin-top: 3px; white-space: nowrap;
  background: #8b5cf6; color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1;
  padding: 2px 6px; border-radius: 5px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.op-cargo-badge {
  background: #8b5cf6; color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 5px;
}

/* A/B пины выбора точки на карте (MapLibre marker) */
.op-pick-pin {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 12px;
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.45);
}
.op-pick-from { background: var(--green-dark); }
.op-pick-to { background: var(--red); }
.op-map .maplibregl-marker { cursor: pointer; }

/* Завершённый/отменённый заказ: 2 сек висит с финальным бейджем, потом плавно уходит */
.op-order-closing { opacity: 0.9; }
.op-order-gone {
  opacity: 0 !important;
  transform: translateX(16px) !important;
  transition: opacity 0.35s ease, transform 0.35s ease !important;
  pointer-events: none;
}

/* Выбранный заказ — маршрут A→B нарисован на карте */
.op-order-selected {
  border-color: #7c3aed !important;
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.25);
}

/* #19: кнопка повторной рассылки (searching > 5 мин) */
.op-btn-redispatch {
  margin-top: 8px; width: 100%;
  padding: 6px 10px; border: 0; border-radius: 6px;
  background: #7c3aed; color: #fff;
  font-family: inherit; font-size: 12px; font-weight: 700;
  cursor: pointer; transition: background 0.15s;
}
.op-btn-redispatch:hover { background: #6d28d9; }
.op-btn-redispatch:disabled { opacity: 0.6; cursor: default; }

@media (max-width: 1180px) {
  .op-grid { grid-template-columns: 1fr; }
  .op-col-right { max-height: none; }
  .op-map { height: 460px; }
  .op-kpis { grid-template-columns: repeat(2, 1fr); }
  .op-form-row { grid-template-columns: 1fr !important; }
  .op-create-inline { flex-wrap: wrap; }
  .op-create-inline .op-field-sm,
  .op-create-inline .op-field-when,
  .op-create-inline .op-field-grow { flex: 1 1 45%; }
}

/* ── #5: «зависшие» заказы (order:search_stuck) — баннер оператору ── */
.op-stuck-banner { margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.op-stuck-alert {
  display: flex; align-items: center; gap: 10px;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.45);
  border-left: 4px solid #ef4444;
  border-radius: 10px; padding: 10px 12px;
  animation: opStuckPulse 1.6s ease-in-out infinite;
}
@keyframes opStuckPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.0); }
  50% { box-shadow: 0 0 0 4px rgba(239,68,68,0.14); }
}
.op-stuck-alert__ic { font-size: 16px; line-height: 1; }
.op-stuck-alert__txt { flex: 1; font-size: 13.5px; font-weight: 600; color: #b91c1c; }
.op-stuck-alert__open {
  background: #ef4444; color: #fff; border: 0; cursor: pointer;
  padding: 7px 14px; border-radius: 8px; font-weight: 700; font-size: 13px;
}
.op-stuck-alert__open:hover { background: #dc2626; }
.op-stuck-alert__x {
  background: transparent; border: 0; cursor: pointer;
  color: #b91c1c; font-size: 20px; line-height: 1; padding: 0 4px;
}
.op-stuck-badge {
  display: inline-block; margin-left: 6px;
  background: rgba(239,68,68,0.15); color: #b91c1c;
  border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 700;
}
