/* ==========================
   VARIÁVEIS GLOBAIS
   ========================== */
:root {
    --chat-bg: #f8f9fa;
    --chat-surface: #ffffff;
    --chat-border: #dee2e6;
    --chat-primary: #0d6efd;
    --chat-radius: 18px;
}

/* ==========================
   ESTRUTURA GERAL & LAYOUT
   ========================== */
html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--chat-bg);
}

#chat-page {
    height: 100vh;
}

#ai-chat-main {
    height: 100vh;
    position: relative;
}

/* ==========================
   SIDEBAR
   ========================== */
#ai-chat-sidebar {
    width: 300px;
    background: white;
    border-right: 1px solid var(--chat-border);
    overflow-y: auto;
    height: 100vh;
    flex-shrink: 0;
}

#ai-conversations {
    padding: .75rem;
    cursor: pointer;
}

#ai-conversations .list-group-item {
    border: none;
    border-radius: 12px;
    margin-bottom: .4rem;
    cursor: pointer;
}

#ai-conversations .list-group-item:hover {
    background: #f2f4f7;
}

.ai-conversation-section {
    font-size: .85rem;
    color: #6c757d;
    padding: 12px 0 5px;
    margin: 0;
}

aside h6 {
    padding-left: 10px;
    padding-top: 10px;
    padding-bottom: 5px;
}

.ai-conversations .ai-conversation {
    margin: 10px 0;
}

.ai-conversation {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px;
    position: relative;
}

.ai-conversation > i {
    flex-shrink: 0;
}

.ai-conversation span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-title-input {
    flex: 1;
    min-width: 0;
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    padding: 0;
    font: inherit;
}

.ai-conversation:hover {
    background-color: #f0f0f0;
    padding: 5px;
    border-radius: 10px;
}

/* Ações da conversa (renomear, favoritar, arquivar) */
.ai-conversation .rename-btn,
.ai-conversation .favorite-btn,
.ai-conversation .archive-btn {
    display: none;
    flex-shrink: 0;
    border: none;
    background: transparent;
    padding: 4px;
    color: #adb5bd;
    cursor: pointer;
}

.ai-conversation .archive-btn {
    right: 5px;
}

.ai-conversation .favorite-btn {
    right: 35px;
}

.ai-conversation .rename-btn {
    right: 65px;
}

.ai-conversation:hover .rename-btn,
.ai-conversation:hover .favorite-btn,
.ai-conversation:hover .archive-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ai-conversation:hover .favorite-btn {
    opacity: 1;
}

.favorite-btn:hover,
.archive-btn:hover,
.rename-btn:hover {
    color: #ffc107;
}

.favorite-btn .fa-solid.fa-star {
    color: #ffc107;
    opacity: 1;
}

/* ==========================
   HEADER & AVATAR
   ========================== */
.ai-chat-header {
    background: white;
    border-bottom: 1px solid var(--chat-border);
    padding: 16px 24px;
}

/* Avatar base */
.ai-chat-avatar,
.ai-chat-header img.rounded-circle {
    width: 48px;
    height: 48px;
    border-radius: 50% !important;
    object-fit: cover;
    /* Adiciona margem/respiro para o ring azul não ser cortado nas bordas */
    margin-top: 4px;
    margin-bottom: 4px;
    /* Transição suave de escala e border */
    transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease !important;
    /* Usa border transparente por padrão para reservarmos o espaço e não cortar */
    border: 3px solid transparent !important;
}

/* Hover perfeito */
.ai-chat-avatar:hover,
.ai-chat-header img.rounded-circle:hover {
    transform: scale(1.05) !important;
    border-color: color-mix(in srgb, var(--chat-primary) 50%, transparent) !important;
}

/* Menu de opções no header */
#ai-chat-options {
    position: relative;
    z-index: 1060;
    width: 38px;
    padding: 0;
}

#ai-chat-options,
#ai-user-menu {
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ==========================
   MENSAGENS & MARKDOWN
   ========================== */
