:root,
[data-theme="dark"] {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-page: #0b0f17;
  --poly-surface: #131b2e;
  --poly-subtle: #1e293b;
  --poly-screen: #060911;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #1e293b;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --truth: #10b981;
  --truth-bg: rgba(16, 185, 129, 0.14);
  --lie: #ef4444;
  --lie-bg: rgba(239, 68, 68, 0.14);
  --doubt: #f59e0b;
  --doubt-bg: rgba(245, 158, 11, 0.14);
  --shadow-card: 0 8px 28px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --poly-surface: #ffffff;
  --poly-subtle: #f1f5f9;
  --poly-screen: #0b1120;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border-color: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --truth: #059669;
  --truth-bg: rgba(5, 150, 105, 0.12);
  --lie: #dc2626;
  --lie-bg: rgba(220, 38, 38, 0.12);
  --doubt: #d97706;
  --doubt-bg: rgba(217, 119, 6, 0.12);
  --shadow-card: 0 4px 20px rgba(15, 23, 42, 0.06);
}

/* Blindaje defensivo de cabecera institucional */
[data-theme="dark"] .app-header {
  background: #131b2e !important;
  border-bottom: 1px solid #1e293b !important;
}
[data-theme="dark"] .brand-title {
  color: #f8fafc !important;
}
[data-theme="light"] .app-header {
  background: #ffffff !important;
  border-bottom: 1px solid #cbd5e1 !important;
}
[data-theme="light"] .brand-title {
  color: #0f172a !important;
}

body {
  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;
  margin: 0;
}

h1, h2, h3, h4, h5, h6,
.brand-title,
.verdict-title {
  font-family: var(--font-heading);
}

.mono,
code,
kbd {
  font-family: var(--font-mono);
}

.tool-layout {
  max-width: 1200px;
  width: 100%;
  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%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* KPIs de sesión */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.kpi-box {
  background: var(--poly-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

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

.kpi-val {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
}

.kpi-truth .kpi-val { color: var(--truth); }
.kpi-lie .kpi-val { color: var(--lie); }

/* Tarjetas principales */
.polygraph-card,
.seo-card {
  background: var(--poly-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

.polygraph-top-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.mode-pills {
  display: inline-flex;
  background: var(--poly-subtle);
  padding: 4px;
  border-radius: 10px;
  gap: 4px;
}

.mode-pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  min-height: 40px;
  transition: background-color 0.2s, color 0.2s;
}

.mode-pill.active {
  background: var(--poly-surface);
  color: var(--text-main);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16);
}

.top-actions-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.btn-calibrate {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 40px;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--poly-subtle);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

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

.btn-calibrate.calibrated {
  border-color: var(--truth);
  color: var(--truth);
}

.cal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.btn-calibrate.calibrated .cal-dot {
  background: var(--truth);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--poly-subtle);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  min-height: 40px;
  box-sizing: border-box;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--truth);
}

.status-badge.scanning .status-dot {
  background: var(--doubt);
  animation: pulseDot 0.7s infinite alternate;
}

.status-badge.alert .status-dot {
  background: var(--lie);
}

@keyframes pulseDot {
  from { opacity: 0.4; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1.25); }
}

/* Preguntas y categorías */
.question-box {
  margin-bottom: 1.25rem;
}

.question-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.55rem;
}

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

.category-select {
  min-height: 40px;
  max-width: 240px;
  width: 100%;
  padding: 0.45rem 40px 0.45rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  font-family: var(--font-main);
  font-size: 0.86rem;
  font-weight: 600;
  color-scheme: dark light;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
}

[data-theme="dark"] .category-select,
[data-theme="dark"] .category-select option {
  background-color: #1e293b;
  color: #f1f5f9;
}
[data-theme="dark"] .category-select {
  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.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="light"] .category-select,
[data-theme="light"] .category-select option {
  background-color: #f8fafc;
  color: #0f172a;
}
[data-theme="light"] .category-select {
  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='%23475569' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

.question-input-row {
  display: flex;
  gap: 0.65rem;
}

.question-input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  min-height: 44px;
  padding: 0.6rem 0.95rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.95rem;
}

