:root {
    --bg-color: #0d1117;
    --text-color: #c9d1d9;
    --accent-color: #58a6ff;
    --secondary-accent: #3fb950;
    --border-color: #30363d;
    --card-bg: #161b22;
    --user-msg-bg: #1f2937;
    --assistant-msg-bg: #161b22;
    --code-bg: #0d1117;
    --muted: #8b949e;
    --danger: #da3633;
    --warning: #d29922;
}

* {
    box-sizing: border-box;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

::selection {
    background: rgba(88, 166, 255, 0.3);
    color: #fff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    line-height: 1.6;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    transition: color 0.2s;
}

header {
    border-bottom: 1px solid var(--border-color);
    padding: 0.85rem 0;
    flex-shrink: 0;
    background: rgba(13, 17, 23, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header a {
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

header a:hover {
    color: var(--accent-color);
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 0 0.5rem;
    scroll-behavior: smooth;
}

#chat-messages .placeholder {
    text-align: center;
    color: var(--muted);
    margin-top: 5rem;
    animation: fadeIn 0.5s ease;
}

#chat-messages .placeholder h2 {
    color: #fff;
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
    font-weight: 600;
}

#chat-messages .placeholder p {
    font-size: 0.9rem;
    opacity: 0.7;
}

.message {
    margin-bottom: 1.25rem;
    animation: messageSlide 0.3s ease;
}

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

.message-header {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--muted);
}

.message-header .avatar {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.message.user .avatar {
    background: linear-gradient(135deg, var(--accent-color), #1a6bcc);
    color: #fff;
}

.message.assistant .avatar {
    background: linear-gradient(135deg, var(--secondary-accent), #1a8a3a);
    color: #fff;
}

.message.error .avatar {
    background: linear-gradient(135deg, var(--danger), #b3302e);
    color: #fff;
}

.message .content {
    padding: 0.85rem 1rem;
    border-radius: 10px;
    line-height: 1.65;
    font-size: 0.95rem;
    overflow-wrap: break-word;
    transition: border-color 0.2s;
}

.message.user .content {
    background: var(--user-msg-bg);
    border: 1px solid var(--border-color);
    margin-left: 3rem;
}

.message.assistant .content {
    background: var(--assistant-msg-bg);
    border: 1px solid var(--border-color);
    margin-right: 3rem;
    position: relative;
}

.message.assistant .content:last-child {
    border-color: rgba(88, 166, 255, 0.15);
}

.message.error .content {
    background: rgba(218, 54, 51, 0.08);
    border: 1px solid rgba(218, 54, 51, 0.25);
    color: #f85149;
}

.message .content p {
    margin: 0 0 0.5rem 0;
}

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

.message .content > p:first-child {
    margin-top: 0;
}

.message .content h1,
.message .content h2,
.message .content h3,
.message .content h4 {
    color: #fff;
    margin: 1.25rem 0 0.5rem 0;
    font-weight: 600;
}

.message .content h1 { font-size: 1.35rem; }
.message .content h2 { font-size: 1.2rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.3rem; }
.message .content h3 { font-size: 1.1rem; }
.message .content h4 { font-size: 1rem; }

.message .content ul,
.message .content ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.message .content li {
    margin-bottom: 0.25rem;
}

.message .content blockquote {
    border-left: 3px solid var(--accent-color);
    padding: 0.25rem 0 0.25rem 1rem;
    margin: 0.5rem 0;
    color: var(--muted);
    background: rgba(88, 166, 255, 0.04);
    border-radius: 0 4px 4px 0;
}

.message .content code {
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
    font-size: 0.82rem;
    background: var(--code-bg);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.message .content pre {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.85rem 1rem;
    overflow-x: auto;
    margin: 0.5rem 0;
    position: relative;
}

.message .content pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.82rem;
    line-height: 1.55;
}

.message .content pre .lang-tag {
    position: absolute;
    top: 0.35rem;
    right: 0.6rem;
    font-size: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.6;
}

.message .content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75rem 0;
    font-size: 0.88rem;
    border-radius: 6px;
    overflow: hidden;
}

.message .content th,
.message .content td {
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.message .content th {
    background: var(--card-bg);
    color: #fff;
    font-weight: 600;
}

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

.message .content a:hover {
    text-decoration: underline;
}

.message .content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1rem 0;
}

.message .content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 0.5rem 0;
    border: 1px solid var(--border-color);
}

.source-info {
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 0.6rem;
    padding: 0.3rem 0.7rem;
    background: var(--card-bg);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid var(--border-color);
    opacity: 0.85;
    transition: opacity 0.2s;
}

.source-info:hover {
    opacity: 1;
}

.source-info::before {
    content: '\1F4CB';
    font-size: 0.7rem;
}

#input-area {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    padding: 0.85rem 0;
    background: var(--bg-color);
}

#input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-color);
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    min-height: 48px;
    max-height: 200px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#chat-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.08);
}

#chat-input::placeholder {
    color: var(--muted);
    opacity: 0.6;
}

#send-btn {
    background: linear-gradient(135deg, var(--accent-color), #1a6bcc);
    color: #fff;
    border: none;
    border-radius: 10px;
    width: 48px;
    height: 48px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.15s;
}

#send-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

#send-btn:active {
    transform: translateY(0);
}