#ai-chat-messages {
    position: relative;
    flex: 1;
    overflow-y: auto;
    padding: 30px;
}

.ai-message {
    padding: 14px 18px;
    border-radius: 18px;
    margin-bottom: 18px;
    line-height: 1.6;
    word-break: break-word;
}

.ai-message.assistant {
    background: white;
    border: 1px solid var(--chat-border);
}

.ai-message.user {
    background: var(--chat-primary);
    color: white;
    margin-left: auto;
}

.ai-message pre {
    border-radius: 10px;
    overflow: auto;
    padding: 1rem;
}

.ai-message code {
    font-size: .9rem;
}

.ai-message-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    align-items: center;
}

.feedback-comment {
    margin-top: 12px;
}

/* ==========================
   BOTÕES DE FEEDBACK
   ========================== */
.btn-feedback {
    border: none;
    background: transparent;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.btn-feedback i {
    font-size: 16px;
}

.btn-feedback:hover {
    background-color: #f1f3f5;
    color: #212529;
}

.btn-feedback.active {
    background-color: #e9ecef;
    color: #0d6efd;
}

.btn-feedback:disabled {
    cursor: default;
    opacity: 0.45;
}

.btn-feedback:disabled:hover {
    background-color: transparent;
    color: #6c757d;
}

/* ==========================
   INPUT & FOOTER
   ========================== */
#ai-chat-footer {
    background: white;
    border-top: 1px solid var(--chat-border);
    padding: 18px;
}

#ai-chat-input {
    resize: none;
    min-height: 52px;
    max-height: 180px;
}

#ai-chat-send {
    min-width: 60px;
}

/* ==========================
   BOTÃO DE GRAVAÇÃO DE ÁUDIO
   ========================== */
#btn-voice {
    color: #6c757d !important;
    border-style: solid !important;
    border-color: #6c757d !important;
    background-color: white !important;
}

#btn-voice i {
    color: #6c757d !important;
}

#btn-voice:hover {
    color: white !important;
    border-style: solid !important;
    border-color: white !important;
    background-color: red !important;
}

#btn-voice:hover i {
    color: white !important;
}

#btn-voice:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#btn-voice.recording {
    animation: pulse-voice 1.2s infinite;
    color: white !important;
    background-color: red !important;
    border-color: red !important;
}

#btn-voice.recording i {
    color: white !important;
}

/* ==========================
   MODO LIVE & BOTÃO LIVE
   ========================== */
.btn-live {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto !important;
    flex: 0 0 auto !important;
    padding: 8px 12px;
    position: relative;
    overflow: visible !important;
    background-color: #fff;
    color: rgb(108, 117, 125) !important;
    border-color: rgb(108, 117, 125) !important;
    border-style: solid;
    border-width: 1px;
}

.btn-live:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.live {
    animation: pulse-voice 1.2s infinite;
    z-index: 1;
}

.live circle {
    fill: #dc3545;
    stroke: #dc3545;
}

.live path {
    transform-origin: center;
    animation: wave 1.4s ease-in-out infinite;
    stroke: #dc3545;
}

.live path:nth-of-type(1) { animation-delay: 0ms; }
.live path:nth-of-type(2) { animation-delay: 150ms; }
.live path:nth-of-type(3) { animation-delay: 300ms; }
.live path:nth-of-type(4) { animation-delay: 450ms; }

.live.listening circle {
    animation: mic .45s ease-in-out infinite;
}

.live-icon {
    color: #6c757d;
    overflow: visible;
}

/* Hover e Estado Ativo do Botão Live */
#btnLive:hover,
#btnLive.live:hover,
#btnLive.live {
    color: white !important;
    border-color: #dc3545 !important;
    background-color: #dc3545 !important;
}

