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

:root {
  --indigo:    #4f46e5;
  --indigo-d:  #4338ca;
  --indigo-l:  #ede9fe;
  --green:     #10b981;
  --red:       #ef4444;
  --amber:     #f59e0b;
  --bg:        #f1f5f9;
  --card:      #ffffff;
  --text:      #1e293b;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --radius:    12px;
  --shadow:    0 1px 6px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.view   { min-height: 100vh; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  padding: 12px 24px;
  background: var(--indigo);
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover:not(:disabled) { background: var(--indigo-d); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary.btn-full { width: 100%; }

.btn-ghost {
  padding: 7px 14px;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-export {
  padding: 9px 18px;
  background: var(--green);
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-export:hover { background: #059669; }

.btn-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
}
.btn-close:hover { background: var(--bg); }

.btn-upgrade-small {
  background: none;
  border: none;
  color: var(--indigo);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: underline;
}

/* ── Auth ──────────────────────────────────────────────────────────────────── */
.auth-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  padding: 24px 16px;
}

.auth-card {
  background: var(--card);
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.auth-logo {
  font-size: 2.8rem;
  text-align: center;
  margin-bottom: 12px;
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: .9rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 28px;
}

.auth-tabs {
  display: flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  padding: 9px;
  font-size: .9rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all .2s;
}

.tab-btn.active {
  background: var(--card);
  color: var(--indigo);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: .83rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field input {
  width: 100%;
  padding: 12px 14px;
  font-size: .95rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--card);
  color: var(--text);
  transition: border-color .2s;
}

.field input:focus { border-color: var(--indigo); }

.form-error {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: .87rem;
  margin-bottom: 14px;
}

.auth-note {
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
  margin-top: 12px;
}

/* ── App Header ────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo { font-size: 1.5rem; }

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--indigo);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-name {
  font-size: .88rem;
  font-weight: 500;
  color: var(--text);
}

.plan-badge {
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.plan-badge.free    { background: #f1f5f9; color: var(--muted); }
.plan-badge.premium { background: #fef3c7; color: #92400e; }
.plan-badge.admin   { background: #dcfce7; color: #166534; }

/* ── App Main ──────────────────────────────────────────────────────────────── */
.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

/* ── Usage Bar ─────────────────────────────────────────────────────────────── */
.usage-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 28px;
}

.usage-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: .87rem;
  color: var(--muted);
}

.usage-track {
  height: 6px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--indigo);
  border-radius: 99px;
  transition: width .4s ease;
}

.usage-fill.warning { background: var(--amber); }
.usage-fill.danger  { background: var(--red); }

/* ── Mapa ──────────────────────────────────────────────────────────────────── */
.map-section {
  position: relative;
  margin-bottom: 24px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#map {
  height: 280px;
  width: 100%;
  background: #e8f0fe;
}

.map-status {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(4px);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: .8rem;
  color: var(--muted);
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  transition: opacity .4s;
}

.map-status.hidden { opacity: 0; pointer-events: none; }

/* ── Search ────────────────────────────────────────────────────────────────── */
.search-section {
  margin-bottom: 28px;
}

.search-heading {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--text);
}

/* Grid de búsqueda: CP | Sector | Botón */
.search-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.search-field { display: flex; flex-direction: column; gap: 6px; }

.search-label {
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.search-label .optional {
  font-weight: 400;
  text-transform: none;
  color: #a0aec0;
  letter-spacing: 0;
}

.search-field input {
  padding: 13px 16px;
  font-size: .97rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  background: var(--card);
  color: var(--text);
  transition: border-color .2s;
}

.search-field input:focus { border-color: var(--indigo); }

.search-btn-wrap { padding-bottom: 0; }

.btn-search-main {
  width: 100%;
  padding: 13px 28px;
  white-space: nowrap;
}

/* Sectores rápidos */
.quick-sectors {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.qs-label {
  font-size: .8rem;
  color: var(--muted);
  font-weight: 500;
}

.qs-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  color: var(--text);
  font-size: .83rem;
  cursor: pointer;
  transition: all .15s;
}

.qs-btn:hover {
  border-color: var(--indigo);
  color: var(--indigo);
  background: var(--indigo-l);
}

.qs-btn.active {
  background: var(--indigo);
  color: #fff;
  border-color: var(--indigo);
}

.qs-clear {
  color: var(--muted);
  font-size: .78rem;
}

/* ── Loading ───────────────────────────────────────────────────────────────── */
.loading-box {
  text-align: center;
  padding: 48px;
  color: var(--muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--indigo);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert-error {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.limit-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
}

.limit-icon { font-size: 1.8rem; }

.limit-banner p {
  font-size: .87rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Results ───────────────────────────────────────────────────────────────── */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}

.results-summary {
  font-size: .9rem;
  font-weight: 500;
  color: var(--muted);
}

.table-wrapper {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

thead th {
  background: var(--indigo);
  color: #fff;
  padding: 13px 16px;
  text-align: left;
  font-weight: 600;
  font-size: .8rem;
  letter-spacing: .04em;
  white-space: nowrap;
}

thead th:first-child { border-radius: 12px 0 0 0; }
thead th:last-child  { border-radius: 0 12px 0 0; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8f7ff; }

tbody td {
  padding: 12px 16px;
  vertical-align: middle;
  color: var(--text);
}

td.t-nombre { font-weight: 600; min-width: 150px; }
td.t-dir    { color: var(--muted); min-width: 200px; font-size: .85rem; }
td.t-tel    { white-space: nowrap; }
td.t-web a  { color: var(--indigo); text-decoration: none; font-weight: 500; font-size: .85rem; }
td.t-web a:hover { text-decoration: underline; }
td.t-web.no-web { color: #cbd5e1; font-style: italic; font-size: .82rem; }

.cat-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--indigo-l);
  color: #5b21b6;
  font-size: .78rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Plans Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.plans-modal {
  background: var(--card);
  border-radius: 20px;
  width: 100%;
  max-width: 880px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
}

.plans-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.plans-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.plan-card {
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
  position: relative;
  transition: border-color .2s;
}

.plan-card:hover { border-color: var(--indigo); }

.plan-card.plan-popular {
  border-color: var(--indigo);
}

.plan-badge-top {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--indigo);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 20px;
  white-space: nowrap;
}

.plan-name {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.plan-price {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--indigo);
  margin-bottom: 16px;
}

.plan-price span {
  font-size: .9rem;
  font-weight: 500;
  color: var(--muted);
}

.plan-features {
  list-style: none;
  margin-bottom: 20px;
  font-size: .85rem;
  color: var(--muted);
}

.plan-features li { padding: 4px 0; }

.plan-current {
  text-align: center;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
}

/* ── Selector de ubicación ─────────────────────────────────────────────────── */
.location-picker {
  background: #fff;
  border: 2px solid var(--indigo);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.loc-title {
  font-weight: 600;
  color: var(--indigo);
  margin-bottom: 12px;
  font-size: .95rem;
}

.location-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.loc-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  background: var(--indigo-l);
  border: 1.5px solid transparent;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.loc-option:hover {
  background: #ddd6fe;
  border-color: var(--indigo);
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .auth-card   { padding: 32px 20px; }
  .app-main    { padding: 16px 14px 40px; }
  .search-grid { grid-template-columns: 1fr; }
  .btn-search-main { width: 100%; }
  .header-right .user-name { display: none; }
  .plans-grid  { grid-template-columns: 1fr 1fr; }
  .limit-banner { flex-wrap: wrap; }
  #map { height: 200px; }
}

@media (max-width: 420px) {
  .plans-grid { grid-template-columns: 1fr; }
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 24px;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 500;
  color: white;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  max-width: 90vw;
  text-align: center;
  transition: opacity .3s;
}
.toast-success { background: #10b981; }
.toast-error   { background: #ef4444; }

/* ── Plan actual ────────────────────────────────────────────────────────────── */
.plan-current {
  margin-top: 12px;
  text-align: center;
  font-size: .85rem;
  font-weight: 600;
  color: var(--indigo);
  padding: 8px;
  background: var(--indigo-l);
  border-radius: 8px;
}
