:root {
  --red: #E94B4D;
  --bg: #050505;
  --bg2: #121212;
  --bg3: #1E1E1E;
  --border: rgba(255,255,255,0.08);
  --text: #F4F4F5;
  --muted: #A1A1AA;
  --success: #25D366;
  --warning: #F59E0B;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app-layout {
  display: grid;
  grid-template-columns: 260px 350px 1fr;
  height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.logo-container {
  padding: 24px;
  border-bottom: 1px solid var(--border);
}
.admin-logo {
  height: 40px;
  filter: drop-shadow(0 2px 8px rgba(233,75,77,0.4));
}
.nav-menu {
  padding: 20px 12px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.2s;
}
.nav-item:hover {
  background: var(--bg3);
  color: var(--text);
}
.nav-item.active {
  background: rgba(233,75,77,0.1);
  color: var(--red);
  border: 1px solid rgba(233,75,77,0.3);
}
.badge {
  background: var(--bg3);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 50px;
}
.nav-item.active .badge {
  background: var(--red);
  color: #fff;
}
.sidebar-footer {
  padding: 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-weight: 600;
  color: var(--text);
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warning);
}
.status-dot.online { background: var(--success); box-shadow: 0 0 10px var(--success); }

/* ─── Orders List ─── */
.orders-column {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
}
.header h2 { font-size: 18px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.orders-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.orders-list:has(.history-container) {
  overflow: hidden;
  padding: 0;
}


.order-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.order-card:hover { border-color: rgba(255,255,255,0.2); }
.order-card.selected { border-color: var(--red); background: rgba(233,75,77,0.05); }
.order-card-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
.order-id { font-weight: 800; color: var(--red); }
.order-time { font-size: 11px; color: var(--muted); }
.order-customer { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.order-total { font-size: 15px; font-weight: 800; color: var(--success); }

/* ─── Calendar UI ─── */
.history-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}
.calendar-container {
  flex-shrink: 0;
  padding: 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.history-results {
  flex: 1;
  overflow-y: auto !important;
  padding: 16px;
  min-height: 0;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}
.history-results::-webkit-scrollbar { width: 6px; }
.history-results::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 10px; }



.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  background: var(--bg3);
  padding: 10px 14px;
  border-radius: 12px;
}
.calendar-title {
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.calendar-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 80%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  text-align: center;
}
.calendar-day-name {
  font-size: 10px;
  color: var(--muted);
  font-weight: 800;
  padding-bottom: 5px;
}
.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg2);
  border: 1px solid transparent;
}
.calendar-day:hover { background: var(--bg3); }
.calendar-day.active { 
  background: var(--red); 
  color: white;
  box-shadow: 0 4px 12px var(--red-glow);
}
.calendar-day.today { border-color: var(--red); color: var(--red); }
.calendar-day.empty { background: transparent; cursor: default; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.history-date-header {
  padding: 12px 16px;
  background: var(--bg3);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  border-radius: 8px;
  margin: 16px 0 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.history-date-header::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.clean-history-btn {
  width: calc(100% - 32px);
  margin: 0 16px 16px;
  padding: 12px;
  background: rgba(233,75,77,0.1);
  border: 1px dashed var(--red);
  color: var(--red);
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}
.clean-history-btn:hover { background: var(--red); color: white; }

/* ─── Detail Column ─── */
.detail-column {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100vh;
  overflow: hidden;
}
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.order-detail {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 0;
}
.detail-body-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0; /* Critical for flexbox scrolling */
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
#detail-order-id { font-size: 24px; font-weight: 900; }
.detail-time { color: var(--muted); font-size: 13px; margin-top: 4px; }
.status-badge {
  background: rgba(255,255,255,0.1);
  padding: 6px 14px;
  border-radius: 50px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
}
.status-badge.PENDIENTE { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.status-badge.PREPARANDO { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.status-badge.EN_CAMINO { background: rgba(168, 85, 247, 0.2); color: #a855f7; }
.status-badge.ENTREGADO { background: rgba(37, 211, 102, 0.2); color: var(--success); }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.detail-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card-title {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.customer-name { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.customer-info { font-size: 13px; color: #ccc; margin-bottom: 2px; }

.items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}
.detail-item {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 8px;
}
.item-qty { color: var(--red); font-weight: 800; margin-right: 8px; }
.item-name { font-size: 14px; font-weight: 600; }
.item-meta { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
.item-price { font-weight: 800; }
.total-row {
  display: flex;
  justify-content: space-between;
  font-size: 20px;
  font-weight: 900;
  color: var(--success);
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.map-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  flex: 1;
  min-height: 250px;
  display: flex;
  flex-direction: column;
}
.admin-map {
  flex: 1;
  border-radius: 8px;
  background: #111;
}

.action-bar {
  display: flex;
  gap: 12px;
  padding: 20px 24px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px rgba(0,0,0,0.5);
  z-index: 100;
}
.btn {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: transform 0.2s, filter 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn:hover { filter: brightness(1.1); }
.btn-accept { background: var(--red); color: white; }
.btn-dispatch { background: #3b82f6; color: white; }
.btn-deliver { background: var(--success); color: white; }

/* ─── Leaflet dark override ─── */
.leaflet-container { background: #111 !important; }
.leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(0.8) contrast(0.85); }
.leaflet-control-attribution { display: none; }

/* ─── Driver Selection Modal ─── */
.driver-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.driver-modal-overlay.open { opacity: 1; }
.driver-modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  width: 420px;
  max-width: 95vw;
  box-shadow: 0 30px 80px rgba(0,0,0,0.8);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}
.driver-modal-overlay.open .driver-modal { transform: translateY(0); }
.driver-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.driver-modal-header h3 { font-size: 20px; font-weight: 800; }
.driver-modal-close {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.driver-modal-close:hover { background: var(--red); color: white; border-color: var(--red); }
.driver-modal-sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
}
.driver-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}
.driver-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.driver-option:hover { border-color: rgba(168,85,247,0.4); background: rgba(168,85,247,0.05); }
.driver-option.selected {
  border-color: #a855f7;
  background: rgba(168,85,247,0.12);
}
.driver-emoji { font-size: 22px; }
.driver-option-name { flex: 1; font-size: 15px; font-weight: 600; }
.driver-check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg2);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #a855f7;
  transition: all 0.2s;
}
.driver-option.selected .driver-check {
  background: #a855f7;
  border-color: #a855f7;
  color: white;
}
.driver-confirm-btn {
  width: 100%;
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: white;
}
.driver-confirm-btn:disabled {
  background: var(--bg3);
  color: var(--muted);
  cursor: not-allowed;
  filter: none;
}

