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

:root {
  --bg: #000;
  --surface: rgba(10,10,15,0.92);
  --surface2: rgba(30,30,40,0.9);
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);
  --text: #fff;
  --text-muted: rgba(255,255,255,0.5);
  --accent: #ff4444;
  --accent-hover: #e63939;
  --green: #22c55e;
  --blue: #4fc3f7;
  --sidebar-w: 300px;
  --header-h: 48px;
  --bottom-h: 260px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%; width: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 13px;
  overflow: hidden;
}

/* ─── Loading ──────────────────────────────────────────────────────────────── */
#loading-screen {
  position: fixed; inset: 0; z-index: 999;
  background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; transition: opacity 0.5s;
}
.loader-spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--blue);
  animation: spin 0.9s linear infinite;
}
.loader-text { color: rgba(255,255,255,0.5); font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Header ───────────────────────────────────────────────────────────────── */
#header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h); z-index: 80;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.85) 0%, transparent 100%);
  pointer-events: none;
}
#header > * { pointer-events: all; }
.header-left { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 15px; font-weight: 600; }
.header-title::first-letter { color: var(--accent); }
.header-stats { font-size: 12px; color: var(--text-muted); }
.icon-btn {
  background: rgba(0,0,0,0.5); border: 1px solid var(--border);
  color: var(--text); width: 34px; height: 34px; border-radius: 8px;
  cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }

/* ─── Globe ────────────────────────────────────────────────────────────────── */
#globe-container {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: var(--bottom-h);
  z-index: 0;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: var(--header-h); left: 0; bottom: var(--bottom-h);
  width: var(--sidebar-w);
  z-index: 90;
  background: var(--surface);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.25s ease;
}
#sidebar.closed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted);
}

#country-search, #city-search, #radius-input, #profile-select {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; color: var(--text);
  padding: 7px 10px; font-size: 13px; outline: none; width: 100%;
}
#country-search:focus, #city-search:focus, #radius-input:focus, #profile-select:focus {
  border-color: rgba(255,68,68,0.5);
}
#city-search:disabled { opacity: 0.4; cursor: not-allowed; }
#profile-select option { background: #1a1a24; }

.search-dropdown {
  position: fixed;
  background: rgba(12,12,18,0.98);
  border: 1px solid var(--border-hover);
  border-radius: 10px;
  max-height: 220px; overflow-y: auto;
  z-index: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  backdrop-filter: blur(12px);
}
.dropdown-item {
  padding: 8px 12px; font-size: 12px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex; align-items: center; justify-content: space-between;
  transition: background 0.1s;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover, .dropdown-item.focused { background: rgba(255,68,68,0.18); }
.dropdown-item b { font-weight: 600; color: var(--text); }
.dropdown-item .di-sub { color: var(--text-muted); font-size: 10px; }

.sidebar-controls { gap: 6px; }
.btn-row { display: flex; gap: 6px; margin-top: 4px; }

.selected-pill {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,68,68,0.15); border: 1px solid rgba(255,68,68,0.4);
  border-radius: 8px; padding: 5px 10px; font-size: 12px; font-weight: 500;
  color: var(--text);
}
.selected-pill .pill-clear {
  background: none; border: none; color: rgba(255,68,68,0.7);
  cursor: pointer; font-size: 14px; padding: 0 0 0 8px; line-height: 1;
}
.selected-pill .pill-clear:hover { color: var(--accent); }

/* ─── Tags ─────────────────────────────────────────────────────────────────── */
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px; padding: 4px 10px; font-size: 11px; color: var(--text);
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.tag:hover { background: rgba(255,255,255,0.12); }
.tag.active { background: rgba(255,68,68,0.25); border-color: var(--accent); color: var(--accent); }
.tag.has-data { border-color: rgba(79,195,247,0.4); color: var(--blue); }
.tag.has-data.active { background: rgba(79,195,247,0.15); border-color: var(--blue); }

/* ─── Job status card ──────────────────────────────────────────────────────── */
.job-status-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.job-row { display: flex; justify-content: space-between; font-size: 11px; }
.job-row span:first-child { color: var(--text-muted); }

.log-box {
  background: rgba(0,0,0,0.4); border: 1px solid var(--border);
  border-radius: 8px; max-height: 160px; overflow-y: auto;
  padding: 6px 8px;
}
.log-line {
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 10px;
  line-height: 1.6; color: rgba(255,255,255,0.55); word-break: break-all;
}

.queue-list { display: flex; flex-direction: column; gap: 6px; }
.queue-empty { color: var(--text-muted); font-size: 11px; }
.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
}
.queue-item strong { font-size: 11px; }
.queue-item small { color: var(--text-muted); font-size: 10px; display: block; }
.queue-item.running { border-color: rgba(34,197,94,0.45); }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: rgba(255,255,255,0.06);
  color: var(--text); cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background 0.15s, border-color 0.15s; white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,0.12); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: rgba(239,68,68,0.2); border-color: rgba(239,68,68,0.5); color: #fca5a5; }
.btn-danger:hover { background: rgba(239,68,68,0.35); }
.btn-sm { padding: 4px 10px; font-size: 11px; }

