/**
 * Fijate Tools - Diagnóstico Pericial de Humedades, Moho y Condensación
 * Estilos corporativos Midnight Slate, responsive y temas claro/oscuro
 */

: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;

  /* Paleta Claro */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --accent-primary: #2563eb;
  --accent-hover: #1d4ed8;

  /* RAG Semáforo */
  --rag-safe-bg: #ecfdf5;
  --rag-safe-border: #a7f3d0;
  --rag-safe-text: #065f46;
  --rag-caution-bg: #fffbeb;
  --rag-caution-border: #fde68a;
  --rag-caution-text: #92400e;
  --rag-warning-bg: #fff7ed;
  --rag-warning-border: #fed7aa;
  --rag-warning-text: #9a3412;
  --rag-danger-bg: #fef2f2;
  --rag-danger-border: #fecaca;
  --rag-danger-text: #991b1b;

  --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;
}

[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #131b2b;
  --bg-card-subtle: #1a2438;
  --bg-input: #1a2438;
  --border-color: #24324a;
  --border-focus: #60a5fa;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-primary: #3b82f6;
  --accent-hover: #60a5fa;

  --rag-safe-bg: rgba(16, 185, 129, 0.12);
  --rag-safe-border: rgba(16, 185, 129, 0.3);
  --rag-safe-text: #34d399;
  --rag-caution-bg: rgba(245, 158, 11, 0.12);
  --rag-caution-border: rgba(245, 158, 11, 0.3);
  --rag-caution-text: #fbbf24;
  --rag-warning-bg: rgba(249, 115, 22, 0.12);
  --rag-warning-border: rgba(249, 115, 22, 0.3);
  --rag-warning-text: #fb923c;
  --rag-danger-bg: rgba(239, 68, 68, 0.14);
  --rag-danger-border: rgba(239, 68, 68, 0.35);
  --rag-danger-text: #f87171;

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

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

body {
  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;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title,
.hero-title,
.triaje-q-title,
.pericial-header h2 {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
}

.mono,
.kpi-value,
.triaje-pct-val,
.vent-timer-digits,
code {
  font-family: var(--font-mono);
}

/* Layout con sidebar */
.tool-layout {
  max-width: 1240px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
  width: 100%;
}

.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%;
}

/* Hero introductorio */
.tool-hero {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.tool-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent-primary);
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tool-hero h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.tool-hero p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Sistema de navegación por pestañas */
.tabs-navigation-wrapper {
  overflow-x: auto;
  margin-bottom: 1.5rem;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.tabs-navigation {
  display: flex;
  gap: 0.5rem;
  min-width: max-content;
  background: var(--bg-card);
  padding: 0.4rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.tab-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.1rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 40px;
  white-space: nowrap;
}

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

.tab-nav-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.tab-panel {
  display: none;
}

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

/* Tarjetas y módulos generales */
.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

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

.card-header-flex h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

/* Grid de controles psicrométricos */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-label-flex {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

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

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: var(--shadow-sm);
}

.select-custom {
  width: 100%;
  min-height: 42px;
  padding: 0.55rem 2.5rem 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.9rem;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' 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;
  background-size: 16px;
  cursor: pointer;
}

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

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

/* Tarjetas KPI de resultados */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
}

.kpi-card.highlight {
  border-color: var(--accent-primary);
  background: rgba(37, 99, 235, 0.05);
}

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

.kpi-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

/* Alerta de riesgo RAG */
.rag-box {
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  border: 1px solid;
}

.badge-rag {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}

.badge-safe {
  background: var(--rag-safe-bg);
  border: 1px solid var(--rag-safe-border);
  color: var(--rag-safe-text);
}

.badge-caution {
  background: var(--rag-caution-bg);
  border: 1px solid var(--rag-caution-border);
  color: var(--rag-caution-text);
}

.badge-warning {
  background: var(--rag-warning-bg);
  border: 1px solid var(--rag-warning-border);
  color: var(--rag-warning-text);
}

.badge-danger {
  background: var(--rag-danger-bg);
  border: 1px solid var(--rag-danger-border);
  color: var(--rag-danger-text);
}

.rag-box h4 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.rag-box p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Canvas psicrométrico */
.canvas-wrapper {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  overflow-x: auto;
  text-align: center;
}

.canvas-wrapper canvas {
  max-width: 100%;
  height: auto;
  display: inline-block;
}

.canvas-legend {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  margin-top: 0.75rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* Módulo de triaje interactivo */
.triaje-header-progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.progress-fill {
  height: 100%;
  background: var(--accent-primary);
  transition: width 0.3s ease;
}

.triaje-q-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.triaje-q-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.triaje-options-grid {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.triaje-option-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.15rem;
  background: var(--bg-card-subtle);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 48px;
}

.triaje-option-card:hover {
  border-color: var(--accent-primary);
  background: rgba(37, 99, 235, 0.04);
}

.triaje-option-card.selected {
  border-color: var(--accent-primary);
  background: rgba(37, 99, 235, 0.08);
}

.triaje-radio-input {
  display: none;
}

.triaje-option-label {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-main);
}

.triaje-check-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  flex-shrink: 0;
}

