/* ==================== 基础样式 ==================== */

* {
    --background: #0b1220;
    --surface: #0f172a;
    --surface-light: #1e293b;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --text-primary: #e5edf5;
    --text-secondary: #94a3b8;
    --border: #334155;
    --success: #22c55e;
    --error: #ef4444;

    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.25);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* ==================== 容器布局 ==================== */

.container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    margin: 0 auto;
}

.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card {
    width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-lg);
}

.login-card h2 {
    margin-bottom: var(--spacing-md);
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: var(--spacing-md);
}

.login-field input {
    padding: var(--spacing-sm);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--text-primary);
}

.login-actions {
    display: flex;
    justify-content: flex-end;
}

.btn-login {
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    padding: 8px 16px;
    cursor: pointer;
}

.btn-login:hover {
    background: var(--primary-hover);
}

.login-error {
    margin-top: var(--spacing-sm);
    color: var(--error);
}

/* ==================== 头部 ==================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    background: linear-gradient(180deg, #0f172a 0%, #0b1220 100%);
    border-bottom: 1px solid var(--border);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.user-badge {
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-full);
    min-width: 80px;
    text-align: center;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-new-chat {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    box-shadow: var(--shadow-md);
}

.btn-new-chat:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-new-chat:active {
    transform: translateY(0);
}

/* ==================== 消息列表 ==================== */

.messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
    scroll-behavior: smooth;
    background: radial-gradient(1200px 600px at 20% 0%, #0f172a 0%, #0b1220 60%);
}

.messages::-webkit-scrollbar {
    width: 6px;
    background: var(--surface);
}

.messages::-webkit-scrollbar-track {
    background: var(--surface);
    border-left: 1px solid var(--border);
}

.messages::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: var(--radius-sm);
}

/* 欢迎消息 */
.welcome-message {
    text-align: center;
    padding: var(--spacing-xl) 0;
    opacity: 0.95;
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-md);
}

.welcome-message h2 {
    margin-bottom: var(--spacing-sm);
}

.welcome-message p {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

.example-queries {
    margin-top: var(--spacing-xl);
    text-align: left;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.example-queries p {
    font-size: 0.9rem;
    margin-bottom: var(--spacing-sm);
}

.example-item {
    background: var(--surface);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-sm);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border);
}

.example-item:hover {
    background: var(--surface-light);
    transform: translateX(4px);
}

/* 消息气泡 */
.message {
    margin-bottom: var(--spacing-lg);
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-user,
.message-assistant {
    display: flex;
    gap: var(--spacing-md);
    align-items: flex-start;
}

.message-user {
    flex-direction: row-reverse;
    align-items: flex-start;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.message-user .message-avatar {
    background: var(--primary-color);
}

.message-assistant .message-avatar {
    background: var(--surface-light);
    color: #e2e8f0;
}

.message-content {
    max-width: 80%;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    box-shadow: var(--shadow-md);
    border: 1px solid transparent;
}

.message-author {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.message-user .message-content {
    background: var(--primary-color);
    border-bottom-right-radius: var(--spacing-xs);
    color: #ffffff;
}

.message-assistant .message-content {
    background: var(--surface);
    border-bottom-left-radius: var(--spacing-xs);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

/* Markdown内容样式 */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin-top: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--spacing-md) 0;
    font-size: 0.9rem;
    overflow-x: auto;
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.message-content th,
.message-content td {
    padding: var(--spacing-sm);
    border: 1px solid var(--border);
    text-align: left;
    color: var(--text-primary);
}

.message-content th {
    background: var(--surface-light);
    font-weight: 600;
    color: var(--text-primary);
}

.message-content code {
    background: var(--surface-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    border: 1px solid var(--border);
}

.message-content pre {
    background: var(--surface-light);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: var(--spacing-sm) 0;
    border: 1px solid var(--border);
}

.message-content pre code {
    padding: 0;
    background: none;
}

.tool-logs {
    margin-top: var(--spacing-md);
    border-top: 1px dashed var(--border);
    padding-top: var(--spacing-md);
}

.tool-entry,
.tool-result {
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

.tool-header {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tool-input pre,
.tool-output pre {
    background: var(--background);
    border: 1px solid var(--border);
}

.tool-entry.collapsed .tool-input,
.tool-result.collapsed .tool-output {
    display: none;
}

.tool-logs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.tool-toggle-all {
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    cursor: pointer;
}

.tool-toggle-all:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

/* 思考指示器 */
.thinking {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: var(--spacing-sm);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.thinking-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* ==================== 输入区域 ==================== */

.input-container {
    padding: var(--spacing-lg);
    background: linear-gradient(180deg, #0f172a 0%, #0b1220 100%);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-end;
}

#userInput {
    flex: 1;
    padding: var(--spacing-md);
    background: var(--background);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    box-shadow: var(--shadow-sm) inset;
}

#userInput:focus {
    outline: none;
    border-color: var(--primary-color);
}

#userInput::placeholder {
    color: var(--text-secondary);
}

.btn-send {
    width: 44px;
    height: 44px;
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: var(--shadow-md);
}

.btn-send:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.9;
    cursor: not-allowed;
}

.send-icon {
    font-size: 1.2rem;
    color: white;
    transform: translateY(-1px);
}

/* ==================== 移动端适配 ==================== */

@media (max-width: 768px) {
    .header {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .btn-new-chat {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 0.85rem;
    }

    .messages {
        padding: var(--spacing-md);
    }

    .message-content {
        max-width: 85%;
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 0.95rem;
    }

    .welcome-icon {
        font-size: 3rem;
    }

    .example-queries {
        padding: 0 var(--spacing-sm);
    }

    .input-container {
        padding: var(--spacing-md);
    }

    #userInput {
        font-size: 16px;
        /* 防止iOS放大 */
    }

    .message-content table {
        font-size: 0.8rem;
        display: block;
        overflow-x: auto;
    }
}

/* iPhone X及以上安全区域适配 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .input-container {
        padding-bottom: calc(var(--spacing-lg) + env(safe-area-inset-bottom));
    }
}
.btn-send.busy,
.btn-send.busy:disabled {
    background: var(--error);
    color: #fff;
    opacity: 1;
}
