/* AIMLAPI Chat — styles mobile first */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg:          #f5f5f5;
    --surface:     #ffffff;
    --border:      #e0e0e0;
    --text:        #1a1a1a;
    --text-muted:  #777;
    --accent:      #2563eb;
    --accent-bg:   #eff6ff;
    --radius:      10px;
    --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --mono:        "Fira Code", "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:         #111;
        --surface:    #1e1e1e;
        --border:     #333;
        --text:       #e8e8e8;
        --text-muted: #888;
        --accent:     #3b82f6;
        --accent-bg:  #1e3a5f;
    }
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
}

/* layout principal */
.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 860px;
    margin: 0 auto;
}

/* en-tête */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: flex-end;
}

#model {
    font-size: 13px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    max-width: 220px;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-muted);
    transition: background 0.15s;
}

.btn-icon:hover {
    background: var(--bg);
}

/* zone de conversation */
#chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

/* messages */
.msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.msg.user {
    align-self: flex-end;
    align-items: flex-end;
}

.msg.assistant {
    align-self: flex-start;
}

.msg-role {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 3px;
    padding: 0 4px;
}

.bubble {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.65;
    word-break: break-word;
}

.msg.user .bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 3px;
}

.msg.assistant .bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 3px;
}

/* rendu markdown dans les bulles */
.bubble h1, .bubble h2, .bubble h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 10px 0 4px;
}

.bubble p {
    margin-bottom: 8px;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble ul, .bubble ol {
    padding-left: 18px;
    margin: 4px 0 8px;
}

.bubble li {
    margin-bottom: 3px;
}

.bubble code {
    font-family: var(--mono);
    font-size: 12px;
    background: rgba(0,0,0,0.07);
    padding: 1px 5px;
    border-radius: 4px;
}

.msg.user .bubble code {
    background: rgba(255,255,255,0.2);
}

.bubble pre {
    background: #1a1a1a;
    color: #e8e8e8;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}

.bubble pre code {
    background: none;
    color: inherit;
    padding: 0;
    font-size: inherit;
}

.bubble strong {
    font-weight: 600;
}

.bubble em {
    font-style: italic;
}

.bubble blockquote {
    border-left: 3px solid var(--border);
    padding-left: 10px;
    color: var(--text-muted);
    margin: 6px 0;
}

/* animation de réflexion */
.thinking {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    border-bottom-left-radius: 3px;
    width: fit-content;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.2s infinite;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-7px); }
}

/* pied de page */
.app-footer {
    padding: 12px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#status {
    font-size: 12px;
    color: var(--text-muted);
    min-height: 16px;
}

#status.error {
    color: #dc2626;
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#prompt {
    flex: 1;
    resize: none;
    font-family: var(--font);
    font-size: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: border-color 0.15s;
}

#prompt:focus {
    outline: none;
    border-color: var(--accent);
}

#btn-send {
    padding: 10px 18px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
    align-self: flex-end;
    height: 42px;
}

#btn-send:hover:not(:disabled) {
    opacity: 0.88;
}

#btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* desktop */
@media (min-width: 1000px) {
    .app-header h1 {
        font-size: 1.15rem;
    }

    #model {
        max-width: 300px;
    }

    .msg {
        max-width: 75%;
    }

    #chat {
        padding: 20px 24px;
        gap: 18px;
    }

    .app-footer {
        padding: 14px 24px;
    }

    #prompt {
        font-size: 15px;
    }
}
