/**
 * Estilos Canónicos y UI Premium
 * Simulador 3D de Propagación de Ondas RF, Cobertura Wi-Fi y LoRa
 * Fijate Tools
 */

:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Paleta Midnight Slate y Neón RF */
  --bg-primary: #070d19;
  --bg-surface: #0f172a;
  --bg-surface-elevated: #1e293b;
  --bg-surface-hover: #334155;
  --border-subtle: #1e293b;
  --border-strong: #334155;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --rf-cyan: #00f0ff;
  --rf-blue: #0284c7;
  --rf-green: #10b981;
  --rf-amber: #f59e0b;
  --rf-red: #ef4444;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
}

/* Modo Claro Canónico */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-surface-hover: #e2e8f0;
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --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 8px 24px rgba(0, 0, 0, 0.12);
}

/* Reset y Contención */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text-primary);
}

.text-mono {
  font-family: var(--font-mono);
}

/* Layout Canónico */
.tool-layout {
  max-width: 1360px;
  margin: 1.25rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
}

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

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

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

/* Sidebar AdSense */
.tool-ad-sidebar {
  display: none;
}

@media (min-width: 1536px) {
  .tool-ad-sidebar {
    display: block;
    position: sticky;
    top: 5rem;
    height: fit-content;
  }
}

.tool-ad-sidebar-sticky {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  text-align: center;
}

/* Tarjeta Principal del Simulador */
.rf-simulator-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Barra Superior de Control */
.rf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.toolbar-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Inputs y Selects Canónicos */
.rf-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 40px;
  padding: 0 40px 0 0.85rem;
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  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;
  transition: border-color 0.15s ease;
}

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

.rf-select option {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

/* Botones de acción */
.btn-rf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 40px;
  min-height: 40px;
  padding: 0 1rem;
  font-family: var(--font-main);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-rf-primary {
  background: linear-gradient(135deg, #0284c7, #00f0ff);
  color: #070d19;
  border-color: #00f0ff;
  box-shadow: 0 2px 8px rgba(0, 240, 255, 0.25);
}

.btn-rf-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 14px rgba(0, 240, 255, 0.4);
}

.btn-rf-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-rf-secondary:hover {
  background: var(--bg-surface-hover);
}

.btn-rf-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-rf-danger:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fff;
}

.btn-rf-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* Viewport 3D y HUD */
.scene3d-container {
  position: relative;
  width: 100%;
  height: 580px;
  background: #0b111e;
  overflow: hidden;
}

.scene3d-viewport {
  width: 100%;
  height: 100%;
}

/* HUD Flotante de Telemetría (Glassmorphism) */
.rf-telemetry-hud {
  position: absolute;
  top: 1rem;
  left: 1rem;
  width: 320px;
  max-width: calc(100% - 2rem);
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  z-index: 10;
  transition: all 0.2s ease;
}

[data-theme="light"] .rf-telemetry-hud {
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(2, 132, 199, 0.25);
}

.hud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.hud-title {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--rf-cyan);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

[data-theme="light"] .hud-title {
  color: var(--rf-blue);
}

.quality-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  text-transform: uppercase;
}

.badge-excellent { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }
.badge-good { background: rgba(56, 189, 248, 0.2); color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.4); }
.badge-fair { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }
.badge-weak { background: rgba(249, 115, 22, 0.2); color: #fb923c; border: 1px solid rgba(249, 115, 22, 0.4); }
.badge-critical { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.badge-none { background: rgba(100, 116, 139, 0.2); color: #94a3b8; border: 1px solid rgba(100, 116, 139, 0.4); }

.hud-rssi-display {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.hud-rssi-value {
  font-family: var(--font-mono);
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.hud-ap-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Barra de Medidor de Señal (Gauge) */
.hud-gauge-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-surface-elevated);
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 0.85rem;
}

.hud-gauge-fill {
  height: 100%;
  width: 80%;
  background: var(--rf-cyan);
  transition: width 0.25s ease, background-color 0.25s ease;
}

/* Grilla de métricas */
.hud-metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

.hud-metric-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
}

.hud-metric-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.15rem;
}

.hud-metric-val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

.text-success { color: var(--rf-green) !important; }
.text-danger { color: var(--rf-red) !important; }

.hud-advice {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.4;
  padding: 0.5rem;
  background: rgba(2, 132, 199, 0.08);
  border-left: 3px solid var(--rf-blue);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Leyenda del Mapa de Calor */
.rf-heatmap-legend {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 10;
  font-size: 0.75rem;
}

[data-theme="light"] .rf-heatmap-legend {
  background: rgba(255, 255, 255, 0.9);
}

.legend-bar {
  width: 220px;
  height: 10px;
  border-radius: 4px;
  background: linear-gradient(to right, #4b0082, #dc2626, #f59e0b, #eab308, #22c55e, #00f0ff);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* Controles de Vista de Cámara en el Canvas */
.rf-viewport-overlay-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 10;
}

.btn-view-mode {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

[data-theme="light"] .btn-view-mode {
  background: rgba(255, 255, 255, 0.9);
}

.btn-view-mode:hover, .btn-view-mode.active {
  background: var(--rf-blue);
  color: #fff;
  border-color: var(--rf-cyan);
}

/* Panel Inferior de Ajustes y Edición */
.rf-control-panel {
  padding: 1.25rem;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.control-block {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.control-block-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.control-label-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.control-input-val {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Sliders de rango */
.rf-slider {
  width: 100%;
  height: 6px;
  background: var(--bg-surface-elevated);
  border-radius: 4px;
  outline: none;
  appearance: none;
  cursor: pointer;
}

.rf-slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--rf-cyan);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
  border: 2px solid #0f172a;
}

/* Checkbox con switch estilo iOS */
.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 9999px;
  transition: all 0.2s ease;
}

.switch-slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: #fff;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.switch-input:checked + .switch-slider {
  background-color: var(--rf-cyan);
  border-color: var(--rf-cyan);
}

.switch-input:checked + .switch-slider::before {
  transform: translateX(20px);
  background-color: #070d19;
}

/* Modales */
.rf-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.rf-modal.active {
  display: flex;
}

.modal-content-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  display: flex;
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  background: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Responsividad Móvil */
@media (max-width: 768px) {
  .scene3d-container {
    height: 440px;
  }

  .rf-telemetry-hud {
    position: static;
    width: 100%;
    max-width: 100%;
    margin-top: 0.75rem;
    box-shadow: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .rf-heatmap-legend {
    display: none; /* Ocultar en pantallas muy estrechas para no tapar interacción */
  }

  .rf-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-group {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-rf {
    width: 100%;
  }
}
