/* ============================================================
   ESTILOS GENERALES Y VARIABLES CLÍNICAS
   ============================================================ */
:root {
  --primary: #0284c7;         /* Azul médico corporativo Vinsego */
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --secondary: #0f172a;       /* Slate oscuro */
  --bg-page: #f8fafc;         /* Gris muy suave */
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --border-focus: #38bdf8;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Semáforo de capacidad */
  --green: #10b981;
  --green-light: #d1fae5;
  --green-text: #065f46;
  --orange: #f59e0b;
  --orange-light: #fef3c7;
  --orange-text: #92400e;
  --red: #ef4444;
  --red-light: #fee2e2;
  --red-text: #991b1b;

  /* Alerta de conflicto de horario */
  --conflict-bg: #fff1f2;
  --conflict-border: #fecdd3;
  --conflict-text: #9f1239;
  --conflict-btn: #e11d48;

  /* Tipos de Indicación */
  --tag-cesarea-bg: #ede9fe;
  --tag-cesarea-text: #5b21b6;
  --tag-induccion-bg: #dbeafe;
  --tag-induccion-text: #1e40af;
  --tag-version-bg: #dcfce7;
  --tag-version-text: #166534;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   LOGOS
   ============================================================ */
.logo-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.logo-link:hover {
  opacity: 0.85;
  transform: scale(1.02);
}

.login-logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.login-logo {
  height: 64px;
  max-width: 220px;
  object-fit: contain;
}

.brand-logo-container {
  display: flex;
  align-items: center;
}

.app-logo {
  height: 38px;
  max-width: 150px;
  object-fit: contain;
}

.print-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.print-logo {
  height: 44px;
  max-width: 130px;
  object-fit: contain;
}

/* Indicador de Sincronización con MariaDB */
.db-sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #cbd5e1;
  transition: all 0.25s ease;
  user-select: none;
}

.db-sync-badge .sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
}

.db-sync-badge.sync-online {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

.db-sync-badge.sync-online .sync-dot {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.db-sync-badge.sync-offline {
  background: #f8fafc;
  color: #64748b;
  border-color: #e2e8f0;
}

.db-sync-badge.sync-error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

.db-sync-badge.sync-error .sync-dot {
  background: #ef4444;
}

/* ============================================================
   PANTALLA DE ACCESO (LOGIN)
   ============================================================ */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  text-align: center;
}

.login-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--secondary);
  margin-bottom: 4px;
}

.login-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.login-form {
  text-align: left;
}

/* ============================================================
   ESTILOS DE FORMULARIO Y BOTONES
   ============================================================ */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.form-row {
  display: flex;
  gap: 12px;
}

.flex-1 {
  flex: 1;
}

.helper-text {
  display: block;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 6px;
}

.error-msg {
  color: var(--red);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 12px;
}

.success-msg {
  color: var(--green);
  font-size: 0.88rem;
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background-color: #f1f5f9;
  color: var(--text-main);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background-color: #e2e8f0;
}

.btn-outline {
  background-color: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-outline:hover {
  background-color: #f1f5f9;
  color: var(--text-main);
}

.btn-danger-outline {
  background-color: transparent;
  color: var(--red);
  border: 1px solid #fecaca;
  padding: 5px 8px;
  font-size: 0.8rem;
}
.btn-danger-outline:hover {
  background-color: var(--red-light);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.85rem;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-icon:hover {
  background: #f1f5f9;
}

/* ============================================================
   APLICACIÓN PRINCIPAL
   ============================================================ */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-left .brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-titles {
  border-left: 2px solid var(--border);
  padding-left: 14px;
}

.header-left h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--secondary);
  line-height: 1.2;
}

.header-left .sub-title {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ============================================================
   BARRA DE NAVEGACIÓN DE VISTAS (TABS)
   ============================================================ */
.view-nav-bar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 59px;
  z-index: 15;
}

.view-tabs {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: var(--radius-md);
  gap: 4px;
}

.view-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.view-tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.view-print-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ============================================================
   CONTENEDOR DE VISTAS
   ============================================================ */
.main-content-area {
  max-width: 1480px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 24px;
  flex: 1;
}

.view-pane {
  display: none;
}
.view-pane.active {
  display: block;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

/* ============================================================
   VISTA 1: MENSUAL
   ============================================================ */
.monthly-layout {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 24px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-controls h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--secondary);
  min-width: 180px;
  text-transform: capitalize;
}

