/* =========================================
   AI Chat - 纯白极简风格样式
   响应式：手机 / PC 全适配
   ========================================= */

:root {
    --bg: #ffffff;
    --bg-secondary: #f7f7f7;
    --bg-tertiary: #f0f0f0;
    --text: #1a1a1a;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --primary: #000000;
    --accent: #007aff;
    --danger: #ff3b30;
    --success: #34c759;
    --warning: #ff9500;
    --border: #e5e5e5;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 16px rgba(0,0,0,0.06);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

button {
    cursor: pointer;
    font-family: var(--font);
    border: none;
    outline: none;
    transition: opacity 0.2s;
}
button:active { opacity: 0.7; }

input, textarea, select {
    font-family: var(--font);
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg);
}
input:focus, textarea:focus {
    border-color: var(--primary);
}

/* ========== 按钮 ========== */
.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover { background: #333; }

.btn-sm {
    padding: 8px 16px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}
.btn-xs {
    padding: 4px 10px;
    background: var(--bg-tertiary);
    color: var(--text);
    border-radius: 4px;
    font-size: 0.75rem;
}

.btn-code {
    padding: 10px 16px;
    background: var(--bg-tertiary);
    color: var(--text);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
}

/* ========== 表单 ========== */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.form-group-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.form-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    min-height: 20px;
}
.flex-1 { flex: 1; }
.form-row {
    display: flex;
    gap: 1rem;
}
.form-row .form-group { flex: 1; }

/* ========== Alert ========== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-success { background: #e8f8ed; color: #1a7a3a; }
.alert-error { background: #ffeaea; color: #c0392b; }
.alert-warning { background: #fff8e8; color: #b07a00; }

/* ========== 认证页 ========== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background: var(--bg-secondary);
}
.auth-container {
    width: 100%;
    max-width: 400px;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}
.auth-header {
    text-align: center;
    margin-bottom: 1.5rem;
}
.auth-header h1 {
    font-size: 1.5rem;
    margin: 0.5rem 0;
}
.auth-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.auth-logo img {
    width: 64px;
    height: 64px;
    border-radius: 16px;
}
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}
.tab {
    flex: 1;
    padding: 10px;
    background: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== 顶部导航 ========== */
.top-bar {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 10px;
}
.top-bar-center {
    flex: 1;
    text-align: center;
}
.balance-display {
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.balance-display span { margin: 0 2px; }
.avatar-link { flex-shrink: 0; }
.avatar-sm {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}
.icon-btn {
    background: none;
    font-size: 1.2rem;
    padding: 4px 8px;
    color: var(--text);
}
.top-bar-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ========== 对话页 ========== */
.chat-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}
.chat-welcome {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}
.chat-welcome h2 {
    margin: 1rem 0 0.5rem;
    color: var(--text);
}
.welcome-icon { margin-bottom: 1rem; }

/* 消息气泡 */
.message-row {
    display: flex;
    margin: 8px 0;
    animation: fadeIn 0.3s ease;
}
.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }

.message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    word-break: break-word;
    line-height: 1.5;
    position: relative;
    font-size: 0.95rem;
}
.message-row.user .message-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message-row.assistant .message-bubble {
    background: var(--bg-secondary);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.message-time {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 4px;
    text-align: right;
}
.message-row.assistant .message-time { text-align: left; }

/* 流式打字效果 */
.typing-cursor::after {
    content: '▊';
    animation: blink 1s infinite;
}
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 输入区域 */
.input-area {
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
    background: var(--bg);
    border-top: 1px solid var(--border);
}
.input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    border: 1px solid var(--border);
}
.message-input {
    flex: 1;
    border: none !important;
    background: transparent;
    font-size: 0.95rem;
    padding: 8px 0;
    outline: none;
}
.send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

/* ========== 页面通用 ========== */
.page-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
}
.page-header h1 {
    flex: 1;
    font-size: 1.1rem;
    text-align: center;
}
.back-btn {
    color: var(--accent);
    font-size: 1rem;
}
.logout-btn {
    color: var(--danger);
    font-size: 0.9rem;
}
.page-content {
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

/* 个人中心 */
.profile-card {
    text-align: center;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.avatar-upload { cursor: pointer; position: relative; display: inline-block; }
.avatar-lg {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
}
.avatar-change-text {
    display: block;
    font-size: 0.8rem;
    color: var(--accent);
    margin-top: 6px;
}
.profile-nickname { display: block; font-size: 1.1rem; font-weight: 600; }
.profile-email { display: block; color: var(--text-secondary); font-size: 0.9rem; }
.profile-balance { display: block; margin-top: 8px; }

.section-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}
.section-card h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}
.section-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}
.inline-form {
    display: flex;
    gap: 8px;
}
.inline-form input { flex: 1; }
.form-stack { display: flex; flex-direction: column; gap: 8px; }

