body {
            font-family: 'Inter', sans-serif;
            --color-primary: 37 99 235; /* blue-600 */
            --color-primary-dark: 29 78 216; /* blue-700 */
            --color-success: 22 163 74; /* green-600 */
            --color-danger: 220 38 38; /* red-600 */
        }
        .calendar-grid {
            display: grid;
            grid-template-columns: repeat(7, 1fr);
            gap: 1px;
            background-color: #e2e8f0; /* gray-200 */
        }
        .calendar-day {
            min-height: 120px;
            position: relative;
            background-color: white;
        }
        .calendar-day.today {
            background-color: #eff6ff; /* blue-50 */
        }
        .calendar-day .day-number {
             transition: all 0.2s ease-in-out;
        }
        .calendar-day.today .day-number {
            background-color: rgb(var(--color-primary));
            color: white;
            border-radius: 50%;
            width: 28px;
            height: 28px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }
        .modal-backdrop {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 50;
            backdrop-filter: blur(4px);
            transition: opacity 0.3s ease;
        }
        .modal-content {
            max-height: 90vh;
            overflow-y: auto;
            transition: transform 0.3s ease;
        }
        .sortable-header {
            cursor: pointer;
            transition: background-color 0.2s ease;
        }
        .sortable-header:hover {
            background-color: #e2e8f0; /* gray-200 */
        }
        .sort-indicator {
            font-size: 0.9em;
            margin-left: 4px;
        }
        /* Zebra stripes for tables */
        .table-zebra tbody tr:hover {
            background-color: #f1f5f9; /* slate-100 */
        }
        /* Custom focus ring color */
        input:focus, select:focus, textarea:focus {
            --tw-ring-color: rgb(var(--color-primary) / 0.5);
        }
        .admin-clickable {
            cursor: pointer;
            transition: color 0.2s ease-in-out;
        }
        .admin-clickable:hover {
            color: rgb(var(--color-primary-dark));
        }
        /* Custom scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }
        ::-webkit-scrollbar-track {
            background: #f1f5f9;
        }
        ::-webkit-scrollbar-thumb {
            background: #cbd5e1;
            border-radius: 10px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: #94a3b8;
        }
        /* --- ESTILOS PARA LA AGENDA AGRUPADA (AÑADIR) --- */
        .patient-group-header {
            cursor: pointer;
            background-color: #f8fafc; /* slate-50 */
            transition: background-color 0.2s ease;
        }
        .patient-group-header:hover {
            background-color: #f1f5f9; /* slate-100 */
        }
        .patient-group-header.expanded {
            background-color: #eef2ff; /* indigo-50 */
            border-bottom: 2px solid #6366f1; /* indigo-500 */
        }
        .visit-detail-row {
            display: none; /* Ocultas por defecto */
            background-color: #ffffff;
        }
        .visit-detail-row.visible {
            display: table-row; /* Se muestran como filas de tabla */
        }
        .visit-detail-cell {
            padding-left: 3rem !important; /* Indentación para las celdas de detalle */
            border-bottom: 1px dashed #e2e8f0; /* slate-200 */
        }
        .toggle-icon {
            transition: transform 0.3s ease;
            display: inline-block;
        }
        .expanded .toggle-icon {
            transform: rotate(90deg);
        }
        /* --- FIN DE ESTILOS AÑADIDOS --- */

    /* Aplicamos estos estilos solo en pantallas con un ancho máximo de 768px */
    @media (max-width: 768px) {
        
        /* 1. Ocultamos la cabecera de días de la semana (DOM, LUN, MAR...) */
        #calendar-header {
            display: none;
        }

        /* 2. Convertimos el contenedor del calendario de grid a un bloque vertical */
        #calendar-body {
            display: block !important;
            border: none;
            background-color: transparent;
            gap: 0;
        }

        /* 3. Ocultamos las celdas vacías del principio del mes */
        #calendar-body > div:not(.calendar-day) {
            display: none;
        }

        /* 4. Ocultamos las celdas de días que no tienen citas */
        .calendar-day.empty-day {
            display: none !important;
        }

        /* 5. Transformamos cada día con citas en una "tarjeta" de la agenda */
        .calendar-day {
            display: block !important;
            width: 100%;
            min-height: auto;
            margin-bottom: 1rem;
            border-radius: 0.75rem;
            box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);
            border: 1px solid #e2e8f0;
            padding: 1rem;
            background-color: white;
        }

        /* 6. Reorganizamos el header del día */
        .calendar-day .day-header {
            flex-direction: row-reverse;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 0.75rem;
            padding-bottom: 0.5rem;
            border-bottom: 1px solid #e2e8f0;
        }

        /* 7. Estilo para el número del día */
        .calendar-day .day-number {
            font-size: 1.25rem;
            font-weight: 700;
            color: #1e40af; /* blue-800 */
        }
        
        .calendar-day.today .day-number {
            background-color: rgb(37, 99, 235);
            color: white;
            border-radius: 50%;
            width: 36px;
            height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* 8. Ajustamos los iconos del día */
        .calendar-day .day-icons {
            display: flex;
            gap: 0.5rem;
            font-size: 1.125rem;
        }

        /* 9. Mejoramos la visualización del contenido */
        .calendar-day .mt-1 {
            margin-top: 0.75rem;
        }

        /* 10. Estilos para el resumen de visitas */
        .calendar-day .text-xs {
            font-size: 0.875rem;
            line-height: 1.25rem;
        }

        .calendar-day .space-y-1 > * + * {
            margin-top: 0.5rem;
        }
    }

    /* --- INICIO: ESTILOS PARA ETIQUETAS DE DATOS ESTRUCTURADOS --- */
    .tags-container {
        display: flex;
        flex-wrap: wrap; /* Permite que las etiquetas pasen a la siguiente línea */
        gap: 0.75rem; /* Espacio entre etiquetas */
    }

    .data-tag {
        display: inline-flex;
        align-items: center;
        background-color: #e2e8f0; /* slate-200 */
        color: #334155; /* slate-700 */
        border-radius: 9999px; /* Para hacerlo una píldora */
        padding: 0.25rem 0.75rem; /* Padding interno */
        font-weight: 500; /* Medium */
        font-size: 0.875rem; /* text-sm */
        transition: background-color 0.2s ease;
    }

    .tag-delete-btn {
        margin-left: 0.5rem;
        color: #64748b; /* slate-500 */
        cursor: pointer;
        background: none;
        border: none;
        padding: 0;
        line-height: 1;
        transition: color 0.2s ease;
    }

    .tag-delete-btn:hover {
        color: #dc2626; /* red-600 */
    }