#send-btn:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    opacity: 1;
    transform: none;
}

#send-btn svg {
    width: 20px;
    height: 20px;
}

#api-status {
    font-size: 0.72rem;
    color: var(--muted);
    padding: 0.5rem 0 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#api-status .status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
}

#api-status .status-dot.ready {
    background: var(--secondary-accent);
    box-shadow: 0 0 6px rgba(63, 185, 80, 0.4);
}

#api-status .status-dot.loading {
    background: var(--warning);
    animation: pulse 1.2s ease-in-out infinite;
}

#api-status .status-dot.error {
    background: var(--danger);
    box-shadow: 0 0 6px rgba(218, 54, 51, 0.4);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

#model-select {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

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

.model-badge {
    font-size: 0.72rem;
    color: var(--muted);
}

footer {
    border-top: 1px solid var(--border-color);
    padding: 0.85rem 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
    flex-shrink: 0;
    opacity: 0.7;
}

#loading-indicator {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0;
    color: var(--muted);
    font-size: 0.82rem;
}

#loading-indicator .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Auth ───────────────────────────────────────────── */

#auth-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 20px;
    position: relative;
    overflow: hidden;
}

#auth-screen::before {
    content: '';
    position: absolute;
    width: 640px;
    height: 640px;
    background: radial-gradient(circle, rgba(88, 166, 255, 0.05) 0%, transparent 70%);
    top: -240px;
    right: -240px;
    pointer-events: none;
}

#auth-screen::after {
    content: '';
    position: absolute;
    width: 540px;
    height: 540px;
    background: radial-gradient(circle, rgba(63, 185, 80, 0.03) 0%, transparent 70%);
    bottom: -240px;
    left: -240px;
    pointer-events: none;
}

.auth-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2.5rem 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
    position: relative;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.03);
    animation: cardEnter 0.4s ease;
}

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

.auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-color), #79c0ff, var(--secondary-accent), var(--accent-color));
    background-size: 300% 100%;
    animation: shimmer 4s ease-in-out infinite;
    border-radius: 16px 16px 0 0;
}

@keyframes shimmer {
    0%, 100% { background-position: 0% 0; }
    50% { background-position: 100% 0; }
}

.auth-logo {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent-color), #1a6bcc);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: #fff;
    box-shadow: 0 4px 16px rgba(88, 166, 255, 0.25);
    transition: transform 0.2s;
}

.auth-card:hover .auth-logo {
    transform: scale(1.03);
}

.auth-card h2 {
    color: #fff;
    margin: 0 0 0.35rem 0;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.auth-subtitle {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0 0 1.75rem 0;
    line-height: 1.4;
}

.auth-error {
    background: rgba(218, 54, 51, 0.08);
    border: 1px solid rgba(218, 54, 51, 0.25);
    border-radius: 8px;
    padding: 0.65rem 1rem;
    margin-bottom: 1rem;
    color: #f85149;
    font-size: 0.82rem;
    text-align: left;
    line-height: 1.4;
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.auth-input-wrap {
    position: relative;
    margin-bottom: 0.85rem;
}

.auth-input-wrap .input-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--muted);
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.2s;
}

.auth-input-wrap:focus-within .input-icon {
    opacity: 0.8;
    color: var(--accent-color);
}

.auth-input {
    display: block;
    width: 100%;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.auth-input::placeholder {
    color: var(--muted);
    opacity: 0.45;
    font-size: 0.88rem;
}

.auth-submit-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-color), #1a6bcc);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.78rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    margin-top: 0.5rem;
    letter-spacing: 0.01em;
}

.auth-submit-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.25);
}

.auth-submit-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.auth-submit-btn:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
    box-shadow: none;
}

.auth-switch {
    margin-top: 1.5rem;
    color: var(--muted);
    font-size: 0.82rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

.auth-switch a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.auth-switch a:hover {
    color: #79c0ff;
    text-decoration: underline;
}

.auth-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 6px;
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.auth-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background: rgba(88, 166, 255, 0.06);
}

.auth-badge {
    font-size: 0.75rem;
    color: var(--secondary-accent);
    padding: 0.2rem 0.6rem;
    border: 1px solid rgba(63, 185, 80, 0.25);
    border-radius: 5px;
    background: rgba(63, 185, 80, 0.06);
    font-weight: 500;
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 900px) {
    #chat-messages {
        padding: 1rem 0 0.25rem;
    }

    .message.user .content {
        margin-left: 0;
    }

    .message.assistant .content {
        margin-right: 0;
    }

    .auth-card {
        padding: 2rem 1.5rem 1.5rem;
    }

    #api-status {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }
}

@media (max-width: 768px) {
    .container, #chat-container {
        padding: 0 12px;
    }

    header .container {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    header nav > div:last-child {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
    }

    header a {
        font-size: 0.82rem;
    }

    #chat-messages {
        padding: 0.75rem 0 0.25rem;
    }

    .message .content {
        font-size: 0.92rem;
    }

    #chat-input {
        font-size: 0.92rem;
        min-height: 44px;
    }

    #send-btn {
        width: 44px;
        height: 44px;
    }

    .auth-card {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }

    #auth-screen::before,
    #auth-screen::after {
        display: none;
    }

    footer {
        font-size: 0.75rem;
        padding: 0.65rem 0;
    }
}
