*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  height: 100vh;
  overflow: hidden;
}

/* ─────────────── APP SHELL ─────────────── */
#app {
  display: flex;
  height: 100vh;
}

/* ─────────────── SIDEBAR ─────────────── */
#sidebar {
  width: 310px;
  flex-shrink: 0;
  background: #151823;
  border-right: 1px solid #1e2235;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 14px 16px 12px;
  background: #0f1117;
  border-bottom: 1px solid #1e2235;
  flex-shrink: 0;
}
#sidebar-header h1 {
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -0.02em;
}
#sidebar-header .subtitle {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
}

/* ─── INPUT ─── */
#input-section {
  padding: 12px;
  border-bottom: 1px solid #1e2235;
  flex-shrink: 0;
}

#drop-zone {
  border: 2px dashed #2d3555;
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 8px;
  font-size: 11.5px;
  color: #64748b;
  background: #0f1117;
}
#drop-zone:hover, #drop-zone.drag-over {
  border-color: #4f6ef7;
  background: rgba(79,110,247,.06);
  color: #4f6ef7;
}
#drop-zone .dz-icon { font-size: 22px; margin-bottom: 4px; }
#file-input { display: none; }

#json-textarea {
  width: 100%;
  height: 72px;
  background: #0f1117;
  border: 1px solid #1e2235;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 11px;
  font-family: 'Consolas', 'Courier New', monospace;
  padding: 7px 9px;
  resize: none;
  margin-bottom: 8px;
  outline: none;
  transition: border-color .15s;
}
#json-textarea:focus { border-color: #4f6ef7; }
#json-textarea::placeholder { color: #2d3555; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all .15s;
}
.btn-primary { background: #4f6ef7; color: #fff; width: 100%; }
.btn-primary:hover { background: #3d5ce0; }
.btn-secondary { background: #1e2235; color: #94a3b8; }
.btn-secondary:hover { background: #2d3555; }

/* ─── STATS BAR ─── */
#stats-bar {
  display: none;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 12px;
  background: #0f1117;
  border-bottom: 1px solid #1e2235;
  flex-shrink: 0;
}
.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #1e2235;
  border-radius: 20px;
  padding: 3px 9px;
  font-size: 10.5px;
  color: #94a3b8;
}
.stat-chip .sdot {
  width: 7px; height: 7px;
  border-radius: 50%;
}

/* ─── SEARCH ─── */
.search-wrap {
  padding: 8px 12px;
  border-bottom: 1px solid #1e2235;
  flex-shrink: 0;
  position: relative;
}
.search-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: #475569;
  pointer-events: none;
  font-size: 13px;
}
.search-input {
  width: 100%;
  background: #0f1117;
  border: 1px solid #1e2235;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 12px;
  padding: 7px 8px 7px 30px;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: #4f6ef7; }
.search-input::placeholder { color: #2d3555; }

/* ─── ROUTES LIST ─── */
#routes-section {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

#empty-routes {
  padding: 32px 16px;
  text-align: center;
  color: #2d3555;
  font-size: 12px;
  line-height: 1.6;
}

.section-lbl {
  padding: 8px 12px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #475569;
  font-weight: 600;
}

.route-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  cursor: pointer;
  transition: background .1s;
  gap: 8px;
  border-radius: 6px;
  margin: 1px 4px;
  position: relative;
}
.route-item:hover { background: #1e2235; }
.route-item.active {
  background: #1e2235;
  box-shadow: inset 2px 0 0 var(--route-color);
}
.route-item.hidden { opacity: .35; }

.route-swatch {
  width: 4px;
  min-height: 36px;
  border-radius: 3px;
  flex-shrink: 0;
}
.route-info { flex: 1; min-width: 0; }
.route-name {
  font-size: 12px;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.route-meta {
  font-size: 10.5px;
  color: #64748b;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.route-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
}
.rbadge {
  font-size: 9.5px;
  background: #1a1f33;
  border-radius: 3px;
  padding: 1px 5px;
  color: #94a3b8;
}
.rbadge-geo {
  color: #7dd3fc;
  background: #0c1a2e;
  border: 1px solid #164e63;
}

.vis-btn {
  background: none;
  border: none;
  color: #475569;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1;
  transition: color .15s, background .15s;
}
.vis-btn:hover { color: #e2e8f0; background: #2d3555; }

/* ─── SELECT ALL BAR ─── */
#select-all-bar {
  display: none;
  align-items: center;
  padding: 5px 12px 5px 14px;
  border-bottom: 1px solid #1e2235;
  gap: 7px;
  flex-shrink: 0;
  background: #0f1117;
}
#select-all-bar label {
  font-size: 11px;
  color: #64748b;
  cursor: pointer;
  user-select: none;
  flex: 1;
}
#select-all-cb {
  width: 13px;
  height: 13px;
  cursor: pointer;
  accent-color: #4f6ef7;
  flex-shrink: 0;
}
#select-all-count { font-size: 10px; color: #475569; }

/* ─── FILL BARS ─── */
.fill-bar-wrap {
  margin-top: 5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.fill-bar-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 9.5px;
}
.fill-lbl-key {
  min-width: 16px;
  color: #475569;
  font-weight: 700;
  font-size: 9px;
}
.fill-bar-track {
  flex: 1;
  height: 4px;
  background: #1a1f33;
  border-radius: 2px;
  overflow: hidden;
}
.fill-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width .3s;
}
.fill-lbl-val { min-width: 62px; color: #94a3b8; text-align: right; font-size: 9px; }

/* ─────────────── MAIN CONTENT ─────────────── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ─── MAP ─── */
#map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}
#map { width: 100%; height: 100%; }

#map-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  display: flex;
  gap: 6px;
}
.map-btn {
  background: #151823;
  border: 1px solid #2d3555;
  color: #cbd5e1;
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.map-btn:hover { background: #1e2235; border-color: #4f6ef7; color: #fff; }

/* ─── RESIZE HANDLE ─── */
#resize-handle {
  height: 5px;
  cursor: row-resize;
  background: #1e2235;
  border-top: 1px solid #2d3555;
  flex-shrink: 0;
  transition: background .15s;
  position: relative;
}
#resize-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: #2d3555;
}
#resize-handle:hover { background: #4f6ef7; }
#resize-handle:hover::after { background: #7b96fa; }

