/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0a0e17;
  --bg2: #111827;
  --bg3: #1a2332;
  --border: #1e3a5f;
  --border2: #2a4a7f;
  --accent: #00e5ff;
  --accent2: #7c4dff;
  --accent3: #ff6d00;
  --text: #e0e6f0;
  --text2: #8b9dc9;
  --text3: #5a6d8a;
  --success: #00c853;
  --error: #ff1744;
  --warn: #ffab00;
  --radius: 8px;
  --radius2: 12px;
  --transition: 0.2s ease;
}
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ===== Background Effects ===== */
.bg-grid {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-image:
    linear-gradient(rgba(0,229,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,229,255,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none; z-index: 0;
}
.bg-glow {
  position: fixed; top: -50%; left: -50%; width: 200%; height: 200%;
  background: radial-gradient(ellipse at 70% 30%, rgba(0,229,255,0.06) 0%, transparent 50%),
              radial-gradient(ellipse at 30% 70%, rgba(124,77,255,0.05) 0%, transparent 50%);
  pointer-events: none; z-index: 0;
}

/* ===== Header ===== */
.header {
  position: relative; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 20px;
  background: rgba(17,24,39,0.9); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.logo-text { font-size: 16px; font-weight: 700; letter-spacing: 2px; background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.header-right { display: flex; align-items: center; gap: 12px; }
.api-key-area { display: flex; align-items: center; gap: 6px; }
.api-key-input {
  width: 240px; height: 32px; padding: 0 10px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; outline: none; transition: var(--transition);
}
.api-key-input:focus { border-color: var(--accent); }
.api-key-input::placeholder { color: var(--text3); }
.key-status { font-size: 11px; white-space: nowrap; }
.key-status.ok { color: var(--success); }
.key-status.err { color: var(--error); }
.health-dots {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.health-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text3);
  transition: var(--transition);
  flex-shrink: 0;
  position: relative;
}
.health-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.health-dot.offline { background: var(--error); box-shadow: 0 0 8px var(--error); }
.health-tooltip {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--text); white-space: nowrap;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 4px; padding: 3px 8px; pointer-events: none;
  opacity: 0; transition: opacity 0.2s ease;
  z-index: 20;
}
.health-dot:hover .health-tooltip { opacity: 1; }
.health-dot.online .health-tooltip { color: var(--success); }
.health-dot.offline .health-tooltip { color: var(--error); }
.health-dot:not(.online):not(.offline) .health-tooltip { color: var(--text3); }

/* ===== Buttons ===== */
.btn {
  height: 32px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg3); color: var(--text); font-size: 13px; cursor: pointer;
  transition: var(--transition); white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--accent); background: rgba(0,229,255,0.08); }
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn-xs { height: 22px; padding: 0 8px; font-size: 11px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent2), #651fff);
  color: #fff; border: none;
}
.btn-primary:hover { box-shadow: 0 0 12px rgba(124,77,255,0.4); }
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.send-btn {
  width: 38px; height: 38px; border-radius: var(--radius); border: none;
  background: linear-gradient(135deg, var(--accent), #0091ea);
  color: var(--bg); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: var(--transition); flex-shrink: 0;
}
.send-btn:hover { box-shadow: 0 0 20px rgba(0,229,255,0.4); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.gen-btn {
  height: 44px; padding: 0 24px; border-radius: var(--radius2); border: none;
  background: linear-gradient(135deg, var(--accent2), #651fff);
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: var(--transition);
}
.gen-btn:hover { box-shadow: 0 0 24px rgba(124,77,255,0.4); transform: translateY(-1px); }
.gen-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ===== Layout ===== */
.main-container {
  display: flex; height: calc(100vh - 52px);
  position: relative; z-index: 1;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: rgba(17,24,39,0.7); backdrop-filter: blur(8px);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
}
.model-nav { padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.model-tab {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; padding: 10px 12px; border-radius: var(--radius); border: 1px solid transparent;
  background: transparent; color: var(--text2); cursor: pointer; text-align: left;
  transition: var(--transition); font-size: 13px;
}
.model-tab svg { flex-shrink: 0; margin-bottom: 2px; }
.model-tab small { font-size: 10px; color: var(--text3); }
.model-tab:hover { background: rgba(0,229,255,0.04); border-color: var(--border); }
.model-tab.active {
  background: rgba(0,229,255,0.08); border-color: var(--accent);
  color: var(--accent);
}
.model-tab.active small { color: var(--accent); }

.sidebar-settings {
  padding: 12px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-settings h4 { font-size: 11px; text-transform: uppercase; color: var(--text3); letter-spacing: 1px; margin-bottom: 2px; }
.settings-group { display: flex; flex-direction: column; gap: 6px; }
.settings-group.hidden { display: none; }
.settings-group label { font-size: 11px; color: var(--text2); }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 12px !important; color: var(--text2); cursor: pointer; }
.checkbox-label input[type="checkbox"] { accent-color: var(--accent); }
input[type="range"] {
  -webkit-appearance: none; width: 100%; height: 4px;
  background: var(--border); border-radius: 2px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; box-shadow: 0 0 6px rgba(0,229,255,0.4);
}
.range-val { font-size: 12px; color: var(--accent); font-weight: 600; }
.num-input, .sel-input {
  height: 30px; padding: 0 8px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 12px; outline: none;
}
.sel-input { cursor: pointer; }
.num-input:focus, .sel-input:focus { border-color: var(--accent); }

/* ===== Content ===== */
.content {
  flex: 1; overflow: hidden; position: relative;
}
.panel { display: none; flex-direction: column; height: 100%; }
.panel.active { display: flex; }

/* ===== Chat Panel ===== */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.chat-welcome {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 12px;
}
.chat-welcome h2 { font-size: 24px; background: linear-gradient(135deg, var(--accent), #fff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.chat-welcome p { color: var(--text2); font-size: 14px; max-width: 400px; line-height: 1.6; }
.welcome-icon { margin-bottom: 8px; opacity: 0.8; }
.quick-prompts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.quick-btn {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2); font-size: 12px; cursor: pointer;
  transition: var(--transition);
}
.quick-btn:hover { border-color: var(--accent); color: var(--accent); }
.message { max-width: 85%; line-height: 1.7; font-size: 14px; }
.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.msg-content {
  padding: 10px 14px; border-radius: var(--radius2);
  word-break: break-word;
}
.message.user .msg-content { background: linear-gradient(135deg, var(--accent), #0091ea); color: #0a0e17; }
.message.assistant .msg-content { background: var(--bg3); border: 1px solid var(--border); }
.msg-content pre {
  background: rgba(0,0,0,0.4); padding: 10px 12px; border-radius: 6px;
  overflow-x: auto; margin: 8px 0; font-size: 12px;
}
.msg-content code { font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 12px; }
.msg-content img, .msg-content video { max-width: 300px; border-radius: 6px; margin: 4px 0; }
.msg-role { font-size: 11px; color: var(--text3); }
.msg-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.msg-copy-btn {
  background: none; border: 1px solid transparent; color: var(--text3);
  cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 4px;
  line-height: 1; opacity: 0; transition: opacity 0.2s, border-color 0.2s;
}
.message:hover .msg-copy-btn, .msg-copy-btn:focus { opacity: 1; }
.msg-copy-btn:hover { border-color: var(--border); background: var(--bg3); color: var(--text); }
/* Markdown 表格样式 */
.msg-content table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.msg-content th, .msg-content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg-content th { background: rgba(0,229,255,0.08); font-weight: 600; }
.msg-content tr:nth-child(even) { background: rgba(0,0,0,0.15); }
/* Markdown 标题、列表 */
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4 { margin: 8px 0 4px; font-weight: 600; }
.msg-content h1 { font-size: 19px; } .msg-content h2 { font-size: 17px; } .msg-content h3 { font-size: 15px; }
.msg-content ul, .msg-content ol { padding-left: 20px; margin: 4px 0; }
.msg-content li { margin: 2px 0; }
.msg-content blockquote { border-left: 3px solid var(--accent); padding: 4px 12px; margin: 6px 0; color: var(--text2); background: rgba(0,229,255,0.03); border-radius: 0 4px 4px 0; }
.msg-content a { color: var(--accent); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
/* 追问区域 */
.followup-section { margin-top: 4px; padding: 10px 14px; border-radius: var(--radius2); background: rgba(0,229,255,0.04); border: 1px dashed rgba(0,229,255,0.15); align-self: flex-start; max-width: 85%; }
.followup-title { font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.followup-list { display: flex; flex-wrap: wrap; gap: 6px; }
.followup-btn {
  padding: 4px 12px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2); font-size: 12px; cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.followup-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(0,229,255,0.06); }
.followup-loading { font-size: 12px; color: var(--text3); }
.typing-cursor { display: inline-block; width: 6px; height: 14px; background: var(--accent); animation: blink 1s step-end infinite; vertical-align: middle; margin-left: 2px; border-radius: 1px; }
@keyframes blink { 50% { opacity: 0; } }

.chat-input-area { padding: 12px 20px; border-top: 1px solid var(--border); background: rgba(17,24,39,0.8); }
.input-row { display: flex; align-items: flex-end; gap: 8px; }
#chatInput {
  flex: 1; min-height: 38px; max-height: 120px; padding: 8px 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px; outline: none; resize: none;
  font-family: inherit; line-height: 1.5;
}
#chatInput:focus { border-color: var(--accent); }
.upload-preview { display: flex; gap: 8px; padding: 8px 0 0; flex-wrap: wrap; min-height: 0; }
.upload-preview:empty { display: none; }
.upload-preview img, .upload-preview video { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.preview-badge {
  position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%);
  font-size: 9px; padding: 1px 5px; border-radius: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text3); white-space: nowrap;
}
.preview-file-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg3); min-width: 120px; max-width: 200px;
  transition: var(--transition);
}
.preview-file-badge:hover { border-color: var(--accent); }
.preview-file-badge .file-icon { font-size: 18px; flex-shrink: 0; }
.preview-file-badge .file-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.preview-file-badge .file-name { font-size: 11px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-file-badge .file-size { font-size: 10px; color: var(--text3); }
.preview-file-badge.text { border-color: rgba(0,229,255,0.3); }
.preview-file-badge.pdf { border-color: rgba(255,23,68,0.3); }
.preview-file-badge.office { border-color: rgba(0,200,83,0.3); }
.preview-file-badge.other { border-color: rgba(255,171,0,0.3); }
.upload-preview .preview-remove {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--error);
  color: #fff; border: none; cursor: pointer; font-size: 10px; display: flex; align-items: center; justify-content: center;
}
.upload-preview .preview-item { position: relative; cursor: pointer; }
.upload-preview .preview-item.preview-active img { border-color: var(--accent); box-shadow: 0 0 8px rgba(0,229,255,0.4); }
.upload-preview .preview-item.preview-active::after {
  content: '✓'; position: absolute; bottom: 2px; right: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: var(--accent);
  color: var(--bg); font-size: 10px; display: flex; align-items: center; justify-content: center;
  z-index: 1;
}
.preview-url-badge {
  padding: 4px 8px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 4px; font-size: 11px; color: var(--accent); white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}

/* ===== Panel Toolbar ===== */
.panel-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: rgba(17,24,39,0.6);
}
.panel-title { font-size: 15px; font-weight: 600; }
.toolbar-actions { display: flex; gap: 6px; }

/* ===== Image/Video Panels ===== */
.gen-header { display: flex; align-items: baseline; gap: 12px; padding: 20px 20px 0; }
.gen-header h2 { font-size: 20px; font-weight: 700; }
.model-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: rgba(0,229,255,0.1); color: var(--accent); border: 1px solid rgba(0,229,255,0.2);
}
.gen-input-area {
  padding: 16px 20px; display: flex; flex-direction: column; gap: 10px;
}
.gen-input-area textarea {
  width: 100%; padding: 12px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none;
  resize: vertical; font-family: inherit; line-height: 1.5;
}
.gen-input-area textarea:focus { border-color: var(--accent); }
.gen-input-area textarea::placeholder { color: var(--text3); }
.video-url-row input {
  width: 100%; height: 36px; padding: 0 10px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none;
}
.video-url-row .video-image-upload-row {
  display: flex; gap: 8px;
}
.video-url-row .video-image-upload-row input {
  flex: 1;
}
.video-url-row input:focus { border-color: var(--accent); }
.video-url-row.hidden { display: none; }
.neg-input {
  width: 100%; height: 32px; padding: 0 10px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none;
}
.neg-input:focus { border-color: var(--accent); }

.gen-results {
  flex: 1; overflow-y: auto; padding: 0 20px 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
  align-content: start;
}
.gen-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius2);
  overflow: hidden; transition: var(--transition);
}
.gen-card:hover { border-color: var(--accent); }
.gen-card img, .gen-card video {
  width: 100%; display: block; border-bottom: 1px solid var(--border);
}
.gen-card .card-info {
  padding: 10px 12px; font-size: 12px; color: var(--text2);
  display: flex; justify-content: space-between; align-items: center;
}
.gen-card .card-actions { display: flex; gap: 6px; }
.gen-card .card-btn {
  font-size: 11px; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--border);
  background: transparent; color: var(--text2); cursor: pointer; transition: var(--transition);
}
.gen-card .card-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ===== 通用 card-btn（表格等容器内使用） ===== */
.card-btn {
  font-size: 11px; padding: 3px 10px; border-radius: 4px; border: 1px solid var(--border);
  background: transparent; color: var(--text2); cursor: pointer; transition: var(--transition);
  white-space: nowrap; min-width: 44px;
}
.card-btn:hover { border-color: var(--accent); color: var(--accent); }
/* 历史表格中的操作按钮固定最小宽度 */
.key-table .card-btn { min-width: 52px; }
.gen-card .card-status {
  font-size: 11px; padding: 2px 6px; border-radius: 4px;
}
.gen-card .card-status.processing { background: rgba(255,171,0,0.15); color: var(--warn); }
.gen-card .card-status.failed { background: rgba(255,23,68,0.15); color: var(--error); }

