/* ==================== ESTILOS DA SIDEBAR ==================== */
/*
 * Todos os estilos relacionados ao menu lateral (sidebar) da aplicação.
 * Inclui: estrutura, navegação, logo, estados hover/collapsed e responsividade.
 */

/* ==================== SIDEBAR CONTAINER ==================== */

.sidebar {
    flex-shrink: 0;
    width: var(--sidebar-collapsed);
    height: 100vh;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-speed) var(--transition-ease);
    z-index: 1000;
    overflow: hidden;
}

/* Comportamento hover para desktop */
@media (min-width: 769px) {
    .sidebar:hover {
        width: var(--sidebar-width);
    }
}

/* ==================== HEADER DA SIDEBAR (Logo) ==================== */

.sidebar-header {
    padding: 24px 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    overflow: hidden;
}

.logo-icon {
    min-width: 32px;
    height: 32px;
    background: var(--text-primary);
    color: var(--bg-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
}

.logo-text {
    font-size: 16px;
    font-weight: 600;
    opacity: 1;
    transition: opacity var(--transition-speed) var(--transition-ease);
    white-space: nowrap;
}

/* Logo text collapsed: esconde com opacity */
.sidebar .logo-text {
    opacity: 0;
    pointer-events: none;
}

@media (min-width: 769px) {
    .sidebar:hover .logo-text {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 768px) {
    .sidebar.mobile-active .logo-text {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ==================== NAVEGAÇÃO DA SIDEBAR ==================== */

.sidebar-nav {
    flex: 1 1 0;
    min-height: 0;
    padding: 24px 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar customizada */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* Firefox scrollbar */
.sidebar-nav {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* Scrollbar ainda mais minimalista no mobile */
@media (max-width: 768px) {
    .sidebar-nav::-webkit-scrollbar {
        width: 3px;
    }
}

/* ==================== LISTA DE NAVEGAÇÃO ==================== */

.nav-list {
    list-style: none;
}

.nav-item {
    margin-bottom: 4px;
    padding: 0 12px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: background-color var(--transition-speed) var(--transition-ease),
                color var(--transition-speed) var(--transition-ease);
    position: relative;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link:hover {
    background-color: var(--hover);
    color: var(--text-primary);
}

.nav-item.active .nav-link {
    background-color: var(--active);
    color: var(--text-primary);
}

/* ==================== ÍCONES E TEXTOS DA NAVEGAÇÃO ==================== */

.nav-icon {
    min-width: 20px;
    width: 20px;
    height: 20px;
    stroke-width: 2;
    flex-shrink: 0;
}

.nav-text {
    font-size: 14px;
    font-weight: 500;
    opacity: 1;
    transition: opacity var(--transition-speed) var(--transition-ease);
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
}

/* Nav text collapsed: esconde com opacity */
.sidebar .nav-text {
    opacity: 0;
    pointer-events: none;
}

@media (min-width: 769px) {
    .sidebar:hover .nav-text {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 768px) {
    .sidebar.mobile-active .nav-text {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ==================== NAV ITEM WITH HISTORY ==================== */

.nav-item-with-history {
    position: relative;
    padding: 0 12px;
}

/* ==================== CHAT HISTORY CONTAINER ==================== */

.chat-history-container {
    padding: 0;
    margin-top: 0;
    margin-left: -12px;
    margin-right: -12px;
    opacity: 0;
    pointer-events: none;
    max-height: 0;
    overflow: hidden;
    transform: translateY(-8px);
    transition: opacity 0.25s var(--transition-ease),
                max-height 0.35s var(--transition-ease),
                padding 0.3s var(--transition-ease),
                transform 0.3s var(--transition-ease),
                margin-top 0.3s var(--transition-ease);
}

/* Esconder container quando estiver vazio (sem chats) */
.chat-history-container.empty {
    display: none;
}

/* Mostrar container quando sidebar expandir (hover ou mobile-active) */
@media (min-width: 769px) {
    .sidebar:hover .nav-item-with-history .chat-history-container:not(.empty) {
        opacity: 1;
        pointer-events: auto;
        max-height: 400px;
        padding: 12px 12px 8px 12px;
        transform: translateY(0);
        margin-top: 8px;
    }
}

@media (max-width: 768px) {
    .sidebar.mobile-active .nav-item-with-history .chat-history-container:not(.empty) {
        opacity: 1;
        pointer-events: auto;
        max-height: 400px;
        padding: 12px 12px 8px 12px;
        transform: translateY(0);
        margin-top: 8px;
    }
}

.chat-history-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    padding: 0 4px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.2s var(--transition-ease),
                transform 0.25s var(--transition-ease);
}

@media (min-width: 769px) {
    .sidebar:hover .chat-history-title {
        opacity: 1;
        transform: translateY(0);
        transition-delay: 0.1s;
    }
}

@media (max-width: 768px) {
    .sidebar.mobile-active .chat-history-title {
        opacity: 1;
        transform: translateY(0);
        transition-delay: 0.1s;
    }
}

.chat-history-list {
    max-height: 320px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

/* Scrollbar minimalista */
.chat-history-list::-webkit-scrollbar {
    width: 4px;
}

.chat-history-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-history-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
    transition: background var(--transition-speed) var(--transition-ease);
}

.chat-history-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Firefox scrollbar */
.chat-history-list {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* Scrollbar ainda mais minimalista no mobile */
@media (max-width: 768px) {
    .chat-history-list::-webkit-scrollbar {
        width: 3px;
    }
}

.chat-history-item-container {
    display: flex;
    align-items: stretch;
    gap: 0;
    margin-bottom: 4px;
    position: relative;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-3px);
    transition: opacity 0.2s var(--transition-ease),
                transform 0.25s var(--transition-ease);
}

@media (min-width: 769px) {
    .sidebar:hover .chat-history-item-container {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
    }
    
    /* Animação escalonada para os itens - efeito cascata */
    .sidebar:hover .chat-history-item-container:nth-child(1) {
        transition-delay: 0.15s;
    }
    .sidebar:hover .chat-history-item-container:nth-child(2) {
        transition-delay: 0.18s;
    }
    .sidebar:hover .chat-history-item-container:nth-child(3) {
        transition-delay: 0.21s;
    }
    .sidebar:hover .chat-history-item-container:nth-child(4) {
        transition-delay: 0.24s;
    }
    .sidebar:hover .chat-history-item-container:nth-child(5) {
        transition-delay: 0.27s;
    }
    .sidebar:hover .chat-history-item-container:nth-child(n+6) {
        transition-delay: 0.3s;
    }
}

@media (max-width: 768px) {
    .sidebar.mobile-active .chat-history-item-container {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
    }
    
    /* Animação escalonada para os itens no mobile */
    .sidebar.mobile-active .chat-history-item-container:nth-child(1) {
        transition-delay: 0.15s;
    }
    .sidebar.mobile-active .chat-history-item-container:nth-child(2) {
        transition-delay: 0.18s;
    }
    .sidebar.mobile-active .chat-history-item-container:nth-child(3) {
        transition-delay: 0.21s;
    }
    .sidebar.mobile-active .chat-history-item-container:nth-child(4) {
        transition-delay: 0.24s;
    }
    .sidebar.mobile-active .chat-history-item-container:nth-child(5) {
        transition-delay: 0.27s;
    }
    .sidebar.mobile-active .chat-history-item-container:nth-child(n+6) {
        transition-delay: 0.3s;
    }
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color var(--transition-speed) var(--transition-ease),
                color var(--transition-speed) var(--transition-ease);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-decoration: none;
    border: none;
    background: none;
    flex: 1;
    min-width: 0;
}


.chat-history-item:hover {
    background-color: var(--hover);
    color: var(--text-primary);
}

.chat-history-item.active {
    background-color: var(--active);
    color: var(--text-primary);
}

/* Quando o item está em hover, aplicar background também no botão para unificar visualmente */
.chat-history-item-container:hover .chat-history-item {
    border-radius: 8px 0 0 8px;
}

.chat-history-item-container:hover .chat-history-delete-btn {
    border-radius: 0 8px 8px 0;
}

.chat-history-item-container:hover .chat-history-item:hover ~ .chat-history-delete-btn {
    background-color: var(--hover);
}

/* Quando o item está ativo, aplicar background no botão também */
.chat-history-item-container .chat-history-item.active ~ .chat-history-delete-btn {
    background-color: var(--active);
}

/* Input de edição do nome do chat */
.chat-history-name-input {
    flex: 1;
    min-width: 0;
    width: 100%;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--text-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition-speed) var(--transition-ease);
}

.chat-history-name-input:focus {
    border-bottom-color: var(--text-primary);
}

.chat-history-name-input::placeholder {
    color: var(--text-secondary);
}

.chat-history-icon {
    min-width: 18px;
    width: 18px;
    height: 18px;
    stroke-width: 2;
    flex-shrink: 0;
    color: inherit;
}

.chat-history-name {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

/* ==================== BOTÃO DE DELETAR CHAT ==================== */

.chat-history-delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    min-width: 36px;
    padding: 10px 8px;
    background: none;
    border: none;
    color: #ef4444; /* Vermelho para lixeira */
    cursor: pointer;
    border-radius: 0 8px 8px 0;
    transition: background-color var(--transition-speed) var(--transition-ease),
                color var(--transition-speed) var(--transition-ease),
                opacity 0.2s var(--transition-ease);
    opacity: 0;
    pointer-events: none;
    flex-shrink: 0;
    align-self: stretch;
}

/* Mostrar botão quando o container estiver visível E o usuário passar o mouse sobre ele (desktop) */
@media (min-width: 769px) {
    .chat-history-item-container:hover .chat-history-delete-btn {
        opacity: 1;
        pointer-events: auto;
    }
}

/* No mobile: sempre visível */
@media (max-width: 768px) {
    .chat-history-delete-btn {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Garantir que o botão apareça quando estiver em modo de confirmação */
.chat-history-delete-btn.confirming {
    opacity: 1;
    pointer-events: auto;
    background-color: rgba(34, 197, 94, 0.1); /* Verde claro para confirmação */
    color: #22c55e; /* Verde para "done" */
}

.chat-history-delete-btn:hover {
    background-color: rgba(239, 68, 68, 0.1); /* Vermelho claro no hover */
}

.chat-history-delete-btn:active {
    background-color: rgba(239, 68, 68, 0.2); /* Vermelho mais escuro no active */
}

.chat-history-delete-btn.confirming:hover {
    background-color: rgba(34, 197, 94, 0.15); /* Verde mais escuro no hover quando confirmando */
}

/* Quando o item está em hover, aplicar background também no botão para unificar visualmente */
.chat-history-item-container:hover .chat-history-item {
    border-radius: 8px 0 0 8px;
}

.chat-history-item-container:hover .chat-history-delete-btn {
    border-radius: 0 8px 8px 0;
}

.chat-history-delete-icon {
    width: 14px;
    height: 14px;
    min-width: 14px;
    stroke-width: 2;
}

/* ==================== BOTÃO DE EDITAR CHAT ==================== */

.chat-history-edit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    min-width: 36px;
    padding: 10px 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 0;
    transition: background-color var(--transition-speed) var(--transition-ease),
                color var(--transition-speed) var(--transition-ease),
                opacity 0.2s var(--transition-ease);
    opacity: 0;
    pointer-events: none;
    flex-shrink: 0;
    align-self: stretch;
}

/* Mostrar botão quando o container estiver visível E o usuário passar o mouse sobre ele (desktop) */
@media (min-width: 769px) {
    .chat-history-item-container:hover .chat-history-edit-btn {
        opacity: 1;
        pointer-events: auto;
    }
}

/* No mobile: sempre visível */
@media (max-width: 768px) {
    .chat-history-edit-btn {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Garantir que o botão apareça quando estiver em modo de edição */
.chat-history-edit-btn.editing {
    opacity: 1;
    pointer-events: auto;
    background-color: rgba(59, 130, 246, 0.1); /* Azul claro para edição */
    color: #3b82f6; /* Azul para lápis/done */
}

.chat-history-edit-btn:hover {
    background-color: rgba(59, 130, 246, 0.1); /* Azul claro no hover */
    color: #3b82f6;
}

.chat-history-edit-btn:active {
    background-color: rgba(59, 130, 246, 0.2); /* Azul mais escuro no active */
}

.chat-history-edit-icon {
    width: 14px;
    height: 14px;
    min-width: 14px;
    stroke-width: 2;
}

/* Quando o item está em hover, aplicar background também no botão de editar */
.chat-history-item-container:hover .chat-history-item:hover ~ .chat-history-edit-btn {
    background-color: var(--hover);
}

/* Quando o item está ativo, aplicar background no botão de editar também */
.chat-history-item-container .chat-history-item.active ~ .chat-history-edit-btn {
    background-color: var(--active);
}

/* Ajustar bordas quando há botão de editar */
.chat-history-item-container:hover .chat-history-edit-btn {
    border-radius: 0;
}

.chat-history-item-container:hover .chat-history-delete-btn {
    border-radius: 0 8px 8px 0;
}

/* ==================== FOOTER DA SIDEBAR (Perfil do Usuário) ==================== */

.sidebar-footer {
    padding: 12px;
    margin-top: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: 8px;
}

/* Avatar do usuário */
.user-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    box-sizing: border-box;
}

/* Borda Free - Cinza */
.user-avatar--free {
    background: var(--text-primary);
    border: 2px solid var(--border);
}

/* Borda Plus - Gradiente Auto */
.user-avatar--plus {
    background: linear-gradient(135deg, #ffffff 0%, #00d4ff 25%, #ffffff 50%, #00ffff 70%, #ffffff 100%);
    background-size: 200% 200%;
    animation: avatar-gradient-flow 3s ease-in-out infinite alternate,
               avatar-glow-plus 3s ease-in-out infinite alternate;
    padding: 2px;
}

.user-avatar--plus .user-avatar-initial {
    display: block;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--text-primary);
    line-height: 36px;
    text-align: center;
    margin: 0;
    padding: 0;
}

/* Borda Pro - Gradiente Vermelho e Rosa */
.user-avatar--pro {
    background: linear-gradient(135deg, #ff006e 0%, #ff0080 25%, #ff1493 50%, #ff0080 75%, #ff006e 100%);
    background-size: 200% 200%;
    animation: avatar-gradient-flow 3s ease-in-out infinite alternate,
               avatar-glow-pro 3s ease-in-out infinite alternate;
    padding: 2px;
}

.user-avatar--pro .user-avatar-initial {
    display: block;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--text-primary);
    line-height: 36px;
    text-align: center;
    margin: 0;
    padding: 0;
}

@keyframes avatar-gradient-flow {
    to {
        background-position: 100% 50%;
    }
}

@keyframes avatar-glow-plus {
    from {
        box-shadow: 0 0 8px rgba(0, 212, 255, 0.4),
                    0 0 16px rgba(0, 255, 255, 0.25);
    }
    to {
        box-shadow: 0 0 12px rgba(0, 212, 255, 0.6),
                    0 0 24px rgba(0, 255, 255, 0.4),
                    0 0 32px rgba(0, 212, 255, 0.25);
    }
}

@keyframes avatar-glow-pro {
    from {
        box-shadow: 0 0 10px rgba(255, 0, 110, 0.5),
                    0 0 20px rgba(255, 20, 147, 0.35),
                    0 0 30px rgba(255, 0, 128, 0.2);
    }
    to {
        box-shadow: 0 0 16px rgba(255, 0, 110, 0.7),
                    0 0 28px rgba(255, 20, 147, 0.5),
                    0 0 42px rgba(255, 0, 128, 0.35),
                    0 0 56px rgba(255, 0, 110, 0.2);
    }
}

.user-avatar-initial {
    color: var(--bg-primary);
    font-weight: 600;
    font-size: 16px;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

/* Informações do usuário */
.user-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-plan {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Botões de ação */
.config-btn,
.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: background-color var(--transition-speed) var(--transition-ease),
                color var(--transition-speed) var(--transition-ease);
    flex-shrink: 0;
}

.config-btn:hover,
.logout-btn:hover {
    background-color: var(--hover);
    color: var(--text-primary);
}

.config-btn:active,
.logout-btn:active {
    background-color: var(--active);
}

.config-btn .nav-icon,
.logout-btn .nav-icon {
    width: 18px;
    height: 18px;
    min-width: 18px;
}

/* Esconder informações do usuário quando sidebar está colapsada */
.sidebar .user-info {
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed) var(--transition-ease);
}

@media (min-width: 769px) {
    .sidebar:hover .user-info {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 768px) {
    .sidebar.mobile-active .user-info {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ==================== RESPONSIVIDADE MOBILE - SIDEBAR ==================== */

@media (max-width: 768px) {
    
    /* Esconder sidebar por padrão no mobile */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform var(--transition-speed) var(--transition-ease);
        width: var(--sidebar-width);
        box-shadow: none;
        z-index: 1001;
        height: 100dvh; /* Usar altura dinâmica no mobile */
        max-height: 100dvh;
        overflow: hidden;
    }
    
    /* Mostrar sidebar quando ativa no mobile */
    .sidebar.mobile-active {
        transform: translateX(0);
    }
}

