@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;600&display=swap');

:root {
    /* WhatsApp Dark Mode Palette */
    --wa-bg-app: #0a1014;
    --wa-bg-panel: #111b21;
    --wa-bg-chat: #0b141a;
    --wa-bg-header: #202c33;
    --wa-bg-input: #2a3942;
    --wa-msg-in: #202c33;
    --wa-msg-out: #005c4b;
    --wa-text-primary: #e9edef;
    --wa-text-secondary: #8696a0;
    --wa-accent: #00a884;
    --wa-border: #222d34;
    --wa-hover: #202c33;
    --wa-active: #2a3942;
}

html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: fixed; /* Prevent body scrolling on iOS/Android */
    width: 100%;
    font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: var(--wa-bg-app);
    color: var(--wa-text-primary);
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16);
    border-radius: 6px;
}

/* Layout Core */
.app-container {
    height: 100vh; /* Fallback */
    height: 100dvh;
    width: 100vw;
    max-width: none;
    margin: 0;
    background: var(--wa-bg-chat);
    display: flex;
    overflow: hidden;
}

/* Left Sidebar */
.sidebar-history {
    background: var(--wa-bg-panel) !important;
    border-right: 1px solid var(--wa-border) !important;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    background: var(--wa-bg-header);
    height: 59px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-right: 1px solid var(--wa-border);
}

.search-container {
    padding: 8px 12px;
    background: var(--wa-bg-panel);
    border-bottom: 1px solid var(--wa-border);
}

.search-bar {
    background: var(--wa-bg-header);
    border-radius: 8px;
    padding: 6px 12px;
    display: flex;
    align-items: center;
}

.search-bar button {
    background: transparent;
    border: none;
    color: var(--wa-text-secondary);
}

.history-list {
    background: var(--wa-bg-panel);
    padding: 0;
}

.history-item {
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--wa-text-primary);
    border-bottom: 1px solid var(--wa-border);
    transition: background 0.2s;
}

.history-item:hover {
    background: var(--wa-bg-header);
}

.history-item.active {
    background: var(--wa-active);
}

.history-avatar {
    width: 49px;
    height: 49px;
    border-radius: 50%;
    background: var(--wa-bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    color: var(--wa-text-secondary);
    font-size: 1.2rem;
}

.history-info {
    flex-grow: 1;
    overflow: hidden;
}

.history-title {
    font-size: 1.05rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main Chat Area */
.chat-main {
    background-color: var(--wa-bg-chat);
    background-image: url('https://web.whatsapp.com/img/bg-chat-tile-dark_a4be512e7195b6b733d9110b408f075d.png');
    background-repeat: repeat;
    background-size: 400px;
    background-blend-mode: overlay;
    position: relative;
}

.chat-header {
    background: var(--wa-bg-header) !important;
    height: 59px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}

.chat-header-profile {
    display: flex;
    align-items: center;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--wa-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    color: white;
    font-size: 1.2rem;
}

.chat-container {
    max-height: calc(100vh - 121px);
    overflow-y: auto;
    padding: 20px 5%;
}

/* Messages Refactor for WhatsApp Style */
.message {
    margin-bottom: 10px;
}

.message-content-wrapper {
    display: flex;
    flex-direction: column;
}

.message-content {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 7.5px;
    font-size: 0.95rem;
    line-height: 1.4;
    box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
    position: relative;
}

/* WhatsApp Tail */
.message-content::before {
    content: "";
    position: absolute;
    top: 0;
    width: 0;
    height: 0;
    border: 8px solid transparent;
}

.message.user .message-content-wrapper {
    align-items: flex-end;
}
.message.assistant .message-content-wrapper {
    align-items: flex-start;
}

.message.user .message-content {
    background: var(--wa-msg-out);
    color: var(--wa-text-primary);
    border-top-right-radius: 0;
}
.message.user .message-content::before {
    right: -8px;
    border-top-color: var(--wa-msg-out);
    border-left-color: var(--wa-msg-out);
}

.message.assistant .message-content {
    background: var(--wa-msg-in);
    color: var(--wa-text-primary);
    border-top-left-radius: 0;
}
.message.assistant .message-content::before {
    left: -8px;
    border-top-color: var(--wa-msg-in);
    border-right-color: var(--wa-msg-in);
}

/* Typography Overrides Markdown */
.message-content p {
    margin-bottom: 5px;
}
.message-content p:last-child {
    margin-bottom: 0;
}

/* Icons inside message (User request: Don't lose the icons) */
.msg-avatar-inline {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.70rem;
    margin-right: 8px;
    background: rgba(255,255,255,0.1);
}

/* Input Area WhatsApp Web Style */
.chat-input-area {
    background: var(--wa-bg-header) !important;
    height: 62px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    z-index: 10;
}

.chat-input-area form {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    width: 100%;
}

.input-container-wa {
    display: flex;
    align-items: center;
    background: var(--wa-bg-input);
    border-radius: 8px;
    padding: 5px 15px;
    flex-grow: 1;
}

#messageInput {
    background: transparent !important;
    border: none !important;
    color: var(--wa-text-primary) !important;
    resize: none;
    max-height: 100px;
    padding: 8px 0;
}
#messageInput:focus {
    box-shadow: none !important;
}
#messageInput::placeholder {
    color: var(--wa-text-secondary) !important;
    max-width: 80% !important;
    opacity: 1 !important;
}