/* ─── Globe tooltip ────────────────────────────────────────────────────────── */
.globe-tooltip {
  background: rgba(0,0,0,0.8); border: 1px solid rgba(255,255,255,0.1);
  padding: 6px 12px; border-radius: 8px; font-size: 12px;
  backdrop-filter: blur(8px); pointer-events: none;
}
.globe-tooltip span { opacity: 0.6; font-size: 11px; }

/* ─── Bottom panel ─────────────────────────────────────────────────────────── */
#bottom-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-h); z-index: 80;
  background: var(--surface);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
}

.tab-bar {
  display: flex; border-bottom: 1px solid var(--border);
  padding: 0 16px; flex-shrink: 0;
}
.tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); padding: 10px 16px; cursor: pointer;
  font-size: 13px; font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; flex: 1; overflow: auto; padding: 10px 14px; flex-direction: column; gap: 8px; }
.tab-content.active { display: flex; }

/* ─── Results tab ──────────────────────────────────────────────────────────── */
.results-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--text-muted); flex-shrink: 0;
}
.results-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.results-select, #results-search {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
}
.results-select { min-width: 220px; max-width: 340px; }
#results-search { min-width: 190px; }
.table-wrap { overflow: auto; flex: 1; }
#results-table { width: 100%; border-collapse: collapse; font-size: 12px; }
#results-table th {
  background: rgba(255,255,255,0.04); color: var(--text-muted);
  padding: 6px 10px; text-align: left; font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0;
}
#results-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--border);
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#results-table tr:hover td { background: rgba(255,255,255,0.03); }
#results-table a { color: var(--blue); text-decoration: none; }

.type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
}

.type-retailer {
  color: #9ad8ff;
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.36);
}

.type-manufacturer {
  color: #ffd58b;
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(251, 191, 36, 0.36);
}

.type-unknown {
  color: #d1d5db;
  background: rgba(148, 163, 184, 0.18);
  border-color: rgba(148, 163, 184, 0.34);
}

.type-editor {
  width: 100%;
  min-width: 118px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  outline: none;
  font-size: 11px;
  font-weight: 600;
  background-color: rgba(255,255,255,0.06);
  color: var(--text);
}

.type-editor.type-retailer {
  color: #9ad8ff;
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.36);
}

.type-editor.type-manufacturer {
  color: #ffd58b;
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(251, 191, 36, 0.36);
}

.type-editor.type-unknown {
  color: #d1d5db;
  background: rgba(148, 163, 184, 0.18);
  border-color: rgba(148, 163, 184, 0.34);
}

.type-editor option {
  background: #11131b;
  color: #f3f4f6;
}

.type-editor option[value="Retailer"] {
  background: #0d2430;
  color: #9ad8ff;
}

.type-editor option[value="Manufacturer"] {
  background: #2d220c;
  color: #ffd58b;
}

.type-editor option[value="Unknown"] {
  background: #1b212c;
  color: #d1d5db;
}

.type-editor:focus {
  box-shadow: 0 0 0 2px rgba(255,255,255,0.14);
}


/* ─── Profiles tab ─────────────────────────────────────────────────────────── */
.profiles-toolbar { flex-shrink: 0; display: flex; justify-content: flex-end; }
#profiles-list { display: flex; flex-direction: column; gap: 6px; }
.profile-card {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.profile-info { display: flex; flex-direction: column; gap: 2px; }
.profile-info small { color: var(--text-muted); font-size: 10px; }
.profile-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ─── Profile form ─────────────────────────────────────────────────────────── */
#profile-form-wrap {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; margin-top: 8px;
  display: flex; flex-direction: column; gap: 10px; flex-shrink: 0;
}
#profile-form-wrap h3 { font-size: 14px; }
#profile-form-wrap label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
}
#profile-form-wrap input[type="text"],
#profile-form-wrap textarea {
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); padding: 6px 9px;
  font-size: 12px; font-family: 'SF Mono', monospace; resize: vertical; outline: none;
}
#profile-form-wrap input:focus, #profile-form-wrap textarea:focus {
  border-color: rgba(255,68,68,0.5);
}
.form-actions { display: flex; gap: 8px; }
.form-error {
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3);
  border-radius: 6px; padding: 7px 10px; color: #fca5a5; font-size: 11px;
}

/* ─── Header auth elements ─────────────────────────────────────────────────── */
.header-user {
  font-size: 12px; color: var(--text-muted);
}
.drive-status {
  font-size: 12px; color: var(--green); opacity: 0.85;
  cursor: default;
}

/* ─── Login modal ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: rgba(14,14,22,0.98);
  border: 1px solid var(--border-hover);
  border-radius: 14px;
  padding: 28px 32px;
  width: 320px;
  display: flex; flex-direction: column; gap: 20px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.7);
}
.modal-title {
  font-size: 18px; font-weight: 700;
}
.modal-label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
}
.modal-label input {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  padding: 8px 10px; font-size: 13px; outline: none;
}
.modal-label input:focus { border-color: rgba(255,68,68,0.5); }
.login-error {
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3);
  border-radius: 6px; padding: 7px 10px; color: #fca5a5; font-size: 11px;
}
#login-form {
  display: flex; flex-direction: column; gap: 14px;
}
.modal-actions {
  display: flex; gap: 8px; margin-top: 6px;
}

/* ─── Scrollbars ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; --bottom-h: 220px; }
  #sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  #sidebar.open { transform: translateX(0); }
}
