/* =====================================================
   VARIABLES Y CONFIGURACIÓN GENERAL
   ===================================================== */
:root {
  /* Colores principales - Verde Esmeralda */
  --emerald-50: #ecfdf5;
  --emerald-100: #d1fae5;
  --emerald-200: #a7f3d0;
  --emerald-300: #6ee7b7;
  --emerald-400: #34d399;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --emerald-800: #065f46;
  --emerald-900: #064e3b;

  /* Escala de grises */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Colores del sistema */
  --white: #ffffff;
  --black: #000000;
  --success: var(--emerald-500);
  --error: #ef4444;

  /* Espaciado */
  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2rem;
  --spacing-xl: 3rem;

  /* Bordes */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Sombras */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

  /* Transiciones */
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =====================================================
   RESET Y ESTILOS BASE
   ===================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(
    135deg,
    var(--gray-50) 0%,
    var(--emerald-50) 100%
  );
  color: var(--gray-900);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

/* =====================================================
   HEADER
   ===================================================== */
.header {
  background: linear-gradient(
    135deg,
    var(--emerald-600) 0%,
    var(--emerald-700) 100%
  );
  color: var(--white);
  padding: var(--spacing-lg) 0;
  box-shadow: var(--shadow-md);
}

.header-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: var(--spacing-xs);
}

.header-subtitle {
  font-size: 1.125rem;
  opacity: 0.9;
  font-weight: 300;
}

/* =====================================================
   INDICADOR DE PROGRESO
   ===================================================== */
.progress-container {
  background: var(--white);
  padding: var(--spacing-lg) 0;
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--spacing-xl);
}

.progress-steps {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.progress-steps::before {
  content: "";
  position: absolute;
  top: 1.5rem;
  left: 25%;
  right: 25%;
  height: 2px;
  background: var(--gray-200);
  z-index: 0;
}

.progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-xs);
  position: relative;
  z-index: 1;
  flex: 1;
}

.step-circle {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: var(--white);
  border: 3px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--gray-400);
  transition: var(--transition);
}

.progress-step.active .step-circle {
  background: var(--emerald-500);
  border-color: var(--emerald-500);
  color: var(--white);
  box-shadow: 0 0 0 4px var(--emerald-100);
}

.progress-step.completed .step-circle {
  background: var(--emerald-600);
  border-color: var(--emerald-600);
  color: var(--white);
}

.step-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-600);
  transition: var(--transition);
}

.progress-step.active .step-label {
  color: var(--emerald-700);
  font-weight: 600;
}

/* =====================================================
   MAIN CONTENT
   ===================================================== */
.main-content {
  flex: 1;
  padding: var(--spacing-xl) 0;
}

/* =====================================================
   WIZARD STEPS
   ===================================================== */
.wizard-step {
  display: none;
  animation: fadeIn 0.4s ease-out;
}

.wizard-step.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.step-header {
  text-align: center;
  margin-bottom: var(--spacing-xl);
}

.step-header h2 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: var(--spacing-sm);
}

.step-header p {
  font-size: 1.125rem;
  color: var(--gray-600);
}

.step-actions {
  display: flex;
  justify-content: center;
  gap: var(--spacing-md);
  margin-top: var(--spacing-xl);
}

/* =====================================================
   PASO 1: SELECCIÓN DE INSTITUCIÓN
   ===================================================== */
.institutions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

.institution-card {
  background: var(--white);
  border: 3px solid var(--gray-200);
  border-radius: var(--radius-xl);
  padding: var(--spacing-xl);
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-md);
}

.institution-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl);
  border-color: var(--emerald-300);
}

.institution-card.selected {
  background: linear-gradient(
    135deg,
    var(--emerald-50) 0%,
    var(--emerald-100) 100%
  );
  border-color: var(--emerald-500);
  border-width: 4px;
  box-shadow: 0 0 0 4px var(--emerald-200);
}

.institution-icon {
  font-size: 4rem;
  margin-bottom: var(--spacing-md);
}

.institution-card h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: var(--spacing-xs);
}

.institution-card p {
  color: var(--gray-600);
  font-size: 1rem;
}

/* =====================================================
   PASO 2: CARGA DE PDF   ===================================================== */
.upload-container {
  max-width: 600px;
  margin: 0 auto;
}

.upload-area {
  background: var(--white);
  border: 3px dashed var(--gray-300);
  border-radius: var(--radius-xl);
  padding: var(--spacing-xl);
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

.upload-area:hover {
  border-color: var(--emerald-400);
  background: var(--emerald-50);
}

.upload-area.drag-over {
  border-color: var(--emerald-500);
  background: var(--emerald-100);
  border-style: solid;
}

.upload-icon {
  font-size: 4rem;
  margin-bottom: var(--spacing-md);
}

.upload-text {
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--gray-900);
  margin-bottom: var(--spacing-xs);
}

.upload-subtext {
  color: var(--gray-500);
  font-size: 0.875rem;
}

.file-info {
  background: var(--white);
  border: 2px solid var(--emerald-500);
  border-radius: var(--radius-lg);
  padding: var(--spacing-md);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  margin-top: var(--spacing-md);
}

