*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface-2:   #21262d;
  --surface-3:   #2d333b;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #1f6feb;
  --accent-hover:#1a63d6;
  --danger:      #f85149;
  --danger-bg:   rgba(248,81,73,.08);
  --success-bg:  rgba(63,185,80,.08);
  --success:     #3fb950;
  --radius:      6px;
  --sidebar:     220px;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

/* ── Login ────────────────────────────────────── */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px 36px;
  width: 360px;
}

.login-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.5px;
  margin-bottom: 28px;
}

/* ── App shell ────────────────────────────────── */
#app-view {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ──────────────────────────────────── */
#sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 18px 16px 16px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.4px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  transition: background .1s, color .1s;
}

.nav-link:hover   { background: var(--surface-2); color: var(--text); }
.nav-link.active  { background: var(--surface-3); color: var(--text); }
.nav-link svg     { flex-shrink: 0; opacity: .8; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.current-user {
  padding: 6px 10px;
}

.current-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.current-user-email {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main content ─────────────────────────────── */
#page-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 36px;
  background: #13181f;
}

/* ── Page header ──────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-title { font-size: 19px; font-weight: 600; letter-spacing: -.3px; }

/* ── Toolbar ──────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

/* ── Table ────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

thead { background: var(--surface); }

th {
  padding: 9px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
}

tbody tr { background: var(--bg); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

.col-id { width: 56px; color: var(--text-muted); }
.col-cb { width: 40px; }
.col-actions { width: 110px; text-align: right; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .1s, border-color .1s, opacity .1s;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger  {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-sm  { padding: 4px 10px; font-size: 12.5px; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition: background .1s, color .1s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ── Forms ────────────────────────────────────── */
.field { margin-bottom: 14px; }

.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
}

input, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 11px;
  font: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s;
}

input::placeholder { color: var(--text-muted); opacity: .6; }
input:focus, select:focus { border-color: #388bfd; }
select option { background: var(--surface-2); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); cursor: pointer; }

input[type="search"] {
  max-width: 280px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  padding-left: 32px;
}

/* ── Modal ────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 460px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
}

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

.modal-header h2 { font-size: 15px; font-weight: 600; }

.modal-body { padding: 20px; overflow-y: auto; }

/* Wide variant with a map pane beside the form */
.modal.modal-wide { width: 880px; }
.modal-body-map { display: flex; gap: 18px; align-items: stretch; }
.modal-body-map #modal-form { flex: 0 0 360px; min-width: 0; }
.modal-map {
  flex: 1;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}
.modal-map .leaflet-container { width: 100%; height: 100%; background: var(--surface-2); }

/* Polygon editor */
.poly-vtx {
  background: #fff;
  border: 2px solid #1f6feb;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  cursor: move;
}
.polygon-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.polygon-count { font-size: 12px; color: var(--text-muted); }
.polygon-help  { margin: 6px 0 0; font-size: 11px; color: var(--text-muted); line-height: 1.4; }
.btn.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Text input with an inline action button (e.g. geocode "Search") */
.input-with-btn { display: flex; gap: 8px; align-items: stretch; }
.input-with-btn input { flex: 1; min-width: 0; }
.input-with-btn .btn { flex: 0 0 auto; white-space: nowrap; }

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

/* ── Badges ───────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.badge-admin  { background: rgba(88,166,255,.12); color: #79b8ff; }
.badge-viewer { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.badge-status-new      { background: rgba(88,166,255,.12);  color: #79b8ff; }
.badge-status-routed   { background: rgba(210,153,34,.12);  color: #e3b341; }
.badge-status-picked   { background: rgba(210,153,34,.12);  color: #e3b341; }
.badge-status-dropped  { background: rgba(58,173,205,.12);  color: #76e3ea; }
.badge-status-noshow   { background: rgba(248,81,73,.12);   color: #ff7b72; }
.badge-status-done     { background: rgba(63,185,80,.12);   color: #3fb950; }
.badge-status-canceled { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* ── Toast ────────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  max-width: 300px;
  animation: toast-in .18s ease;
}

.toast-success { background: #12261e; border: 1px solid #2ea043; color: var(--success); }
.toast-error   { background: #2a0f0e; border: 1px solid #da3633; color: #ff7b72; }

@keyframes toast-in {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Misc ─────────────────────────────────────── */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 14px; }