.log-list { max-height: 300px; overflow-y: auto; }
.log-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.log-type { color: var(--text-secondary); }
.log-amount.positive { color: var(--success); }
.log-amount.negative { color: var(--danger); }
.log-time { color: var(--text-tertiary); }

.empty-text { text-align: center; color: var(--text-tertiary); padding: 1rem; }

.info-list {
    list-style: none;
    padding: 0;
}
.info-list li {
    padding: 6px 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}
.info-list li:last-child { border-bottom: none; }

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.toast.show { opacity: 1; }

/* 公告栏 */
.announcement-bar {
    background: #fef9e7;
    color: #7d6608;
    padding: 8px 16px;
    font-size: 0.85rem;
    text-align: center;
    border-bottom: 1px solid #f9e79f;
}

/* ========== 管理员后台 ========== */
.admin-layout {
    display: flex;
    min-height: 100vh;
}
.admin-sidebar {
    width: 220px;
    background: var(--bg-secondary);
    padding: 1rem;
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
}
.admin-sidebar h2 {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    padding: 0 8px;
}
.admin-sidebar nav a {
    display: block;
    padding: 10px 12px;
    color: var(--text);
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    font-size: 0.9rem;
}
.admin-sidebar nav a.active {
    background: var(--primary);
    color: #fff;
}
.admin-main {
    flex: 1;
    padding: 1.5rem;
    overflow-x: auto;
}
.admin-main h1 {
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
}

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.stat-card h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}
.stat-number {
    font-size: 1.8rem;
    font-weight: 700;
    display: block;
}
.stat-card small {
    color: var(--text-tertiary);
    font-size: 0.8rem;
}

/* 数据表格 */
.table-responsive {
    overflow-x: auto;
    margin-bottom: 1rem;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.data-table th,
.data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    position: sticky;
    top: 0;
}
.data-table tbody tr:hover {
    background: var(--bg-secondary);
}
.message-preview {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.status-badge {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
}
.status-badge.active {
    background: #e8f5e9;
    color: #2e7d32;
}
.status-badge.disabled {
    background: #ffebee;
    color: #c62828;
}
.role-badge.user { color: var(--accent); }
.role-badge.assistant { color: var(--success); }
.empty-cell {
    text-align: center;
    color: var(--text-tertiary);
    padding: 2rem !important;
}
.action-cell {
    display: flex;
    gap: 4px;
}

/* 搜索表单 */
.search-form {
    display: flex;
    gap: 8px;
    margin-bottom: 1rem;
}
.search-form input {
    max-width: 300px;
}

/* 分页 */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin: 1rem 0;
}
.pagination a {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text);
}
.pagination a.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 1rem;
}
.modal-content {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 400px;
}
.modal-content h3 { margin-bottom: 1rem; }
.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 1rem;
}

/* 管理员登录 */
.admin-login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-secondary);
}
.admin-login-container {
    width: 100%;
    max-width: 380px;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}
.admin-login-container h1 { text-align: center; margin-bottom: 0.5rem; }
.subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.9rem; }
.hint { text-align: center; color: var(--text-tertiary); font-size: 0.8rem; margin-top: 1rem; }

/* 配置表单 */
.config-form .section-card {
    background: var(--bg);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

/* Toast */
#copyToast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
#copyToast.show {
    opacity: 1;
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .admin-layout {
        flex-direction: column;
    }
    .admin-sidebar {
        width: 100%;
        height: auto;
        position: relative;
        display: flex;
        overflow-x: auto;
        padding: 8px;
    }
    .admin-sidebar nav {
        display: flex;
        gap: 4px;
    }
    .admin-sidebar nav a {
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 8px 12px;
    }
    .admin-sidebar h2 { display: none; }
    .admin-main { padding: 1rem; }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .message-bubble {
        max-width: 90%;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }
}

@media (max-width: 480px) {
    .auth-container {
        padding: 1.5rem;
        border-radius: 0;
        box-shadow: none;
        max-width: 100%;
    }
    .auth-page {
        padding: 0;
        background: var(--bg);
        align-items: flex-start;
        padding-top: 10vh;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .stat-number { font-size: 1.4rem; }

    .top-bar { padding: 10px 12px; }
    .chat-container { padding: 0.75rem; }
    .input-area { padding: 8px 12px; }
}

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 选中文字样式 */
::selection {
    background: #e0e0e0;
    color: var(--text);
}

/* 滚动条 */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* 打印样式 */
@media print {
    .top-bar, .input-area, .admin-sidebar { display: none; }
}