/* /ELEAM/static/css/theme.css */
/**
 * /ELEAM/static/css/theme.css
 * Sistema de estilos base y temas para el sistema ELEAM
 * CORREGIDO: Layout y conflictos de header
 */

/* ======================================================
   Variables globales del sistema
   ====================================================== */
:root {
    /* Paleta de colores principal */
    --primary: #2c6ea3;         /* Azul profesional */
    --secondary: #6c757d;       /* Gris neutro */
    --success: #28a745;         /* Verde */
    --info: #17a2b8;            /* Azul claro */
    --warning: #d97706;         /* Ámbar — reemplaza el amarillo brillante */
    --danger: #dc3545;          /* Rojo para errores */
    --light: #f8f9fa;
    --dark: #343a40;

    /* Colores por tipo de usuario */
    --user-theme-color: var(--primary);
    --user-theme-color-light: rgba(44, 110, 163, 0.1);
    --user-theme-color-border: rgba(44, 110, 163, 0.25);

    /* Acento para section-cards (borde izquierdo) */
    --section-card-accent: var(--primary);

    /* Palette de ingestas (progresión rojo → ámbar → verde) */
    --intake-none:    #dc3545;  /* 0%  */
    --intake-quarter: #d97706;  /* 25% */
    --intake-half:    #ca8a04;  /* 50% */
    --intake-most:    #0d9488;  /* 75% */
    --intake-full:    #28a745;  /* 100% */

    /* Tipografía */
    --font-family-sans: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-family-mono: SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    /* Layout */
    --header-height: 70px;
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 60px;
    --border-radius: 0.375rem;
    --border-radius-lg: 0.5rem;

    /* Animaciones y sombras */
    --transition-base: all 0.2s ease-in-out;
    --box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --box-shadow-lg: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);

    --title-color: #343a40;
}

/* ======================================================
   Temas específicos por tipo de usuario - más sobrios
   ====================================================== */
body[data-user-type="admin"] {
    --user-theme-color: #495057;                /* Gris oscuro */
    --user-theme-color-light: rgba(73, 80, 87, 0.1);
    --user-theme-color-border: rgba(73, 80, 87, 0.25);
}

body[data-user-type="professional"] {
    --user-theme-color: #2c6ea3;                /* Azul profesional */
    --user-theme-color-light: rgba(44, 110, 163, 0.1);
    --user-theme-color-border: rgba(44, 110, 163, 0.25);
}

body[data-user-type="staff"] {
    --user-theme-color: #17a2b8;                /* Azul claro */
    --user-theme-color-light: rgba(23, 162, 184, 0.1);
    --user-theme-color-border: rgba(23, 162, 184, 0.25);
}

body[data-user-type="family"] {
    --user-theme-color: #5a8d57;                /* Verde oscuro - no tan llamativo */
    --user-theme-color-light: rgba(90, 141, 87, 0.1);
    --user-theme-color-border: rgba(90, 141, 87, 0.25);
}

/* ======================================================
   RESET Y LAYOUT BASE CORREGIDO
   ====================================================== */
* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-family-sans);
    background-color: #f5f5f5;
    color: var(--dark);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a {
    text-decoration: none;
    transition: var(--transition-base);
    color: var(--user-theme-color);
}

a:hover {
    color: var(--user-theme-color);
    text-decoration: underline;
}

/* ======================================================
   HEADER CORREGIDO
   ====================================================== */
.header {
    position: sticky;
    top: 0;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    height: var(--header-height);
    width: 100%;
}

.header .container-fluid {
    height: 100%;
    max-width: none;
    padding: 0 1rem;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    width: 100%;
}

/* Logo y controles izquierda */
.header-content > div:first-child {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Botones de toggle */
.sidebar-toggle,
.mobile-menu-toggle {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background-color: #fff;
    transition: var(--transition-base);
    color: var(--primary);
    cursor: pointer;
}

.sidebar-toggle:hover,
.mobile-menu-toggle:hover {
    background-color: var(--user-theme-color-light);
    color: var(--user-theme-color);
}

/* Brand/Logo */
.brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: var(--transition-base);
}

.brand-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.brand:hover .brand-logo {
    transform: scale(1.02);
}

/* Centro activo */
.center-selector {
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: var(--transition-base);
}

.center-selector:hover {
    opacity: 0.8;
}

/* Dropdown de usuario */
.user-dropdown {
    display: flex;
    align-items: center;
    background: none;
    border: none;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition-base);
    color: var(--dark);
}

.user-dropdown:hover {
    background-color: var(--user-theme-color-light);
    color: var(--user-theme-color);
}

/* ======================================================
   SIDEBAR CORREGIDO
   ====================================================== */
.sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    background-color: #fff;
    box-shadow: var(--box-shadow);
    z-index: 990;
    transition: var(--transition-base);
    overflow-y: auto;
}

.sidebar-sticky {
    padding: 1.5rem 0;
}

.sidebar .nav-link {
    padding: 0.75rem 1.5rem;
    color: var(--dark);
    font-weight: 500;
    transition: var(--transition-base);
    display: flex;
    align-items: center;
}

.sidebar .nav-link:hover {
    background-color: var(--user-theme-color-light);
    color: var(--user-theme-color);
}