.file-icon {
  font-size: 2rem;
}

.file-details {
  flex: 1;
}

.file-name {
  font-weight: 600;
  color: var(--gray-900);
  word-break: break-word;
}

.file-size {
  font-size: 0.875rem;
  color: var(--gray-600);
}

.file-remove {
  background: var(--error);
  color: var(--white);
  border: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.file-remove:hover {
  background: #dc2626;
  transform: scale(1.1);
}

/* =====================================================
   SPINNER DE CARGA
   ===================================================== */
.loading-spinner {
  text-align: center;
  padding: var(--spacing-xl);
}

.spinner {
  width: 3rem;
  height: 3rem;
  border: 4px solid var(--gray-200);
  border-top-color: var(--emerald-500);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto var(--spacing-md);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-spinner p {
  color: var(--gray-600);
  font-weight: 500;
}

/* =====================================================
   PASO 3: MEDICIONES
   ===================================================== */
.patient-info {
  background: linear-gradient(
    135deg,
    var(--emerald-50) 0%,
    var(--emerald-100) 100%
  );
  border: 2px solid var(--emerald-300);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
  text-align: center;
}

.patient-info h3 {
  font-size: 1.5rem;
  color: var(--gray-900);
  margin-bottom: var(--spacing-xs);
}

.patient-info p {
  color: var(--gray-700);
}

.measurements-form {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: var(--spacing-xl);
  box-shadow: var(--shadow-md);
  max-width: 500px;
  margin: 0 auto;
}

.form-group {
  margin-bottom: var(--spacing-lg);
}

.form-group label {
  display: block;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: var(--spacing-xs);
}

.form-input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-size: 1rem;
  transition: var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--emerald-500);
  box-shadow: 0 0 0 3px var(--emerald-100);
}

/* Badge para mediciones automáticas */
.auto-badge {
  background: linear-gradient(135deg, var(--emerald-100) 0%, var(--emerald-200) 100%);
  color: var(--emerald-800);
  padding: var(--spacing-xs) var(--spacing-md);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: var(--spacing-lg);
  display: inline-block;
  width: 100%;
  box-shadow: var(--shadow-sm);
}

/* Texto informativo */
.info-text {
  background: var(--gray-50);
  border-left: 4px solid var(--emerald-500);
  padding: var(--spacing-md);
  margin-top: var(--spacing-lg);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--gray-700);
  line-height: 1.5;
}

/* Display de mediciones automáticas */
.measurement-display {
  background: linear-gradient(135deg, var(--gray-50) 0%, var(--emerald-50) 100%);
  border: 2px solid var(--emerald-300);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.measurement-display:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.measurement-display.total {
  background: linear-gradient(135deg, var(--emerald-100) 0%, var(--emerald-200) 100%);
  border-color: var(--emerald-500);
  border-width: 3px;
}

.measurement-value {
  display: block;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--emerald-700);
  line-height: 1;
  margin-bottom: var(--spacing-xs);
}

.measurement-display.total .measurement-value {
  color: var(--emerald-800);
}

.measurement-label {
  display: block;
  font-size: 0.875rem;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}


/* =====================================================
   PASO 4: RESUMEN Y GENERACIÓN
   ===================================================== */
.summary-card {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: var(--spacing-xl);
  box-shadow: var(--shadow-lg);
  margin-bottom: var(--spacing-xl);
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}

.summary-card h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: var(--spacing-lg);
  text-align: center;
}

.summary-grid {
  display: grid;
  gap: var(--spacing-md);
}

.summary-item {
  display: flex;
  justify-content: space-between;
  padding: var(--spacing-md);
  background: var(--gray-50);
  border-radius: var(--radius-md);
}

.summary-label {
  font-weight: 600;
  color: var(--gray-700);
}

.summary-value {
  color: var(--emerald-700);
  font-weight: 500;
}

/* =====================================================
   BOTONES
   ===================================================== */
.btn {
  padding: 0.875rem 2rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--emerald-600);
  color: var(--white);
  box-shadow: var(--shadow-md);
}

.btn-primary:hover:not(:disabled) {
  background: var(--emerald-700);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--gray-600);
  color: var(--white);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-700);
}

.btn-secondary-outline {
  background: var(--white);
  color: var(--emerald-600);
  border: 2px solid var(--emerald-600);
}

.btn-secondary-outline:hover:not(:disabled) {
  background: var(--emerald-50);
}

.btn-success {
  background: linear-gradient(
    135deg,
    var(--emerald-500) 0%,
    var(--emerald-600) 100%
  );
  color: var(--white);
  padding: 1rem 2.5rem;
  font-size: 1.125rem;
  box-shadow: var(--shadow-lg);
}

.btn-success:hover:not(:disabled) {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl);
}

/* =====================================================
   FOOTER
   ===================================================== */
.footer {
  background: var(--gray-900);
  color: var(--white);
  padding: var(--spacing-lg) 0;
  text-align: center;
  margin-top: auto;
}

