:root {
    --bg-main: #000000;
    --bg-sidebar: #0a0a0a;
    --bg-input: #121212;
    --bg-hover: #1f1f1f;
    --border-color: #222222;
    --text-primary: #ffffff;
    --text-secondary: #888888;
    --accent: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.3s ease;
    z-index: 10;
}

.sidebar-top {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
    overflow-y: auto;
}

.logo-text {
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: -0.5px;
}

.new-chat-btn {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s;
    text-align: left;
}

.new-chat-btn:hover {
    background-color: var(--bg-hover);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
}

.history-item {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s;
}

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

.sidebar-bottom {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.tokens-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tokens-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.tokens-bar {
    width: 100%;
    height: 4px;
    background-color: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.tokens-progress {
    height: 100%;
    background-color: var(--text-primary);
    transition: width 0.3s ease;
}

/* Chat Main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-main);
}

.chat-header {
    height: 50px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 15px;
}

.mobile-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    display: none;
}

.current-chat-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

.message {
    max-width: 750px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    font-size: 0.95rem;
    line-height: 1.6;
}

.message.user {
    align-items: flex-end;
}

.message.user .message-content {
    background-color: #1f1f1f;
    padding: 10px 16px;
    border-radius: 12px;
    max-width: 80%;
}

.message.assistant .message-content {
    background-color: transparent;
    color: var(--text-primary);
    width: 100%;
}

/* Input area */
.chat-input-container {
    padding: 20px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-input-wrapper {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    align-items: flex-end;
    padding: 10px 14px;
    gap: 10px;
    transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
    border-color: #444;
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    resize: none;
    max-height: 200px;
    outline: none;
    line-height: 1.5;
}

textarea::placeholder {
    color: var(--text-secondary);
}

#sendBtn {
    background-color: var(--text-primary);
    color: var(--bg-main);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

#sendBtn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
}

.footer-note {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .mobile-toggle {
        display: block;
    }
}
.message-content { overflow-wrap: anywhere; }
button:focus-visible, textarea:focus-visible { outline: 2px solid #888; outline-offset: 3px; }


/* Bouton « Tap to copy » sous chaque réponse de l'assistant */
.copy-message-btn {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 9px;
    padding: 6px 9px;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    font-size: 0.76rem;
    cursor: pointer;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.copy-message-btn:hover { color: var(--text-primary); background: var(--bg-hover); border-color: var(--border-color); }
.copy-message-btn.copied { color: #9be6ad; }


/* Sélecteur du fournisseur IA près du bouton Envoyer */
.provider-select {
    max-width: 145px;
    min-width: 0;
    padding: 8px 6px;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.72rem;
    cursor: pointer;
}
.provider-select:focus-visible { outline: 2px solid #888; outline-offset: 2px; }
.provider-tag { display: block; margin-top: 8px; color: var(--text-secondary); font-size: 0.68rem; }
@media (max-width: 480px) { .provider-select { max-width: 112px; font-size: 0.65rem; padding: 7px 3px; } .chat-input-wrapper { gap: 6px; padding: 8px; } }

.api-key-settings { margin-bottom: 10px; color: var(--text-secondary); font-size: .82rem; }
.api-key-settings summary { cursor: pointer; width: fit-content; padding: 5px 0; }
.api-key-fields { display: grid; grid-template-columns: 1fr; gap: 7px; padding: 10px; border: 1px solid var(--border-color); border-radius: 10px; margin-top: 6px; }
.api-key-fields input { width: 100%; box-sizing: border-box; background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: 7px; padding: 9px; }
.api-key-fields button { justify-self: start; padding: 8px 12px; border: 1px solid var(--border-color); border-radius: 7px; background: var(--bg-input); color: var(--text-primary); cursor: pointer; }
.api-key-fields p { margin: 0; font-size: .75rem; }


/* Expérience mobile / téléphone */
html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}
body {
    min-height: 100%;
    min-height: 100dvh;
    overscroll-behavior: none;
}
.app-container {
    min-height: 100%;
    min-height: 100dvh;
}
.sidebar {
    flex-shrink: 0;
}
.chat-main {
    min-width: 0;
    min-height: 0;
}
.chat-header {
    flex-shrink: 0;
}
.chat-messages {
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.chat-input-container {
    flex-shrink: 0;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}
textarea {
    min-width: 0;
    -webkit-appearance: none;
}
button, select {
    touch-action: manipulation;
}
@media (max-width: 768px) {
    .app-container {
        position: relative;
        overflow: hidden;
    }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(84vw, 310px);
        height: 100vh;
        height: 100dvh;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 16px 0 40px rgba(0,0,0,.45);
        transform: translateX(-110%);
        transition: transform .25s ease;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .chat-main {
        width: 100%;
        height: 100vh;
        height: 100dvh;
    }
    .chat-header {
        height: auto;
        min-height: 54px;
        padding: max(8px, env(safe-area-inset-top)) 14px 8px;
        gap: 12px;
    }
    .mobile-toggle {
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
        border-radius: 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: var(--bg-input);
    }
    .current-chat-title {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .chat-messages {
        padding: 16px 13px;
        gap: 20px;
    }
    .message {
        font-size: 0.94rem;
    }
    .message.user .message-content {
        max-width: 92%;
        padding: 10px 13px;
    }
    .chat-input-container {
        padding: 10px 10px max(12px, env(safe-area-inset-bottom));
        gap: 8px;
    }
    .chat-input-wrapper {
        align-items: flex-end;
        border-radius: 16px;
        padding: 9px;
        gap: 7px;
    }
    textarea {
        font-size: 16px; /* Évite le zoom automatique sur iPhone */
        max-height: 32vh;
        min-height: 32px;
        padding: 6px 2px;
    }
    #sendBtn {
        width: 40px;
        height: 40px;
    }
    .provider-select {
        max-width: 118px;
        min-height: 38px;
        font-size: 0.68rem;
    }
    .footer-note {
        font-size: 0.68rem;
        line-height: 1.35;
        padding: 0 4px;
    }
}
@media (max-width: 380px) {
    .provider-select {
        max-width: 94px;
        font-size: 0.62rem;
    }
    .chat-messages {
        padding-inline: 10px;
    }
    .footer-note {
        font-size: 0.64rem;
    }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
    }
}


/* Adaptation PC : espace de travail large, meilleure lisibilité et zone de saisie stable */
@media (min-width: 769px) {
    .app-container {
        min-height: 100vh;
        min-height: 100dvh;
    }
    .sidebar {
        width: clamp(245px, 21vw, 300px);
        height: 100vh;
        height: 100dvh;
    }
    .chat-header {
        min-height: 58px;
        height: 58px;
        padding-inline: clamp(20px, 4vw, 48px);
    }
    .chat-messages {
        padding: 28px clamp(24px, 5vw, 64px);
    }
    .message {
        max-width: 820px;
        font-size: 1rem;
    }
    .chat-input-container {
        width: 100%;
        max-width: 940px;
        margin-inline: auto;
        padding: 16px 28px 22px;
    }
    .chat-input-wrapper {
        border-radius: 18px;
    }
    .mobile-toggle {
        display: none !important;
    }
}
@media (min-width: 769px) and (max-width: 1100px) {
    .sidebar {
        width: 235px;
    }
    .chat-messages {
        padding-inline: 24px;
    }
}
@media (hover: hover) and (pointer: fine) {
    button, select {
        transition: background-color .18s ease, border-color .18s ease, opacity .18s ease;
    }
}
