@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #162033;
  --muted: #6b7587;
  --line: #e4e9f1;
  --primary: #2457d6;
  --primary-dark: #183e9e;
  --secondary: #eef3ff;
  --success: #0d8a62;
  --danger: #c8374d;
  --warning: #e8a11b;
  --shadow: 0 14px 38px rgba(31, 54, 92, .09);
  font-family: "Tajawal", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; justify-content: space-between; align-items: center; gap: 24px;
  padding: 12px 28px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 18px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.brand-mark {
  width: 58px; height: 58px; border-radius: 18px;
  display: grid; place-items: center; font-weight: 800; font-size: 30px; color: white;
  background: linear-gradient(145deg, #2c68ef, #163988); box-shadow: 0 12px 24px rgba(36,87,214,.25);
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 22px; }
.topbar nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.nav-btn, .nav-link {
  border: 0; background: transparent; color: var(--muted);
  padding: 10px 13px; border-radius: 10px; font-weight: 600;
}
.nav-btn.active { background: var(--secondary); color: var(--primary); }
.nav-link.danger { color: var(--danger); }

.app-shell { max-width: 1600px; margin: 0 auto; padding: 22px; }
.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats-grid article {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 15px 17px; box-shadow: 0 8px 24px rgba(31,54,92,.05);
}
.stats-grid span { color: var(--muted); font-size: 13px; }
.stats-grid strong { display: block; font-size: 27px; margin-top: 4px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.search-card, .leads-toolbar {
  display: flex; align-items: end; gap: 12px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); padding: 16px;
  border-radius: 18px; box-shadow: var(--shadow);
}
.field { min-width: 190px; flex: 1; }
.field.compact { min-width: 110px; max-width: 145px; }
.field label, .auth-card label {
  display: block; color: var(--muted); font-size: 13px; font-weight: 600; margin-bottom: 6px;
}
.field input, .field select, .auth-card input, .status-select, .notes-input {
  width: 100%; border: 1px solid #d9e0eb; background: #fff; color: var(--ink);
  border-radius: 11px; padding: 11px 12px; outline: none; transition: .2s;
}
.field input:focus, .field select:focus, .auth-card input:focus, .status-select:focus, .notes-input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(36,87,214,.10);
}
.btn {
  border: 0; border-radius: 11px; padding: 11px 16px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { color: #fff; background: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { color: var(--primary); background: var(--secondary); }
.btn.success { color: white; background: var(--success); }
.btn.danger { color: white; background: var(--danger); }
.btn.whatsapp { color: white; background: #159b65; }
.btn.tiny { padding: 7px 10px; font-size: 12px; border-radius: 9px; }
.btn.full { width: 100%; margin-top: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.search-btn { min-height: 43px; }
.unlimited-badge {
  min-height: 43px; display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 13px; color: var(--success); background: #eaf8f3;
  border: 1px solid #bce7d8; border-radius: 11px; font-size: 12px; font-weight: 800;
}

.search-progress {
  display: grid; grid-template-columns: minmax(220px, .7fr) minmax(260px, 1.4fr) auto;
  align-items: center; gap: 14px; margin: 13px 0; padding: 13px 15px;
  background: #f0f5ff; border: 1px solid #cfdcff; border-radius: 14px;
}
.progress-copy { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.progress-copy strong { font-size: 13px; }
.progress-copy span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.progress-track { height: 10px; overflow: hidden; background: #dce6fb; border-radius: 999px; }
.progress-track span {
  display: block; width: 0; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #43a3ff); transition: width .3s ease;
}
.progress-actions { display: flex; gap: 7px; }

.notice {
  margin: 13px 0; padding: 12px 15px; color: #6c5313; background: #fff8dc;
  border: 1px solid #f1dda1; border-radius: 13px; font-size: 13px;
}

.discovery-grid { display: grid; grid-template-columns: minmax(380px, .9fr) minmax(500px, 1.1fr); gap: 15px; }
.map-card, .results-card, .table-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow);
}
#map { min-height: 640px; width: 100%; }
.map-attribution { padding: 7px 12px; color: var(--muted); font-size: 11px; border-top: 1px solid var(--line); }
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.section-head h2 { margin: 0 0 3px; font-size: 18px; }
.section-head span { color: var(--muted); font-size: 12px; }
.head-actions { display: flex; align-items: center; gap: 9px; }
.check-label { color: var(--muted); font-size: 12px; white-space: nowrap; }

.result-list { height: 597px; overflow: auto; }
.show-more-results {
  width: 100%; padding: 11px; border: 0; border-top: 1px solid var(--line);
  color: var(--primary); background: #f8faff; font-weight: 800;
}
.result-item {
  display: grid; grid-template-columns: 34px minmax(0,1fr) auto; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); transition: background .2s;
}
.result-item:hover { background: #fafcff; }
.result-index {
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 9px;
  color: var(--primary); background: var(--secondary); font-weight: 700; font-size: 12px;
}
.result-title-row { display: flex; align-items: center; gap: 8px; }
.result-main h3 { margin: 0; font-size: 15px; }
.distance { color: var(--muted); font-size: 11px; }
.muted { color: var(--muted); font-size: 12px; margin: 5px 0 8px; }
.contact-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.contact-chips a, .contact-chips span {
  background: #f6f8fc; border: 1px solid #e8edf4; border-radius: 8px; padding: 5px 8px; font-size: 11px;
}
.missing { color: #9aa3b2; }
.result-actions { display: flex; flex-direction: column; gap: 6px; min-width: 95px; }
.empty-state { display: grid; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.empty-icon { font-size: 54px; color: #b9c4d6; }

.leads-toolbar { margin-bottom: 14px; }
.table-card { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 1050px; }
.data-table th, .data-table td { text-align: right; vertical-align: top; padding: 13px; border-bottom: 1px solid var(--line); }
.data-table th { background: #f9fbfe; color: var(--muted); font-size: 12px; position: sticky; top: 0; }
.data-table td { font-size: 13px; }
.data-table td strong { display: block; }
.data-table td small, .data-table td a, .data-table td span { display: block; margin-top: 4px; }
.wa-link { color: var(--success); font-weight: 700; }
.inline-links { display: flex; gap: 10px; }
.notes-input { min-width: 210px; resize: vertical; }
.link-btn { border: 0; background: none; color: var(--primary); padding: 4px 0; font-size: 12px; }
.table-actions { display: flex; gap: 6px; }
.empty-cell { text-align: center !important; padding: 40px !important; color: var(--muted); }

.auth-page { display: grid; place-items: center; padding: 24px; min-height: 100vh; background: radial-gradient(circle at top, #eaf0ff, var(--bg) 45%); }
.auth-card {
  width: min(440px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 24px; padding: 30px; box-shadow: var(--shadow);
}
.auth-card .brand-mark { margin: 0 auto 16px; }
.auth-card h1 { text-align: center; margin: 0 0 8px; }
.auth-card p { text-align: center; color: var(--muted); margin: 0 0 22px; }
.auth-card label { margin: 12px 0; }
.auth-card small { display: block; color: var(--muted); margin-top: 13px; text-align: center; }
.alert { border-radius: 10px; padding: 10px 12px; margin: 12px 0; font-size: 13px; }
.alert.error { color: #8f1d32; background: #fff0f3; border: 1px solid #f4c5ce; }

.loading-overlay {
  position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; align-content: center;
  background: rgba(13, 25, 47, .52); color: white; backdrop-filter: blur(3px);
}
.spinner {
  width: 46px; height: 46px; border: 4px solid rgba(255,255,255,.3); border-top-color: white;
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#toast-container { position: fixed; left: 18px; bottom: 18px; z-index: 4000; display: grid; gap: 8px; }
.toast {
  min-width: 260px; max-width: 420px; padding: 12px 14px; border-radius: 12px;
  color: white; background: #26344e; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: .22s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.map-popup { min-width: 180px; }
.map-popup button { margin-top: 7px; border: 0; border-radius: 7px; padding: 6px 9px; color: white; background: var(--primary); }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .discovery-grid { grid-template-columns: 1fr; }
  #map { min-height: 420px; }
  .result-list { height: 560px; }
}
@media (max-width: 700px) {
  .topbar { position: static; padding: 12px; align-items: flex-start; flex-direction: column; }
  .topbar nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav-btn, .nav-link { white-space: nowrap; }
  .app-shell { padding: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .field, .field.compact { min-width: 100%; max-width: none; }
  .search-card .btn { width: 100%; }
  .unlimited-badge { width: 100%; }
  .search-progress { grid-template-columns: 1fr; }
  .progress-actions .btn { flex: 1; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .head-actions { width: 100%; justify-content: space-between; }
  .result-item { grid-template-columns: 30px 1fr; }
  .result-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; padding-right: 40px; }
}