/* ─── ORDERS PANEL ─── */
#orders-panel {
  height: 260px;
  flex-shrink: 0;
  background: #151823;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#orders-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #0f1117;
  border-bottom: 1px solid #1e2235;
  flex-shrink: 0;
}
#orders-header h3 {
  font-size: 12px;
  font-weight: 700;
  color: #f1f5f9;
}
#orders-header .hdr-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-pill {
  background: #1e2235;
  color: #64748b;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
}
#clear-selection-btn {
  background: none;
  border: 1px solid #2d3555;
  color: #64748b;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 5px;
  cursor: pointer;
  display: none;
  transition: all .15s;
}
#clear-selection-btn:hover { border-color: #4f6ef7; color: #4f6ef7; }

#orders-search-wrap {
  padding: 8px 12px;
  border-bottom: 1px solid #1e2235;
  flex-shrink: 0;
  position: relative;
}

#orders-table-wrap {
  flex: 1;
  overflow-y: auto;
}

#empty-orders {
  padding: 24px 16px;
  text-align: center;
  color: #2d3555;
  font-size: 12px;
}

.orders-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}
.orders-table th {
  position: sticky;
  top: 0;
  background: #0f1117;
  padding: 6px 10px;
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #475569;
  font-weight: 600;
  border-bottom: 1px solid #1e2235;
  z-index: 2;
  white-space: nowrap;
}
.orders-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #0f1117;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.orders-table td.title-cell {
  max-width: 210px;
}
.orders-table tbody tr {
  cursor: pointer;
  transition: background .08s;
}
.orders-table tbody tr:hover td { background: #1e2235; }
.orders-table tbody tr.row-highlighted td {
  background: rgba(79,110,247,.12);
}
.orders-table tbody tr.row-unrouted td {
  color: #4b5563;
}

.clr-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: middle;
  margin-right: 3px;
}
.unrouted-tag {
  font-size: 9px;
  background: #1e2235;
  color: #4b5563;
  border-radius: 3px;
  padding: 1px 5px;
}

/* ─────────────── SCROLLBAR ─────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2d3555; border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #3d4566; }

/* ─────────────── TOAST ─────────────── */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: #ef4444;
  color: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  display: none;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(239,68,68,.4);
  animation: toastIn .2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
}

/* ─── Leaflet popup theming ─── */
.leaflet-popup-content-wrapper {
  background: #151823 !important;
  color: #e2e8f0 !important;
  border: 1px solid #2d3555 !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,.6) !important;
}
.leaflet-popup-tip { background: #151823 !important; }
.leaflet-popup-close-button { color: #64748b !important; }
.leaflet-popup-close-button:hover { color: #e2e8f0 !important; }
