/* ============================================================
   dock.css — Mac-style ERP Dock
   ============================================================ */

/* --- Botón flotante para restaurar el dock --- */
.dock-restore-btn {
    position: fixed;
    bottom: 1rem;
    left: 0.5rem; /* deja espacio al botón de Smartsupp (~60px + gap), ambos del lado izquierdo */
    z-index: 1200;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
    color: #1c1c1e;
}

.dock-restore-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}

/* --- Wrapper fijo inferior del dock --- */
.dock-wrapper {
    position: fixed;
    bottom: .5rem;
    left: 0;
    right: 0;
    margin: 0 auto;
    z-index: 1100;
    display: flex;
    justify-content: center;
    pointer-events: none; /* el contenedor no captura clicks, los items sí */
}

/* --- Contenedor principal del dock (estilo glassmorphism) --- */
.dock-container {
    --icon-w: 3rem;
    background: rgb(135 135 135 / 18%);
   /*  box-shadow: 0 4px 30px rgba(0,0,0,0.07), 0 0 0.8em 0.8em rgba(0,0,0,0.12);
   backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);*/
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 1.1rem;
    height: var(--icon-w);
    overflow: visible;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    padding: 0 .4rem;
    gap: 0;
    pointer-events: all;
    transition: box-shadow .3s ease;
    max-width: 95vw;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(14px);
}

/* --- Separador vertical entre secciones del dock --- */
.dock-separator {
    width: 1px;
    height: 60%;
    background: rgba(255,255,255,0.35);
    margin: 0 .3rem;
    align-self: center;
    flex-shrink: 0;
}

/* --- Ítem individual del dock --- */
.dock-item {
    position: relative;
    min-width: var(--icon-w);
    height: var(--icon-w);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    transform-origin: bottom;
    transition: transform .25s ease, margin .25s ease;
    cursor: pointer;
    flex-shrink: 0;
}

/* Hover principal */
.dock-item:hover {
    transform: scale(2.5);
    margin-inline: 1.3rem;
    z-index: 10;
}

/* Vecinos inmediatos */
.dock-item:hover + .dock-item,
.dock-item:has(+ .dock-item:hover) {
    transform: scale(1.9);
    margin-inline: .65rem;
}

/* Segundos vecinos */
.dock-item:hover + .dock-item + .dock-item,
.dock-item:has(+ .dock-item + .dock-item:hover) {
    transform: scale(1.45);
    margin-inline: .3rem;
}

/* Terceros vecinos */
.dock-item:hover + .dock-item + .dock-item + .dock-item,
.dock-item:has(+ .dock-item + .dock-item + .dock-item:hover) {
    transform: scale(1.15);
    margin-inline: .1rem;
}

/* --- Imagen/ícono del ítem --- */
.dock-item-img {
    position: absolute;
    bottom: -7%;
    left: 50%;
    translate: -50% 0;
    width: 110%;
    aspect-ratio: 1 / 1;
    border-radius: .6em;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: rgba(200,200,210,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: translate .1s linear;
    overflow: hidden;
}

.dock-item-img i,
.dock-item-img svg {
    font-size: 1.4rem;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,.4);
}

.dock-item:active .dock-item-img {
    translate: -50% 3%;
}

/* --- Tooltip/label --- */
.dock-item-label {
    --bg: rgba(200, 200, 200, 0.85);
    position: absolute;
    bottom: calc(100% + .3rem);
    left: 50%;
    translate: -50% 0;
    font-size: .42rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: #1c1c1e;
    background: var(--bg);
    padding: .15rem .45rem;
    border-radius: .4em;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
    z-index: 20;
}

.dock-item-label::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    margin-left: -3px;
    margin-bottom: -5px;
    border: 3px solid transparent;
    border-top-color: var(--bg);
    border-bottom: 0;
}

.dock-item:hover .dock-item-label {
    opacity: 1;
}

/* --- Indicador de ítem activo (punto debajo) --- */
.dock-item-dot {
    width: 4px;
    height: 4px;
    background: rgba(80,80,80,0.7);
    border-radius: 50%;
    position: absolute;
    bottom: 1px;
    left: 50%;
    translate: -50% 0;
}

