/* ==========================================================================
   ESTILOS - SISTEMA DE TRIAJE CLÍNICO (UPP - CICLO II)
   ========================================================================== */

:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --danger-dark: #b91c1c;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --info: #6366f1;
  --info-light: #e0e7ff;
  --bg-main: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.12);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

/* Contenedor general */
.app-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 60px 20px;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}

.app-header::after {
  content: "";
  position: absolute;
  top: -50%;
  right: -10%;
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, rgba(14, 165, 233, 0.15) 0%, rgba(255,255,255,0) 70%);
  pointer-events: none;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.academic-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.1);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 600;
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.server-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: 9999px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.server-badge.offline {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.3);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.header-title-area h1 {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title-area p {
  color: #94a3b8;
  font-size: 0.95rem;
  max-width: 850px;
}

/* Barra de presets / casos rápidos */
.presets-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.presets-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.presets-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-btn {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.preset-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.preset-btn.highlight {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border-color: #0284c7;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}

.preset-btn.highlight:hover {
  background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
  color: #ffffff;
}

/* Grid de pacientes */
.patients-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

@media (max-width: 860px) {
  .patients-grid {
    grid-template-columns: 1fr;
  }
}

.patient-card {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.25s, box-shadow 0.25s;
  position: relative;
}

.patient-card.patient-a {
  border-top: 5px solid #0284c7;
}

.patient-card.patient-b {
  border-top: 5px solid #8b5cf6;
}

.patient-card.winner {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2), var(--shadow-md);
}

.patient-card.waiting {
  border-color: var(--warning);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
}

.patient-pill {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.patient-a .patient-pill {
  background: var(--primary-light);
  color: var(--primary);
}

.patient-b .patient-pill {
  background: #ede9fe;
  color: #7c3aed;
}

.live-badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.badge-critico {
  background: var(--danger-light);
  color: var(--danger-dark);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-moderado {
  background: var(--warning-light);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Campos de formulario */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 6px;
}

.form-hint {
  font-size: 0.78rem;
  font-weight: normal;
  color: var(--text-muted);
}

.input-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1.5px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--text-main);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

/* Estilos de Error de Validación */
.input-control.is-invalid {
  border-color: #ef4444 !important;
  background-color: #fff5f5 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25) !important;
}

.input-error-msg {
  color: #b91c1c;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 6px;
  padding: 6px 10px;
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  animation: fadeIn 0.2s ease-in;
}

.banner-alerta-error {
  background: #fef2f2;
  border: 1.5px solid #ef4444;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 20px;
  color: #991b1b;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

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

.badge-invalido {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #f87171;
}

.badge-neutral {
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #cbd5e1;
}

.input-with-unit {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-unit .input-control {
  padding-right: 40px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.input-unit {
  position: absolute;
  right: 14px;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
  font-size: 0.95rem;
  user-select: none;
}

/* Switch de antecedentes */
.switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s;
}

.switch-container:hover {
  background: #f1f5f9;
}

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

.switch-title {
  font-size: 0.9rem;
  font-weight: 600;
}

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

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 34px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider {
  background-color: var(--danger);
}

input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

/* Barra de control principal */
.main-actions-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.actions-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(2, 132, 199, 0.45);
}

.btn-secondary {
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  color: #334155;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.mode-toggle-group {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
}

.mode-option {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: #64748b;
  border: none;
  background: transparent;
  transition: all 0.2s;
}

.mode-option.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}

/* Pipeline visual del algoritmo / Diagrama de flujo */
.pipeline-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
}

.section-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #1e293b;
}

.pipeline-steps {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  position: relative;
}

@media (max-width: 980px) {
  .pipeline-steps {
    grid-template-columns: 1fr;
  }
}

.pipeline-step {
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 16px 14px;
  text-align: center;
  transition: all 0.3s ease;
  position: relative;
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e2e8f0;
  color: #64748b;
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.step-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 4px;
}

.step-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.step-detail-badge {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  background: #e2e8f0;
  color: #475569;
}

/* Estados de paso activo */
.pipeline-step.active {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.2);
}

