/* ===================================
   VISOR DE ACTIVIDAD HOSPITALIZACIÓN
   =================================== */

:root {
  --visor-trat: #1a6fc4;
  --visor-manej: #0f9e8a;
  --visor-bg: #f0f2f5;
  --visor-header: #1c2a3a;
  --visor-border: #dee2e6;
}

/* ── Contenedor principal ─────────────────────────────────────────────────── */
#visor-actividad {
  display: flex;
  flex-direction: column;
  background: var(--visor-bg);
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

#visor-actividad.visor-activo {
  transform: translateY(0);
}

/* ── Barra de encabezado ──────────────────────────────────────────────────── */
.visor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--visor-header);
  color: #fff;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.visor-header-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .3px;
  margin-right: 6px;
  white-space: nowrap;
}

.visor-header-sep {
  width: 1px;
  height: 22px;
  background: rgba(255, 255, 255, .25);
  flex-shrink: 0;
}

.visor-nav-btn {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .25);
  color: #fff;
  border-radius: 5px;
  padding: 4px 11px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}

.visor-nav-btn:hover {
  background: rgba(255, 255, 255, .22);
}

.visor-nav-btn.activo {
  background: rgba(255, 255, 255, .28);
  border-color: rgba(255, 255, 255, .55);
  font-weight: 600;
}

.visor-filtro-select {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .3);
  color: #fff;
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}

.visor-rango-label {
  font-size: 13px;
  color: rgba(255, 255, 255, .85);
  white-space: nowrap;
}

.visor-spacer {
  flex: 1;
}

/* Leyenda */
.visor-leyenda {
  display: flex;
  gap: 10px;
  align-items: center;
}

.visor-leyenda-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: rgba(255, 255, 255, .85);
}

.visor-leyenda-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Botones de acción en header */
.visor-action-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .3);
  color: #fff;
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
}

.visor-action-btn:hover {
  background: rgba(255, 255, 255, .15);
}

/* ── Barra de polling (countdown) ─────────────────────────────────────────── */
.visor-polling-bar-wrap {
  height: 4px;
  background: rgba(255, 255, 255, .15);
  flex-shrink: 0;
  position: relative;
}

.visor-polling-bar {
  height: 100%;
  background: #4fc3f7;
  transition: width .9s linear;
  width: 100%;
}

.visor-polling-label {
  position: absolute;
  right: 6px;
  top: 5px;
  font-size: 10px;
  color: rgba(255, 255, 255, .6);
  background: var(--visor-header);
  padding: 0 4px;
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
}

