/**
 * BOTTOM NAVIGATION - Sistema unificado para Claudia
 * Version: 1.0
 * Estilo: Dashboard mobile nav con iconos SVG
 */

/* =============================================
   CSS VARIABLES
   ============================================= */
:root {
    --bottom-nav-height: 64px;
    --bottom-nav-bg: #0D1F3C;
    --bottom-nav-border: rgba(255, 255, 255, 0.1);
    --bottom-nav-accent: #00D4AA;
    --bottom-nav-accent-bg: rgba(0, 212, 170, 0.15);
    --bottom-nav-inactive: rgba(255, 255, 255, 0.5);
    --bottom-nav-transition: 200ms ease-out;
    /* Mobile spacing - shared variable for consistent bottom space */
    --mobile-bottom-space: calc(var(--bottom-nav-height) + 20px);
    /* Z-index hierarchy - organized layers */
    --z-bottom-nav: 1000;
    --z-bottom-nav-dropdown: 998;
    --z-fab: 1050;
    --z-fab-backdrop: 1049;
    --z-scroll-top: 1040;
}

/* =============================================
   BODY PADDING FOR BOTTOM NAV
   ============================================= */
body.has-bottom-nav {
    padding-bottom: var(--mobile-bottom-space);
}

/* =============================================
   BOTTOM NAVIGATION BAR
   ============================================= */
.bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bottom-nav-bg);
    border-top: 1px solid var(--bottom-nav-border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    z-index: var(--z-bottom-nav);
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* =============================================
   NAV ITEMS
   ============================================= */
.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 12px;
    transition: all var(--bottom-nav-transition);
    min-width: 56px;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.bottom-nav-item:active {
    transform: scale(0.95);
}

/* Icon */
.bottom-nav-item .nav-icon {
    width: 24px;
    height: 24px;
    color: var(--bottom-nav-inactive);
    transition: color var(--bottom-nav-transition), transform var(--bottom-nav-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.bottom-nav-item .nav-icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* Label */
.bottom-nav-item .nav-label {
    font-size: 10px;
    font-weight: 500;
    color: var(--bottom-nav-inactive);
    transition: color var(--bottom-nav-transition);
    white-space: nowrap;
    text-align: center;
}

/* Hover state */
.bottom-nav-item:hover .nav-icon,
.bottom-nav-item:hover .nav-label {
    color: rgba(255, 255, 255, 0.7);
}

/* Active state */
.bottom-nav-item.active {
    background: var(--bottom-nav-accent-bg);
}

.bottom-nav-item.active .nav-icon {
    color: var(--bottom-nav-accent);
    transform: scale(1.1);
}

.bottom-nav-item.active .nav-label {
    color: var(--bottom-nav-accent);
}

/* =============================================
   VIEW CONTENT PANELS
   ============================================= */
.view-content {
    display: none;
    opacity: 0;
    transition: opacity var(--bottom-nav-transition);
}

.view-content.active {
    display: block;
    opacity: 1;
    animation: viewFadeIn 0.2s ease-out;
}

@keyframes viewFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================
   ACCESSIBILITY
   ============================================= */
.bottom-nav-item:focus-visible {
    outline: 2px solid var(--bottom-nav-accent);
    outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 480px) {
    .bottom-nav-item {
        min-width: 48px;
        padding: 6px 8px;
    }
    
    .bottom-nav-item .nav-label {
        font-size: 9px;
    }
}

@media (min-width: 769px) {
    /* On desktop, bottom nav still works */
    .bottom-nav {
        max-width: 100%;
    }
}

/* =============================================
   BOTTOM NAV DROPDOWN - Servidores
   ============================================= */
.bottom-nav-item.has-dropdown {
    position: relative;
}

.bottom-nav-dropdown {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) scale(0.95);
    min-width: 200px;
    max-width: 280px;
    max-height: 60vh;
    overflow-y: auto;
    background: var(--bottom-nav-bg);
    border: 1px solid var(--bottom-nav-border);
    border-radius: 12px;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    z-index: var(--z-bottom-nav-dropdown);
}

.bottom-nav-dropdown.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1);
}

/* Dropdown Items */
.dropdown-server-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.dropdown-server-item:last-child {
    border-bottom: none;
}

.dropdown-server-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.dropdown-server-item:active {
    background: rgba(255, 255, 255, 0.12);
}

.dropdown-server-item.active {
    background: var(--bottom-nav-accent-bg);
}

