/**
 * Fijate Tools - Explorador de la Cuarta Dimensión
 * Estilos canónicos corporativos, tema Midnight Slate, visor 3D y controles táctiles
 */

: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 */
  --bg-page: #0b0f17;
  --bg-card: #111827;
  --bg-card-hover: #1f2937;
  --bg-surface: #1e293b;
  --border-color: #334155;
  --border-subtle: rgba(255, 255, 255, 0.08);

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

  /* Acentos 4D */
  --accent-cyan: #38bdf8;
  --accent-purple: #a855f7;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;

  --accent-primary: #38bdf8;
  --accent-primary-hover: #0284c7;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(56, 189, 248, 0.2);
}

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

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --accent-primary: #0284c7;
  --accent-primary-hover: #0369a1;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 20px rgba(2, 132, 199, 0.15);
}

/* Reset y estructura canónica */
*, *::before, *::after {
  box-sizing: border-box;
}

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

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

/* Contenedor principal de la herramienta */
.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.25rem auto 3rem;
  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 {
  width: 300px;
  flex-shrink: 0;
  display: none;
}

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

/* =========================================================================
   VISOR 3D Y LIENZO PRINCIPAL (CANVAS)
   ========================================================================= */

.viewer-wrapper {
  position: relative;
  width: 100%;
  height: clamp(420px, 58vh, 600px);
  background: radial-gradient(circle at 50% 45%, #111a2e 0%, #080d16 80%, #04070c 100%);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.viewer-wrapper.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  height: 100vh !important;
  width: 100vw !important;
  border-radius: 0;
  border: none;
  margin: 0;
}

#canvas-container {
  width: 100%;
  height: 100%;
  cursor: grab;
}

#canvas-container:active {
  cursor: grabbing;
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* HUD superior flotante sobre el visor */
.viewer-hud-top {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.hud-badge-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  pointer-events: auto;
}

.hud-poly-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.hud-pulse-dot {
  width: 8px;
  height: 8px;
  background-color: var(--accent-cyan);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent-cyan);
  animation: pulse4D 2s infinite ease-in-out;
}

@keyframes pulse4D {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.2); }
}

.hud-sub-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-cyan);
  width: fit-content;
}

.hud-controls-top {
  display: flex;
  gap: 0.5rem;
  pointer-events: auto;
}

.btn-hud-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(10px);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.btn-hud-icon:hover {
  background: var(--bg-card-hover);
  color: var(--accent-cyan);
  transform: translateY(-2px);
}

/* HUD inferior flotante sobre el visor */
.viewer-hud-bottom {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

.hud-instruction {
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  color: var(--text-muted);
  pointer-events: auto;
}

/* =========================================================================
   PANEL DE CONTROL PRINCIPAL CON PESTAÑAS
   ========================================================================= */

.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  margin-bottom: 2rem;
}

/* Barra de pestañas */
.panel-tabs-bar {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.15);
  padding: 0.35rem 0.5rem 0;
  gap: 0.35rem;
  scrollbar-width: thin;
}

.panel-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.15rem;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  min-height: 44px;
}

.panel-tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
}

.panel-tab-btn.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  background: var(--bg-card);
}

.panel-tab-pane {
  display: none;
  padding: 1.5rem;
}

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

/* Cuadrícula de tarjetas de polítopos (Pestaña 1) */
.poly-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.poly-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-align: left;
}

.poly-card:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.poly-card.active {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.08);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.2);
}

.poly-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.poly-card-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
}

.poly-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border-radius: var(--radius-sm);
}

.poly-card-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

/* Rotaciones 4D (Pestaña 2) */
.rotation-presets-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.btn-rotate-preset {
  padding: 0.6rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 40px;
}

.btn-rotate-preset:hover {
  border-color: var(--accent-cyan);
}

.btn-rotate-preset.active {
  background: var(--accent-cyan);
  color: #0b0f17;
  border-color: var(--accent-cyan);
  font-weight: 700;
}

.rotation-planes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.plane-control-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.plane-control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.plane-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.plane-badge-4d {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  background: rgba(168, 85, 247, 0.2);
  color: var(--accent-purple);
  border-radius: var(--radius-sm);
}

.plane-badge-3d {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-emerald);
  border-radius: var(--radius-sm);
}

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

.slider-4d {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  height: 6px;
  -webkit-appearance: none;
  background: var(--border-color);
  border-radius: 4px;
  outline: none;
}

.slider-4d::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.6);
  transition: transform 0.1s;
}

.slider-4d::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.step-btn-group {
  display: flex;
  gap: 0.35rem;
}

.btn-step {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-step:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* Escáner de corte transversal (Pestaña 3) */
.scanner-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.scanner-hero-box {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, rgba(17, 24, 39, 0.9) 100%);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.scanner-status-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.scanner-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Botones estándar y táctiles */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--accent-primary);
  color: #0b0f17;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  color: var(--text-main);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  cursor: pointer;
  min-height: 44px;
  transition: all 0.2s ease;
}

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

.btn-warning {
  background: var(--accent-amber);
  color: #0b0f17;
  border: none;
}

/* Cámara y proyección (Pestaña 4) */
.controls-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Desplegable select canónico */
.select-canonical {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  padding: 0.65rem 2.5rem 0.65rem 0.85rem;
  font-family: var(--font-main);
  font-size: 0.92rem;
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  min-height: 42px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-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='%2338bdf8' 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 0.85rem center;
}

.checkbox-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 38px;
}

.checkbox-toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

/* =========================================================================
   PANEL DE KPIS Y DATOS MATEMÁTICOS EN TIEMPO REAL
   ========================================================================= */

.kpi-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-align: center;
}

.kpi-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  text-transform: none;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.kpi-euler-card {
  grid-column: 1 / -1;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Toast de feedback */
.expl-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid var(--accent-cyan);
  color: var(--text-main);
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100000;
}

.expl-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* =========================================================================
   MODAL ACCESIBLE CORPORATIVO (SIN WINDOW.ALERT)
   ========================================================================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  max-width: 680px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

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

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

.btn-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
}

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

.modal-body {
  padding: 1.5rem;
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.6;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* =========================================================================
   GUÍA EDUCATIVA Y ACORDEONES SEO
   ========================================================================= */

.seo-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 2rem;
  margin-top: 2rem;
  box-shadow: var(--shadow-sm);
}

.seo-guide-section h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--text-main);
}

.seo-guide-section h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--accent-cyan);
}

.seo-guide-section p {
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 1rem;
}

.faq-accordion {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.faq-question {
  width: 100%;
  padding: 1rem 1.25rem;
  text-align: left;
  background: transparent;
  border: none;
  font-family: var(--font-heading);
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-answer {
  padding: 0 1.25rem 1rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

/* =========================================================================
   RESPONSIVIDAD Y CONTROLES MÓVILES
   ========================================================================= */

@media (max-width: 768px) {
  .tool-layout {
    margin-top: 0.5rem;
    padding: 0 0.75rem;
  }

  .viewer-wrapper {
    height: 420px;
    border-radius: var(--radius-lg);
  }

  .panel-tab-pane {
    padding: 1rem;
  }

  .poly-grid {
    grid-template-columns: 1fr;
  }

  .rotation-planes-grid {
    grid-template-columns: 1fr;
  }

  .kpi-board {
    grid-template-columns: repeat(2, 1fr);
  }

  .btn-primary, .btn-secondary {
    width: 100%;
  }

  .scanner-actions {
    flex-direction: column;
  }

  .scanner-actions button {
    width: 100%;
  }
}