/* ── Cuerpo: grid + panel edición ─────────────────────────────────────────── */
.visor-body {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.visor-grid-wrap {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /*padding: 10px;*/
  min-width: 0;
  transition: margin-right .25s ease;
}

/* ── Grid semanal ─────────────────────────────────────────────────────────── */
.visor-grid {
  display: grid;
  grid-template-columns: 70px repeat(7, minmax(120px, 1fr));
  gap: 1px;
  background: var(--visor-border);
  border: 1px solid var(--visor-border);
  border-radius: 6px;
  overflow: clip;
}

/* ── Grid diario (filas=pacientes, columnas=horas) ────────────────────────── */
.visor-grid-dia-pac {
  display: grid;
  grid-template-columns: 150px repeat(24, minmax(72px, 1fr));
  gap: 1px;
  background: var(--visor-border);
  border: 1px solid var(--visor-border);
  border-radius: 6px;
  overflow: clip;
  min-width: max-content;
}

.visor-dia-corner {
  background: var(--visor-header);
  color: rgba(255, 255, 255, .8);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px 4px;
  position: sticky;
  left: 0;
  z-index: 10;
}

.visor-dia-hora-hdr {
  background: var(--visor-header);
  color: #fff;
  text-align: center;
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 5;
}

.visor-dia-hora-hdr.hora-act {
  background: #1a6fc4;
}

.visor-dia-pac-label {
  background: #f0f2f5;
  padding: 5px 8px;
  border-right: 2px solid var(--visor-border);
  position: sticky;
  left: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 48px;
}

.visor-dia-pac-nombre {
  font-size: 12px;
  font-weight: 700;
  color: #1c2a3a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visor-dia-pac-cliente {
  font-size: 10px;
  color: #6c757d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visor-dia-slot {
  background: #fff;
  min-height: 48px;
  position: relative;
  padding: 2px;
}

.visor-dia-slot:hover {
  background: #f5f9ff;
}

.visor-dia-slot.slot-act {
  background: rgba(26, 111, 196, .04);
}

.visor-col-header {
  background: var(--visor-header);
  color: #fff;
  text-align: center;
  padding: 8px 4px;
  font-weight: 700;
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.visor-col-header.hoy {
  background: #1a6fc4;
}

.visor-col-header.col-hora {
  background: #263647;
}

.visor-hora-label {
  background: #f8f9fa;
  padding: 6px 4px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #6c757d;
  border-right: 1px solid var(--visor-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.visor-hora-label.hora-actual-active-hosp {
  color: #1a6fc4;
  font-weight: 700;
  border-right: 2px solid #1a6fc4;
  background: rgba(26, 111, 196, .12) !important;
}

.visor-slot {
  background: #fff;
  min-height: 44px;
  position: relative;
  padding: 2px 3px;
}

.visor-slot:hover {
  background: #f5f9ff;
}

/* ── Eventos ──────────────────────────────────────────────────────────────── */
.visor-evento {
  border-radius: 4px;
  padding: 3px 6px;
  margin-bottom: 2px;
  font-size: 12.5px;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .1);
  transition: transform .1s, opacity .15s;
  width: calc(100% - 4px);
  margin-left: 2px;
  display: flex;
  align-items: center;
  gap: 3px;
  border-left: 3px solid rgba(0, 0, 0, .2);
}

.visor-evento:hover {
  transform: scale(1.02);
  z-index: 10;
}

/* Tipo */
.visor-evento.tipo-tratamiento {
  background-color: var(--visor-trat);
}

.visor-evento.tipo-manejo {
  background-color: var(--visor-manej);
}

/* Estado overrides */
.visor-evento.status-aplicado {
  background-color: #28a745 !important;
  opacity: .85;
}

.visor-evento.status-anulado {
  background-color: #f3d9dc !important;
  color: #7b1e2a !important;
  text-decoration: line-through;
  opacity: .75;
  border-left-color: #c0392b !important;
}

.visor-evento.status-atrasado {
  background-color: #dc3545 !important;
  animation: visor-pulse-red 2s ease-in-out infinite;
}

@keyframes visor-pulse-red {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: .75;
  }
}

/* Check rápido dentro del evento */
.visor-check-rapido {
  width: 13px;
  height: 21px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #fff;
  opacity: .9;
  transform: scale(1.5);
  margin-right: 11px;
}

.visor-check-rapido:disabled {
  cursor: default;
  opacity: .5;
}

.visor-evento-texto {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* Indicador tipo */
.visor-tipo-badge {
  font-size: 8.5px;
  font-weight: 700;
  background: rgba(255, 255, 255, .25);
  border-radius: 3px;
  padding: 1px 3px;
  flex-shrink: 0;
  letter-spacing: .3px;
}

/* ── Línea vertical de hora actual (vista diaria) ────────────────────────── */
.hora-actual-line-vertical {
  position: absolute;
  top: 0;
  width: 2px;
  background: #ea4335;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(234, 67, 53, .6);
}

.hora-actual-line-vertical::before {
  content: "";
  position: absolute;
  top: 0;
  left: -5px;
  width: 12px;
  height: 12px;
  background: #ea4335;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(234, 67, 53, .8);
}

/* ── Línea de hora actual ─────────────────────────────────────────────────── */
.hora-actual-line-hosp {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #ea4335;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(234, 67, 53, .6);
}

.hora-actual-line-hosp::before {
  content: "";
  position: absolute;
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  background: #ea4335;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(234, 67, 53, .8);
}

/* ── Spinner de carga ─────────────────────────────────────────────────────── */
.visor-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
  color: #6c757d;
  font-size: 14px;
}

.visor-spinner i {
  font-size: 2rem;
  color: var(--visor-trat);
}

/* ── Panel de edición deslizante (derecha, overlay sobre el grid) ─────────── */
.visor-edit-panel {
  display: none;
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 300px;
  overflow-y: auto;
  background: #fff;
  border-left: 1px solid var(--visor-border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, .18);
  flex-direction: column;
  z-index: 20;
}

.visor-edit-panel.abierto {
  display: flex;
  animation: visorPanelEntrar .22s ease;
}

@keyframes visorPanelEntrar {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.visor-edit-panel-inner {
  width: 300px;
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
}

.visor-edit-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--visor-border);
}

.visor-edit-panel-title {
  font-size: 14px;
  font-weight: 700;
  color: #1c2a3a;
}

.visor-edit-panel-close {
  background: none;
  border: none;
  color: #6c757d;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.visor-edit-panel-close:hover {
  color: #dc3545;
}

/* Info del evento seleccionado */
.visor-edit-info {
  background: var(--visor-bg);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 14px;
  font-size: 12px;
  line-height: 1.6;
  color: #495057;
}

.visor-edit-info strong {
  display: block;
  font-size: 13px;
  color: #1c2a3a;
  margin-bottom: 2px;
}

/* Tabs de operación */
.visor-ops-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--visor-border);
}