/* Status Indicator */
.server-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.server-status-dot.online {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.server-status-dot.warning {
    background: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

.server-status-dot.offline {
    background: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

/* Server Info */
.server-info {
    flex: 1;
    min-width: 0;
}

.server-name {
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    margin-bottom: 2px;
}

.server-role {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Notification Badge */
.server-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
    flex-shrink: 0;
}

.server-badge.hidden {
    display: none;
}

/* Divider */
.dropdown-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 4px 0;
}

/* Add Instance Button */
.dropdown-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    color: var(--bottom-nav-accent);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}

.dropdown-add-btn:hover {
    background: var(--bottom-nav-accent-bg);
}

/* Badge on nav item */
.bottom-nav-item .nav-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bottom-nav-item .nav-badge.hidden {
    display: none;
}

/* Arrow indicator for dropdown */
.bottom-nav-item.has-dropdown .nav-icon {
    position: relative;
}

.bottom-nav-item.has-dropdown.dropdown-open .nav-icon {
    color: var(--bottom-nav-accent);
}

/* Hide bottom nav on desktop */
@media (min-width: 769px) {
    .bottom-nav {
        display: none;
    }
}

/* =============================================
   MOBILE LAYOUT OPTIMIZATION (2-4 buttons)
   ============================================= */
@media (max-width: 768px) {
    /* Mostrar bottom-nav en móvil */
    .bottom-nav {
        display: flex !important;
        justify-content: space-around;
        gap: 4px;
    }

    .bottom-nav-item {
        flex: 1;
        max-width: none;
        min-width: 60px;
    }

    /* Iconos adaptativos */
    .bottom-nav-item .nav-icon {
        width: 24px;
        height: 24px;
    }

    .bottom-nav-item .nav-icon svg {
        width: 24px;
        height: 24px;
    }

    /* Labels compactos */
    .bottom-nav-item .nav-label {
        font-size: 10px;
        font-weight: 500;
    }

    /* Para páginas con solo 2 botones */
    .bottom-nav:has(.bottom-nav-item:nth-child(2):last-child) .bottom-nav-item {
        max-width: 45%;
        min-width: 120px;
    }

    .bottom-nav:has(.bottom-nav-item:nth-child(2):last-child) .bottom-nav-item .nav-icon {
        width: 28px;
        height: 28px;
    }

    .bottom-nav:has(.bottom-nav-item:nth-child(2):last-child) .bottom-nav-item .nav-label {
        font-size: 12px;
        font-weight: 600;
    }

    /* Dropdowns - ancho maximo responsivo */
    .bottom-nav-dropdown {
        min-width: 220px;
        max-width: calc(100vw - 32px);
    }

    /* Dropdown del primer boton (Servidores) - alinear a la izquierda */
    .bottom-nav-item:first-child .bottom-nav-dropdown {
        left: 0;
        right: auto;
        transform: scale(0.95);
    }

    .bottom-nav-item:first-child .bottom-nav-dropdown.visible {
        transform: scale(1);
    }

    /* Dropdown del segundo boton (Instancia Activa) - alinear a la derecha */
    .bottom-nav-item:last-child .bottom-nav-dropdown {
        left: auto;
        right: 0;
        transform: scale(0.95);
    }

    .bottom-nav-item:last-child .bottom-nav-dropdown.visible {
        transform: scale(1);
    }
}

/* =============================================
   DROPDOWN VIEWPORT CONSTRAINTS
   ============================================= */
@media (max-width: 480px) {
    /* Ensure dropdowns don't exceed viewport on small screens */
    .bottom-nav-dropdown {
        max-height: 50vh;
        max-width: calc(100vw - 24px) !important;
        min-width: 180px !important;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Add safe area at bottom for iOS */
    .bottom-nav-dropdown::after {
        content: '';
        display: block;
        height: env(safe-area-inset-bottom, 0);
    }
}

/* Scrollbar styling for dropdowns */
.bottom-nav-dropdown::-webkit-scrollbar {
    width: 4px;
}

.bottom-nav-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.bottom-nav-dropdown::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.bottom-nav-dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* =============================================
   ACTIVE INSTANCE BUTTON
   ============================================= */

/* Instance status dot (in button) */
.instance-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-bottom: 4px;
}

.instance-status-dot.online {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
    animation: pulse-green 2s infinite;
}

.instance-status-dot.warning {
    background: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
}

.instance-status-dot.offline {
    background: #6b7280;
    box-shadow: none;
}

@keyframes pulse-green {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Dropdown header */
.dropdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--bottom-nav-accent);
}

.dropdown-header .instance-status-dot {
    margin-bottom: 0;
}

/* Command items */
.dropdown-command-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.dropdown-command-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.dropdown-command-item:active {
    background: rgba(255, 255, 255, 0.12);
}

.dropdown-command-item .cmd-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.dropdown-command-item .cmd-label {
    font-size: 13px;
    color: #fff;
}

/* Empty state */
.dropdown-empty {
    padding: 16px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
}

/* Action button (clear context) */
.dropdown-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    color: #ef4444;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.dropdown-action-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

.dropdown-action-btn svg {
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}
