/* ==========================================================================
   Fijate Tools — Calculadora de Percentiles de Crecimiento OMS (0 a 5 años)
   Estilos Canónicos y Sistema de Diseño Pediátrico
   ========================================================================== */

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

  /* Tema Oscuro (Midnight Slate Pediátrico) */
  --bg-app: #0b0f17;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(31, 41, 55, 0.95);
  --bg-input: #111827;
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: #10b981;
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --primary: #10b981;
  --primary-color: #10b981;
  --primary-light: rgba(16, 185, 129, 0.15);
  --primary-hover: #059669;
  --bg-card-header: #19243d;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --accent-blue: #38bdf8;
  --accent-pink: #f472b6;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;

  --chart-grid: rgba(255, 255, 255, 0.08);
  --chart-text: #9ca3af;
  --chart-p50: #10b981;
  --chart-p15-p85: #f59e0b;
  --chart-p3-p97: #f87171;
  --chart-bg: rgba(15, 23, 42, 0.6);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-header: #f1f5f9;
  --bg-card-hover: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #059669;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --primary: #059669;
  --primary-color: #059669;
  --primary-light: #ecfdf5;
  --primary-hover: #047857;
  --primary-glow: rgba(5, 150, 105, 0.2);
  --accent-blue: #0284c7;
  --accent-pink: #db2777;
  --accent-amber: #d97706;
  --accent-red: #dc2626;

  --chart-grid: #e2e8f0;
  --chart-text: #64748b;
  --chart-p50: #059669;
  --chart-p15-p85: #d97706;
  --chart-p3-p97: #dc2626;
  --chart-bg: #f8fafc;

  color-scheme: light;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* Layout Principal con Sidebar */