.pipeline-step.active .step-num {
  background: var(--primary);
  color: white;
}

.pipeline-step.completed {
  border-color: var(--success);
  background: #f0fdf4;
}

.pipeline-step.completed .step-num {
  background: var(--success);
  color: white;
}

/* Resultados de la asignación */
.results-container {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
  margin-bottom: 28px;
}

@media (max-width: 880px) {
  .results-container {
    grid-template-columns: 1fr;
  }
}

.winner-card {
  background: linear-gradient(135deg, #064e3b 0%, #065f46 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: 0 10px 25px rgba(6, 78, 59, 0.25);
  position: relative;
  overflow: hidden;
}

.winner-card::before {
  content: "CAMA ASIGNADA";
  position: absolute;
  top: 18px;
  right: -32px;
  background: #10b981;
  color: #064e3b;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 1px;
  padding: 4px 40px;
  transform: rotate(45deg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.winner-badge-top {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.3);
  border: 1px solid rgba(16, 185, 129, 0.6);
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #a7f3d0;
  margin-bottom: 14px;
}

.winner-name {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.winner-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.winner-spec-item {
  background: rgba(255, 255, 255, 0.12);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.winner-rationale {
  background: rgba(0, 0, 0, 0.22);
  border-left: 4px solid #34d399;
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 0.92rem;
  line-height: 1.45;
  color: #ecfdf5;
}

.waiting-card {
  background: var(--card-bg);
  border: 1.5px solid #fed7aa;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.waiting-badge-top {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--warning-light);
  border: 1px solid #fcd34d;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #b45309;
  margin-bottom: 12px;
  align-self: flex-start;
}

.waiting-name {
  font-size: 1.6rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 6px;
}

.waiting-info {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.waiting-box {
  background: #fffbeb;
  border-left: 4px solid var(--warning);
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 0.88rem;
  color: #92400e;
}

/* Tabla comparativa formal */
.comparison-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 28px;
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin-top: 14px;
}

.comparison-table th, 
.comparison-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.comparison-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.comparison-table tr:hover td {
  background: #f8fafc;
}

/* Modal de Reporte Clínico Imprimible */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: white;
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

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

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

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 26px;
}

.modal-footer {
  padding: 16px 26px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #f8fafc;
}

/* Documento clínico estilo hoja impresa */
.printable-report {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 30px;
  background: #ffffff;
  color: #0f172a;
  font-family: 'Times New Roman', Times, serif;
}

.report-header-doc {
  text-align: center;
  border-bottom: 2px solid #0f172a;
  padding-bottom: 12px;
  margin-bottom: 20px;
}

.report-header-doc h2 {
  font-size: 1.3rem;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.report-header-doc p {
  font-size: 0.9rem;
  color: #475569;
}

.report-section-doc {
  margin-bottom: 18px;
}

.report-section-doc h4 {
  font-size: 1rem;
  border-bottom: 1px solid #cbd5e1;
  padding-bottom: 4px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.report-signatures {
  display: flex;
  justify-content: space-around;
  margin-top: 50px;
  padding-top: 20px;
}

.signature-box {
  text-align: center;
  width: 220px;
  border-top: 1px solid #0f172a;
  padding-top: 8px;
  font-size: 0.85rem;
}

/* Estilos de impresión */
@media print {
  body * {
    visibility: hidden;
  }
  .modal-overlay {
    position: static;
    background: none;
    padding: 0;
  }
  .modal-content {
    box-shadow: none;
    max-height: none;
    overflow: visible;
  }
  .modal-header, .modal-footer, .app-header, .presets-card, .patients-grid, .main-actions-card, .pipeline-section {
    display: none !important;
  }
  .printable-report, .printable-report * {
    visibility: visible;
  }
  .printable-report {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    border: none;
    padding: 0;
  }
}