.visor-op-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 600;
  color: #6c757d;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  text-align: center;
  white-space: nowrap;
}

.visor-op-tab:hover {
  color: #1a6fc4;
}

.visor-op-tab.activo {
  color: #1a6fc4;
  border-bottom-color: #1a6fc4;
}

/* Paneles de operación */
.visor-op-panel {
  display: none;
}

.visor-op-panel.activo {
  display: block;
}

/* Formulario de operación */
.visor-op-label {
  font-size: 11px;
  font-weight: 600;
  color: #495057;
  display: block;
  margin-bottom: 4px;
}

.visor-op-input {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--visor-border);
  border-radius: 4px;
  margin-bottom: 10px;
  outline: none;
  box-sizing: border-box;
}

.visor-op-input:focus {
  border-color: #1a6fc4;
  box-shadow: 0 0 0 2px rgba(26, 111, 196, .15);
}

.visor-op-hint {
  font-size: 10.5px;
  color: #6c757d;
  margin-bottom: 10px;
  line-height: 1.4;
}

.visor-op-btn {
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  color: #fff;
}

.visor-op-btn:hover {
  opacity: .88;
}

.visor-op-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.visor-op-btn-reprogramar {
  background: #6f42c1;
}

.visor-op-btn-frecuencia {
  background: #e67e22;
}

.visor-op-btn-extension {
  background: #1a6fc4;
}

/* ── Botón abrir visor ────────────────────────────────────────────────────── */
.btn-visor-actividad {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #1c2a3a 0%, #1a6fc4 100%);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(26, 111, 196, .3);
  transition: opacity .15s, transform .1s;
}

.btn-visor-actividad:hover {
  opacity: .9;
  transform: translateY(-1px);
}

.btn-visor-actividad:active {
  transform: translateY(0);
}

/* ── Tooltip local visor ──────────────────────────────────────── */
#visor-tooltip {
  position: fixed;
  z-index: 99999;
  background: rgba(28, 42, 58, .95);
  color: #fff;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.45;
  padding: 5px 9px;
  border-radius: 5px;
  pointer-events: none;
  white-space: normal;
  max-width: 280px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .3);
  opacity: 0;
  transition: opacity .12s ease;
}

#visor-tooltip.visible {
  opacity: 1;
}

#visor-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(28, 42, 58, .95);
}