.main-wrapper {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

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

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

.tool-ad-sidebar {
  width: 300px;
  flex-shrink: 0;
  position: sticky;
  top: 1.5rem;
  display: none;
}

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

/* Cabecera / Hero */
.tool-hero {
  margin-bottom: 2rem;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 999px;
  font-size: 0.825rem;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.hero-title {
  font-family: var(--font-heading);
  font-size: 2.15rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin-bottom: 0.6rem;
  color: var(--text-main);
  line-height: 1.25;
}

.hero-desc {
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 850px;
  line-height: 1.65;
}

/* Rejilla de Trabajo: Formulario + Gráfico */
.workspace-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.75rem;
  margin-bottom: 2.5rem;
}

@media (min-width: 1024px) {
  .workspace-grid {
    grid-template-columns: 380px 1fr;
  }
}

/* Tarjeta Contenedora Glassmorphism */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.panel-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Selector Niño / Niña */
.sex-selector-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.btn-sex {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.6rem 1rem;
  background: var(--bg-input);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-sex:hover {
  border-color: var(--primary);
  color: var(--text-main);
}

.btn-sex.active[data-sex="boys"] {
  border-color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-blue);
}

.btn-sex.active[data-sex="girls"] {
  border-color: var(--accent-pink);
  background: rgba(244, 114, 182, 0.15);
  color: var(--accent-pink);
}

/* Modos de Entrada de Edad */
.mode-toggle-group {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.mode-radio-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
}

.mode-radio-label input {
  cursor: pointer;
  accent-color: var(--primary);
}

/* Campos de Formulario */
.form-group {
  margin-bottom: 1.15rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.45rem;
}

.form-row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.input-wrapper-unit {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-wrapper-unit:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-wrapper-unit input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  min-height: 42px;
  padding: 0.6rem 0.85rem;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 1rem;
  outline: none;
}

.input-unit-suffix {
  padding: 0 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  border-left: 1px solid var(--border-color);
  min-height: 42px;
  display: flex;
  align-items: center;
}

.input-standard {
  width: 100%;
  min-height: 42px;
  padding: 0.6rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-standard:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Prematuridad Switch */
.switch-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 1.15rem;
}

.switch-label-group {
  display: flex;
  flex-direction: column;
}

.switch-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.switch-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.premature-notice-box {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--accent-amber);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

/* Pestañas del Gráfico */
.chart-controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.chart-tabs-group {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  max-width: 100%;
  padding-bottom: 2px;
}

.tab-chart-indicator {
  padding: 0.45rem 0.95rem;
  min-height: 38px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.tab-chart-indicator:hover {
  color: var(--text-main);
  border-color: var(--primary);
}

.tab-chart-indicator.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.chart-range-select {
  min-height: 38px;
  padding: 0.35rem 2.2rem 0.35rem 0.75rem;
  background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239ca3af' viewBox='0 0 16 16'%3E%3Cpath d='M8 11.5l-5-5h10l-5 5z'/%3E%3C/svg%3E") no-repeat right 0.75rem center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

/* Gráfico SVG */
.chart-svg-wrapper {
  width: 100%;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--chart-bg);
  border: 1px solid var(--border-color);
}

.percentiles-svg-chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart-plot-bg {
  fill: transparent;
}

.chart-grid-line {
  stroke: var(--chart-grid);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

.chart-axis-label {
  fill: var(--chart-text);
  font-family: var(--font-mono);
  font-size: 11px;
}

.chart-axis-title {
  fill: var(--chart-text);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 600;
}

.chart-main-title {
  fill: var(--text-main);
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
}

.chart-curve {
  fill: none;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-curve-p3,
.chart-curve-p97 {
  stroke: var(--chart-p3-p97);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.chart-curve-p15,
.chart-curve-p85 {
  stroke: var(--chart-p15-p85);
  stroke-width: 1.75;
}

.chart-curve-p50 {
  stroke: var(--chart-p50);
  stroke-width: 3;
}

.chart-tag-text {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

.tag-p97, .tag-p3 { fill: var(--chart-p3-p97); }
.tag-p85, .tag-p15 { fill: var(--chart-p15-p85); }
.tag-p50 { fill: var(--chart-p50); }

/* Marcador del Bebé */
.chart-marker-pulse {
  fill: rgba(16, 185, 129, 0.3);
  animation: markerPulse 2s infinite ease-out;
}

@keyframes markerPulse {
  0% { r: 7; opacity: 1; }
  100% { r: 20; opacity: 0; }
}

.chart-marker-dot {
  fill: var(--primary);
  stroke: #ffffff;
  stroke-width: 2.5;
}

.chart-tooltip-bg {
  fill: rgba(15, 23, 42, 0.95);
  stroke: var(--primary);
  stroke-width: 1.5;
}

.chart-tooltip-text {
  fill: #ffffff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

.chart-history-line {
  fill: none;
  stroke: #38bdf8;
  stroke-width: 2.5;
  stroke-dasharray: 5 4;
}

.chart-history-point {
  fill: #38bdf8;
  stroke: #ffffff;
  stroke-width: 1.5;
}

/* Cockpit de Resultados: Tarjetas KPI */
.kpi-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.kpi-metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.kpi-metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(16, 185, 129, 0.4);
}

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

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

.kpi-main-val {
  font-family: var(--font-mono);
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  margin-bottom: 0.35rem;
}

.kpi-zscore {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.kpi-status-badge {
  display: inline-block;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: auto;
  align-self: flex-start;
}

.kpi-status-badge.normal {
  background: rgba(16, 185, 129, 0.15);
  color: var(--primary);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.kpi-status-badge.mild-low,
.kpi-status-badge.mild-high {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.kpi-status-badge.extreme-low,
.kpi-status-badge.extreme-high {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Ficha Médica y Orientación Pediátrica */
.clinical-guidance-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2.5rem;
}

.clinical-guidance-card h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

.clinical-guidance-content {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.clinical-guidance-content p {
  margin-bottom: 0.5rem;
}

.clinical-guidance-content p:last-child {
  margin-bottom: 0;
}

/* Tabla Histórica de Revisiones */
.history-section {
  margin-bottom: 2.5rem;
}

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

.table-responsive-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  text-align: left;
}

.data-table th {
  background: rgba(255, 255, 255, 0.03);
  padding: 0.85rem 1rem;
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-muted);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.btn-action-delete {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-action-delete:hover {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.1);
}

/* Botones Principales */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 42px;
  padding: 0.65rem 1.25rem;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  color: #ffffff;
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 14px var(--primary-glow);
}

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

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--primary);
}

/* Acordeón FAQ y Guía SEO */
.seo-guide-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

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

.faq-accordion-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
  overflow: hidden;
  background: var(--bg-card);
}

.faq-accordion-header {
  padding: 1.15rem 1.25rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.faq-accordion-content {
  padding: 0 1.25rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.65;
}

/* Modales Accesibles */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  padding: 1.5rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  transform: translateY(12px);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

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

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

.modal-btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* Estilos de Impresión (@media print) */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-header,
  .fijate-footer,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .chart-controls-bar,
  .btn-print-wrapper,
  .btn-action-delete,
  .modal-overlay,
  .seo-guide-section,
  #btn-save-record {
    display: none !important;
  }

  .main-wrapper {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .workspace-grid {
    display: block !important;
  }

  .glass-panel {
    border: 1px solid #ccc !important;
    background: transparent !important;
    box-shadow: none !important;
    page-break-inside: avoid;
    margin-bottom: 1.5rem;
  }

  .chart-svg-wrapper {
    background: #ffffff !important;
    border: 1px solid #ccc !important;
  }

  .chart-grid-line {
    stroke: #e2e8f0 !important;
  }

  .chart-axis-label,
  .chart-axis-title,
  .chart-main-title {
    fill: #000000 !important;
  }
}
