:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --sidebar: #171c26;
    --background: #ffffff;
    --text: #172033;
    --muted: #64748b;
    --border: #e2e8f0;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont,
                 "Segoe UI", Arial, sans-serif;
    color: var(--text);
    background: var(--background);
}

button, input, textarea {
    font: inherit;
}

button {
    cursor: pointer;
    transition: background .15s;
}

button:disabled {
    cursor: not-allowed;
    opacity: .45;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 3px;
}

.brand {
    font-size: 26px;
    font-weight: 750;
    letter-spacing: 1.5px;
}

.brand span {
    color: #60a5fa;
}

/* Connexion */

#login-screen {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #111827;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 40px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px #0003;
}

.login-card .brand {
    text-align: center;
    font-size: 34px;
}

.login-card > p {
    text-align: center;
    color: var(--muted);
    line-height: 1.6;
    margin-bottom: 32px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#login-form label {
    font-size: 14px;
    font-weight: 600;
}

#login-form input {
    width: 100%;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    margin-bottom: 8px;
}

#login-form button,
#send-button,
#stop-button {
    border: 0;
    background: var(--primary);
    color: white;
    padding: 13px 20px;
    border-radius: 9px;
    font-weight: 600;
}

#login-form button:hover,
#send-button:hover,
#stop-button:hover {
    background: var(--primary-hover);
}

#login-error {
    color: #b91c1c;
    font-size: 14px;
    margin: 0;
}

.login-card > small {
    display: block;
    text-align: center;
    color: var(--muted);
    margin-top: 24px;
}

/* Application */

#app-screen {
    display: flex;
    height: 100dvh;
    overflow: hidden;
}

#sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    gap: 20px;
}

#sidebar .brand {
    padding: 0 8px;
}

#sidebar button {
    color: inherit;
    border: 0;
    background: transparent;
    border-radius: 8px;
    padding: 12px;
    text-align: left;
}

#sidebar button:hover:not(:disabled) {
    background: #303846;
}

#new-chat {
    border: 1px solid #475569 !important;
    font-weight: 600;
}

.sidebar-label {
    font-size: 11px;
    letter-spacing: 1.5px;
    color: #94a3b8;
    padding: 0 10px;
}

#conversation-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

#conversation-list button {
    display: block;
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 14px;
}

#conversation-list button.active {
    background: #303846;
}

.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-top: 1px solid #334155;
    padding-top: 14px;
}

#user-profile {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 14px 12px;
}

#user-profile small {
    color: #94a3b8;
}

#logout-button {
    color: #fca5a5 !important;
}

/* Discussion */

#chat-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 18px 25px;
    border-bottom: 1px solid var(--border);
}

.chat-header small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.local-status {
    margin-left: auto;
    color: #15803d;
    font-size: 13px;
}

#menu-toggle {
    display: none;
    background: transparent;
    border: 0;
    font-size: 22px;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 30px max(24px, calc((100% - 850px) / 2));
}

#welcome {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

#welcome h1 {
    font-size: clamp(24px, 4vw, 34px);
    font-weight: 600;
    margin-bottom: 8px;
}

#welcome p {
    color: var(--muted);
}

.message {
    margin-bottom: 28px;
    line-height: 1.75;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message.user {
    background: #eff6ff;
    border-radius: 18px 18px 4px 18px;
    padding: 16px 20px;
    margin-left: 12%;
}

.message.assistant {
    padding: 10px 0;
}

.message.pending {
    color: var(--muted);
    font-style: italic;
}

.message.error {
    color: #b91c1c;
}

.composer {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 15px 24px 20px;
}

#message-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 3px 15px #00000008;
}

#message-input {
    flex: 1;
    min-width: 0;
    border: 0;
    resize: vertical;
    max-height: 200px;
    padding: 10px;
    line-height: 1.5;
    background: transparent;
}

.composer > small {
    display: block;
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    margin-top: 12px;
}

/* Mobile */

@media (max-width: 760px) {
    #sidebar {
        display: none;
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 100;
        width: min(280px, 85vw);
        box-shadow: 10px 0 30px #0003;
    }

    #sidebar.open {
        display: flex;
    }

    #menu-toggle {
        display: block;
    }

    .chat-header {
        padding: 14px 16px;
    }

    #messages {
        padding: 20px 16px;
    }

    .composer {
        padding: 10px 12px 15px;
    }

    .login-card {
        padding: 28px;
    }

    #send-button,
    #stop-button {
        padding: 12px;
    }
}
