:root {
    --bg-main: #ffffff;
    --sidebar-bg: #f8f9fa;
    --chat-bg: #ffffff;
    --text-main: #1a1a1a;
    --text-muted: #6e6e73;
    --accent: #333333;
    --accent-light: #f5f5f7;
    --user-msg: #f5f5f7;
    --bot-msg: transparent;
    --input-bg: #ffffff;
    --sidebar-hover: #efeff3;
    --sidebar-active: #e5e5ea;
    --border-color: rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    display: flex;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Splash Screen */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 1s ease, visibility 1s;
}

.splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.splash-content {
    text-align: center;
    animation: splashIn 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.splash-brand {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -1px;
    margin-bottom: 0.5rem;
}

.splash-version {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Sidebar - Hidden globally */
.sidebar {
    display: none;
}

/* Main Chat Area */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--chat-bg);
}

.chat-header {
    padding: 0 1.2rem;
    height: 60px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center; /* Centrage vertical du conteneur H2 */
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(10px);
    z-index: 10;
}

.chat-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--accent);
    display: flex;
    align-items: baseline; /* Retour à baseline pour l'alignement du texte */
    gap: 6px;
    margin: 0;
    line-height: 1; /* Stabilise la ligne de base */
}

.header-subtitle {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.85rem;
    display: flex;
    align-items: baseline; /* Alignement sur la ligne de base du texte */
}

.header-subtitle strong {
    color: var(--accent);
    font-weight: 700;
    font-size: 1rem;
    margin-right: 4px;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scrollbar-width: none;
    padding: 10px 0 40px 0; /* Padding réduit en haut pour être "ferré" */
}

#chat-messages::-webkit-scrollbar {
    display: none;
}

.message-wrapper {
    width: 100%;
    display: flex;
    padding: 1rem 1.5rem;
    animation: fadeIn 0.4s ease-out;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

/* Centrage vertical uniquement sur desktop et si le contenu est court */
@media (min-width: 769px) {
    #chat-messages:not(:empty) .message-wrapper:first-child {
        margin-top: auto;
    }
    #chat-messages:not(:empty) .message-wrapper:last-child {
        margin-bottom: auto;
    }
}

/* Animation fadeIn */

.message-wrapper:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

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

.message {
    max-width: 850px;
    margin: 0 auto;
    display: flex;
    width: 100%;
}

.avatar {
    display: none;
}

.content {
    flex: 1;
    line-height: 1.6;
    font-size: 0.95rem;
    color: #333;
}

.content p { margin-bottom: 1.2rem; }
.content code { background: #f5f5f7; padding: 3px 6px; border-radius: 6px; font-family: 'SF Mono', monospace; font-size: 0.9em; }
.content pre { background: #1a1a1a; color: white; padding: 1.2rem; border-radius: 12px; overflow-x: auto; margin-bottom: 1.5rem; }

/* Bot Actions - Always visible */
.bot-actions {
    display: flex;
    gap: 8px;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
    opacity: 1;
}

.action-btn {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: 0.2s;
    font-weight: 600;
}

.action-btn svg {
    width: 14px;
    height: 14px;
}

.action-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

/* Empty State */
.empty-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin-bottom: 1.5rem;
    transition: opacity 0.5s ease;
}

.empty-state .header-subtitle {
    font-size: 1.1rem;
    font-weight: 400;
    color: var(--text-muted);
}

.empty-state .header-subtitle strong {
    font-size: 1.1rem;
    color: var(--accent);
    font-weight: 700;
}

/* Centering Logic */
.main-chat.is-empty, .main-chat.is-loading {
    justify-content: center;
    align-items: center;
}

.main-chat.is-empty .chat-header, .main-chat.is-loading .chat-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
}

.main-chat.is-empty #chat-messages, .main-chat.is-loading #chat-messages {
    display: none;
}

.main-chat.is-empty .empty-state {
    display: flex;
}

/* Input Container */
.input-container {
    max-width: 600px;
    width: 92%;
    margin: 0 auto 2.5rem auto;
    position: relative;
    transition: opacity 0.5s ease;
    z-index: 5;
}

.main-chat.is-empty .input-container {
    margin: 0;
    max-width: 500px;
    transform: none; /* Supprime tout transform */
}