.calendar-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-empty { background: #cbd5e1; }
.dot-green { background: var(--green); }
.dot-orange { background: var(--orange); }
.dot-red { background: var(--red); }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.weekday-header {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  padding: 6px 0;
  text-transform: uppercase;
}

.weekday-header.weekend {
  color: var(--text-light);
}

.calendar-days-container {
  display: contents;
}

.calendar-day {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  background: var(--bg-card);
  transition: all 0.15s ease;
  position: relative;
  user-select: none;
}

.calendar-day:hover {
  border-color: var(--primary);
  background: #f0fdf4;
}

.calendar-day.other-month {
  opacity: 0.35;
  background: #f8fafc;
}

.calendar-day.today .day-number {
  background: var(--primary);
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar-day.selected {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  background: #f0f9ff;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.day-number {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
}

.day-badges {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.day-count-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 12px;
  text-align: center;
  display: inline-block;
}

.badge-zero { display: none; }
.badge-one { background: var(--green-light); color: var(--green-text); }
.badge-two { background: var(--orange-light); color: var(--orange-text); }
.badge-critical {
  background: var(--red-light);
  color: var(--red-text);
  animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* AGENDA LATERAL */
.agenda-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.agenda-tag {
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.5px;
}

.agenda-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--secondary);
  margin-top: 2px;
}

.capacity-badge {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
}
.badge-green { background: var(--green-light); color: var(--green-text); }
.badge-orange { background: var(--orange-light); color: var(--orange-text); }
.badge-red { background: var(--red-light); color: var(--red-text); }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}
.alert-warning {
  background: var(--red-light);
  color: var(--red-text);
  border: 1px solid #fca5a5;
}

.alert-conflict {
  background: var(--conflict-bg);
  border: 1px solid var(--conflict-border);
  color: var(--conflict-text);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: shake-alert 0.3s ease-in-out;
}

@keyframes shake-alert {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.conflict-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--conflict-btn);
  font-size: 0.95rem;
}

.conflict-details {
  font-size: 0.88rem;
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.7);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--conflict-btn);
}

.conflict-actions {
  display: flex;
  justify-content: flex-end;
}

.btn-conflict-action {
  background: white;
  color: var(--conflict-btn);
  border: 1px solid var(--conflict-border);
  font-weight: 600;
}
.btn-conflict-action:hover {
  background: #ffe4e6;
}

.agenda-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.agenda-actions .btn {
  flex: 1;
}

.agenda-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: 520px;
  padding-right: 4px;
}

.empty-agenda {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}
.empty-agenda svg {
  margin-bottom: 12px;
  stroke: var(--text-light);
}
.empty-agenda p {
  font-size: 0.95rem;
  font-weight: 500;
}

.agenda-item-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--bg-card);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.agenda-item-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.item-time {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.item-indication {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
}
.tag-cesarea { background: var(--tag-cesarea-bg); color: var(--tag-cesarea-text); }
.tag-induccion { background: var(--tag-induccion-bg); color: var(--tag-induccion-text); }
.tag-version { background: var(--tag-version-bg); color: var(--tag-version-text); }
.tag-default { background: #e2e8f0; color: #475569; }

.item-patient {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--secondary);
  margin-bottom: 4px;
}

.item-doctor {
  font-size: 0.83rem;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.item-reason {
  font-size: 0.83rem;
  color: var(--text-muted);
  background: #f8fafc;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  white-space: pre-line;
}

.item-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

/* ============================================================
   VISTA 2: SEMANAL (7 COLUMNAS)
   ============================================================ */
.weekly-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.weekly-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
  min-height: 520px;
}

.weekly-col {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.weekly-col.is-today {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.weekly-col-header {
  padding: 10px 8px;
  background: white;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.weekly-col.is-today .weekly-col-header {
  background: var(--primary-light);
}

.weekly-day-name {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.weekly-day-date {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--secondary);
  margin: 2px 0 6px;
}

.weekly-col-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  display: inline-block;
}

.weekly-cards-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
}

.weekly-mini-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.weekly-mini-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.weekly-mini-time {
  font-weight: 700;
  color: var(--secondary);
  margin-bottom: 2px;
}

.weekly-mini-patient {
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}

.weekly-mini-doc {
  font-size: 0.72rem;
  color: var(--primary);
}

.btn-add-week-day {
  margin-top: auto;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px;
  cursor: pointer;
  text-align: center;
  border-top: 1px dashed var(--border);
}
.btn-add-week-day:hover {
  background: white;
}

/* ============================================================
   VISTA 3: DIARIO (TABLERO COMPLETO)
   ============================================================ */
.daily-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.daily-capacity-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.daily-full-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* ============================================================
   VISTA 4: FECHA A FECHA (RANGO)
   ============================================================ */
.range-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--secondary);
  margin-bottom: 4px;
}
.range-header p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.range-filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  padding: 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.filter-field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.filter-field input,
.filter-field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  background: white;
}