/* --- INICIO: ESTILOS PARA AUTOCOMPLETADO DE DIAGNÓSTICO --- */
    .diagnosis-tag {
        display: inline-flex;
        align-items: center;
        background-color: #3b82f6; /* blue-500 */
        color: white;
        border-radius: 0.25rem; /* rounded */
        padding: 0.25rem 0.5rem;
        font-size: 0.875rem;
        font-weight: 500;
    }
    .diagnosis-tag-delete {
        margin-left: 0.5rem;
        font-size: 1rem;
        font-weight: bold;
        cursor: pointer;
        opacity: 0.7;
        transition: opacity 0.2s;
    }
    .diagnosis-tag-delete:hover {
        opacity: 1;
    }
    .suggestion-item {
        padding: 0.5rem 0.75rem;
        cursor: pointer;
        transition: background-color 0.2s;
    }
    .suggestion-item:hover, .suggestion-item.highlighted {
        background-color: #eff6ff; /* blue-50 */
    }
    @media (max-width: 768px) {
        .dispositivo-row {
            grid-template-columns: 1fr;
        }
    }
/* --- MEJORAS MÓVIL JEFE DE RUTA --- */

/* Ocultar scrollbar en la navegación de pestañas (mantiene el scroll táctil) */
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* Rol badge compacto */
.role-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.role-admin     { background: #dbeafe; color: #1e40af; }
.role-gestor    { background: #dcfce7; color: #166534; }
.role-jefe_de_ruta { background: #fef3c7; color: #92400e; }
.role-medico    { background: #ccfbf1; color: #0f766e; }
.role-lector    { background: #f1f5f9; color: #475569; }

/* Chips de rol temporal (Gestión de Usuarios): el ✓ solo aparece con el chip activo */
.chip-check { display: none; }
.rol-temporal-chk:checked + span .chip-check { display: inline-block; }

/* Tarjetas Mi Ruta - asegurar que no se desborden */
#mi-ruta-container .rounded-xl {
    width: 100%;
    box-sizing: border-box;
}

/* Modal de reporte - scroll interno en móvil */
@media (max-width: 768px) {
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0;
        border-radius: 1rem 1rem 0 0;
        position: fixed;
        bottom: 0;
        max-height: 92vh;
    }
    .modal-backdrop {
        align-items: flex-end;
    }
    #route-view .bg-white {
        border-radius: 0.75rem;
    }
}
/* ─── Panel de contexto de solicitud + modal de agendamiento ──────────────────
   Gestión Cama → Solicitudes → "Abrir Agendamiento".
   El panel se acopla a la izquierda y el modal se desplaza a la derecha, de
   modo que la solicitud queda legible mientras se edita la visita. La pestaña
   lateral pliega/despliega el panel sin perder su contenido.                  */
:root {
    --ancho-panel-solicitud: 22rem;
}

.solicitud-dock {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--ancho-panel-solicitud);
    max-width: 100%;
    z-index: 60;            /* por encima de .modal-backdrop (z-index: 50) */
    pointer-events: none;   /* solo el panel y su pestaña capturan clics */
}

.solicitud-dock .solicitud-panel {
    position: relative;
    height: 100%;
    width: 100%;
    pointer-events: auto;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
}

.solicitud-dock.abierto .solicitud-panel {
    transform: translateX(0);
}

/* Pestaña de plegado: viaja con el panel, por lo que al plegarse queda
   pegada al borde izquierdo de la pantalla. */
.solicitud-panel-toggle {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: auto;
    width: 1.5rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: #2563eb;
    border: 1px solid #e2e8f0;
    border-left: none;
    border-radius: 0 0.5rem 0.5rem 0;
    box-shadow: 2px 2px 6px rgba(15, 23, 42, 0.15);
    cursor: pointer;
    font-size: 0.75rem;
}

.solicitud-panel-toggle:hover {
    background: #eff6ff;
}

.solicitud-panel-toggle i {
    transition: transform 0.3s ease-in-out;
}

/* Plegado: la flecha invita a desplegar */
.solicitud-dock:not(.abierto) .solicitud-panel-toggle i {
    transform: rotate(180deg);
}

/* Vista dividida real: solo hay espacio a partir de pantallas grandes. */
@media (min-width: 1024px) {
    .modal-backdrop.con-panel-solicitud {
        padding-left: var(--ancho-panel-solicitud);
    }
    .modal-backdrop.con-panel-solicitud .modal-content {
        width: min(100%, 44rem);
    }
}

/* Bajo 1024 px el panel se superpone al modal; la pestaña permite alternar. */
@media (max-width: 1023px) {
    :root {
        --ancho-panel-solicitud: min(20rem, 85vw);
    }
}