/* ==========================================================
   1. 全局 CSS 变量和重置
   ========================================================== */
:root {
    --color-primary: #4f46e5;
    --color-primary-dark: #4338ca;
    --color-primary-light: #e0e7ff;
    --color-secondary: #6b7280;
    --color-secondary-light: #f3f4f6;
    --color-danger: #dc2626;
    --color-danger-dark: #b91c1c;
    --color-danger-light: #fef2f2;
    --color-success: #16a34a;
    --color-success-light: #f0fdf4;
    --color-warning: #d97706;
    --color-warning-light: #fffbeb;
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-text-muted: #9ca3af;
    --color-bg: #f1f5f9;
    --color-white: #ffffff;
    --color-border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.08);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-2xl: 1rem;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 0.5rem;
}
h1 { font-size: 1.25rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.1rem; }

/* ==========================================================
   2. 基础表格
   ========================================================== */
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}
thead th {
    background: linear-gradient(90deg, #f8f9ff 0%, #f5f3ff 100%);
    color: var(--color-text-light);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color 0.15s; }
tbody tr:hover { background-color: #faf9ff; }
td small {
    color: var(--color-text-light);
    font-family: monospace;
    font-size: 0.82em;
}
.table-loading {
    text-align: center;
    color: var(--color-text-muted);
    padding: 2rem !important;
    font-size: 0.9rem;
    white-space: normal !important;
}

/* ==========================================================
   3. 公共卡片与容器
   ========================================================== */
.card {
    background: var(--color-white);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    border: 1px solid rgba(255,255,255,0.8);
}
.table-container {
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

/* ==========================================================
   4. 辅助 / 工具类
   ========================================================== */
.hidden { display: none !important; }
.mt-2 { margin-top: 2rem; }
.full-width { width: 100%; }
.error-text {
    color: var(--color-danger);
    font-size: 0.875rem;
    min-height: 1.25rem;
}
.success-text { color: var(--color-success) !important; font-weight: 600; }
.fail-text { color: var(--color-danger) !important; font-weight: 600; }

.loading-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 3rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-xl);
}
.loading-spinner {
    display: inline-block;
    width: 1.1rem;
    height: 1.1rem;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================
   5. 登录遮罩
   ========================================================== */
#login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #4f46e5 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.login-box {
    width: 100%;
    max-width: 420px;
    background: var(--color-white);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    padding: 2.5rem 2rem;
    text-align: center;
    animation: loginFadeIn 0.4s ease;
}
@keyframes loginFadeIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-box h2 {
    font-size: 1.75rem;
    background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--color-text-light);
    font-size: 0.9rem;
    margin-bottom: 1.75rem;
}

.login-box .input-group {
    text-align: left;
    margin-bottom: 1rem;
}

.login-box label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.4rem;
    display: block;
}

/* input-icon-wrap 保留为弹性容器，图标已移除，input 正常宽度填充 */
.input-icon-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.login-box .button-primary {
    margin-top: 0.5rem;
    padding: 0.85rem;
    font-size: 1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
    letter-spacing: 0.05em;
}
.login-box .button-primary:hover {
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, #6d28d9 100%);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5);
    transform: translateY(-2px);
}

/* ==========================================================
   6. 顶部导航栏
   ========================================================== */
#top-bar {
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    gap: 1rem;
}
.header-brand { display: flex; align-items: center; gap: 0.75rem; }
.header-logo { font-size: 1.6rem; line-height: 1; }
.header-brand h1 {
    font-size: 1.1rem;
    margin: 0;
    background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.header-tagline { font-size: 0.72rem; color: var(--color-text-muted); display: block; margin-top: 0.05rem; }
.header-actions { display: flex; align-items: center; gap: 1rem; }
.header-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.75rem;
    background: var(--color-success-light);
    border: 1px solid #bbf7d0;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-success);
}
.status-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--color-success);
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(0.85); }
}

/* ==========================================================
   7. 主应用容器
   ========================================================== */
#app-container {
    max-width: 1200px;
    margin: 1.25rem auto;
    padding: 0 1.5rem;
}