/* Fix CSS for dark mode inputs autofill */
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active{
    -webkit-box-shadow: 0 0 0 30px #212529 inset !important;
    -webkit-text-fill-color: white !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* Bootstrap class overriding for Dark Mode Contrast */
.text-muted { color: var(--wa-text-secondary) !important; }
.text-success { color: var(--wa-accent) !important; }
.text-info { color: #38bdf8 !important; }

#sendBtn {
    background: transparent;
    border: none;
    color: var(--wa-text-secondary);
    font-size: 1.3rem;
    padding: 0 10px;
    transition: color 0.2s;
}
#sendBtn:hover:not(:disabled) {
    color: var(--wa-accent);
    transform: none;
}
#sendBtn:disabled {
    color: var(--wa-bg-panel);
}

/* Image/Camera attachment preview */
.attachment-preview {
    background: var(--wa-bg-header);
    border-top: 1px solid var(--wa-border);
    padding: 10px 16px;
    display: none;
    position: relative;
}
.attachment-preview img {
    max-height: 80px;
    border-radius: 8px;
    border: 2px solid var(--wa-accent);
}
.attachment-preview .remove-attachment {
    position: absolute;
    top: 5px;
    left: 80px;
    background: rgba(0,0,0,0.7);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
}

/* Token Progress specific */
.progress {
    background-color: var(--wa-bg-panel) !important;
    border-radius: 4px;
    height: 4px !important;
}
.progress-bar {
    background: var(--wa-accent) !important;
    box-shadow: none;
}

#emptyState i {
    color: var(--wa-accent);
}

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

.empty-state-anim {
    animation: fadeInUpDesktop 0.8s ease-out forwards;
    transition: opacity 0.4s ease;
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-15px); }
    to { opacity: 1; transform: translateX(0); }
}
.history-anim {
    opacity: 0;
    animation: slideInLeft 0.4s ease-out forwards;
}
/* Premium Animations & UI Enhancements */
@keyframes pulse-dot {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.15); opacity: 1; color: var(--wa-accent); }
    100% { transform: scale(1); opacity: 0.8; }
}

.pulsing-ellipsis {
    animation: pulse-dot 2.5s infinite ease-in-out;
    display: inline-block;
}

