/**
 * Herramienta: Nivel de burbuja digital y medidor de ángulos / pendientes
 * Archivo: css/style.css
 * Estándar canónico: Inter, Outfit, JetBrains Mono, soporte [data-theme="dark"],
 * layout adaptable y controles táctiles mínimos de 40 px.
 */

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

  /* Paleta cromática - Modo claro */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --accent-primary: #16a34a;
  --accent-primary-hover: #15803d;
  --accent-primary-bg: #dcfce7;
  --accent-blue: #2563eb;
  --accent-blue-hover: #1d4ed8;

  --color-level-safe: #22c55e;
  --color-level-glow: rgba(34, 197, 94, 0.4);
  --color-warn: #eab308;
  --color-danger: #ef4444;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #151d2c;
  --bg-card-subtle: #1e293b;
  --bg-input: #1a2436;
  --border-color: #243046;
  --border-strong: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-light: #64748b;

  --accent-primary: #22c55e;
  --accent-primary-hover: #4ade80;
  --accent-primary-bg: rgba(34, 197, 94, 0.15);
  --accent-blue: #3b82f6;
  --accent-blue-hover: #60a5fa;

  --color-level-safe: #22c55e;
  --color-level-glow: rgba(34, 197, 94, 0.55);
  --color-warn: #facc15;
  --color-danger: #f87171;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

*, *::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);
  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);
  margin-top: 0;
  color: var(--text-main);
}

button, input, select, textarea {
  font-family: inherit;
}

/* Layout principal de herramienta */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

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

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

/* Tarjeta principal de la herramienta */
.card-main {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
}

@media (max-width: 640px) {
  .card-main {
    padding: 1rem;
    border-radius: var(--radius-md);
  }
}

/* Banner de solicitud de permiso en iOS */
.permission-banner {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(34, 197, 94, 0.12));
  border: 1px solid var(--accent-blue);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.banner-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 240px;
}

.banner-icon {
  color: var(--accent-blue);
  flex-shrink: 0;
}

.banner-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
}

.banner-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.btn-permission {
  min-height: 40px;
  padding: 0.5rem 1.25rem;
  background-color: var(--accent-blue);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-permission:hover {
  background-color: var(--accent-blue-hover);
}

/* Selector de modos de visualización (Segmented control) */
.view-mode-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  background-color: var(--bg-card-subtle);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  border: 1px solid var(--border-color);
}

@media (max-width: 640px) {
  .view-mode-selector {
    grid-template-columns: repeat(2, 1fr);
  }
}

.btn-view-mode {
  min-height: 40px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.5rem 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
}

.btn-view-mode:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .btn-view-mode:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.btn-view-mode.active {
  background-color: var(--bg-card);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.btn-view-mode.auto-detected {
  border-bottom: 2px solid var(--color-level-safe);
}

/* Contenedor central del nivel y canvas */
.level-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
  position: relative;
}

.canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: var(--radius-lg);
  background: radial-gradient(circle, var(--bg-card-subtle) 0%, var(--bg-card) 70%);
  border: 1px solid var(--border-color);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

#level-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  touch-action: none;
}

/* Insignia de estado de nivelación */
.status-pill-container {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.25s ease;
}

.status-pill-success {
  background-color: var(--accent-primary-bg);
  color: var(--color-level-safe);
  border: 1px solid var(--color-level-safe);
  box-shadow: 0 0 12px var(--color-level-glow);
}

.status-pill-warning {
  background-color: rgba(234, 179, 8, 0.15);
  color: var(--color-warn);
  border: 1px solid var(--color-warn);
}

.status-pill-normal {
  background-color: var(--bg-card-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
}

/* Panel de métricas KPI */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 640px) {
  .metrics-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

.metric-card {
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  transition: transform 0.15s ease;
}

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

.metric-value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.metric-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Barra de controles primarios (Tara, Hold, Sonido, Háptico) */
.controls-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.btn-control {
  min-height: 44px;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-card-subtle);
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
  flex: 1 1 160px;
}

.btn-control:hover {
  background-color: var(--border-color);
}

.btn-control.active {
  background-color: var(--accent-primary-bg);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.btn-control-danger {
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* Fila de configuración de tolerancia y presets */
.settings-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

@media (max-width: 640px) {
  .settings-row {
    grid-template-columns: 1fr;
  }
}

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

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

.form-select {
  width: 100%;
  min-height: 42px;
  padding: 0.5rem 2.25rem 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-size: 0.9rem;
  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='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  cursor: pointer;
}

.form-select:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.form-select option {
  background-color: var(--bg-card);
  color: var(--text-main);
  padding: 0.5rem;
}

/* Panel interactivo de simulación manual para PC */
.simulation-section {
  background-color: var(--bg-card-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-top: 1.5rem;
}

.simulation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.simulation-title {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.simulation-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.75rem;
}

@media (max-width: 640px) {
  .simulation-controls-grid {
    grid-template-columns: 1fr;
  }
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.slider-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.slider-val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-main);
}

.range-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background-color: var(--border-color);
  outline: none;
  cursor: pointer;
}

.sim-presets-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn-sim-preset {
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-sim-preset:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

/* Botones de acción secundaria y ayuda */
.quick-help-row {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

.btn-text-link {
  background: none;
  border: none;
  color: var(--accent-blue);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text-link:hover {
  color: var(--accent-blue-hover);
}

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

.modal-overlay.modal-visible {
  display: flex;
}

.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  position: relative;
}

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

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

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

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

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

.modal-body h4 {
  font-size: 1rem;
  margin-top: 1rem;
  margin-bottom: 0.35rem;
}

.modal-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.85rem;
}

.modal-table th,
.modal-table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  text-align: left;
}

.modal-table th {
  background-color: var(--bg-card-subtle);
  font-weight: 600;
}

.modal-table tr:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .modal-table tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.02);
}

/* Sección de contenido SEO y Guía Técnica */
.seo-guide-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem 1.75rem;
  margin-top: 2.5rem;
  box-shadow: var(--shadow-sm);
}

@media (max-width: 640px) {
  .seo-guide-section {
    padding: 1.25rem 1rem;
  }
}

.seo-guide-title {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

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

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0;
}

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

.guide-card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.guide-card p {
  font-size: 0.88rem;
  margin: 0;
}

/* Preguntas frecuentes (Acordeones FAQ) */
.faq-accordion {
  margin-top: 1.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.faq-item {
  border-bottom: 1px solid var(--border-color);
}

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

.faq-question {
  width: 100%;
  min-height: 48px;
  background-color: var(--bg-card);
  border: none;
  text-align: left;
  padding: 0.9rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  list-style: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-chevron {
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

details[open] .faq-chevron {
  transform: rotate(180deg);
}

.faq-question:hover {
  background-color: var(--bg-card-subtle);
}

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