/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #ffffff;
    --bg-2: #f9f9f9;
    --bg-3: #f0f0f0;
    --border: #e5e5e5;
    --border-2: #d4d4d4;
    --text: #171717;
    --text-2: #525252;
    --text-3: #a3a3a3;
    --accent: #171717;
    --accent-fg: #ffffff;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-w: 256px;
    --input-h: 44px;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

    a:hover {
        text-decoration: underline;
    }

/* ── Auth pages ────────────────────────────────────────────────────────────── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-2);
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
}

.auth-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.auth-title {
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 6px;
    letter-spacing: -0.3px;
}

.auth-subtitle {
    font-size: 14px;
    color: var(--text-2);
    text-align: center;
    margin-bottom: 28px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.form-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    height: var(--input-h);
    padding: 0 12px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

    .form-input:focus {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px rgba(23,23,23,0.08);
    }

    .form-input::placeholder {
        color: var(--text-3);
    }

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.check-input {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
}

.check-label {
    font-size: 13px;
    color: var(--text-2);
    cursor: pointer;
}

.field-error {
    display: block;
    font-size: 12px;
    color: var(--danger);
    margin-top: 4px;
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

    .alert:empty {
        display: none;
    }

.alert-error {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger);
}

.btn-primary {
    width: 100%;
    height: var(--input-h);
    background: var(--accent);
    color: var(--accent-fg);
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
    margin-bottom: 20px;
}

    .btn-primary:hover {
        opacity: 0.88;
    }

    .btn-primary:active {
        opacity: 0.76;
    }

.auth-footer {
    font-size: 13px;
    color: var(--text-2);
    text-align: center;
}

/* ── Chat app layout ───────────────────────────────────────────────────────── */
.chat-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.sidebar-top {
    padding: 14px 12px 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 4px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s;
}

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

.sidebar-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sessions-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    padding: 6px 8px 4px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-2);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s;
    white-space: nowrap;
    overflow: hidden;
}

    .session-item:hover {
        background: var(--bg-3);
        color: var(--text);
        text-decoration: none;
    }

    .session-item.active {
        background: var(--bg-3);
        color: var(--text);
        font-weight: 500;
    }

.session-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-delete {
    display: none;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
}

.session-item:hover .session-delete {
    display: flex;
}

.session-delete:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.model-label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    margin-bottom: 4px;
}

.model-select {
    width: 100%;
    padding: 7px 10px;
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
    outline: none;
}

    .model-select:focus {
        border-color: var(--accent);
    }

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-fg);
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.12s, color 0.12s;
}

    .logout-btn:hover {
        background: var(--bg-3);
        color: var(--text);
    }

/* Main chat area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px 0;
    scroll-behavior: smooth;
}

/* Messages */
.msg {
    display: flex;
    gap: 16px;
    padding: 12px 0;
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
    padding-left: 24px;
    padding-right: 24px;
}

    .msg.user {
        flex-direction: row-reverse;
    }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

    .msg-avatar.assistant {
        background: var(--accent);
        color: var(--accent-fg);
    }

    .msg-avatar.user {
        background: var(--bg-3);
        color: var(--text);
        border: 1px solid var(--border-2);
    }

.msg-bubble {
    flex: 1;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
    min-width: 0;
}

.msg.user .msg-bubble {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px 2px 12px 12px;
    padding: 12px 16px;
    flex: none;
    max-width: 72%;
}

/* Markdown rendering */
.msg-bubble p {
    margin-bottom: 10px;
}

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

.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
    margin: 16px 0 8px;
    font-weight: 600;
}

.msg-bubble h1 {
    font-size: 20px;
}

.msg-bubble h2 {
    font-size: 17px;
}

.msg-bubble h3 {
    font-size: 15px;
}

.msg-bubble ul, .msg-bubble ol {
    padding-left: 20px;
    margin-bottom: 10px;
}

.msg-bubble li {
    margin-bottom: 4px;
}

.msg-bubble code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
}

.msg-bubble pre {
    background: #1e1e1e;
    border-radius: var(--radius);
    padding: 14px 16px;
    overflow-x: auto;
    margin: 10px 0;
}

    .msg-bubble pre code {
        font-size: 13px;
        background: none;
        border: none;
        padding: 0;
        color: #d4d4d4;
    }

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

.msg-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 13px;
}

.msg-bubble th, .msg-bubble td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.msg-bubble th {
    background: var(--bg-2);
    font-weight: 600;
}

.msg-bubble strong {
    font-weight: 600;
}

.msg-bubble em {
    font-style: italic;
}

.msg-bubble a {
    color: #2563eb;
    text-decoration: underline;
}

.msg-bubble hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

/* Typing indicator */
.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 6px 0;
}

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

        .typing-dots span:nth-child(2) {
            animation-delay: 0.2s;
        }

        .typing-dots span:nth-child(3) {
            animation-delay: 0.4s;
        }

@keyframes bounce {
    0%,80%,100% {
        transform: translateY(0)
    }

    40% {
        transform: translateY(-6px)
    }
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 24px 40px;
    min-height: 60vh;
    gap: 10px;
}

.empty-logo {
    margin-bottom: 8px;
}

.empty-state h2 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.3px;
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-2);
    margin-bottom: 20px;
}

.suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-width: 520px;
    width: 100%;
}

.suggestion-chip {
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-2);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    line-height: 1.4;
}

    .suggestion-chip:hover {
        background: var(--bg-2);
        border-color: var(--accent);
        color: var(--text);
    }

/* Input area */
.chat-input-area {
    padding: 16px 24px 20px;
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
}

.input-container {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-lg);
    padding: 10px 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

    .input-container:focus-within {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px rgba(23,23,23,0.07);
    }

.message-textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 15px;
    color: var(--text);
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
}

    .message-textarea::placeholder {
        color: var(--text-3);
    }

.send-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    border: none;
    background: var(--accent);
    color: var(--accent-fg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

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

    .send-btn:not(:disabled):hover {
        opacity: 0.82;
    }

    .send-btn:not(:disabled):active {
        opacity: 0.64;
    }

.input-hint {
    font-size: 11px;
    color: var(--text-3);
    text-align: center;
    margin-top: 8px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: 10px;
}