@keyframes text-glow {
    0% { text-shadow: 0 0 5px rgba(0, 168, 132, 0); }
    50% { text-shadow: 0 0 15px rgba(0, 168, 132, 0.4); color: #fff; }
    100% { text-shadow: 0 0 5px rgba(0, 168, 132, 0); }
}

.premium-loader-text {
    font-weight: 500;
    letter-spacing: 0.5px;
    animation: text-glow 2s infinite ease-in-out;
    background: linear-gradient(90deg, var(--wa-text-secondary), #fff, var(--wa-text-secondary));
    background-size: 200% auto;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shine 3s linear infinite, text-glow 2s infinite ease-in-out;
}

@keyframes shine {
    to { background-position: 200% center; }
}

.loader-brain-icon {
    filter: drop-shadow(0 0 8px rgba(37, 211, 102, 0.5));
    animation: brain-bounce 1.5s infinite alternate ease-in-out;
}

@keyframes brain-bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-3px); }
}
/* --- MOBILE RESPONSIVE & DRAWER SYSTEM --- */

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Adjustments */
@media (max-width: 767.98px) {
    .sidebar-history {
        position: fixed;
        top: 0;
        left: -300px; /* Hidden by default */
        width: 280px;
        height: 100vh;
        height: 100dvh;
        z-index: 2000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 10px 0 25px rgba(0,0,0,0.5);
        background: var(--wa-bg-panel);
    }

    .sidebar-history.active {
        left: 0;
    }

    .chat-main {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    .chat-header {
        padding: 8px 12px;
    }

    .chat-header-profile h6 {
        font-size: 0.95rem;
    }

    /* Adjust Token display and logout for mobile space */
    #tokenDisplay {
        font-size: 0.65rem !important;
    }
    #btnLogout {
        padding: 4px 8px !important;
        font-size: 0.7rem !important;
    }

    /* Input area optimization */
    /* Input area optimization */
    .chat-input-area {
        padding: 10px 8px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 15px)); /* Force space for Android/iOS bars */
        height: auto;
        min-height: 62px;
        background: var(--wa-bg-header) !important;
        position: relative;
        z-index: 100;
        box-shadow: 0 -5px 15px rgba(0,0,0,0.2);
    }
    
    .input-container-wa textarea {
        font-size: 0.95rem;
    }

    /* Message bubbles on mobile */
    .message-content {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 0.95rem;
    }

    .chat-header-avatar {
        width: 35px;
        height: 35px;
    }

    /* Optimization for Empty State content on small screens */
    #emptyState {
        padding: 5px !important;
        justify-content: center !important;
        overflow: hidden;
    }
    .robot-icon-wrapper {
        padding: 1.2rem !important;
        margin-bottom: 0.8rem !important;
    }
    .robot-icon-main {
        font-size: 2.5rem !important;
    }
    .main-welcome-title {
        font-size: 1.4rem !important;
        margin-bottom: 0.4rem !important;
    }
    .empty-description {
        font-size: 0.85rem !important;
        padding: 0 20px;
        line-height: 1.4 !important;
        color: var(--wa-text-secondary) !important;
    }
    .trademark-branding {
        margin-top: 1.5rem !important;
        opacity: 0.5;
    }
    .trademark-branding small, 
    .trademark-branding small i {
        font-size: 0.55rem !important;
    }

    /* Force the main column to respect the viewport strictly */
    .chat-main {
        height: 100% !important;
        max-height: 100dvh !important;
        overflow: hidden;
    }
}

/* Unified Solid WhatsApp Buttons */
.btn-wa-solid {
    background: var(--wa-accent) !important;
    border: none !important;
    color: #fff !important;
    border-radius: 12px !important;
    font-weight: 600 !important;
    letter-spacing: 0.3px;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}
.btn-wa-solid:hover {
    filter: brightness(1.1);
    color: #fff !important;
}
.btn-wa-solid:active {
    filter: brightness(0.95);
}
/* Cerrar Sesión: mismo verde, icono cambia */
.btn-wa-logout {
    background: var(--wa-accent) !important;
    border: none !important;
    color: #fff !important;
    border-radius: 12px !important;
    font-weight: 600 !important;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    opacity: 0.85;
}
.btn-wa-logout:hover {
    opacity: 1;
    color: #fff !important;
}

/* Ensure smooth transitions for sidebar elements */
.sidebar-history {
    background-color: var(--wa-bg-panel);
    border-right: 1px solid var(--wa-border);
}