.gen-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 40px 20px;
}
.gen-loading.hidden { display: none; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-bar {
  width: 300px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px; transition: width 0.3s ease; width: 0%;
}

/* ===== Task Status Panel ===== */
.task-query-area { padding: 16px 20px; }
.task-query-row { display: flex; gap: 8px; }
.task-id-input {
  flex: 1; height: 38px; padding: 0 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px; outline: none;
}
.task-id-input:focus { border-color: var(--accent); }
.task-id-input::placeholder { color: var(--text3); }
.task-result {
  padding: 0 20px; margin-bottom: 16px;
}
.task-result pre {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; font-size: 12px; overflow-x: auto; color: var(--text2);
  max-height: 300px; overflow-y: auto;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
}
.task-result.hidden { display: none; }
.task-list {
  flex: 1; overflow-y: auto; padding: 0 20px 20px;
}
.task-list h4 { font-size: 12px; color: var(--text3); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 1px; }
.task-history-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 6px; font-size: 12px;
}
.task-history-id { color: var(--accent); font-family: monospace; flex-shrink: 0; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.task-history-status { flex-shrink: 0; }
.task-history-time { color: var(--text3); margin-left: auto; flex-shrink: 0; }

/* ===== API Key Panel ===== */
.key-table-wrap { flex: 1; overflow: auto; padding: 16px 20px; }
.key-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.key-table th {
  text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border);
  color: var(--text3); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  position: sticky; top: 0; background: var(--bg2);
}
.key-table td { padding: 10px 12px; border-bottom: 1px solid rgba(30,58,95,0.4); color: var(--text2); }
.key-table tr:hover td { background: rgba(0,229,255,0.03); }
.key-code { font-family: monospace; font-size: 12px; color: var(--accent); }
.key-vis-toggle { display: inline-flex !important; width: 26px; height: 26px; font-size: 13px; vertical-align: middle; }
.radio-btn { cursor: pointer; font-size: 18px; user-select: none; transition: var(--transition); }
.radio-btn:hover { opacity: 0.7; }
.empty-cell { text-align: center; color: var(--text3); padding: 30px !important; }
.del-key-btn { color: var(--error) !important; }
.del-key-btn:hover { background: rgba(255,23,68,0.1) !important; border-color: var(--error) !important; }

