/* ==========================================================================
   Descargador de Mapas del IGN - Estilos Oficiales Canónicos
   ========================================================================== */

:root {
  --bg-page: #0b0f17;
  --bg-card: #131b26;
  --bg-card-subtle: #1a2433;
  --bg-card-hover: #222f42;
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: #3b82f6;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-accent: #06b6d4;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-card-hover: #e2e8f0;
  --border-color: rgba(0, 0, 0, 0.1);
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.12);
}

/* --------------------------------------------------------------------------
   Layout base
   -------------------------------------------------------------------------- */
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
}

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
  box-sizing: border-box;
}

.tool-with-sidebar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 1536px) {
  .tool-with-sidebar {
    grid-template-columns: 1fr 300px;
  }
}

.tool-main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

/* --------------------------------------------------------------------------
   Tarjeta principal
   -------------------------------------------------------------------------- */
.card-main {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .card-main {
    padding: 1.75rem;
  }
}

/* --------------------------------------------------------------------------
   Barra superior de búsqueda y ubicación
   -------------------------------------------------------------------------- */
.map-search-bar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 768px) {
  .map-search-bar {
    flex-direction: row;
    align-items: center;
  }
}

.search-input-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input-wrap input {
  width: 100%;
  height: 44px;
  box-sizing: border-box;
  padding: 0 38px 0 40px;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-wrap input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.btn-clear-input {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

.btn-clear-input:hover {
  color: var(--text-main);
}

.search-suggestions-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 260px;
  overflow-y: auto;
  z-index: 1000;
}

.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background-color 0.15s;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.highlighted {
  background-color: var(--bg-card-hover);
}

.suggestion-main {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-main);
}

.suggestion-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.search-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-secondary {
  height: 44px;
  min-height: 40px;
  padding: 0 1rem;
  box-sizing: border-box;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.2s, border-color 0.2s;
}

.btn-secondary:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--text-dim);
}

.btn-secondary.active {
  background-color: rgba(59, 130, 246, 0.15);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* --------------------------------------------------------------------------
   Visor de mapa Leaflet
   -------------------------------------------------------------------------- */
.map-viewport-wrapper {
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: #0b0f17;
}

.map-container {
  width: 100%;
  height: 520px;
  min-height: 380px;
  background-color: #1a202c;
}

@media (min-width: 1024px) {
  .map-container {
    height: 600px;
  }
}

/* Selector flotante de capas */
.map-layer-selector {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  background-color: rgba(19, 27, 38, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 220px;
}

[data-theme="light"] .map-layer-selector {
  background-color: rgba(255, 255, 255, 0.92);
}

.layer-selector-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.layer-btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.btn-layer {
  padding: 6px 8px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.btn-layer:hover {
  color: var(--text-main);
  background-color: var(--bg-card-hover);
}

.btn-layer.active {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
}

.layer-selector-divider {
  height: 1px;
  background-color: var(--border-color);
  margin: 2px 0;
}

.layer-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-main);
  cursor: pointer;
}

.layer-checkbox-label input {
  accent-color: var(--color-primary);
}

/* Badge flotante de coordenadas */
.map-coords-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  z-index: 500;
  background-color: rgba(11, 15, 23, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Tarjeta de información de la hoja oficial
   -------------------------------------------------------------------------- */
.sheet-info-card {
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sheet-info-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 768px) {
  .sheet-info-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.sheet-icon-box {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background-color: rgba(59, 130, 246, 0.15);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sheet-info-titles {
  flex: 1 1 auto;
}

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

.sheet-name {
  margin: 2px 0 0 0;
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
}

.sheet-badge-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.sheet-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 600;
}

.pill-mtn25 {
  background-color: rgba(6, 182, 212, 0.15);
  color: var(--color-accent);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.pill-mtn50 {
  background-color: rgba(59, 130, 246, 0.15);
  color: var(--color-primary);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.pill-huso {
  background-color: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.sheet-info-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sheet-coords-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

@media (min-width: 640px) {
  .sheet-coords-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.coord-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.coord-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.coord-val {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.sheet-cnig-download {
  display: flex;
}

.btn-cnig {
  width: 100%;
  text-decoration: none;
  font-size: 0.85rem;
}

.external-icon {
  margin-left: 4px;
}

/* --------------------------------------------------------------------------
   Sección de opciones de descarga
   -------------------------------------------------------------------------- */
.download-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 0.5rem;
}

.section-title {
  margin: 0;
  font-family: 'Outfit', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.section-subtitle {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.export-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  background-color: var(--bg-card-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
}

@media (min-width: 640px) {
  .export-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.export-tab {
  height: 44px;
  min-height: 40px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
}

.export-tab:hover {
  color: var(--text-main);
}

.export-tab.active {
  background-color: var(--bg-card);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 768px) {
  .config-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.config-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
}

.form-input {
  width: 100%;
  height: 44px;
  min-height: 40px;
  box-sizing: border-box;
  padding: 0 0.85rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Reglas estrictas canónicas para desplegables */
.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 44px;
  min-height: 40px;
  box-sizing: border-box;
  padding: 0 40px 0 0.85rem;
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.88rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

.form-select option,
.form-select optgroup {
  background-color: var(--bg-card);
  color: var(--text-main);
}

.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
}

.resolution-preview-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.76rem;
  color: var(--text-muted);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  font-family: 'JetBrains Mono', monospace;
  margin-top: 2px;
}

.resolution-preview-badge strong {
  color: var(--color-primary);
}

.checkbox-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  min-height: 40px;
}

.checkbox-option input {
  accent-color: var(--color-primary);
  width: 18px;
  height: 18px;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.action-wrap {
  display: flex;
  width: 100%;
}

.btn-primary {
  width: 100%;
  height: 48px;
  min-height: 40px;
  box-sizing: border-box;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
}

.btn-primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.45);
}

.btn-primary:active {
  transform: translateY(1px);
}

/* --------------------------------------------------------------------------
   Guía informativa inferior
   -------------------------------------------------------------------------- */
.info-guide-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.guide-title {
  margin: 0;
  font-family: 'Outfit', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.guide-cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 768px) {
  .guide-cards-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.guide-card {
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

.guide-card h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
}

.guide-card p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* --------------------------------------------------------------------------
   Modal accesible canónico
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.modal-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: modalSpin 0.8s linear infinite;
}

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

.modal-title {
  margin: 0;
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  color: var(--text-main);
}

.modal-desc {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-actions {
  width: 100%;
  margin-top: 0.5rem;
}

/* Leaflet overrides */
.leaflet-container {
  font-family: 'Inter', sans-serif;
}

.leaflet-bar a {
  background-color: var(--bg-card) !important;
  color: var(--text-main) !important;
  border-color: var(--border-color) !important;
}

.leaflet-bar a:hover {
  background-color: var(--bg-card-hover) !important;
}

.leaflet-control-attribution {
  background-color: rgba(11, 15, 23, 0.8) !important;
  color: var(--text-dim) !important;
  font-size: 0.68rem !important;
}

.leaflet-control-attribution a {
  color: var(--text-muted) !important;
}