/* --- Submenú flotante (empresas/sucursales/módulos) --- */
.dock-submenu {
    position: absolute;
    bottom: calc(100% + 0.6rem);
    left: 50%;
    background: rgba(245, 245, 247, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 0.4rem 0.3rem;
    min-width: 90px;
    max-width: 130px;
    max-height: 45vh; /* Usa el 45% de la altura de la pantalla para permitir scroll */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* CRÍTICO: Habilita scroll con inercia en iOS/Android */
    z-index: 9999;
    transform: translateX(-50%);
    animation: dockSubMenuIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Fuerza al ícono padre a mantenerse grande cuando el submenú está abierto */
.dock-item-open {
    transform: scale(1.25) !important;
    margin-inline: 1rem !important;
    z-index: 100 !important;
}

@keyframes dockSubMenuIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

.dock-submenu-title {
    font-size: 0.5rem;
    font-weight: 700;
    color: #86868b;
    padding: 0.1rem 0.4rem 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: center;
}

.dock-submenu-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.4rem;
    border-radius: 0.4rem;
    cursor: pointer;
    transition: background 0.15s ease;
    font-size: 0.55rem;
    color: #1c1c1e;
    white-space: nowrap;
}

    .dock-submenu-item:hover, .dock-submenu-item:active {
        background: rgba(0, 122, 255, 0.15); /* Color de selección tipo Apple */
    }

    .dock-submenu-item img {
        width: 1.2rem;
        height: 1.2rem;
        border-radius: 0.2rem;
        object-fit: cover;
        flex-shrink: 0;
    }

.dock-submenu-item-icon {
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 0.2rem;
    background: #e5e5ea;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.6rem;
    color: #636366;
}

/* --- Fondo transparente para iconos con imagen local --- */
.dock-item-img[style*="background-image"] {
    background-color: transparent;
}

/* --- Iconos de módulos personalizados sin imagen --- */
.dock-icon-module    { background: linear-gradient(145deg, #30d158, #32ade6); }

/* --- Overlay para cerrar submenús al hacer click fuera --- */
.dock-overlay {
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: transparent;
}


/* ============================================================
   Mobile & Touch Device Fixes
   ============================================================ */
.dock-modules-mobile {
    display: none;
}

@media (max-width: 768px) {
    /* 1. Mostrar solo el ícono agrupado de módulos */
    .dock-modules-mobile {
        display: flex !important;
    }

    .dock-module-item-desktop {
        display: none !important;
    }

    .dock-modules-separator {
        display: none !important;
    }

    .dock-wrapper {
        right: 70px; /* deja espacio al botón de Smartsupp, ahora del lado izquierdo */
    }

    /* 2. CRÍTICO: Eliminar backdrop-filter en móvil */
    /* backdrop-filter crea un "containing block" que rompe position: fixed */
    /* Sin esto, el submenú queda atrapado dentro del overflow-y: hidden del dock */
    .dock-container {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    /* 3. Permitir deslizamiento horizontal (swipe) del dock */
    .dock-container {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        scroll-snap-type: x proximity !important;
        height: auto !important;
        min-height: calc(var(--icon-w, 3rem) + 1rem);
        padding-top: 0.3rem !important;
        padding-bottom: 0.3rem !important;
        align-items: flex-end;
    }

    /* 4. Submenú con posición FIJA en móvil (ahora SÍ funcionará correctamente) */
    .dock-submenu {
        position: fixed !important;
        bottom: 85px !important; /* Ajusta si el submenú queda muy arriba/abajo del dock */
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 99999 !important;
        max-height: 60vh !important;
        width: 75vw !important;
        max-width: 280px !important;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* 5. EVITAR que los íconos se agranden en móvil (TAMAÑO NORMAL) */
    /* Incluimos TODAS las reglas: hover, active, open y los VECINOS */
    .dock-item:hover,
    .dock-item:active,
    .dock-item-open,
    .dock-item:hover + .dock-item,
    .dock-item:has(+ .dock-item:hover),
    .dock-item:hover + .dock-item + .dock-item,
    .dock-item:has(+ .dock-item + .dock-item:hover),
    .dock-item:hover + .dock-item + .dock-item + .dock-item,
    .dock-item:has(+ .dock-item + .dock-item + .dock-item:hover) {
        transform: none !important;
        margin-inline: 0 !important;
        z-index: auto !important;
    }

    /* Asegurar que los ítems del dock no se encojan al deslizar */
    .dock-item {
        scroll-snap-align: center;
        flex-shrink: 0;
    }
}