.sidebar .nav-link.active {
    background-color: var(--user-theme-color-light);
    color: var(--user-theme-color);
    border-left: 3px solid var(--user-theme-color);
}

.sidebar .nav-link i {
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

.sidebar .nav-header {
    padding: 0.75rem 1.5rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--secondary);
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* Nueva Farmacia — iconos y enlaces en negro para diferenciar de medications */
.sidebar .nav-link.nueva-farmacia {
    color: #000;
}

.sidebar .nav-link.nueva-farmacia:hover {
    background-color: rgba(0, 0, 0, 0.07);
    color: #000;
}

.sidebar .nav-link.nueva-farmacia.active {
    background-color: rgba(0, 0, 0, 0.1);
    color: #000;
    border-left-color: #000;
}

.sidebar .nav-link.nueva-farmacia i {
    color: #000;
}

/* Sidebar colapsado */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .content-wrapper {
    margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .sidebar .nav-header {
    display: none;
}

body.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding: 0.75rem;
}

body.sidebar-collapsed .sidebar .nav-link i {
    margin-right: 0;
    font-size: 1.25rem;
}

/* Botón de colapso/despliegue, ahora dentro del propio sidebar */
.sidebar-toggle-wrapper {
    display: flex;
    justify-content: flex-end;
    padding: 0 1rem 1rem;
}

body.sidebar-collapsed .sidebar-toggle-wrapper {
    justify-content: center;
    padding: 0 0 1rem;
}

.sidebar-toggle-wrapper .sidebar-toggle {
    color: var(--dark);
}

.sidebar-toggle i {
    transition: var(--transition-base);
}

body.sidebar-collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

/* ======================================================
   CONTENIDO PRINCIPAL CORREGIDO
   ====================================================== */
.content-wrapper {
    margin-left: var(--sidebar-width);
    padding: 0;
    flex: 1;
    transition: var(--transition-base);
    min-height: calc(100vh - var(--header-height));
}

/* ======================================================
   Componentes reutilizables
   ====================================================== */

/* --- Cards --- */
.card {
    border-radius: var(--border-radius-lg);
    border: none;
    box-shadow: var(--box-shadow);
    transition: var(--transition-base);
    overflow: hidden;
}

.card:hover {
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
}

.card-header {
    background-color: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
    padding: 1rem 1.25rem;
}

.card-body {
    padding: 1.25rem;
}

/* --- Buttons --- */
.btn {
    border-radius: var(--border-radius);
    padding: 0.5rem 1rem;
    font-weight: 500;
    transition: var(--transition-base);
    /* Sin esto el navegador táctil retrasa el click ~300 ms esperando un
       doble toque, y si llega lo convierte en zoom descartando el click. */
    touch-action: manipulation;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--box-shadow);
}

/* En dispositivos táctiles el :hover se queda "pegado" al botón tocado: el
   desplazamiento se vuelve permanente y el siguiente toque puede caer sobre
   el botón vecino de un btn-group. */
@media (hover: none) {
    .btn:hover {
        transform: none;
        box-shadow: none;
    }
}

.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background-color: var(--primary);
    filter: brightness(90%);
    border-color: var(--primary);
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* --- Forms --- */
.form-control {
    border-radius: var(--border-radius);
    padding: 0.5rem 0.75rem;
    border: 1px solid #ced4da;
    transition: var(--transition-base);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.25rem rgba(44, 110, 163, 0.25);
}

.form-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--dark);
}

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* --- Tables --- */
.table {
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    background-color: rgba(0, 0, 0, 0.02);
}

.table tbody tr {
    transition: background-color 0.15s ease;
}

.table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.025);
}

/* --- Badges --- */
.badge {
    font-weight: 600;
    padding: 0.35em 0.65em;
    border-radius: 0.25rem;
}

/* ======================================================
   Utilidades
   ====================================================== */
.user-theme-color {
    color: var(--user-theme-color) !important;
}

.user-theme-bg {
    background-color: var(--user-theme-color) !important;
    color: #fff !important;
}

.user-theme-border {
    border-color: var(--user-theme-color) !important;
}

/* ======================================================
   Responsive CORREGIDO
   ====================================================== */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    body.sidebar-show .sidebar {
        transform: translateX(0);
    }
    
    .content-wrapper {
        margin-left: 0 !important;
    }
}

@media (max-width: 768px) {
    .card-header {
        padding: 0.75rem 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .brand-logo {
        height: 30px;
    }
    
    .header .container-fluid {
        padding: 0 0.5rem;
    }
}

/* ======================================================
   CORRECCIONES ESPECÍFICAS PARA FORMULARIOS
   ====================================================== */

/* Evitar conflictos con formularios */
.form-card {
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.08) !important;
    border-radius: 12px !important;
}

.form-card:hover {
    transform: none !important;
}

/* Asegurar que los contenedores de formulario respeten el layout */
.container-fluid {
    width: 100%;
    padding-right: 1rem;
    padding-left: 1rem;
    margin-right: auto;
    margin-left: auto;
}

/* Corregir paddings específicos */
.page-header {
    margin-bottom: 2rem;
    padding: 1.5rem 0;
}

/* Animaciones */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}