/**
 * Estilos para Registro de Tensión Arterial y Semáforo HTA (fijate.com)
 * Sistema de diseño responsive, variables temáticas, accesibilidad y @media print
 */

:root {
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --bg-card-subtle: #182234;
  --bg-input: #0b1120;
  --border-color: #334155;
  --border-color-hover: #475569;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #ef4444;
  --accent-hover: #dc2626;
  --accent-glow: rgba(239, 68, 68, 0.2);
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-crisis: #991b1b;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
}

[data-theme="light"], body.light-theme {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --border-color-hover: #94a3b8;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent-primary: #e11d48;
  --accent-hover: #be123c;
  --accent-glow: rgba(225, 29, 72, 0.15);
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.08);
}

/* Reset básico y contención */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  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: 'Outfit', sans-serif;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-primary);
}

.mono-num {
  font-family: 'JetBrains Mono', monospace;
}

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

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

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

/* Tarjetas */
.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-card);
}

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

.card-title {
  font-size: 1.35rem;
  margin-bottom: 0.25rem;
}

.card-desc {
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-private {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Formularios adaptados a estándares */
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
}

.input-group label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.label-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  color: var(--text-muted);
}

.input-unit-wrap {
  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, box-shadow 0.2s;
}

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

.input-unit-wrap input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  height: 44px;
  padding: 0 0.85rem;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.15rem;
  font-weight: 700;
  outline: none;
}

.input-unit {
  padding: 0 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
  border-left: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.05);
  height: 44px;
  display: flex;
  align-items: center;
}

