/* ==========================================================================
   Monitor de Peak Flow y plan de acción de asma (GEMA / GINA / ERS)
   Estilos corporativos fijate.com (Dark / Light Theme + Print Mode)
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Colores del semáforo respiratorio GEMA */
  --color-green: #10b981;
  --color-green-soft: rgba(16, 185, 129, 0.15);
  --color-green-border: rgba(16, 185, 129, 0.35);

  --color-yellow: #f59e0b;
  --color-yellow-soft: rgba(245, 158, 11, 0.15);
  --color-yellow-border: rgba(245, 158, 11, 0.35);

  --color-red: #ef4444;
  --color-red-soft: rgba(239, 68, 68, 0.15);
  --color-red-border: rgba(239, 68, 68, 0.35);

  --color-blue: #0284c7;
  --color-blue-soft: rgba(2, 132, 199, 0.15);
}

/* Tema Oscuro por defecto en :root */
:root {
  --bg-page: #0b0f19;
  --bg-primary: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-alt: #1a243d;
  --bg-input: #0e1526;
  --border-color: #23304d;
  --border-focus: #38bdf8;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --btn-primary-bg: #0284c7;
  --btn-primary-hover: #0369a1;
  --btn-secondary-bg: #1e293b;
  --btn-secondary-hover: #334155;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
}

/* Tema Claro */
[data-theme="light"], body.light-theme {
  --bg-page: #f8fafc;
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-alt: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #0284c7;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --btn-primary-bg: #0284c7;
  --btn-primary-hover: #0369a1;
  --btn-secondary-bg: #f1f5f9;
  --btn-secondary-hover: #e2e8f0;
  --shadow-card: 0 4px 15px -2px rgba(0, 0, 0, 0.05);
}

/* Reset y base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  overflow-x: clip;
}

h1, h2, h3, h4, h5 {
  font-family: var(--font-heading);
  color: var(--text-primary);
  font-weight: 700;
  letter-spacing: -0.01em;
}

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

.text-secondary {
  color: var(--text-secondary);
}

.text-sm {
  font-size: 0.875rem;
}

.text-xs {
  font-size: 0.75rem;
}

/* Contención y layout */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
}

.tool-with-sidebar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  width: 100%;
}

@media (min-width: 1536px) {
  .tool-with-sidebar {
    grid-template-columns: 1fr 300px;
  }
}

.tool-main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

/* Tarjetas */
.card-main {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

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

/* Intro */
.card-intro h2 {
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
}

.intro-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--color-blue-soft);
  color: #38bdf8;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  margin-bottom: 0.75rem;
}

/* Panel de referencia basal */
.baseline-current-badge {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.baseline-current-badge strong {
  font-family: var(--font-mono);
  color: #38bdf8;
  font-size: 1.05rem;
}

.baseline-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .baseline-options-grid {
    grid-template-columns: 1fr 1.25fr;
  }
}

.baseline-col {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.calc-params-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.btn-apply-calc {
  width: 100%;
  margin-top: 0.5rem;
}

/* Formulario */
.flow-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .flow-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .flow-form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

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

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

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

.field-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.4rem;
}

.form-input, .form-select {
  width: 100%;
  height: 42px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0 0.85rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-select {
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  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='%2394a3b8' 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;
  padding-right: 40px;
}

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

.form-input:focus, .form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.input-with-suffix {
  display: flex;
  align-items: center;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  height: 42px;
}

.input-with-suffix .form-input {
  border: none;
  height: 100%;
  border-radius: 0;
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
}

.input-with-suffix .suffix {
  padding: 0 0.85rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  background: var(--bg-card-alt);
  height: 100%;
  display: flex;
  align-items: center;
  border-left: 1px solid var(--border-color);
}

/* Tags de síntomas y rescate */
.flow-tags-group {
  margin-bottom: 1.25rem;
}

.tags-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.tag-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.tag-checkbox input[type="checkbox"] {
  accent-color: var(--color-blue);
  width: 15px;
  height: 15px;
}

.tag-checkbox:hover {
  border-color: var(--border-focus);
}

.tag-checkbox.highlight-rescue {
  border-color: rgba(245, 158, 11, 0.4);
  background: var(--color-yellow-soft);
  color: #fbbf24;
  font-weight: 600;
}

/* Botones */
.btn-primary, .btn-secondary, .btn-danger, .btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 42px;
  padding: 0 1.25rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
  text-decoration: none;
  border: none;
}

.btn-primary {
  background-color: var(--btn-primary-bg);
  color: #ffffff;
}

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

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

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

.btn-danger {
  background-color: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background-color: #ef4444;
  color: #ffffff;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  height: 32px;
  padding: 0 0.85rem;
  font-size: 0.8rem;
}

.btn-outline.active, .btn-outline:hover {
  border-color: var(--border-focus);
  color: #38bdf8;
  background: var(--color-blue-soft);
}

.btn-sm {
  height: 34px;
  padding: 0 0.85rem;
  font-size: 0.82rem;
}

.btn-submit-flow {
  width: 100%;
}

/* Tarjeta dinámica de evaluación de zona */
.card-zone-status {
  border-left: 6px solid var(--color-green);
  transition: all 0.3s ease;
}

