/* ============================================================
   ROUTE DISPATCHER — GLOBAL STYLES
   ============================================================ */

:root {
  --blue:       #1a6fc4;
  --blue-light: #e8f2fc;
  --blue-dark:  #0d4a8a;
  --green:      #3a8a22;
  --green-light:#e8f5e2;
  --amber:      #b06010;
  --amber-light:#fef3e2;
  --red:        #c0392b;
  --red-light:  #fdecea;
  --purple:     #6c3fa8;
  --purple-light:#f0ebfa;
  --gray-50:    #f8f8f7;
  --gray-100:   #f0eeeb;
  --gray-200:   #e0ddd8;
  --gray-300:   #c8c5be;
  --gray-400:   #9e9b94;
  --gray-500:   #72706a;
  --gray-700:   #3d3c38;
  --gray-900:   #1a1a18;
  --white:      #ffffff;
  --radius:     8px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 3px 10px rgba(0,0,0,0.10);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-50);
  line-height: 1.5;
}

/* ============================================================
   NAVBAR
   ============================================================ */

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 52px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-icon { font-size: 20px; }

.nav-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
}

.nav-sub {
  font-size: 12px;
  color: var(--gray-400);
  border-left: 1px solid var(--gray-200);
  padding-left: 10px;
  margin-left: 2px;
}

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 5px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  text-decoration: none;
  transition: all 0.15s;
}

.nav-link:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-link.active { background: var(--blue-light); color: var(--blue); }

/* ============================================================
   MAIN PAGE LAYOUT (Lookup)
   ============================================================ */

.page-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - 52px);
}

.sidebar {
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar-section {
  padding: 1.25rem;
  border-bottom: 1px solid var(--gray-100);
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.section-title-sm {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.section-desc {
  font-size: 12px;
  color: var(--gray-400);
  margin-bottom: 1rem;
}

/* ============================================================
   FORM FIELDS
   ============================================================ */

.field-group {
  margin-bottom: 10px;
}

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 5px;
}

.field-input {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--gray-900);
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.field-input:hover { border-color: var(--gray-300); }
.field-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(26,111,196,0.12); }

.field-hint {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 4px;
}

textarea.paste-area {
  width: 100%;
  padding: 10px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--gray-900);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

textarea.paste-area:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(26,111,196,0.12); }

/* ============================================================
   BUTTONS
   ============================================================ */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--white);
  background: var(--blue);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: 4px;
}

.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:active { transform: scale(0.98); }

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-700);
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-outline:hover { background: var(--gray-100); border-color: var(--gray-300); }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 500;
  color: var(--red);
  background: var(--red-light);
  border: 1px solid rgba(192,57,43,0.2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-danger:hover { background: rgba(192,57,43,0.15); }

/* ============================================================
   RESULT PANEL
   ============================================================ */

.result-panel {
  padding: 1.25rem;
  border-bottom: 1px solid var(--gray-100);
  min-height: 130px;
}

.result-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 1rem 0;
}

.result-empty-icon { font-size: 28px; opacity: 0.3; }
.result-empty p { font-size: 12px; color: var(--gray-400); }

.result-run-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  border: 1px solid transparent;
}

.run-number {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.run-area {
  font-size: 13px;
  font-weight: 500;
}

/* Dynamic colour classes applied by JS */
.badge-101 { background: var(--blue-light); border-color: rgba(26,111,196,0.2); color: var(--blue); }
.badge-102 { background: var(--green-light); border-color: rgba(58,138,34,0.2); color: var(--green); }
.badge-110 { background: var(--amber-light); border-color: rgba(176,96,16,0.2); color: var(--amber); }
.badge-purple { background: var(--purple-light); border-color: rgba(108,63,168,0.2); color: var(--purple); }
.badge-unknown { background: var(--gray-100); border-color: var(--gray-200); color: var(--gray-500); }

.confidence-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.conf-label { font-size: 11px; color: var(--gray-400); white-space: nowrap; }

.conf-bar-wrap {
  flex: 1;
  height: 5px;
  background: var(--gray-100);
  border-radius: 3px;
  overflow: hidden;
}

.conf-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.conf-pct { font-size: 11px; font-weight: 600; color: var(--gray-700); min-width: 30px; text-align: right; }

.result-meta {
  font-size: 12px;
  color: var(--gray-500);
  line-height: 1.7;
  margin-bottom: 10px;
}

.result-meta strong { color: var(--gray-900); font-weight: 500; }

.result-actions { display: flex; gap: 6px; }

/* ============================================================
   RUN LEGEND (sidebar)
   ============================================================ */

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 2px;
}

.legend-item:hover { background: var(--gray-50); }
.legend-item.active { background: var(--blue-light); }

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

.legend-text h4 { font-size: 12px; font-weight: 600; color: var(--gray-900); }
.legend-text p { font-size: 11px; color: var(--gray-400); }