.otp-hint { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.otp-hint span { color: var(--text); }

/* ── Tag input (attribute multi-select) ───────── */
.tag-input {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  padding: 4px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: text;
}

.tag-input:focus-within { border-color: #388bfd; }

.passenger-filter { width: 200px; flex: 0 0 auto; }

.tag-chips { display: contents; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 10px;
  background: var(--surface-3);
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
}

.tag-chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.tag-chip-remove:hover { color: var(--danger); }

.tag-search {
  flex: 1;
  min-width: 80px;
  border: none !important;
  background: transparent !important;
  outline: none !important;
  padding: 2px 0 !important;
  font-size: 13.5px;
  color: var(--text);
  width: auto !important;
}

.tag-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 200px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

.tag-option {
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
}

.tag-option:hover { background: var(--surface-2); }

/* ── Attribute chips (table cell) ─────────────── */
.attr-chip {
  display: inline-block;
  padding: 1px 7px;
  background: var(--surface-3);
  border-radius: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 1px 2px 1px 0;
}

/* ── Select-all bar ───────────────────────────── */
#select-all-bar {
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 0 2px 10px;
}

#select-all-bar a {
  color: var(--accent);
  text-decoration: none;
}

#select-all-bar a:hover { text-decoration: underline; }

/* ── Search toolbar ───────────────────────────── */
.toolbar input[type="text"] {
  width: 240px;
}

.site-filter-select {
  width: auto;
  min-width: 140px;
}

/* ── Sortable columns ─────────────────────────── */
th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover { color: var(--text); }

th.sorted { color: var(--text); }

.sort-icon {
  font-size: 10px;
  opacity: .5;
  margin-left: 2px;
}

th.sorted .sort-icon { opacity: 1; color: var(--accent); }

/* ── Pagination ───────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.pagination-info {
  font-size: 12.5px;
  color: var(--text-muted);
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.page-gap {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 2px;
}

/* ── Import page ─────────────────────────────────────────────────────────────── */
.import-intro {
  color: var(--text-muted);
  font-size: 13.5px;
  max-width: 760px;
  margin: 0 0 16px;
  line-height: 1.5;
}
.import-intro code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

.import-drop {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color .15s, background .15s;
}
.import-drop:hover, .import-drop.dragover {
  border-color: var(--accent);
  background: var(--surface-2);
}
.import-drop-inner strong { color: var(--text); }

.import-panel { margin-top: 20px; }

.import-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.import-row label { font-size: 13px; color: var(--text-muted); }
.import-confidence { font-size: 12px; color: var(--text-muted); }
.import-reasoning {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 14px;
  line-height: 1.5;
}

.import-sample { color: var(--text-muted); font-size: 12.5px; }
.import-note   { color: var(--danger); font-size: 12px; }
.import-map { min-width: 160px; }

.import-actions { margin-top: 16px; }

.import-progress { padding: 24px 4px; }
/* Centered full-screen overlay shown while an import runs, so progress is
   visible regardless of scroll position. */
.import-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  z-index: 1000;
}
.import-overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: min(440px, 90vw);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.import-progress-label { font-size: 13.5px; color: var(--text); margin-bottom: 10px; }
.progress-track {
  height: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .2s ease;
}
.import-progress-count { margin-top: 8px; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.import-summary {
  display: flex;
  gap: 18px;
  align-items: baseline;
  margin: 20px 0 12px;
  flex-wrap: wrap;
}
.import-stat { font-size: 13px; color: var(--text-muted); }
.import-stat strong { color: var(--text); font-size: 16px; margin-right: 4px; }
.import-stat.muted { color: var(--text-muted); }

.import-bad { background: var(--danger-bg); }

.import-skipped {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.import-skipped summary { cursor: pointer; color: var(--text); }
.import-skipped ul { margin: 8px 0 0; padding-left: 18px; }
.import-skipped li { margin: 2px 0; }
