/* ==========================================================================
   Localizador y visor cartográfico de códigos postales de España
   Estándar de diseño canónico fijate.com (Dark Mode nativo, acentos azul postal y ámbar)
   ========================================================================== */

:root {
  --bg-page: #0b0f17;
  --bg-card: #131b28;
  --bg-card-hover: #182335;
  --bg-surface: #1e293b;
  --border-color: #24344d;
  --border-focus: #3b82f6;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --postal-blue: #3b82f6;
  --postal-blue-hover: #2563eb;
  --postal-blue-light: rgba(59, 130, 246, 0.15);
  --postal-blue-glow: rgba(59, 130, 246, 0.35);
  --postal-amber: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
  --shadow-hover: 0 10px 30px -4px rgba(0, 0, 0, 0.7);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-title: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-surface: #e2e8f0;
  --border-color: #cbd5e1;
  --border-focus: #2563eb;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --postal-blue: #2563eb;
  --postal-blue-hover: #1d4ed8;
  --postal-blue-light: rgba(37, 99, 235, 0.12);
  --postal-blue-glow: rgba(37, 99, 235, 0.25);
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 10px 30px -4px rgba(0, 0, 0, 0.15);
}

/* Reset y contención */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Layout institucional */
.tool-layout {
  max-width: 1240px;
  width: 100%;
  margin: 1.5rem auto 3.5rem;
  padding: 0 1rem;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

.tool-ad-sidebar {
  display: none;
  width: 300px;
  flex-shrink: 0;
}

@media (min-width: 1536px) {
  .tool-ad-sidebar {
    display: block;
  }
}

.ad-sticky-box {
  position: sticky;
  top: 90px;
}

/* Panel de búsqueda postal */
.postal-search-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
}

.search-mode-nav {
  display: flex;
  background: var(--bg-surface);
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  gap: 0.5rem;
}

.btn-search-mode {
  flex: 1;
  height: 42px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-search-mode:hover {
  color: var(--text-primary);
}

.btn-search-mode.active {
  background: var(--bg-card);
  color: var(--postal-blue);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.postal-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.postal-input-box {
  flex: 1 1 280px;
  position: relative;
}

.postal-input {
  width: 100%;
  height: 50px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1.1rem;
  font-weight: 500;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.postal-input:focus {
  outline: none;
  border-color: var(--postal-blue);
  box-shadow: 0 0 0 3px var(--postal-blue-light);
}

.btn-submit-postal {
  height: 50px;
  min-height: 40px;
  padding: 0 1.75rem;
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

.btn-submit-postal:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

/* Píldoras de códigos postales célebres */
.emblematic-cp-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.emblematic-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.btn-emblematic-cp {
  height: 32px;
  padding: 0 0.85rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-emblematic-cp:hover {
  border-color: var(--postal-blue);
  color: var(--text-primary);
}

/* Tarjeta Ficha Postal */
.postal-detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
}

.postal-detail-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.25rem;
}

.postal-code-big-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.postal-badge-huge {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--postal-blue);
  background: var(--postal-blue-light);
  border: 2px solid var(--postal-blue);
  padding: 4px 18px;
  border-radius: var(--radius-md);
  letter-spacing: 0.08em;
}

.postal-locality-title {
  font-family: var(--font-title);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
}

.postal-province-sub {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin: 4px 0 0 0;
}

/* Grilla de datos postales */
.postal-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.postal-info-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.postal-info-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
}

.postal-info-val {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Visor Cartográfico Leaflet */
.postal-map-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
}

.postal-map-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.postal-map-title {
  font-family: var(--font-title);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

#mapa-codigo-postal {
  width: 100%;
  height: 480px;
  background-color: #0b0f17;
}

@media (max-width: 768px) {
  #mapa-codigo-postal {
    height: 360px;
  }
}

/* Tabla de los 52 Prefijos Provinciales */
.provinces-reference-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
}

.provinces-ref-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.provinces-ref-title {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.provinces-filter-input {
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.85rem;
  width: 240px;
}

.provinces-table-wrapper {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

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

.provinces-table th,
.provinces-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.88rem;
}

.provinces-table th {
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  z-index: 10;
}

.provinces-table tr:hover td {
  background: var(--bg-surface);
}

.prefijo-chip {
  font-family: var(--font-mono);
  font-weight: 800;
  background: var(--postal-blue-light);
  color: var(--postal-blue);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Modal Canónico (Regla 251: position: fixed; inset: 0; z-index: 9999;) */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-dialog {
  transform: scale(1);
}

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

.modal-title {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.modal-close-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-close-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.modal-body {
  padding: 1.4rem;
  overflow-y: auto;
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.btn-help-modal {
  height: 40px;
  min-height: 40px;
  padding: 0 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.btn-help-modal:hover {
  border-color: var(--postal-blue);
  color: var(--postal-blue);
}

/* Toast */
.toast-postal {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--postal-blue);
  color: var(--text-primary);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
