/* ── RESET & BASE ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d0f14;
  --bg2:      #13161e;
  --surface:  rgba(255,255,255,0.04);
  --border:   rgba(255,255,255,0.08);
  --accent:   #6c63ff;
  --accent2:  #a78bfa;
  --green:    #10b981;
  --red:      #ef4444;
  --amber:    #f59e0b;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --radius:   14px;
  --shadow:   0 8px 32px rgba(0,0,0,0.4);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── HEADER ──────────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(135deg, #1a1040 0%, #0f1623 50%, #0d1a2e 100%);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-inner { display: flex; align-items: center; gap: 16px; }

.logo { display: flex; align-items: center; gap: 10px; font-size: 1.4rem; font-weight: 700; }
.logo-icon { font-size: 1.6rem; }
.logo-pro  { color: var(--accent2); }

.header-tabs {
  display: flex;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin: 0 20px;
  flex: 1;
  max-width: 400px;
}

.nav-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-tab:hover { color: var(--text); }
.nav-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.btn-settings {
  background: rgba(108,99,255,0.15);
  border: 1px solid rgba(108,99,255,0.3);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: auto;
  white-space: nowrap;
}
.btn-settings:hover { background: rgba(108,99,255,0.3); }

/* ── MODAL ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: #181c28;
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 440px;
  max-width: 95vw;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: slideUp 0.25s ease;
}

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

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

.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 14px 22px 20px; }

.db-status {
  font-size: 0.8rem; border-radius: 8px; padding: 8px 12px;
  display: none;
}
.db-status.ok    { background: rgba(16,185,129,0.12); color: var(--green); border: 1px solid rgba(16,185,129,0.25); display: block; }
.db-status.error { background: rgba(239,68,68,0.1);   color: var(--red);   border: 1px solid rgba(239,68,68,0.25);   display: block; }

/* ── LAYOUT & TABS ───────────────────────────────────────────── */
.tab-content { display: none; flex: 1; min-height: 0; }
.tab-content.active { display: flex; flex-direction: column; }

.app-layout, .db-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  flex: 1;
  min-height: 0;
}

/* ── SIDEBAR ─────────────────────────────────────────────────── */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: calc(100vh - 65px);
}

.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent2);
}

/* ── MAP / GEOCODER ──────────────────────────────────────────── */
.map-hint { font-size: 0.76rem; color: var(--muted); line-height: 1.5; }

.geocoder-row { display: flex; gap: 6px; }

.geocoder-row input[type="text"] {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.83rem;
  outline: none;
  transition: border-color 0.2s;
}
.geocoder-row input[type="text"]:focus { border-color: var(--accent); }

.btn-geo {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  border: none; border-radius: 8px;
  padding: 8px 12px; font-size: 1rem;
  cursor: pointer; flex-shrink: 0;
  transition: all 0.2s;
}
.btn-geo:hover:not(:disabled) { transform: translateY(-1px); }
.btn-geo:disabled { opacity: 0.5; cursor: not-allowed; }

#pickerMap {
  width: 100%; height: 200px;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden; cursor: crosshair;
  transition: border-color 0.2s;
}
#pickerMap:hover { border-color: var(--accent); }

.leaflet-container { background: #1a1f2e; }
.leaflet-tile { filter: brightness(0.85) saturate(0.9); }
.leaflet-control-zoom a { background: #1e2334 !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-attribution { background: rgba(13,15,20,0.8) !important; color: #475569 !important; font-size: 0.65rem !important; }
.leaflet-control-attribution a { color: #6c63ff !important; }

.coords-row {
  display: flex; align-items: center; gap: 8px;
  background: rgba(108,99,255,0.08);
  border: 1px solid rgba(108,99,255,0.2);
  border-radius: 8px; padding: 7px 10px;
}
.coords-hint-row { background: rgba(255,255,255,0.03); border-color: var(--border); }
.coords-icon { font-size: 0.95rem; flex-shrink: 0; }
.coords-text { font-size: 0.75rem; color: var(--text); flex: 1; }
.coords-hint { font-size: 0.75rem; color: var(--muted); flex: 1; text-align: center; }

.btn-icon {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 0.85rem;
  padding: 2px 4px; border-radius: 4px;
  transition: color 0.15s; flex-shrink: 0; line-height: 1;
}
.btn-icon:hover { color: var(--red); }

/* ── PRESETS ─────────────────────────────────────────────────── */
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }

.preset-btn {
  background: rgba(108,99,255,0.1);
  border: 1px solid rgba(108,99,255,0.25);
  color: var(--text); border-radius: 7px;
  padding: 6px 4px; font-size: 0.73rem;
  font-family: inherit; cursor: pointer;
  transition: all 0.2s; text-align: center;
}
.preset-btn:hover, .preset-btn.active {
  background: rgba(108,99,255,0.3);
  border-color: var(--accent);
}

/* ── INPUTS ──────────────────────────────────────────────────── */
.input-group { display: flex; flex-direction: column; gap: 5px; }

.input-group label {
  font-size: 0.76rem; font-weight: 500; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}

.range-inline-val { color: var(--accent2); font-weight: 600; }

.input-group input[type="text"] {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px;
  color: var(--text); font-family: inherit;
  font-size: 0.87rem; outline: none;
  transition: border-color 0.2s;
}
.input-group input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.15);
}

