/* ==========================================================================
   DELIVERY PRO - DISPATCH CONTROL TOWER & ADMIN DASHBOARD
   ========================================================================== */

.dispatch-container {
  display: grid;
  grid-template-columns: 390px 1fr 390px;
  height: calc(100vh - 78px);
  overflow: hidden;
  background: var(--bg-main);
}

/* LEFT COLUMN: Engine Config & Dispatch Queue */
.dispatch-sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

/* DUAL DISPATCH TOGGLE CARD */
.dispatch-mode-card {
  margin: 0.65rem 0.85rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(31, 41, 55, 0.8), rgba(17, 24, 39, 0.95));
  border: 1px solid rgba(99, 102, 241, 0.3);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.dispatch-mode-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(to right, var(--primary), var(--accent-orange));
}

.mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.mode-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* Interactive Switcher Pill */
.mode-switch-control {
  display: flex;
  background: rgba(0, 0, 0, 0.45);
  border-radius: var(--radius-full);
  padding: 2px;
  position: relative;
  border: 1px solid var(--border-subtle);
  margin-bottom: 0.4rem;
}

.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: all var(--transition-fast);
}

.mode-btn.active[data-mode="auto"] {
  background: var(--primary);
  color: white;
  box-shadow: 0 0 12px var(--primary-glow);
}

.mode-btn.active[data-mode="manual"] {
  background: var(--accent-orange);
  color: white;
  box-shadow: 0 0 12px var(--shadow-glow-orange);
}

.mode-description {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin-bottom: 0.5rem;
}

/* Dispatch Sliders (Config en caliente) */
.dispatch-tuning {
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.tuning-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tuning-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.tuning-value {
  color: var(--text-main);
  font-weight: 700;
}

.tuning-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}

.tuning-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 8px var(--primary-glow);
}

/* ORDERS QUEUE IN SIDEBAR */
.queue-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--border-subtle);
}

.queue-header {
  padding: 0.85rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
}

.order-count-badge {
  background: var(--primary-light);
  color: #a5b4fc;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
}

.order-list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.dispatch-order-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.dispatch-order-card:hover {
  border-color: rgba(99, 102, 241, 0.4);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.dispatch-order-card.selected {
  border-color: var(--accent-orange);
  background: rgba(249, 115, 22, 0.08);
}

.card-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.order-code {
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--text-main);
}

.order-time {
  font-size: 0.72rem;
  color: var(--text-subtle);
}

.card-merchant-row {
  font-size: 0.82rem;
  font-weight: 600;
  color: #e5e7eb;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.card-dest-row {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.card-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.5rem;
}

.order-price {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-emerald);
}

/* CENTER COLUMN: Interactive Operations Map */
.dispatch-center-col {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.map-control-bar {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 500;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(12px);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-lg);
}

.map-legend {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.78rem;
  font-weight: 600;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.driver-free { background: #10b981; box-shadow: 0 0 8px #10b981; }
.legend-dot.driver-busy { background: #f59e0b; box-shadow: 0 0 8px #f59e0b; }
.legend-dot.merchant { background: #6366f1; }
.legend-dot.customer { background: #f43f5e; }

#dispatch-map {
  flex: 1;
  width: 100%;
  height: 100%;
  background: #0d131f;
}

/* RIGHT COLUMN: Fleet Status & Manual Dispatch Assistant */
.dispatch-fleet-col {
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fleet-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fleet-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

/* Selected Order Focus Card */
.focused-order-banner {
  padding: 0.85rem 1rem;
  background: rgba(249, 115, 22, 0.1);
  border-bottom: 1px solid rgba(249, 115, 22, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
}

.fleet-list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.driver-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.driver-card:hover {
  border-color: rgba(16, 185, 129, 0.4);
}

.driver-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.driver-identity {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.driver-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  position: relative;
}

.driver-online-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface-elevated);
}

.driver-online-status.free { background: var(--accent-emerald); }
.driver-online-status.busy { background: var(--accent-amber); }
.driver-online-status.offline { background: var(--text-subtle); }

.driver-details h4 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.driver-details p {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.driver-metrics-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
}

.metric-pill {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-muted);
}

.metric-pill strong {
  color: var(--text-main);
}

/* Manual Assign Action Button */
.manual-assign-btn {
  background: var(--accent-orange);
  color: white;
  border: none;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: all var(--transition-fast);
}

.manual-assign-btn:hover {
  background: var(--accent-orange-hover);
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.4);
}

.manual-assign-btn:disabled {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-subtle);
  cursor: not-allowed;
  box-shadow: none;
}

/* KPI Summary Ribbon at bottom of Fleet Column */
.kpi-ribbon {
  padding: 0.5rem 0.85rem;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.3);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.kpi-box {
  background: var(--bg-surface-elevated);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
}

.kpi-title {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.kpi-value {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
}

/* Responsive adjustments for dispatch */
@media (max-width: 1200px) {
  .dispatch-container {
    grid-template-columns: 300px 1fr 320px;
  }
}

@media (max-width: 992px) {
  .dispatch-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 400px auto;
    height: auto;
    overflow-y: auto;
  }
  .dispatch-sidebar, .dispatch-fleet-col {
    height: 450px;
  }
}