/* ==========================================================
   8. 选项卡导航
   ========================================================== */
.tabs {
    display: flex;
    padding: 0.4rem;
    background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%);
    border-radius: var(--radius-2xl);
    border: 1px solid var(--color-primary-light);
    box-shadow: var(--shadow-md);
    margin-bottom: 1.25rem;
}
.tab-button {
    flex: 1;
    position: relative;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    background-color: transparent;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    color: var(--color-text-light);
    transition: all 0.2s;
    letter-spacing: 0.01em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    white-space: nowrap;
}
.tab-icon { font-size: 1rem; }
.tab-button:hover {
    color: var(--color-primary);
    background-color: rgba(79, 70, 229, 0.06);
    transform: none;
    box-shadow: none;
}
.tab-button.active {
    background: var(--color-white);
    color: var(--color-primary);
    box-shadow: var(--shadow-md);
    font-weight: 700;
}
.tab-content { display: none; }
.tab-content.active {
    display: block;
    animation: tabFadeIn 0.22s ease;
}
@keyframes tabFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================
   9. API 配置区块
   ========================================================== */
.config-tab-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--color-border);
}
.config-tab-header h2 { margin-bottom: 0.2rem; }
.config-tab-desc { font-size: 0.85rem; color: var(--color-text-light); margin: 0; }
.config-tab-header .button-primary {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
    white-space: nowrap;
}
.config-tab-header .button-primary:hover {
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, #6d28d9 100%);
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
}

#config-schemes-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
#config-schemes-container > p {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.95rem;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-xl);
    background-color: #fafafa;
}

.scheme-block {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}
.scheme-block:hover { box-shadow: var(--shadow-md); }

