:root {
    --primary-blue: #004080;
    --secondary-blue: #0066cc;
    --light-blue: #e6f0fa;
    --accent-blue: #00264d;
    --bg-light: #f8fafc;
    --text-dark: #333333;
    --white: #ffffff;
    --border-color: #cbd5e1;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
}

body {
    background-color: var(--bg-light);
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header & Footer */
header {
    background: linear-gradient(135deg, var(--accent-blue), var(--primary-blue));
    color: var(--white);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

header .nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

header a {
    color: var(--white);
    text-decoration: none;
    font-weight: 600;
    transition: opacity 0.2s;
}

header a:hover {
    opacity: 0.8;
}

footer {
    background-color: var(--accent-blue);
    color: var(--white);
    text-align: center;
    padding: 1rem;
    margin-top: auto;
    font-size: 0.9rem;
}

/* Contenedores y Tarjetas */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
    width: 100%;
}

.card {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    padding: 2rem;
    margin-bottom: 1.5rem;
    border-top: 4px solid var(--secondary-blue);
}

/* Formularios y Botones */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--accent-blue);
}

input[type="text"],
input[type="password"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--secondary-blue);
    box-shadow: 0 0 0 3px rgba(0,102,204,0.1);
}

.btn {
    display: inline-block;
    background-color: var(--secondary-blue);
    color: var(--white);
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.2s;
}

.btn:hover {
    background-color: var(--primary-blue);
}

.btn-success { background-color: #10b981; }
.btn-success:hover { background-color: #059669; }
.btn-warning { background-color: #f59e0b; color: #fff; }
.btn-warning:hover { background-color: #d97706; }

/* Tablas */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    background: var(--white);
}

th, td {
    padding: 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: var(--light-blue);
    color: var(--accent-blue);
    font-weight: 700;
}

/* Login Atractivo */
.login-body {
    background: linear-gradient(135deg, var(--light-blue), #b3d1ff);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.login-card {
    background: var(--white);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card h2 {
    color: var(--accent-blue);
    margin-bottom: 1.5rem;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 1rem;
    border: 3px solid var(--secondary-blue);
}

/* Responsivo */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    header .nav-links {
        flex-direction: column;
        gap: 0.5rem;
    }
    .container {
        padding: 0 0.5rem;
    }
}
/* --- CABECERA PRINCIPAL Y BARRA DE NAVEGACIÓN --- */
.main-header {
    background: #0b2545; /* Azul institucional profundo */
    color: #ffffff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.5rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap; /* EVITA QUE LOS ELEMENTOS SALTEN DE LÍNEA EN ESCRITORIO */
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.header-brand {
    display: flex;
    align-items: center;
    flex-shrink: 0; /* Evita que el logo se deforme */
}

.header-brand a {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    gap: 0.75rem;
}

.header-logo {
    height: 42px;
    width: auto;
    object-fit: contain;
}

.header-titles {
    display: flex;
    flex-direction: column;
}

.hospital-name {
    font-size: 0.75rem;
    color: #93c5fd;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.1;
}

.system-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
    white-space: nowrap;
}

/* Navegación de Escritorio (Siempre Horizontal) */
.header-nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.nav-link {
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: color 0.2s ease;
    white-space: nowrap;
}

.nav-link:hover, .nav-link.active {
    color: #ffffff;
}

/* Bloque de Usuario y Logout */
.user-profile-menu {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    padding-left: 1rem;
    flex-shrink: 0;
}

.user-info-mini {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #38bdf8;
}

.user-text {
    display: flex;
    flex-direction: column;
}

.u-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #f8fafc;
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.u-role {
    font-size: 0.65rem;
    color: #38bdf8;
    text-transform: uppercase;
    line-height: 1.1;
}

.btn-logout {
    background: #ef4444;
    color: white;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.btn-logout:hover {
    background: #dc2626;
}

/* Botón Hamburguesa Oculto por Defecto en Escritorio */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
}

.nav-toggle span {
    width: 100%;
    height: 3px;
    background: #ffffff;
    border-radius: 3px;
    transition: all 0.3s ease;
}

/* --- DISEÑO RESPONSIVO EXCLUSIVO PARA MÓVILES Y TABLETS (Pantallas menores a 950px) --- */
@media (max-width: 950px) {
    .nav-toggle {
        display: flex;
    }

    .header-nav {
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background: #0b2545;
        flex-direction: column;
        align-items: flex-start;
        padding: 1.25rem 1.5rem;
        gap: 1rem;
        box-shadow: 0 10px 15px rgba(0, 0, 0, 0.2);
        clip-path: polygon(0 0, 100% 0, 100% 0, 0 0);
        transition: clip-path 0.4s ease-in-out;
        pointer-events: none;
        box-sizing: border-box;
    }

    .header-nav.nav-active {
        clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
        pointer-events: auto;
    }

    .user-profile-menu {
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.15);
        padding-left: 0;
        padding-top: 0.85rem;
        width: 100%;
        justify-content: space-between;
    }

    .u-name {
        max-width: 180px;
    }

    /* Animación del botón hamburguesa a 'X' */
    .toggle-active span:nth-child(1) {
        transform: translateY(8.5px) rotate(45deg);
    }
    .toggle-active span:nth-child(2) {
        opacity: 0;
    }
    .toggle-active span:nth-child(3) {
        transform: translateY(-8.5px) rotate(-45deg);
    }
}
/* --- ESTILO DE RESALTADO INTELIGENTE PARA CAMPOS CON DATOS --- */
.input-ref-dinamico {
    background-color: #f8fafc;
    transition: all 0.25s ease;
}

/* Estado cuando el input tiene texto escrito (Resaltado institucional atractivo) */
.input-ref-dinamico.input-con-datos {
    background-color: #f0fdf4 !important; /* Verde muy suave y elegante, o puedes usar #f0f9ff para azul suave */
    border-color: #22c55e !important;     /* Borde verde esmeralda distintivo */
    color: #14532d !important;            /* Texto oscuro altamente legible */
    font-weight: 600 !important;
}

/* Refuerzo para la vista de historial (cuando está deshabilitado / disabled) */
input.input-ref-dinamico:disabled {
    opacity: 1 !important;
    -webkit-text-fill-color: inherit !important;
}

input.input-ref-dinamico.input-con-datos:disabled {
    background-color: #f0fdf4 !important;
    border-color: #86efac !important;
    color: #166534 !important;
}
/* --- ESTILOS PROFESIONALES PARA TEXTAREA AUTOAJUSTABLE EN TABLAS --- */
.input-ref-dinamico.auto-expand {
    width: 100%;
    min-height: 38px;
    max-height: 120px;
    padding: 8px 10px;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.4;
    text-align: left;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: #f8fafc;
    resize: none; /* Evita que el usuario lo deforme manualmente con el mouse */
    overflow-y: hidden;
    box-sizing: border-box;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

/* Efecto al escribir o mantener datos (Resaltado institucional verde suave) */
.input-ref-dinamico.input-con-datos {
    background-color: #f0fdf4 !important;
    border-color: #22c55e !important;
    color: #14532d !important;
    font-weight: 600 !important;
}

/* Compatibilidad absoluta para cuando se consulte en el historial ($es_visor = true) */
textarea.input-ref-dinamico:disabled {
    opacity: 1 !important;
    -webkit-text-fill-color: inherit !important;
}

textarea.input-ref-dinamico.input-con-datos:disabled {
    background-color: #f0fdf4 !important;
    border-color: #86efac !important;
    color: #166534 !important;
}