.question-input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.btn-secondary {
  min-height: 44px;
  padding: 0.55rem 1.05rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--poly-subtle);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.2s, border-color 0.2s;
}

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

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.quick-chip {
  border: 1px solid var(--border-color);
  background: var(--poly-subtle);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.quick-chip:hover {
  color: var(--text-main);
  border-color: var(--accent);
}

/* Pantalla de polígrafo 3 canales */
.polygraph-screen {
  background: var(--poly-screen);
  border-radius: 14px;
  border: 1px solid #1e293b;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.screen-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.55rem 1rem;
  background: rgba(15, 23, 42, 0.85);
  border-bottom: 1px solid #1e293b;
  font-size: 0.76rem;
  font-weight: 600;
  color: #cbd5e1;
}

.screen-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.leg-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.leg-cardio { background: #10b981; }
.leg-voice { background: #38bdf8; }
.leg-gsr { background: #f43f5e; }

#polygraph-canvas {
  display: block;
  width: 100%;
  height: 220px;
}

.polygraph-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid #1e293b;
  background: rgba(15, 23, 42, 0.85);
}

.metric-item {
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  border-right: 1px solid #1e293b;
}

.metric-item:last-child {
  border-right: none;
}

.metric-label {
  font-size: 0.75rem;
  color: #94a3b8;
  user-select: none;
}

.metric-value {
  font-size: 1rem;
  font-weight: 700;
  color: #f1f5f9;
}

/* Zona de escaneo y veredicto */
.scanner-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

.scanner-pad-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.scanner-pad {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.75rem 1rem;
  border-radius: 14px;
  border: 2px dashed var(--border-color);
  background: var(--poly-subtle);
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  min-height: 205px;
  transition: border-color 0.2s, background-color 0.2s, transform 0.15s;
}

.scanner-pad:hover {
  border-color: var(--accent);
}

.scanner-pad.scanning {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  transform: scale(0.99);
}

.scanner-pad.scanning .fingerprint-icon {
  color: var(--accent);
  animation: pulseIcon 0.85s infinite alternate;
}

@keyframes pulseIcon {
  from { transform: scale(0.95); opacity: 0.8; }
  to { transform: scale(1.07); opacity: 1; }
}

.scanner-pad-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}

.scanner-pad-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.scan-progress-track {
  width: 100%;
  height: 8px;
  background: var(--poly-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.scan-progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.08s linear;
}

/* Panel de veredicto con lámparas */
.verdict-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1.5rem;
  border-radius: 14px;
  background: var(--poly-subtle);
  border: 1px solid var(--border-color);
  gap: 0.65rem;
}

.verdict-lights {
  display: flex;
  gap: 0.55rem;
  margin-bottom: 0.2rem;
}

.lamp {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.28);
  transition: background-color 0.2s, box-shadow 0.2s;
}

.verdict-panel.is-truth {
  background: var(--truth-bg);
  border-color: var(--truth);
}
.verdict-panel.is-truth .lamp-truth {
  background: var(--truth);
  box-shadow: 0 0 12px var(--truth);
}

.verdict-panel.is-lie {
  background: var(--lie-bg);
  border-color: var(--lie);
}
.verdict-panel.is-lie .lamp-lie {
  background: var(--lie);
  box-shadow: 0 0 12px var(--lie);
}

.verdict-panel.is-doubt {
  background: var(--doubt-bg);
  border-color: var(--doubt);
}
.verdict-panel.is-doubt .lamp-doubt {
  background: var(--doubt);
  box-shadow: 0 0 12px var(--doubt);
}

.verdict-badge {
  align-self: flex-start;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: var(--poly-surface);
  color: var(--text-muted);
}

.verdict-panel.is-truth .verdict-badge { color: var(--truth); }
.verdict-panel.is-lie .verdict-badge { color: var(--lie); }
.verdict-panel.is-doubt .verdict-badge { color: var(--doubt); }

.verdict-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
}

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

.verdict-actions {
  margin-top: 0.4rem;
}

/* Historial */
.history-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
}

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

.history-header h3 {
  margin: 0;
  font-size: 1rem;
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  min-height: 40px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  background: var(--poly-subtle);
  font-size: 0.9rem;
}

.history-tag {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  white-space: nowrap;
}

.history-tag.truth { background: var(--truth-bg); color: var(--truth); }
.history-tag.lie { background: var(--lie-bg); color: var(--lie); }
.history-tag.doubt { background: var(--doubt-bg); color: var(--doubt); }

/* Bloque editorial SEO y FAQs */
.seo-card h2 {
  margin-top: 0;
  font-size: 1.28rem;
}

.seo-card h3 {
  font-size: 1.05rem;
  margin: 1.2rem 0 0.5rem;
}

.seo-card p,
.seo-list li {
  color: var(--text-muted);
  line-height: 1.65;
  font-size: 0.95rem;
}

.seo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.1rem 0;
}

.seo-block {
  background: var(--poly-subtle);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}

.seo-block h3 {
  margin-top: 0;
}

.seo-list {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.faq-item {
  border-top: 1px solid var(--border-color);
  padding: 0.9rem 0;
}

.faq-item:first-child {
  border-top: none;
  padding-top: 0.25rem;
}

.faq-item summary {
  font-weight: 600;
  cursor: pointer;
  line-height: 1.45;
}

.faq-item p {
  margin: 0.6rem 0 0;
  font-size: 0.93rem;
}

kbd {
  background: var(--poly-subtle);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-size: 0.85em;
}

@media (max-width: 768px) {
  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .scanner-grid,
  .seo-grid {
    grid-template-columns: 1fr;
  }

  .question-input-row {
    flex-direction: column;
  }

  .category-select {
    max-width: 100%;
  }

  .btn-secondary,
  .mode-pill,
  .btn-calibrate {
    width: 100%;
    justify-content: center;
  }

  .mode-pills {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .polygraph-metrics {
    grid-template-columns: 1fr;
  }

  .metric-item {
    border-right: none;
    border-bottom: 1px solid #1e293b;
  }

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