/* Força todas as partes do SVG (traços de onda e círculo) a ficarem brancas no hover/live */
#btnLive:hover svg path,
#btnLive:hover svg circle,
#btnLive.live:hover svg path,
#btnLive.live:hover svg circle,
#btnLive.live svg path,
#btnLive.live svg circle {
    stroke: white !important;
    fill: white !important;
}

.muted {
    background-color: #dc3545 !important;
    color: white !important;
}

/* ==========================
   ANIMAÇÕES (KEYFRAMES)
   ========================== */
@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: .4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

@keyframes pulse-voice {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.7);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 12px rgba(255, 0, 0, 0);
    }
}

@keyframes wave {
    0%, 100% {
        opacity: .35;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.08);
    }
}

@keyframes mic {
    50% {
        transform: scale(1.25);
    }
}

/* ==========================
   INDICADOR DE DIGITAÇÃO (TYPING)
   ========================== */
.ai-typing {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 10px 14px;
}

.ai-typing span {
    width: 8px;
    height: 8px;
    background-color: var(--chat-primary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.ai-typing span:nth-child(1) { animation-delay: 0s; }
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }

/* ==========================
   LIMITES DE INTERAÇÃO & OVERLAY
   ========================== */
.ai-limit-message {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.ai-limit-card {
    width: 90%;
    max-width: 400px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, .15);
    pointer-events: auto;
}

.ai-limit-card p {
    margin: 0;
    color: #6c757d;
    font-size: .9rem;
}

.ai-limit-card button {
    white-space: nowrap;
}

.ai-limit-overlay {
    position: absolute;
    top: 64px;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .55);
    pointer-events: none;
    z-index: 20;
}

/* ==========================
   PWA INSTALL BAR
   ========================== */
#pwa-install-bar {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 20, 20, 0.72);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: white;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    display: flex;
    gap: 10px;
    align-items: center;
    z-index: 9999;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

#pwa-install-bar.hide {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

#pwa-install-bar button {
    background: #4f46e5;
    border: none;
    color: white;
    padding: 6px 10px;
    border-radius: 999px;
    cursor: pointer;
}

#pwa-install-bar img {
    width: 50px;
    border-radius: 50%;
}

/* ==========================
   UTILITÁRIOS
   ========================== */
.d-none {
    display: none !important;
}

/* ==========================
   SCROLLBARS CUSTOMIZADAS
   ========================== */
#ai-chat-sidebar::-webkit-scrollbar,
#ai-chat-messages::-webkit-scrollbar {
    width: 8px;
}

#ai-chat-sidebar::-webkit-scrollbar-thumb,
#ai-chat-messages::-webkit-scrollbar-thumb {
    background: #c7c7c7;
    border-radius: 10px;
}

/* ==========================
   PRIVACIDADE
   ========================== */

.ai-chat-privacy {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 10px;
    padding: 0 8px 6px;
    font-size: 10px;
    line-height: 1.3;
    color: #8a8f98;
    text-align: center;
}

.ai-chat-privacy i {
    font-size: 10px;
    flex-shrink: 0;
}

.ai-chat-privacy a {
    color: inherit;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-chat-privacy a:hover {
    color: var(--bs-primary);
}

/* ==========================
   RESPONSIVIDADE (MEDIA QUERIES)
   ========================== */

/* Tablet */
@media (max-width: 991px) {
    #ai-chat-sidebar {
        width: 250px;
    }

    .ai-message {
        max-width: 90%;
    }
}

/* Celular */
@media (max-width: 768px) {
    html,
    body {
        margin: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    #chat-page {
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
    }

    #ai-chat-main {
        height: 100%;
        min-height: 0;
        overflow: hidden;
    }

    #ai-chat-messages {
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto;
    }

    .ai-message {
        max-width: 100%;
    }

    #ai-chat-footer {
        padding: 12px;
        flex-shrink: 0;
    }

    #ai-chat-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 90%;
        max-width: 360px;
        background: white;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform .3s ease;
    }

    #ai-chat-sidebar.show {
        transform: translateX(0);
    }

    .ai-chat-privacy{
        display: block;
    }
}