input[type="range"] {
  width: 100%; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: var(--accent); border-radius: 50%;
  box-shadow: 0 0 6px rgba(108,99,255,0.6);
  transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* ── BUTTONS ─────────────────────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  border: none; border-radius: 10px; padding: 11px;
  color: #fff; font-family: inherit; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  gap: 8px; transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(108,99,255,0.35);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(108,99,255,0.5); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-save-db {
  background: linear-gradient(135deg, #0ea5e9, #0369a1);
  border: none; border-radius: 10px; padding: 11px;
  color: #fff; font-family: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(14,165,233,0.3);
}
.btn-save-db:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(14,165,233,0.45); }
.btn-save-db:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-export {
  background: linear-gradient(135deg, var(--green), #059669);
  border: none; border-radius: 10px; padding: 11px;
  color: #fff; font-family: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(16,185,129,0.3);
}
.btn-export:hover:not(:disabled) { transform: translateY(-2px); }

.btn-secondary {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; color: var(--text);
  font-family: inherit; font-size: 0.8rem; cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.08); }

/* ── SAVE STATUS ─────────────────────────────────────────────── */
.save-status {
  font-size: 0.76rem; text-align: center; min-height: 18px;
  color: var(--muted);
}

/* ── SAVED SEARCHES LIST ─────────────────────────────────────── */
#savedList { display: flex; flex-direction: column; gap: 7px; }

.saved-item {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 10px; transition: border-color 0.2s;
}
.saved-item:hover { border-color: rgba(108,99,255,0.3); }

.saved-item-info { flex: 1; min-width: 0; }
.saved-item-name { font-size: 0.82rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item-meta { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

.btn-load {
  background: rgba(108,99,255,0.15);
  border: 1px solid rgba(108,99,255,0.3);
  color: var(--accent2); border-radius: 6px;
  padding: 4px 10px; font-size: 0.72rem; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-load:hover { background: rgba(108,99,255,0.3); }

.btn-del {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  color: var(--red); border-radius: 6px;
  padding: 4px 8px; font-size: 0.75rem;
  font-family: inherit; cursor: pointer; transition: all 0.2s;
}
.btn-del:hover { background: rgba(239,68,68,0.2); }

/* ── LOADING BAR ─────────────────────────────────────────────── */
.loading-bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; display: none; }
.loading-bar.active { display: block; }
.loading-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.4s ease;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

.search-status { font-size: 0.75rem; color: var(--muted); text-align: center; min-height: 16px; }

/* ── COL CHECKS ──────────────────────────────────────────────── */
.col-checks { display: flex; flex-direction: column; gap: 7px; }
.col-check-item { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.82rem; }
.col-check-item input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }
.export-hint { font-size: 0.8rem; color: var(--muted); text-align: center; }
.export-hint span { color: var(--accent2); font-weight: 600; }

/* ── RESULTS AREA ────────────────────────────────────────────── */
.results-area { display: flex; flex-direction: column; overflow: hidden; }

.filter-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px; background: var(--bg2);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.filter-label { font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.filter-pills { display: flex; gap: 7px; }

.pill { padding: 5px 13px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 0.78rem; font-family: inherit; cursor: pointer; transition: all 0.2s; font-weight: 500; }
.pill.active, .pill:hover { color: var(--text); border-color: var(--accent); background: rgba(108,99,255,0.15); }
.pill-green.active, .pill-green:hover { border-color: var(--green); background: rgba(16,185,129,0.15); color: var(--green); }
.pill-red.active,   .pill-red:hover   { border-color: var(--red);   background: rgba(239,68,68,0.15);  color: var(--red); }

.result-count { margin-left: auto; font-size: 0.78rem; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 4px 11px; border-radius: 20px; }

/* ── TABLE ───────────────────────────────────────────────────── */
.table-wrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
thead { position: sticky; top: 0; z-index: 10; }
th { background: #181c26; padding: 11px 15px; text-align: left; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); background: #1e2334; }
th .sort-icon { margin-left: 4px; opacity: 0.4; }
th.sort-asc .sort-icon, th.sort-desc .sort-icon { opacity: 1; }
td { padding: 10px 15px; border-bottom: 1px solid rgba(255,255,255,0.04); color: var(--text); vertical-align: middle; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:hover td   { background: rgba(255,255,255,0.025); }
tr.selected td { background: rgba(108,99,255,0.08); }
td a { color: var(--accent2); text-decoration: none; font-weight: 500; }
td a:hover { text-decoration: underline; }
td:first-child, th:first-child { width: 40px; text-align: center; }

.badge-yes { background: rgba(16,185,129,0.15); color: var(--green); border: 1px solid rgba(16,185,129,0.3); padding: 2px 9px; border-radius: 20px; font-size: 0.7rem; font-weight: 600; white-space: nowrap; }
.badge-no  { background: rgba(239,68,68,0.1);   color: var(--red);   border: 1px solid rgba(239,68,68,0.25); padding: 2px 9px; border-radius: 20px; font-size: 0.7rem; font-weight: 600; white-space: nowrap; }

/* ── EMPTY STATES ────────────────────────────────────────────── */
.empty-state, .no-results { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; gap: 12px; padding: 80px 20px; text-align: center; }
.empty-icon { font-size: 3.5rem; opacity: 0.5; }
.empty-state h3, .no-results h3 { font-size: 1.15rem; font-weight: 600; }
.empty-state p, .no-results p   { color: var(--muted); font-size: 0.85rem; }

/* ── TOAST ───────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 24px; right: 24px; background: #1e2334; border: 1px solid var(--border); border-radius: 10px; padding: 11px 18px; font-size: 0.84rem; color: var(--text); box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: all 0.3s; pointer-events: none; z-index: 9999; max-width: 320px; }
.toast.show { opacity: 1; transform: translateY(0); }

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; border-right: none; border-bottom: 1px solid var(--border); }
}