/* Loading Dots - Always Centered */
.loading-dots {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    opacity: 0;
    transition: opacity 0.5s ease;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.dots-row {
    display: flex;
    gap: 12px;
}

/* Refined Scrolling Bands with dynamic H animation */
.h-loader-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.h-loader {
    width: 64px;
    height: 64px;
    background: #1a1a1a;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.h-letter-container {
    width: 26px;
    height: 32px;
    position: relative;
    z-index: 10;
    filter: drop-shadow(0 0 12px #000);
    pointer-events: none;
}

.h-v-bar {
    position: absolute;
    width: 6px;
    height: 100%;
    background: white;
    border-radius: 1px;
    transition: opacity 0.6s ease, transform 0.6s ease;
    opacity: 1;
}

.h-v-bar.left { left: 0; }
.h-v-bar.right { right: 0; }

.h-c-bar {
    position: absolute;
    width: 100%;
    height: 6px;
    background: white;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 1px;
    transition: opacity 0.6s ease, transform 0.6s ease;
}

/* État caché pendant le chargement (barre horizontale s'efface) */
.loading-dots.show .h-c-bar {
    opacity: 0;
    transform: translateY(-50%) scaleX(0.5);
}

/* État réapparu avant la fin */
.loading-dots.show .h-c-bar.reappear {
    opacity: 1;
    transform: translateY(-50%) scaleX(1);
}

.bands-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.band {
    position: absolute;
    width: 4px;
    height: 8px;
    background: white;
    top: 50%;
    right: -10px;
    transform: translateY(-50%);
    border-radius: 2px;
    opacity: 0;
}

/* Animations recalibrées pour un centrage parfait et une hauteur ajustée */
.band:nth-child(1) { animation: band-flow-1 3s infinite ease-in-out; }
.band:nth-child(2) { animation: band-flow-2 3.5s infinite ease-in-out; animation-delay: 0.8s; }
.band:nth-child(3) { animation: band-flow-3 4s infinite ease-in-out; animation-delay: 1.5s; }
.band:nth-child(4) { animation: band-flow-1 3.2s infinite ease-in-out; animation-delay: 2.2s; }

@keyframes band-flow-1 {
    0% { transform: translate(0, -50%); height: 8px; opacity: 0; }
    20% { opacity: 0.3; height: 16px; }
    /* Pause milieu (40px de trajet pour un centrage parfait sur 64px) */
    45% { transform: translate(-40px, -50%); height: 36px; opacity: 1; }
    55% { transform: translate(-40px, -50%); height: 36px; opacity: 1; }
    80% { opacity: 0.3; height: 16px; }
    100% { transform: translate(-84px, -50%); height: 8px; opacity: 0; }
}

@keyframes band-flow-2 {
    0% { transform: translate(0, -50%); height: 8px; opacity: 0; }
    30% { opacity: 0.3; height: 18px; }
    /* Pause milieu plus longue */
    40% { transform: translate(-40px, -50%); height: 38px; opacity: 1; }
    70% { transform: translate(-40px, -50%); height: 38px; opacity: 1; }
    90% { opacity: 0.3; height: 16px; }
    100% { transform: translate(-84px, -50%); height: 8px; opacity: 0; }
}

@keyframes band-flow-3 {
    0% { transform: translate(0, -50%); height: 8px; opacity: 0; }
    /* Pas de pause, juste un passage centré */
    50% { transform: translate(-40px, -50%); height: 34px; opacity: 1; }
    100% { transform: translate(-84px, -50%); height: 8px; opacity: 0; }
}

.loading-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    transition: opacity 0.5s ease;
    text-align: center;
    min-height: 1.2em;
}

.loading-text.fade {
    opacity: 0;
}

.loading-dots.show {
    display: flex;
    opacity: 1;
}

.dot {
    width: 15px;
    height: 15px;
    background-color: var(--accent);
    border-radius: 50%;
    animation: dotPulse 1.5s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1.2); opacity: 1; }
}

/* Animations */
.fade-out { opacity: 0 !important; pointer-events: none; }

/* Input Row Layout */
.input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.reset-chat-btn {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    height: 40px;
    padding: 0 1rem;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s;
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 600;
}

@media (max-width: 480px) {
    .reset-chat-btn {
        width: 40px;
        padding: 0;
        background: var(--accent);
        color: white;
        border: none;
    }
    .reset-chat-btn span {
        display: none;
    }
}

.reset-chat-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

.main-chat.is-empty .reset-chat-btn {
    display: none;
}

.input-wrapper {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.4rem 0.6rem 0.4rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.05);
    transition: border-color 0.3s, box-shadow 0.3s;
    flex: 1;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    max-height: 200px;
    outline: none;
    padding: 8px 0;
    line-height: 1.4;
    overflow-y: hidden;
}

.send-btn {
    background: var(--accent);
    color: white;
    border: none;
    outline: none;
    height: 32px;
    padding: 0 1rem;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 700;
}

.send-btn.is-icon {
    width: 32px;
    padding: 0;
    border-radius: 50%;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    background: #000;
}

.send-btn.is-icon:hover:not(:disabled) {
    transform: scale(1.1);
}

.send-btn svg {
    display: none;
}

.send-btn.is-icon svg {
    display: block;
    width: 16px;
    height: 16px;
    transform: translateX(1px);
}

.send-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.footer-brand {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0.5px;
}

.footer-version {
    font-size: 0.6rem;
    color: var(--text-muted);
    font-weight: 500;
    opacity: 0.8;
}

/* Mobile Menu - Always visible */
.mobile-menu-container {
    display: block;
    position: relative;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 280px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    padding: 1rem;
    z-index: 100;
    max-height: 80vh;
    overflow-y: auto;
}

.mobile-dropdown.show {
    display: block;
    animation: slideDown 0.2s ease-out;
}

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

.new-chat-btn-mobile {
    background: var(--accent);
    border: none;
    color: white;
    height: 35px;
    padding: 0 1rem;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
    font-size: 0.8rem;
    margin-bottom: 1rem;
}

.conv-item {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: 0.2s;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item:hover {
    background-color: var(--sidebar-hover);
    font-weight: 600;
}

.conv-item.active {
    background-color: var(--sidebar-active);
    font-weight: 600;
}

@media (max-width: 768px) {
    .message { gap: 1rem; }
    .input-container { 
        width: 95%; 
        margin-bottom: 1rem;
    }
    .main-chat {
        height: 100%;
    }
}