/* ===== Modal ===== */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius2);
  padding: 24px; min-width: 400px; max-width: 90vw;
  display: flex; flex-direction: column; gap: 16px;
}
.modal-content h3 { font-size: 16px; font-weight: 600; }
.modal-input {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px; outline: none;
}
.modal-input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-result { padding: 12px; background: var(--bg3); border-radius: var(--radius); border: 1px solid var(--border); }
.modal-result.hidden { display: none; }
.modal-result p { font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.modal-result code {
  display: block; padding: 8px; background: rgba(0,0,0,0.3); border-radius: 4px;
  font-size: 12px; word-break: break-all; color: var(--accent); font-family: monospace; margin-bottom: 6px;
}

/* ===== Toast ===== */
.toast {
  position: fixed; top: 64px; left: 50%; z-index: 100;
  padding: 10px 18px; border-radius: var(--radius); font-size: 13px;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform: translateX(-50%) translateY(-16px); pointer-events: none;
  opacity: 0;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(-16px); }
.toast.success { background: rgba(0,200,83,0.2); border: 1px solid var(--success); color: var(--success); }
.toast.error { background: rgba(255,23,68,0.2); border: 1px solid var(--error); color: var(--error); }
.toast.info { background: rgba(0,229,255,0.15); border: 1px solid var(--accent); color: var(--accent); }
.toast.warn { background: rgba(255,171,0,0.2); border: 1px solid var(--warn); color: var(--warn); }

/* ===== Login Overlay ===== */
.login-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.login-overlay.hidden {
  opacity: 0; visibility: hidden; pointer-events: none;
}
.login-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius2); padding: 40px 36px;
  width: 400px; max-width: 90vw;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  box-shadow: 0 0 60px rgba(0,229,255,0.08);
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 20px; font-weight: 700; letter-spacing: 2px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.login-desc { color: var(--text2); font-size: 14px; }
.login-form { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.login-field input {
  width: 100%; height: 42px; padding: 0 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none;
}
.login-field input:focus { border-color: var(--accent); }
.login-field input::placeholder { color: var(--text3); }
.login-code-row { display: flex; gap: 8px; }
.login-code-row input { flex: 1; }
.login-code-row .btn { flex-shrink: 0; height: 42px; }
.login-code-row .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-btn {
  height: 44px; border-radius: var(--radius); border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  width: 100%; justify-content: center;
}
.login-btn:hover { box-shadow: 0 0 20px rgba(0,229,255,0.3); }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-hint { font-size: 12px; color: var(--text3); text-align: center; min-height: 18px; }
.login-hint.success { color: var(--success); }
.login-hint.error { color: var(--error); }
.login-footer { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* ===== User Badge ===== */
.user-badge {
  font-size: 12px; padding: 2px 10px; border-radius: 10px;
  background: rgba(0,229,255,0.1); color: var(--accent);
  border: 1px solid rgba(0,229,255,0.2);
  white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}

/* ===== Admin-only visibility ===== */
.admin-only { transition: var(--transition); }

/* ===== Role Badge ===== */
.role-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  display: inline-block;
}
.role-badge.admin { background: rgba(124,77,255,0.15); color: var(--accent2); border: 1px solid rgba(124,77,255,0.3); }
.role-badge.user { background: rgba(0,229,255,0.1); color: var(--accent); border: 1px solid rgba(0,229,255,0.2); }

/* ===== User Expire ===== */
.expire-valid { color: var(--text2); font-size: 12px; }
.expire-expired { color: var(--error); font-size: 12px; font-weight: 600; }
.user-expired-row td { background: rgba(255,23,68,0.05) !important; }
.renew-btn:hover { background: rgba(0,200,83,0.1) !important; }

/* ===== Log Panel ===== */
.log-filter-sel {
  height: 26px; padding: 0 8px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 12px; outline: none;
  cursor: pointer;
}
.log-filter-sel:focus { border-color: var(--accent); }
.log-filter-input {
  height: 26px; width: 150px; padding: 0 8px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 12px; outline: none;
}
.log-filter-input:focus { border-color: var(--accent); }
.log-filter-input::placeholder { color: var(--text3); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 180px; }
  .api-key-input { width: 140px; }
}
@media (max-width: 600px) {
  .main-container { flex-direction: column; }
  .sidebar { width: 100%; max-height: 140px; flex-shrink: 0; }
  .model-nav { flex-direction: row; }
  .model-tab { flex-direction: row; align-items: center; gap: 6px; }
  .model-tab svg { margin-bottom: 0; }
}

