/* ============================================
   多模型 LLM 网关 - 样式
   ============================================ */

:root {
    --bg: #f5f5f5;
    --card: #ffffff;
    --text: #1a1a1a;
    --text-secondary: #666;
    --border: #e0e0e0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ── Topbar ── */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 56px;
    gap: 32px;
}
.logo {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
    text-decoration: none;
}
.nav-links { display: flex; gap: 16px; }
.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: all 0.2s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--primary); color: white; }

/* ── Container ── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ── Chat Layout ── */
.chat-layout {
    display: flex;
    gap: 16px;
    height: calc(100vh - 100px);
}
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    overflow-y: auto;
}
.sidebar-section { margin-bottom: 16px; }
.sidebar-section h3 {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.radio-item {
    display: block;
    padding: 4px 0;
    font-size: 14px;
    cursor: pointer;
}
.radio-item input { margin-right: 6px; }

#model-list label {
    display: block;
    font-size: 13px;
    padding: 3px 0;
    cursor: pointer;
}
#model-list input { margin-right: 6px; }

.model-status-item {
    font-size: 12px;
    padding: 2px 0;
    display: flex;
    justify-content: space-between;
}
.status-ok { color: var(--success); }
.status-fail { color: var(--danger); }
.status-open { color: var(--warning); }

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}
.welcome {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.welcome h2 { font-size: 24px; color: var(--text); margin-bottom: 12px; }
.welcome p { margin-bottom: 8px; }

/* ── Message Bubbles ── */
.message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
}
.message.user { align-items: flex-end; }
.message .bubble {
    max-width: 70%;
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}
.message.user .bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
    background: var(--bg);
    border-bottom-left-radius: 4px;
}
.message .model-tag {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    margin-left: 4px;
}
.message.system .bubble {
    background: #fef3c7;
    color: #92400e;
    font-size: 13px;
    text-align: center;
    max-width: 100%;
}

/* Broadcast columns */
.broadcast-columns {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}
.broadcast-col {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    min-width: 0;
}
.broadcast-col .col-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.broadcast-col .col-content {
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ── Input Area ── */
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--card);
}
.chat-input-area textarea {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
    min-height: 44px;
    max-height: 150px;
}
.chat-input-area textarea:focus { border-color: var(--primary); }

/* ── Buttons ── */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
    background: var(--border);
    color: var(--text);
    border: none;
    border-radius: var(--radius);
    padding: 10px 24px;
    font-size: 14px;
    cursor: pointer;
}

/* ── Table ── */
.table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.table th, .table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
}
.table tbody tr:hover { background: var(--bg); }
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 16px;
    border-radius: 4px;
}
.btn-icon:hover { background: var(--border); }

/* ── Modal ── */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 640px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}
.modal-close:hover { color: var(--text); }
.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}
.form-row label {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
}
.form-row input, .form-row select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    margin-top: 4px;
    outline: none;
}
.form-row input:focus { border-color: var(--primary); }

/* ── Stats ── */
.stats-tabs { margin-bottom: 16px; display: flex; gap: 8px; }
.tab-btn {
    padding: 8px 20px;
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}
.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.stats-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.stats-card h3 { font-size: 14px; margin-bottom: 16px; color: var(--text-secondary); }
.chart { min-height: 200px; }

/* Progress bar */
.progress-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--border);
    overflow: hidden;
    margin-top: 4px;
}
.progress-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--primary);
    transition: width 0.3s;
}

/* ── Responsive ── */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    color: var(--text);
}

@media (max-width: 768px) {
    /* 顶栏：折叠为汉堡按钮 */
    .topbar-inner { gap: 12px; height: 48px; }
    .menu-toggle { display: inline-block; }
    .logo { font-size: 15px; }
    .nav-links {
        display: none;
        position: absolute;
        top: 48px;
        left: 0;
        right: 0;
        background: var(--card);
        flex-direction: column;
        gap: 0;
        box-shadow: var(--shadow);
        border-top: 1px solid var(--border);
    }
    .nav-links.open { display: flex; }
    .nav-link {
        padding: 12px 16px;
        border-radius: 0;
        border-bottom: 1px solid var(--border);
    }

    /* 聊天布局：垂直排列，sidebar 收起 */
    .container { padding: 12px; }
    .chat-layout { flex-direction: column; height: auto; }
    .sidebar { width: 100%; max-height: none; }
    .chat-messages { padding: 12px; }
    .chat-input-area { padding: 8px; }
    .chat-input-area textarea { font-size: 16px; min-height: 40px; }
    .broadcast-columns { flex-direction: column; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }

    /* 表格：横向滚动 */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table { min-width: 600px; }
    .table th, .table td { padding: 8px 10px; font-size: 12px; }

    /* 消息气泡：占满 */
    .message .bubble { max-width: 90%; }

    /* 模态框 */
    .modal-content { padding: 20px; width: 95%; }

    /* 工具调用卡片 */
    .tool-call-card, .tool-result-card { font-size: 11px; }

    /* 思考块 */
    .reasoning-block { font-size: 11px; padding: 6px 10px; }

    /* Vditor 预览文字稍小 */
    .vditor-reset { font-size: 14px; }
}

/* 超小屏优化 */
@media (max-width: 480px) {
    .logo { display: none; }
    .topbar-inner { justify-content: center; }
    .chat-input-area .btn-primary { padding: 8px 14px; }
}

/* ── 服务下拉菜单 ── */
.nav-dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-trigger {
    cursor: pointer;
    user-select: none;
}
.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 200;
    padding: 6px 0;
}
.nav-dropdown:hover .dropdown-menu,
.dropdown-menu:hover {
    display: block;
}
.dropdown-item {
    display: block;
    padding: 8px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
}
.dropdown-item:hover {
    background: var(--bg);
    color: var(--primary);
}
/* 移动端适配：下拉菜单变内联 */
@media (max-width: 768px) {
    .nav-dropdown { display: block; width: 100%; }
    .dropdown-menu {
        position: static;
        display: none;
        box-shadow: none;
        border: none;
        padding-left: 16px;
    }
    .nav-dropdown.open .dropdown-menu { display: block; }
}