.form-input {
  width: 100%;
  height: 44px;
  padding: 0 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

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

.input-hint {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Selectores con estilo explícito y flecha SVG */
.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 40px 0 0.85rem;
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  outline: none;
  appearance: none;
  -webkit-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 14px center;
  background-size: 16px;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

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

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

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

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

/* Caja de diagnóstico en vivo */
.live-diagnosis-box {
  margin-top: 1.5rem;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.diagnosis-tag {
  padding: 0.35rem 0.9rem;
  border-radius: 9999px;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.diagnosis-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.metric-card {
  background: var(--bg-card);
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

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

.metric-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.45rem;
  font-weight: 800;
}

.metric-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.diagnosis-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Colores de clasificación médica */
.status-optima { background: rgba(16, 185, 129, 0.2); color: #10b981; border: 1px solid #10b981; }
.status-normal { background: rgba(34, 197, 94, 0.2); color: #22c55e; border: 1px solid #22c55e; }
.status-normal-alta { background: rgba(245, 158, 11, 0.2); color: #f59e0b; border: 1px solid #f59e0b; }
.status-hta1 { background: rgba(249, 115, 22, 0.2); color: #f97316; border: 1px solid #f97316; }
.status-hta2 { background: rgba(239, 68, 68, 0.2); color: #ef4444; border: 1px solid #ef4444; }
.status-hta3 { background: rgba(220, 38, 38, 0.25); color: #dc2626; border: 1px solid #dc2626; }
.status-crisis { background: rgba(153, 27, 27, 0.35); color: #ff6b6b; border: 1px solid #ef4444; }

/* Tabs de navegación */
.card-tabs-section {
  padding: 0;
  overflow: hidden;
}

.tabs-nav-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  padding: 0 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.tabs-nav {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.9rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

.tab-btn.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.tabs-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.btn-action-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

.btn-danger-soft:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--color-danger);
}

.tab-pane {
  display: none;
  padding: 1.5rem;
}

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

/* AMPA Metrics Grid */
.ampa-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.ampa-metric-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.ampa-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.ampa-big-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

.ampa-sub-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.ampa-tag {
  display: inline-block;
  align-self: flex-start;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.74rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
}

.ampa-note, .ampa-sub-hint {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Tablas Clínicas */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

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

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

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

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

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 2.5rem 1rem;
}

.btn-table-del {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.btn-table-del:hover {
  color: var(--color-danger);
  background: rgba(239, 68, 68, 0.15);
}

/* Gráfico Canvas */
.chart-container-box {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chart-header-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.chart-legend {
  display: flex;
  gap: 1.25rem;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

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

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.color-pas { background: #ef4444; }
.color-pad { background: #3b82f6; }
.color-pulso { background: #10b981; }

.chart-filters {
  display: flex;
  gap: 0.4rem;
}

.btn-filter {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-filter.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.canvas-responsive-wrapper {
  width: 100%;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  overflow: hidden;
}

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

.chart-footnote {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Guía de medición y tabla ESC */
.guide-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

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

.guide-icon {
  width: 28px;
  height: 28px;
  background: var(--accent-primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

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

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

.esc-title {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.esc-ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.esc-ref-table th, .esc-ref-table td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.esc-ref-table th {
  background: var(--bg-card-subtle);
  color: var(--text-secondary);
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.dot-optima { background: #10b981; }
.dot-normal { background: #22c55e; }
.dot-normal-alta { background: #f59e0b; }
.dot-hta1 { background: #f97316; }
.dot-hta2 { background: #ef4444; }
.dot-hta3 { background: #dc2626; }
.dot-crisis { background: #991b1b; }

/* FAQ */
.faq-section {
  margin-top: 1rem;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  padding: 0.85rem 1.15rem;
}

.faq-question {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}

.faq-answer {
  margin-top: 0.6rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Modales accesibles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

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

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-width: 500px;
  width: 100%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: modalScale 0.2s ease-out;
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-title {
  font-size: 1.15rem;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 1.25rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  background: var(--bg-card-subtle);
  border-top: 1px solid var(--border-color);
}

/* Área de informe para imprimir (oculta en pantalla) */
.report-clinical-header,
.report-footer-signatures {
  display: none;
}

/* Responsive Móvil */
@media (max-width: 768px) {
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .form-actions .btn {
    width: 100%;
  }
  .diagnosis-metrics {
    grid-template-columns: 1fr;
  }
  .ampa-summary-grid {
    grid-template-columns: 1fr 1fr;
  }
  .guide-grid {
    grid-template-columns: 1fr;
  }
  .tabs-nav-wrapper {
    flex-direction: column;
    align-items: stretch;
  }
  .tabs-actions {
    justify-content: space-between;
  }
  .tabs-actions .btn-action-sm {
    flex: 1;
    justify-content: center;
  }
}

/* @media print para informe médico oficial A4 */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt;
  }
  .app-header,
  .fijate-footer,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .form-tension,
  .tabs-nav-wrapper,
  .chart-header-controls,
  .card-header-flex .card-badges,
  .live-diagnosis-box,
  .faq-section,
  #tab-grafico,
  #tab-historial,
  #tab-guia,
  .btn-action-sm,
  .btn-table-del {
    display: none !important;
  }
  .tool-layout {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .card-main {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: transparent !important;
  }
  .tab-pane {
    display: block !important;
    padding: 0 !important;
  }
  .report-clinical-header {
    display: flex !important;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #000;
    padding-bottom: 12px;
    margin-bottom: 15px;
  }
  .report-doc-title h3 {
    font-size: 15pt;
    color: #000;
    margin-bottom: 3px;
  }
  .report-doc-title p {
    font-size: 9pt;
    color: #555;
  }
  .report-patient-meta {
    text-align: right;
    font-size: 9pt;
  }
  .ampa-summary-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 15px !important;
  }
  .ampa-metric-card {
    border: 1px solid #ccc !important;
    background: #fdfdfd !important;
    padding: 8px !important;
  }
  .ampa-big-val, .ampa-sub-val {
    color: #000 !important;
    font-size: 13pt !important;
  }
  .clinical-table {
    border: 1px solid #333 !important;
    font-size: 9pt !important;
  }
  .clinical-table th {
    background: #eaeaea !important;
    color: #000 !important;
    border: 1px solid #ccc !important;
    padding: 6px 8px !important;
  }
  .clinical-table td {
    border: 1px solid #ddd !important;
    padding: 5px 8px !important;
    color: #000 !important;
  }
  .report-footer-signatures {
    display: flex !important;
    justify-content: space-between;
    margin-top: 40px;
    gap: 30px;
  }
  .sig-box {
    flex: 1;
    font-size: 9pt;
  }
  .sig-line {
    border-bottom: 1px dashed #666;
    margin-top: 50px;
  }
}