/* ===== History Group Collapse ===== */
.history-group-row { cursor: pointer; background: var(--bg3); }
.history-group-row:hover { background: var(--bg4); }
.history-group-toggle { display: inline-block; width: 16px; transition: transform 0.2s; }
.history-group-toggle.expanded { transform: rotate(90deg); }
.history-sub-row { display: none; }
.history-sub-row.expanded { display: table-row; }
.history-sub-row td { padding-left: 28px !important; font-size: 12px; opacity: 0.85; }
.history-media-row { display: none; background: var(--bg2); }
.history-media-row.expanded { display: table-row; }
.history-media-link { text-decoration: none; transition: opacity 0.2s; }
.history-media-link:hover { opacity: 0.8; }
.history-group-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px;
  border-radius: 8px; background: var(--accent2); color: #fff; margin-left: 6px;
  vertical-align: middle;
}

/* 图片加载失败占位 */
.broken-img {
  display: inline-block; padding: 6px 12px; margin: 4px 0;
  background: var(--bg3); border: 1px dashed var(--border);
  border-radius: var(--radius); color: var(--text3); font-size: 12px;
  white-space: nowrap;
}

/* ===== 生图/生视频面板 连续对话区域 ===== */
.panel-chat-area {
  display: flex; flex-direction: column;
  border-top: 1px solid var(--border);
  background: rgba(17,24,39,0.6);
  flex-shrink: 0; max-height: 380px;
}
.panel-chat-area.hidden { display: none; }
.panel-chat-messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 280px;
}
.panel-chat-messages:empty { display: none; }
.panel-chat-messages .message { max-width: 100%; font-size: 13px; }
.panel-chat-messages .msg-content { font-size: 13px; }
.panel-chat-input-row {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 16px; border-top: 1px solid var(--border);
}
.panel-chat-input {
  flex: 1; min-height: 34px; max-height: 80px; padding: 6px 10px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; outline: none; resize: none;
  font-family: inherit; line-height: 1.4;
}
.panel-chat-input:focus { border-color: var(--accent); }
.panel-chat-input::placeholder { color: var(--text3); }
.panel-send-btn { width: 34px; height: 34px; }