.scheme-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 60%, #e0e7ff 100%);
    border-bottom: 1px solid var(--color-primary-light);
}
.scheme-header-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.scheme-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
    color: var(--color-white);
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.35);
}
.scheme-header h3 {
    font-size: 0.9rem;
    font-weight: 700;
    margin: 0;
    color: var(--color-primary-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.scheme-header h3 small {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--color-text-light);
    margin-left: 0.35rem;
}
.scheme-header-right { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.scheme-count-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    background-color: rgba(79, 70, 229, 0.1);
    color: var(--color-primary);
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}
.scheme-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.28rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    background-color: var(--color-white);
    border: 1px solid var(--color-primary-light);
    border-radius: 999px;
    color: var(--color-primary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.scheme-toggle-btn:hover {
    background-color: var(--color-primary-light);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.config-card-list { display: flex; flex-direction: column; }
.config-card {
    display: grid;
    grid-template-columns: 2.5rem 1fr auto;
    align-items: center;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    transition: background-color 0.15s;
}
.config-card:last-child { border-bottom: none; }
.config-card:hover { background-color: #faf9ff; }

.config-card-priority {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary-light) 0%, #ddd6fe 100%);
    color: var(--color-primary-dark);
    font-size: 0.82rem;
    font-weight: 700;
    flex-shrink: 0;
}
.config-card-body { min-width: 0; padding: 0 1rem; }
.config-card-row1 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    min-width: 0;
}
.config-card-url {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}
.config-card-model {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    background-color: var(--color-success-light);
    color: var(--color-success);
    border: 1px solid #bbf7d0;
    white-space: nowrap;
}
.config-card-model.is-passthrough {
    background-color: var(--color-secondary-light);
    color: var(--color-text-light);
    border-color: var(--color-border);
}
.config-card-tags { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.tag {
    display: inline-flex;
    align-items: center;
    padding: 0.08rem 0.45rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid transparent;
}
.tag-key      { background: #fefce8; color: #854d0e; border-color: #fde68a; font-family: monospace; }
.tag-ua       { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.tag-retry    { background: var(--color-success-light); color: #15803d; border-color: #bbf7d0; }
.tag-circuit  { background: var(--color-warning-light); color: #92400e; border-color: #fde68a; }
.tag-stream   { background: #fdf4ff; color: #7e22ce; border-color: #e9d5ff; }
.tag-inject   { background: #f0f9ff; color: #0369a1; border-color: #bae6fd; }
.tag-override { background: #fafafa; color: var(--color-text-light); border-color: var(--color-border); }

.config-card-id {
    margin-top: 0.25rem;
    font-size: 0.65rem;
    color: var(--color-text-muted);
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.config-card-actions { display: flex; flex-direction: column; gap: 0.35rem; flex-shrink: 0; }
.config-card-actions .edit-btn,
.config-card-actions .delete-btn {
    padding: 0.3rem 0.8rem;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s;
    cursor: pointer;
    border: 1px solid transparent;
    white-space: nowrap;
}
.config-card-actions .edit-btn {
    background-color: var(--color-primary-light);
    border-color: rgba(79, 70, 229, 0.2);
    color: var(--color-primary-dark);
}
.config-card-actions .edit-btn:hover {
    background-color: #c7d2fe;
    border-color: rgba(79, 70, 229, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.15);
}
.config-card-actions .delete-btn {
    background-color: var(--color-danger-light);
    border-color: rgba(220, 38, 38, 0.2);
    color: var(--color-danger);
}
.config-card-actions .delete-btn:hover {
    background-color: #fee2e2;
    border-color: rgba(220, 38, 38, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.15);
}
.config-card-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* ==========================================================
   10. 配置模态窗
   ========================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    animation: overlayFadeIn 0.2s ease;
}
@keyframes overlayFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.modal-content {
    position: relative;
    width: 100%;
    max-width: 820px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: var(--color-white);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--color-border);
    background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%);
    flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: 1.05rem; font-weight: 700; color: var(--color-primary-dark); }
.modal-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    background: var(--color-white);
    border: 1px solid var(--color-border);
    font-size: 1.25rem;
    line-height: 1;
    color: var(--color-text-light);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    padding: 0;
}
.modal-close-btn:hover {
    background-color: var(--color-danger-light);
    border-color: rgba(220, 38, 38, 0.3);
    color: var(--color-danger);
    transform: none;
    box-shadow: none;
}
.modal-body { overflow-y: auto; padding: 1.5rem 1.75rem; flex: 1; }

/* ==========================================================
   11. 配置表单（模态窗内）
   ========================================================== */
.form-section {
    margin-bottom: 1.25rem;
    padding: 1.1rem 1.25rem;
    background: #fafbff;
    border: 1px solid #eef0ff;
    border-radius: var(--radius-xl);
}
.form-section:last-of-type { margin-bottom: 0; }
.form-section-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-primary-dark);
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid #eef0ff;
}
.form-section-icon { font-size: 0.95rem; }
.form-section-hint { font-size: 0.72rem; font-weight: 400; color: var(--color-text-muted); margin-left: 0.25rem; }
.label-hint { font-weight: 400; font-size: 0.78rem; color: var(--color-text-muted); }
.form-hint { display: block; margin-top: 0.4rem; font-size: 0.78rem; color: var(--color-text-light); line-height: 1.5; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 0.85rem; }
@media (min-width: 600px) {
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .full-span { grid-column: 1 / -1; }
}
.form-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border);
}

.preset-card {
    margin-top: 1.25rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}
.preset-card:hover { box-shadow: var(--shadow-md); }
.preset-card-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.8rem 1.1rem;
    background: linear-gradient(135deg, #fafafa 0%, #f5f3ff 100%);
    border: none;
    border-bottom: 1px solid transparent;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s;
    border-radius: 0;
}
.preset-card-toggle:hover {
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    transform: none;
    box-shadow: none;
}
.preset-card.is-open .preset-card-toggle {
    border-bottom-color: var(--color-border);
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
}
.preset-card-toggle-left { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.preset-card-icon { font-size: 1rem; flex-shrink: 0; }
.preset-card-title { font-size: 0.88rem; font-weight: 700; color: var(--color-primary-dark); white-space: nowrap; }
.preset-card-desc { font-size: 0.75rem; color: var(--color-text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset-card-chevron {
    font-size: 1.3rem;
    line-height: 1;
    color: var(--color-primary);
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: inline-block;
}
.preset-card.is-open .preset-card-chevron { transform: rotate(90deg); }
.preset-card-body { padding: 1rem; animation: presetFadeIn 0.2s ease; }
@keyframes presetFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.preset-card-body .table-container { border-radius: var(--radius-md); }
.preset-card-body thead th { font-size: 0.72rem; }
.preset-card-body tbody tr:hover { background-color: #faf9ff; }
.preset-card-body td { font-size: 0.82rem; padding: 0.55rem 0.85rem; }
.preset-card-body code {
    font-family: Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    color: var(--color-primary-dark);
    background: var(--color-primary-light);
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-sm);
}
.preset-add-btn {
    padding: 0.22rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--color-primary-light) 0%, #ddd6fe 100%);
    color: var(--color-primary-dark);
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.18s;
    white-space: nowrap;
}
.preset-add-btn:hover {
    background: linear-gradient(135deg, #c7d2fe 0%, #c4b5fd 100%);
    border-color: rgba(79, 70, 229, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.15);
}

.model-picker-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 0.45fr);
    gap: 0.65rem;
    align-items: stretch;
}
.model-dropdown-wrap {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.4rem;
    padding: 0.3rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: var(--shadow-sm);
}
.model-query-button {
    white-space: nowrap;
    padding: 0.55rem 0.85rem;
    font-size: 0.85rem;
    background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
    color: var(--color-white);
    border: none;
}
.model-query-button:hover { background: linear-gradient(135deg, var(--color-primary-dark) 0%, #6d28d9 100%); }
.model-query-button:disabled,
.model-picker-select:disabled { opacity: 0.65; cursor: not-allowed; }
.model-picker-select {
    border: none;
    background-color: transparent;
    padding: 0.55rem 0.4rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text);
}
.model-picker-select:focus { box-shadow: none; }
.model-query-status { display: block; margin-top: 0.4rem; font-size: 0.78rem; color: var(--color-text-light); }
#config-custom-user-agent:disabled {
    background-color: var(--color-secondary-light);
    color: var(--color-text-light);
    cursor: not-allowed;
}

.injected-messages-editor { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.65rem; }
.injected-message-row {
    display: grid;
    grid-template-columns: 120px 100px 1fr auto;
    gap: 0.45rem;
    align-items: start;
    padding: 0.65rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background-color: var(--color-white);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.injected-message-row:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}
.injected-message-row .injected-content-input { min-height: 2.8rem; }
.btn-sm { padding: 0.45rem 0.85rem !important; font-size: 0.82rem !important; }

/* ==========================================================
   12. 统计区块
   ========================================================== */
.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}
.section-header h2 { margin-bottom: 0.15rem; }
.section-desc { font-size: 0.82rem; color: var(--color-text-muted); margin: 0; }

.stats-overview {
    display: flex;
    align-items: stretch;
    gap: 1rem;
    background: linear-gradient(135deg, #fafbff 0%, #f5f3ff 100%);
    border: 1px solid #eef0ff;
    border-radius: var(--radius-xl);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.stats-overview-group { flex: 1; min-width: 200px; }
.stats-overview-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}
.stats-overview-cards { display: flex; gap: 0.75rem; }
.stats-overview-divider { width: 1px; background: var(--color-border); align-self: stretch; flex-shrink: 0; }

.stat-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-lg);
    flex: 1;
    min-width: 0;
    border: 1px solid transparent;
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card--success { background: var(--color-success-light); border-color: #bbf7d0; }
.stat-card--fail    { background: var(--color-danger-light);  border-color: #fecaca; }
.stat-card-icon { font-size: 1.4rem; flex-shrink: 0; }
.stat-card-value { font-size: 1.75rem; font-weight: 800; line-height: 1; color: var(--color-text); }
.stat-card--success .stat-card-value { color: var(--color-success); }
.stat-card--fail    .stat-card-value { color: var(--color-danger); }
.stat-card-label { font-size: 0.75rem; color: var(--color-text-muted); margin-top: 0.15rem; font-weight: 500; }

.stats-detail-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.stats-scheme-block {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}
.stats-scheme-block:hover { box-shadow: var(--shadow-md); }

.stats-scheme-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 60%, #e0e7ff 100%);
    border-bottom: 1px solid var(--color-primary-light);
}
.stats-scheme-header-left { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.stats-scheme-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
    color: var(--color-white);
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}
.stats-scheme-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--color-primary-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stats-scheme-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}
.stats-scheme-summary {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.stats-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}
.stats-badge--success {
    background: var(--color-success-light);
    color: var(--color-success);
    border: 1px solid #bbf7d0;
}
.stats-badge--fail {
    background: var(--color-danger-light);
    color: var(--color-danger);
    border: 1px solid #fecaca;
}

.stats-scheme-tables {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.stats-table-label {
    display: flex;
    align-items: center;
    padding: 0.55rem 1.1rem;
    background: #fafbff;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-primary-dark);
    gap: 0.4rem;
}
.stats-tables-divider {
    height: 1px;
    background: var(--color-border);
}
.stats-scheme-block .table-container {
    border: none;
    border-radius: 0;
}
.stats-scheme-block thead th { background: #fafbff; font-size: 0.72rem; }
.stats-scheme-block tbody tr:hover { background-color: #faf9ff; }
.stats-scheme-block td.success-text { font-weight: 700; }
.stats-scheme-block td.fail-text    { font-weight: 700; }

/* ==========================================================
   13. 日志区块
   ========================================================== */
.logs-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
}
.logs-header h2 { margin-bottom: 0.15rem; }
.logs-controls { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }

.toggle-label { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; user-select: none; }
.toggle-switch-wrap { position: relative; flex-shrink: 0; }
.toggle-input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-switch {
    display: block;
    width: 2.4rem;
    height: 1.35rem;
    background: var(--color-border);
    border-radius: 999px;
    transition: background 0.25s;
    position: relative;
}
.toggle-switch::after {
    content: '';
    position: absolute;
    top: 0.18rem;
    left: 0.18rem;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toggle-input:checked + .toggle-switch { background: var(--color-primary); }
.toggle-input:checked + .toggle-switch::after { transform: translateX(1.05rem); }
.toggle-text { font-size: 0.85rem; font-weight: 600; color: var(--color-text); white-space: nowrap; }
.log-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--color-secondary-light);
    color: var(--color-text-light);
    border: 1px solid var(--color-border);
    white-space: nowrap;
    transition: all 0.25s;
}

.logs-container {
    background: #0f172a;
    color: #e2e8f0;
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    height: 420px;
    overflow-y: auto;
    font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    border: 1px solid #1e293b;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}
.logs-container::-webkit-scrollbar { width: 5px; }
.logs-container::-webkit-scrollbar-track { background: transparent; }
.logs-container::-webkit-scrollbar-thumb { background: #334155; border-radius: 99px; }
#logs-content {
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 0.82rem;
    line-height: 1.65;
    color: #94a3b8;
}

/* ==========================================================
   14. 公共表单元素
   ========================================================== */
.input-group { text-align: left; }
.input-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
    font-size: 0.82rem;
    color: var(--color-text);
}
input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background-color: var(--color-white);
    color: var(--color-text);
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
textarea {
    min-height: 7rem;
    resize: vertical;
    font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.85rem;
}

/* ==========================================================
   15. 公共按钮
   ========================================================== */
.button, button {
    display: inline-block;
    padding: 0.65rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    font-family: inherit;
}
.button:hover, button:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.button-primary { background-color: var(--color-primary); color: var(--color-white); }
.button-primary:hover { background-color: var(--color-primary-dark); }
.button-secondary {
    background-color: var(--color-secondary-light);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}
.button-secondary:hover { background-color: var(--color-border); }
.danger, .button.danger { background-color: var(--color-danger); color: var(--color-white); }
.danger:hover, .button.danger:hover { background-color: var(--color-danger-dark); }

/* ==========================================================
   16. 响应式布局
   ========================================================== */
@media (max-width: 768px) {
    .config-card { grid-template-columns: 2.2rem 1fr; grid-template-rows: auto auto; }
    .config-card-actions {
        grid-column: 1 / -1;
        flex-direction: row;
        justify-content: flex-end;
        padding-top: 0.5rem;
        border-top: 1px solid var(--color-border);
        margin-top: 0.4rem;
    }
    .preset-card-desc { display: none; }
    .stats-overview-divider { display: none; }
    .stats-overview { flex-direction: column; }
}
@media (max-width: 600px) {
    #app-container { margin: 0.5rem auto; padding: 0 0.5rem; }
    .card { padding: 1rem; border-radius: var(--radius-xl); }
    .tabs { flex-direction: column; padding: 0.3rem; gap: 0.2rem; }
    .tab-button { border-radius: var(--radius-md); padding: 0.6rem 1rem; }
    #top-bar { padding: 0.65rem 1rem; }
    .header-tagline { display: none; }
    .header-status { display: none; }
    .model-picker-row,
    .model-dropdown-wrap,
    .injected-message-row { grid-template-columns: 1fr; }
    .modal-content { max-width: 100%; border-radius: var(--radius-xl); }
    .modal-body { padding: 1rem; }
    .modal-header { padding: 1rem; }
    .config-tab-header { flex-direction: column; align-items: stretch; }
    .config-tab-header .button-primary { justify-content: center; }
    .scheme-count-badge { display: none; }
    .logs-header { flex-direction: column; }
    .stats-overview-cards { flex-direction: column; }
    .stats-scheme-header { flex-wrap: wrap; }
    .stats-scheme-summary { width: 100%; justify-content: flex-end; }
}

body {
    overflow-y: scroll;
    scrollbar-gutter: stable;
}

/* 使用日志 */
.usage-logs-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.usage-logs-actions { display: flex; gap: 0.5rem; }
.usage-logs-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; align-items: center; }
.filter-input, .filter-select { padding: 0.375rem 0.625rem; border: 1px solid var(--color-border); border-radius: var(--radius-md); font-size: 0.8rem; background: var(--color-white); color: var(--color-text); }
.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-light); }
.filter-input[type="datetime-local"] { width: 170px; }
.usage-logs-table-wrap { overflow-x: auto; }
.usage-logs-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; white-space: nowrap; }
.usage-logs-table th { background: var(--color-secondary-light); padding: 0.5rem 0.625rem; text-align: left; font-weight: 600; color: var(--color-text-light); border-bottom: 2px solid var(--color-border); position: sticky; top: 0; }
.usage-logs-table td { padding: 0.4rem 0.625rem; border-bottom: 1px solid var(--color-border); color: var(--color-text); max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.usage-logs-table tbody tr:hover { background: var(--color-primary-light); }
.loading-cell { text-align: center; color: var(--color-text-muted); padding: 2rem !important; }
.status-success { color: var(--color-success); font-weight: 600; }
.status-fail { color: var(--color-danger); font-weight: 600; }
.usage-logs-pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 0.75rem; font-size: 0.8rem; color: var(--color-text-light); }
.pagination-btns { display: flex; align-items: center; gap: 0.5rem; }
.button-sm { padding: 0.25rem 0.625rem; font-size: 0.78rem; }
.button-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.button-danger:hover { background: var(--color-danger-dark); border-color: var(--color-danger-dark); }

/* 使用日志详情模态窗 */
.usage-detail-modal { max-width: 800px; }
.usage-detail-body {
    max-height: 70vh;
    overflow: auto;
    background: var(--color-secondary-light);
    padding: 1rem;
    border-radius: var(--radius-md);
    font-size: 0.78rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
/* JSON 高亮配色 */
.json-key { color: #c026d3; }
.json-str { color: #16a34a; }
.json-num { color: #2563eb; }
.json-bool { color: #d97706; }
.json-null { color: var(--color-text-muted); }
.usage-detail-body span { white-space: pre-wrap; }
.usage-detail-link {
    background: var(--color-primary-light);
    color: var(--color-primary);
    border: none;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
}
.usage-detail-link:hover { background: var(--color-primary); color: #fff; }
}