.card-zone-status.zone-green {
  border-left-color: var(--color-green);
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(16, 185, 129, 0.06) 100%);
}

.card-zone-status.zone-yellow {
  border-left-color: var(--color-yellow);
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(245, 158, 11, 0.08) 100%);
}

.card-zone-status.zone-red {
  border-left-color: var(--color-red);
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(239, 68, 68, 0.09) 100%);
}

.zone-badge {
  display: inline-block;
  padding: 0.35rem 0.9rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.zone-badge.zone-green-badge {
  background: var(--color-green);
  color: #064e3b;
}

.zone-badge.zone-yellow-badge {
  background: var(--color-yellow);
  color: #451a03;
}

.zone-badge.zone-red-badge {
  background: var(--color-red);
  color: #ffffff;
  animation: pulse-red 1.8s infinite;
}

@keyframes pulse-red {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.zone-details-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .zone-details-grid {
    grid-template-columns: 1.2fr 1fr;
  }
}

.zone-result-big {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.zone-result-big #zone-res-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.zone-unit {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.zone-percent {
  font-size: 1.1rem;
  font-weight: 700;
  color: #38bdf8;
}

.zone-action-heading {
  font-size: 1.15rem;
  margin-bottom: 0.4rem;
}

.zone-action-text {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.zone-alert-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.15rem;
}

.zone-alert-box h5 {
  font-size: 0.92rem;
  margin-bottom: 0.65rem;
  color: var(--text-primary);
}

.zone-steps-list {
  padding-left: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* Semáforo apilado y estadísticas */
.traffic-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

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

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot-green { background: var(--color-green); }
.dot-yellow { background: var(--color-yellow); }
.dot-red { background: var(--color-red); }

.traffic-stacked-bar {
  display: flex;
  height: 24px;
  background-color: var(--bg-card-alt);
  border-radius: 9999px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.traffic-bar-seg {
  height: 100%;
  transition: width 0.4s ease;
}

.seg-green { background: var(--color-green); }
.seg-yellow { background: var(--color-yellow); }
.seg-red { background: var(--color-red); }

/* Métricas en cuadrícula */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (min-width: 768px) {
  .metrics-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.metric-card {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.metric-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.metric-val-unit {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}

.metric-val {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.metric-unit {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

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

/* Gráfico */
.chart-wrapper {
  position: relative;
  width: 100%;
  height: 340px;
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
}

#flowChart {
  display: block;
  width: 100%;
  height: 100%;
}

/* Tabla de historial */
.history-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

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

.data-table th {
  background-color: var(--bg-card-alt);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.badge-zone-mini {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-zone-green {
  background: var(--color-green-soft);
  color: var(--color-green);
  border: 1px solid var(--color-green-border);
}

.badge-zone-yellow {
  background: var(--color-yellow-soft);
  color: var(--color-yellow);
  border: 1px solid var(--color-yellow-border);
}

.badge-zone-red {
  background: var(--color-red-soft);
  color: var(--color-red);
  border: 1px solid var(--color-red-border);
}

.badge-rescue-mini {
  display: inline-block;
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 0.2rem;
}

.table-empty {
  text-align: center;
  padding: 2.5rem 1rem !important;
  color: var(--text-secondary);
}

/* Guía de técnica de soplido */
.guide-steps-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin: 1rem 0;
}

@media (min-width: 640px) {
  .guide-steps-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .guide-steps-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.guide-step {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.15rem;
  position: relative;
}

.guide-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-blue);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.65rem;
}

.guide-step h4 {
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}

.guide-step p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.guide-note {
  background: var(--color-blue-soft);
  border-left: 4px solid var(--border-focus);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-primary);
}

/* Modales */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 99999;
}

.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.75rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.modal-icon-warn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}

.modal-title {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Área de impresión para consulta médica */
.printable-report-area {
  display: none;
}

@media print {
  body {
    background-color: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt;
  }

  .app-header,
  .fijate-footer,
  .tools-ad-banner-section,
  .tool-ad-sidebar,
  .card-intro,
  .card-baseline,
  .card-entry,
  .card-zone-status,
  .card-summary-stats,
  .card-chart,
  .card-history,
  .card-guide,
  .modal-backdrop {
    display: none !important;
  }

  .printable-report-area {
    display: block !important;
    padding: 0.5cm;
  }

  .print-header {
    border-bottom: 2px solid #000000;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
  }

  .print-header h2 {
    font-size: 14pt;
    color: #000000;
  }

  .print-header p {
    font-size: 9pt;
    color: #444444;
  }

  .print-meta-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    font-size: 9pt;
    margin-bottom: 1rem;
    border-bottom: 1px solid #cccccc;
    padding-bottom: 0.5rem;
  }

  .print-summary-box {
    background: #f4f4f4;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 9pt;
    margin-bottom: 1rem;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8.5pt;
    margin-bottom: 2rem;
  }

  .print-table th, .print-table td {
    border: 1px solid #cccccc;
    padding: 4px 6px;
    text-align: left;
  }

  .print-table th {
    background-color: #eeeeee;
    font-weight: bold;
  }

  .print-footer-signature {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    margin-top: 3rem;
  }

  .sig-line {
    border-top: 1px solid #000000;
    padding-top: 0.5rem;
    text-align: center;
    font-size: 9pt;
  }
}