/* ===== Feedback ===== */
.fb-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  z-index: 200; display: none; justify-content: center; align-items: center;
}
.fb-overlay.fb-show { display: flex; }
.fb-modal {
  width: 420px; max-width: 92vw; max-height: 90vh; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius2); box-shadow: 0 12px 48px rgba(0,0,0,.5);
}
.fb-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(0,229,255,0.1), rgba(124,77,255,0.1));
}
.fb-header h3 { font-size: 16px; font-weight: 600; color: var(--accent); }
.fb-close {
  width: 28px; height: 28px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.fb-close:hover { border-color: var(--accent); color: var(--accent); }
.fb-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.fb-label { font-size: 13px; color: var(--text2); font-weight: 500; }
.fb-rating-row { display: flex; gap: 8px; }
.fb-rating-btn {
  flex: 1; height: 40px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2); font-size: 18px; cursor: pointer;
  transition: var(--transition); display: flex; align-items: center; justify-content: center;
}
.fb-rating-btn:hover { border-color: var(--accent); }
.fb-rating-btn.fb-selected {
  background: rgba(0,229,255,0.15); border-color: var(--accent); color: var(--accent);
  box-shadow: 0 0 8px rgba(0,229,255,0.2);
}
.fb-select {
  width: 100%; height: 36px; padding: 0 10px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; outline: none; cursor: pointer;
}
.fb-select:focus { border-color: var(--accent); }
.fb-select option { background: var(--bg2); color: var(--text); }
.fb-textarea {
  width: 100%; min-height: 80px; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; outline: none; resize: vertical;
  font-family: inherit; line-height: 1.5;
}
.fb-textarea:focus { border-color: var(--accent); }
.fb-textarea::placeholder { color: var(--text3); }
.fb-submit {
  height: 40px; border-radius: var(--radius); border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: var(--transition);
}
.fb-submit:hover { box-shadow: 0 0 16px rgba(0,229,255,0.3); }
.fb-submit:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.fb-success-title { color: var(--success); }
.fb-err-title { color: var(--error); }