.triaje-option-card.selected .triaje-check-icon {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.triaje-nav-actions {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 42px;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-card-subtle);
}

.btn-secondary:disabled, .btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Resultados del triaje */
.triaje-results-box {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.probability-bars-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.prob-item {
  background: var(--bg-card-subtle);
  padding: 0.85rem;
  border-radius: var(--radius-sm);
}

.prob-label-flex {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.prob-track {
  width: 100%;
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.prob-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: 4px;
}

.dominant-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.dominant-card h4 {
  font-size: 1.25rem;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.dominant-certainty {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-primary);
  margin-bottom: 0.85rem;
}

.dominant-card p {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  line-height: 1.6;
}

/* Caja de responsabilidades y desmitificador */
.legal-box, .bleach-box {
  border-radius: var(--radius-md);
  padding: 1.2rem;
  margin-bottom: 1.25rem;
}

.legal-box {
  background: rgba(37, 99, 235, 0.06);
  border-left: 4px solid var(--accent-primary);
}

.bleach-box {
  background: var(--rag-danger-bg);
  border-left: 4px solid var(--rag-danger-text);
}

.legal-box h5, .bleach-box h5 {
  font-size: 0.98rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.legal-box p, .bleach-box p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.solutions-list {
  padding-left: 1.25rem;
  font-size: 0.92rem;
  color: var(--text-main);
  line-height: 1.6;
}

.solutions-list li {
  margin-bottom: 0.5rem;
}

/* Ventilación de choque */
.vent-timer-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.75rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.vent-timer-digits {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--accent-primary);
  line-height: 1;
  margin-bottom: 0.65rem;
}

.vent-timer-status {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.vent-advice-alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-top: 1rem;
}

.vent-advice-alert.is-info {
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.2);
  color: var(--text-main);
}

.vent-advice-alert.is-danger {
  background: var(--rag-danger-bg);
  border: 1px solid var(--rag-danger-border);
  color: var(--rag-danger-text);
}

/* Deshumidificador */
.tech-presc-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-top: 1rem;
}

.tech-presc-card h4 {
  font-size: 1.05rem;
  color: var(--accent-primary);
  margin-bottom: 0.4rem;
}

.tech-presc-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Generador de informe pericial */
.report-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.pericial-doc {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem;
  color: var(--text-main);
}

.pericial-header {
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
}

.pericial-stamp {
  display: inline-block;
  background: #0f172a;
  color: #ffffff;
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.pericial-header h2 {
  font-size: 1.4rem;
  margin-bottom: 0.35rem;
}

.pericial-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pericial-section {
  margin-bottom: 1.75rem;
}

.pericial-section h3 {
  font-size: 1.05rem;
  margin-bottom: 0.65rem;
  color: var(--accent-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.35rem;
}

.pericial-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-bottom: 0.85rem;
}

.pericial-table td {
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border-color);
}

.pericial-verdict {
  font-size: 0.9rem;
  background: var(--bg-card-subtle);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
}

.pericial-legal-box {
  background: var(--bg-card-subtle);
  border-left: 3px solid var(--accent-primary);
  padding: 0.75rem 1rem;
  margin-top: 0.65rem;
  font-size: 0.88rem;
}

.pericial-plan-list {
  padding-left: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

.pericial-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* Modal accesible */
.app-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.app-modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  max-width: 500px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  z-index: 10;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

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

.modal-footer {
  display: flex;
  justify-content: flex-end;
}

/* Estilos de impresión */
@media print {
  .app-header,
  .fijate-footer,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .tabs-navigation-wrapper,
  .report-actions,
  .tool-hero,
  .tab-panel:not(#tab-report) {
    display: none !important;
  }

  body, .tool-layout, .tool-with-sidebar, .tool-main-content {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .pericial-doc {
    border: none !important;
    padding: 0 !important;
  }
}

/* Responsividad móvil */
@media (max-width: 768px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.75rem;
  }

  .tool-hero {
    padding: 1.25rem;
  }

  .tool-card {
    padding: 1.15rem;
  }

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

  .vent-timer-digits {
    font-size: 2.75rem;
  }

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

  .triaje-nav-actions {
    flex-direction: column;
  }
}