.range-stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-pill {
  padding: 6px 14px;
  border-radius: 20px;
  background: #f1f5f9;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-num {
  font-weight: 700;
  color: var(--secondary);
}

.stat-cesarea { background: var(--tag-cesarea-bg); color: var(--tag-cesarea-text); }
.stat-induccion { background: var(--tag-induccion-bg); color: var(--tag-induccion-text); }
.stat-version { background: var(--tag-version-bg); color: var(--tag-version-text); }

.range-table-wrapper {
  max-height: 520px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

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

.range-data-table th,
.range-data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.range-data-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

/* ============================================================
   MODALES
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modal-appear 0.18s ease-out;
}

.modal-lg {
  max-width: 720px;
}

@keyframes modal-appear {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--secondary);
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-light);
  cursor: pointer;
}
.btn-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

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

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  background: #f8fafc;
  overflow-x: auto;
}

.tab-btn {
  padding: 12px 18px;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--bg-card);
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

.tab-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.inline-add-form {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.inline-add-form input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.table-container {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.settings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.settings-table th,
.settings-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.settings-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
}
.settings-table tr:last-child td {
  border-bottom: none;
}

/* GESTIÓN DE LÍMITES */
.limits-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.limit-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.warning-box {
  background: #fffbeb;
  border-color: #fde68a;
}
.critical-box {
  background: #fef2f2;
  border-color: #fecaca;
}

.limit-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.limit-info h4 {
  font-size: 0.95rem;
  color: var(--secondary);
  margin-bottom: 4px;
}
.limit-info p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.limit-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.limit-input-wrap input {
  width: 70px;
  padding: 8px 10px;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.limits-save-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

.backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.backup-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: #f8fafc;
}
.backup-box h4 {
  font-size: 0.95rem;
  margin-bottom: 6px;
  color: var(--secondary);
}
.backup-box p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.hidden {
  display: none !important;
}

/* ============================================================
   ESTILOS DE IMPRESIÓN (PDF / IMPRESORA - SIN PÁGINAS EN BLANCO)
   ============================================================ */
.print-only {
  display: none;
}

@page {
  size: A4 portrait;
  margin: 10mm 12mm 10mm 12mm;
}

@media print {
  html, body {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    color: black !important;
    overflow: visible !important;
    display: block !important;
  }

  /* Ocultar ABSOLUTAMENTE toda la interfaz de la web para evitar páginas en blanco previas */
  body > *:not(#printArea),
  #loginScreen,
  #appScreen,
  .app-container,
  .app-header,
  .view-nav-bar,
  .main-content-area,
  .modal-overlay,
  .login-wrapper {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    visibility: hidden !important;
  }

  /* Mostrar exclusivamente la zona de impresión */
  #printArea,
  .print-only {
    display: block !important;
    visibility: visible !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    position: static !important;
  }

  .print-header {
    border-bottom: 2px solid #000;
    padding-bottom: 8px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
  }

  .hospital-title h2 {
    font-size: 13pt;
    font-weight: bold;
    margin-bottom: 2px;
  }
  .hospital-title h3 {
    font-size: 10.5pt;
    font-weight: normal;
    color: #222;
  }

  .print-meta p {
    font-size: 9.5pt;
    margin-bottom: 2px;
    text-align: right;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    page-break-inside: auto;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #333;
    padding: 6px 8px;
    font-size: 9pt;
    text-align: left;
  }

  .print-table tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  .print-table th {
    background-color: #f2f2f2 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-weight: bold;
  }

  .print-signatures {
    margin-top: 25px !important;
    margin-bottom: 0 !important;
    display: flex;
    justify-content: space-between;
    page-break-inside: avoid;
  }

  .signature-line {
    width: 200px;
    border-top: 1px solid #000;
    text-align: center;
    padding-top: 5px;
    font-size: 8.5pt;
  }
}

/* ============================================================
   RESPONSIVIDAD (TABLETS Y MÓVILES)
   ============================================================ */
@media (max-width: 1024px) {
  .monthly-layout {
    grid-template-columns: 1fr;
  }
  .weekly-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 10px 16px;
  }
  .view-nav-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 16px;
    top: 59px;
  }
  .view-tabs {
    overflow-x: auto;
  }
  .view-print-actions {
    justify-content: flex-end;
  }
  .weekly-grid {
    grid-template-columns: 1fr;
  }
  .main-content-area {
    padding: 12px;
  }
  .card {
    padding: 14px;
  }
  .nav-controls h2 {
    font-size: 1.1rem;
    min-width: auto;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .backup-actions {
    grid-template-columns: 1fr;
  }
}