.footer p {
  opacity: 0.8;
  font-size: 0.875rem;
}

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
  .header-title {
    font-size: 1.5rem;
  }

  .step-header h2 {
    font-size: 1.5rem;
  }

  .institutions-grid {
    grid-template-columns: 1fr;
  }

  .progress-step {
    flex-direction: row;
    gap: var(--spacing-xs);
  }

  .step-circle {
    width: 2.5rem;
    height: 2.5rem;
  }

  .step-label {
    font-size: 0.75rem;
  }

  .step-actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }
}

/* =====================================================
   MODE TABS — estilo pestaña de carpeta
   ===================================================== */

.mode-tabs-container {
  background: var(--gray-100);
  border-bottom: 3px solid var(--primary-600);
  padding-top: 1.25rem;
}

.mode-tabs {
  display: flex;
  align-items: flex-end;
  gap: 0.25rem;
  padding: 0 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.mode-tab {
  padding: 0.6rem 2rem;
  border: 1px solid var(--gray-300);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: var(--gray-200);
  color: var(--gray-500);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
  bottom: -1px;
  -webkit-user-select: none;
  user-select: none;
}

.mode-tab:hover:not(.active) {
  background: var(--gray-300);
  color: var(--gray-700);
}

.mode-tab.active {
  background: var(--white);
  color: var(--primary-700);
  font-weight: 700;
  border-color: var(--gray-300);
  border-bottom: 3px solid var(--white);
  bottom: -3px;
  z-index: 1;
}

/* =====================================================
   AWP SECTION
   ===================================================== */

.hidden {
  display: none !important;
}

.awp-section {
  padding: 2rem 0;
}

.awp-upload-zone {
  margin-top: 2rem;
}

.awp-drop-area {
  border: 2px dashed var(--gray-300);
  border-radius: 1rem;
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--gray-50);
}

.awp-drop-area:hover,
.awp-drop-area.drag-over {
  border-color: var(--primary-500);
  background: var(--primary-50);
}

/* =====================================================
   AWP FILE LIST
   ===================================================== */

.awp-file-list {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.awp-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.awp-file-item.ok {
  border-left: 4px solid var(--emerald-500);
}

.awp-file-item.warn {
  border-left: 4px solid #f59e0b;
}

.awp-file-item.err {
  border-left: 4px solid #dc2626;
}

.awp-file-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.awp-file-status {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.awp-file-details {
  min-width: 0;
}

.awp-patient-name {
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.awp-file-meta {
  font-size: 0.78rem;
  color: var(--gray-500);
  margin-top: 0.1rem;
}

.awp-error-msg {
  font-size: 0.78rem;
  color: #dc2626;
  margin-top: 0.1rem;
}

.btn-awp-whatsapp {
  padding: 0.4rem 0.9rem;
  background: #25D366;
  color: var(--white);
  border: none;
  border-radius: 0.5rem;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

/* =====================================================
   HISTORIAL
   ===================================================== */

.historial-section {
  margin-top: 3rem;
  border-top: 1px solid var(--gray-200);
  padding-top: 1.5rem;
}

.historial-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.historial-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
}

.btn-limpiar-historial {
  padding: 0.35rem 0.9rem;
  background: transparent;
  border: 1px solid var(--gray-300);
  border-radius: 0.4rem;
  color: var(--gray-500);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-limpiar-historial:hover {
  border-color: #dc2626;
  color: #dc2626;
}

.historial-vacio {
  color: var(--gray-400);
  font-size: 0.875rem;
  padding: 1rem 0;
}

.historial-tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.historial-tabla thead th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: var(--gray-100);
  color: var(--gray-600);
  font-weight: 600;
  border-bottom: 2px solid var(--gray-200);
}

.historial-tabla tbody tr {
  border-bottom: 1px solid var(--gray-100);
  transition: background 0.1s;
}

.historial-tabla tbody tr:hover {
  background: var(--gray-50);
}

.historial-tabla tbody td {
  padding: 0.55rem 0.75rem;
  color: var(--gray-700);
  vertical-align: middle;
}

.historial-estado {
  font-weight: 600;
  font-size: 0.8rem;
}

.historial-estado.ok    { color: var(--emerald-600); }
.historial-estado.warn  { color: #d97706; }
.historial-estado.err   { color: #dc2626; }

/* =====================================================
   UNIR PDFs
   ===================================================== */

.unir-section {
  padding: 2rem 0;
}

.unir-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.unir-slot-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 0.5rem;
}

.unir-drop {
  border: 2px dashed var(--gray-300);
  border-radius: 1rem;
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--gray-50);
}

.unir-drop:hover,
.unir-drop.drag-over {
  border-color: var(--primary-500);
  background: var(--primary-50);
}

.unir-drop.loaded {
  border-color: var(--emerald-500);
  background: #f0fdf4;
}

.unir-file-name {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  color: var(--emerald-600);
  font-weight: 500;
  min-height: 1.2rem;
}

.unir-upload-zone {
  margin-top: 2rem;
}

.unir-caratula-info {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 0.5rem;
  color: #1d4ed8;
  font-size: 0.85rem;
}

.unir-actions {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

@media (max-width: 600px) {
  .unir-grid {
    grid-template-columns: 1fr;
  }
}