/* ============================================================
   RECENT LOOKUPS
   ============================================================ */

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--gray-100);
  margin-bottom: 5px;
  transition: all 0.12s;
}

.recent-item:hover { border-color: var(--gray-200); background: var(--gray-50); }

.recent-addr { font-size: 12px; color: var(--gray-700); font-weight: 500; }
.recent-suburb { font-size: 11px; color: var(--gray-400); }

.recent-run {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

/* ============================================================
   MAP
   ============================================================ */

.map-area { position: relative; }

#map {
  width: 100%;
  height: 100%;
}

.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  gap: 6px;
}

.map-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s;
  color: var(--gray-700);
}

.map-btn:hover { background: var(--gray-50); }

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-md) !important;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif !important;
}

.popup-content h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.popup-content p { font-size: 12px; color: var(--gray-500); margin: 0; }
.popup-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}

/* ============================================================
   ADMIN LAYOUT
   ============================================================ */

.admin-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.admin-header {
  margin-bottom: 1.5rem;
}

.admin-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.admin-desc {
  font-size: 13px;
  color: var(--gray-400);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.admin-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 6px;
}

.card-desc {
  font-size: 12px;
  color: var(--gray-400);
  margin-bottom: 1rem;
  line-height: 1.6;
}

code {
  display: inline-block;
  margin-top: 4px;
  padding: 3px 8px;
  background: var(--gray-100);
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--blue-dark);
}

/* ============================================================
   DROP ZONE
   ============================================================ */

.drop-zone {
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
  margin-bottom: 12px;
}

.drop-zone.dragover {
  border-color: var(--blue);
  background: var(--blue-light);
}

.drop-icon { font-size: 32px; margin-bottom: 8px; }
.drop-main { font-size: 14px; font-weight: 500; color: var(--gray-700); margin-bottom: 4px; }
.drop-sub { font-size: 12px; color: var(--gray-400); margin-bottom: 10px; }
.drop-hint { font-size: 11px; color: var(--gray-300); margin-top: 10px; }

/* ============================================================
   PROGRESS BAR
   ============================================================ */

.progress-bar-wrap {
  height: 6px;
  background: var(--gray-100);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}

.progress-text { font-size: 12px; color: var(--gray-500); text-align: center; }

/* ============================================================
   CSV PREVIEW TABLE
   ============================================================ */

.csv-preview {
  overflow-x: auto;
  margin-bottom: 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.preview-table th {
  background: var(--gray-50);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-500);
  border-bottom: 1px solid var(--gray-200);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-table td {
  padding: 6px 10px;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
}

.preview-table .preview-more td { color: var(--gray-300); font-style: italic; }

/* ============================================================
   STATS
   ============================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 1rem;
}

.stat-box {
  background: var(--gray-50);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.stat-num {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--blue);
  line-height: 1.2;
}

.stat-lbl {
  display: block;
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 2px;
}

.run-breakdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 12px;
}

.run-breakdown-item:last-child { border-bottom: none; }

.run-breakdown-name { font-weight: 500; color: var(--gray-700); display: flex; align-items: center; gap: 8px; }
.run-breakdown-count { color: var(--gray-400); }

/* ============================================================
   DATA TABLE
   ============================================================ */

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th {
  background: var(--gray-50);
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

.data-table td {
  padding: 8px 12px;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.data-table tr:hover td { background: var(--gray-50); }

.table-count { font-size: 12px; color: var(--gray-400); margin-top: 10px; }

.run-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 3px 6px;
  border-radius: 4px;
  color: var(--gray-400);
  transition: all 0.12s;
}

.icon-btn:hover { background: var(--gray-100); color: var(--gray-900); }
.icon-btn.danger:hover { background: var(--red-light); color: var(--red); }

/* ============================================================
   RUNS MANAGEMENT PAGE
   ============================================================ */

.run-manage-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 8px;
  transition: box-shadow 0.15s;
}

.run-manage-card:hover { box-shadow: var(--shadow-sm); }

.run-manage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.run-manage-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
}

.run-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.run-manage-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  background: var(--gray-100);
  color: var(--gray-500);
  border-radius: 20px;
  font-size: 11px;
}

.meta-pill strong { color: var(--gray-700); font-weight: 600; }

.run-notes {
  font-size: 11px;
  color: var(--amber);
  background: var(--amber-light);
  border-radius: 4px;
  padding: 4px 8px;
  margin-top: 6px;
  display: inline-block;
}

.run-manage-actions { display: flex; gap: 5px; }

/* ============================================================
   MODAL
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--white);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
}

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

.modal-title { font-size: 15px; font-weight: 600; color: var(--gray-900); }

.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--gray-400);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.modal-close:hover { background: var(--gray-100); color: var(--gray-900); }

.modal-body { padding: 1.25rem; max-height: 70vh; overflow-y: auto; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--gray-100);
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--gray-900);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 9999;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.warning { background: var(--amber); }
