:root {
  color-scheme: light;
  --page: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #eef3f7;
  --text: #1f2933;
  --heading: #111827;
  --muted: #64748b;
  --subtle: #94a3b8;
  --border: #dbe3eb;
  --border-strong: #c7d2df;
  --brand: #0f9f8f;
  --brand-strong: #087f74;
  --brand-soft: #e4f7f3;
  --danger: #d64752;
  --danger-soft: #feecee;
  --warning: #b7791f;
  --warning-soft: #fff6da;
  --info: #2563eb;
  --info-soft: #eaf1ff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 10px 28px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

.bg-orb {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 159, 143, 0.22);
  outline-offset: 2px;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #102a43;
  color: #e4f7f3;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: inset 0 -8px 18px rgba(15, 159, 143, 0.22);
}

.brand-text {
  min-width: 0;
}

.brand-text h1,
h1 {
  margin: 0;
  color: var(--heading);
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
  font-weight: 800;
}

.brand-text p,
.muted {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.system-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

h2 {
  margin: 0;
  color: var(--heading);
  font-size: 17px;
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: 0;
}

h3 {
  margin: 0;
  color: var(--heading);
  font-size: 15px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 80;
  display: flex;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
  overflow-x: auto;
}

.tab-btn {
  flex: 0 0 auto;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.tab-btn:hover {
  background: var(--surface-soft);
  color: var(--heading);
}

.tab-btn.active,
.tab-btn[aria-selected="true"] {
  background: var(--heading);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.16);
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 18px;
}

.tab-pane.active {
  display: flex;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.list-head h2 {
  min-width: 0;
}

.quick-actions-card {
  padding: 16px 18px;
}

.token-list-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.form-actions {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

button,
.preview-download,
.file-open-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 12px;
  background: var(--brand);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

button:hover,
.preview-download:hover,
.file-open-link:hover {
  background: var(--brand-strong);
}

button.secondary,
button.small,
.file-open-link,
.preview-download {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

button.secondary:hover,
button.small:hover,
.file-open-link:hover,
.preview-download:hover {
  background: var(--surface-strong);
  border-color: #b9c7d5;
}

button.danger {
  background: #ffffff;
  border-color: #f0b7bd;
  color: var(--danger);
}

button.danger:hover {
  background: var(--danger-soft);
  border-color: #e58a93;
}

button.small {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.msg {
  color: var(--muted);
  font-size: 13px;
}

.msg.success {
  color: var(--brand-strong);
}

.msg.error {
  color: var(--danger);
}

.text-muted,
.inline-placeholder {
  color: var(--muted);
}

.text-subtle,
.cell-muted {
  color: #667085;
}

.text-strong {
  color: var(--heading);
}

.text-warning {
  color: var(--warning);
}

.text-danger {
  color: var(--danger);
}

.cell-compact {
  color: #475467;
  font-size: 12px;
  line-height: 1.35;
}

.section-help {
  margin-bottom: 14px;
}

.help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.token-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.token-summary span,
.token-credits-summary {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  padding: 4px 10px;
  color: var(--muted);
  font-size: 12px;
}

.token-summary strong,
.token-credits-summary strong {
  color: var(--heading);
  font-size: 13px;
  font-weight: 800;
}

.config-form,
.add-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.config-category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.config-cat-btn {
  min-height: 32px;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 800;
}

.config-cat-btn:hover {
  background: #ffffff;
  color: var(--heading);
}

.config-cat-btn.active {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.config-cat-pane {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
}

.config-cat-pane.active {
  display: grid;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.config-cat-pane .form-group:has(.checkbox-label),
.config-cat-pane .form-group:has(#confApiKey),
.config-cat-pane .form-group:has(#confPublicBaseUrl) {
  grid-column: 1 / -1;
}

.proxy-presets-group {
  grid-column: 1 / -1;
}

.config-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.proxy-preset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.proxy-preset-table-wrap {
  max-height: 360px;
}

#proxyPresetTable {
  table-layout: auto;
}

#proxyPresetTable td {
  vertical-align: middle;
}

.proxy-preset-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.proxy-test-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 800;
}

.proxy-test-status.ok {
  border-color: #8fd8cd;
  color: var(--brand-strong);
  background: var(--brand-soft);
}

.proxy-test-status.fail {
  border-color: #f0b7bd;
  color: var(--danger);
  background: var(--danger-soft);
}

.config-inline-row {
  display: contents;
}

.form-group label,
.checkbox-label {
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.import-proxy-label {
  margin-top: 10px;
}

.input-text,
.input-select,
textarea,
input[type="file"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
  font-family: var(--sans);
  font-size: 13px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

textarea,
.log-model-cell,
.generated-file-name,
.error-detail-content pre {
  font-family: var(--mono);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

textarea#cookieInput {
  min-height: 170px;
}

.input-text:focus,
.input-select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 159, 143, 0.12);
  outline: none;
}

.input-text::placeholder,
textarea::placeholder {
  color: #98a5b3;
}

input[type="checkbox"] {
  accent-color: var(--brand);
}

.table-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
}

th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: #475467;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid #edf1f5;
  color: var(--text);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #fbfcfd;
}

.empty-state {
  padding: 38px 16px !important;
  color: var(--muted);
  text-align: center;
}

#logsTable,
#runningLogsTable,
#generatedFilesTable,
#auditTable {
  table-layout: auto;
}

#logsTable td,
#runningLogsTable td,
#generatedFilesTable td,
#auditTable td {
  vertical-align: top;
}

#logsTable th:nth-child(1),
#logsTable td:nth-child(1) {
  width: 86px;
}

#auditTable {
  min-width: 860px;
  table-layout: fixed;
}

#auditTable th:nth-child(1),
#auditTable td:nth-child(1) {
  width: 150px;
}

#auditTable th:nth-child(2),
#auditTable td:nth-child(2) {
  width: 240px;
}

#logsTable th:nth-child(3),
#logsTable td:nth-child(3),
#logsTable th:nth-child(4),
#logsTable td:nth-child(4),
#logsTable th:nth-child(8),
#logsTable td:nth-child(8),
#auditTable th:nth-child(4),
#auditTable td:nth-child(4),
#generatedFilesTable th:nth-child(1),
#generatedFilesTable td:nth-child(1),
#generatedFilesTable th:nth-child(3),
#generatedFilesTable td:nth-child(3),
#generatedFilesTable th:nth-child(4),
#generatedFilesTable td:nth-child(4),
#generatedFilesTable th:nth-child(5),
#generatedFilesTable td:nth-child(5) {
  white-space: nowrap;
}

#logsTable th:nth-child(5),
#logsTable td:nth-child(5) {
  min-width: 220px;
}

#logsTable th:nth-child(6),
#logsTable td:nth-child(6) {
  min-width: 190px;
}

#logsTable th:nth-child(7),
#logsTable td:nth-child(7) {
  min-width: 260px;
  width: 36%;
}

#auditTable th:nth-child(3),
#auditTable td:nth-child(3) {
  min-width: 320px;
  width: 48%;
}

#auditTable th:nth-child(4),
#auditTable td:nth-child(4) {
  width: 80px;
  text-align: right;
}

#generatedFilesTable th:nth-child(2),
#generatedFilesTable td:nth-child(2) {
  min-width: 280px;
  width: 55%;
}

#tokenTable {
  min-width: 1360px;
}

/* ===== Token 账号表：视觉优化 + 菜单不被裁切 ===== */
.list .table-wrapper {
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

#tokenTable thead th {
  background: #f6f8fb;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  padding-top: 12px;
  padding-bottom: 12px;
}

#tokenTable tbody td {
  padding-top: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eef2f6;
  transition: background 0.14s ease;
}

#tokenTable tbody tr:nth-child(even) td {
  background: #fbfcfe;
}

#tokenTable tbody tr:hover td {
  background: #eff5ff;
}

#tokenTable tbody tr:last-child td {
  border-bottom: 0;
}

#tokenTable .account-cell {
  line-height: 1.55;
  font-size: 12px;
  color: var(--muted);
}

#tokenTable .account-cell .account-token {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f8fafc;
  color: #475569;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

#tokenTable th:nth-child(1),
#tokenTable td:nth-child(1) {
  width: 44px;
  min-width: 44px;
  max-width: 44px;
}

#tokenTable th:nth-child(2),
#tokenTable td:nth-child(2) {
  width: 220px;
  min-width: 220px;
  max-width: 220px;
}

#tokenTable th:nth-child(3),
#tokenTable td:nth-child(3) {
  min-width: 184px;
}

#tokenTable th:nth-child(7),
#tokenTable td:nth-child(7) {
  width: 116px;
  min-width: 116px;
}

#tokenTable th:nth-child(8),
#tokenTable td:nth-child(8) {
  width: 180px;
  min-width: 180px;
}

#tokenTable th:nth-child(9),
#tokenTable td:nth-child(9) {
  width: 196px;
  min-width: 196px;
  max-width: 196px;
}

#tokenTable th:nth-child(1),
#tokenTable td:nth-child(1),
#tokenTable th:nth-child(2),
#tokenTable td:nth-child(2),
#tokenTable th:nth-child(9),
#tokenTable td:nth-child(9) {
  position: sticky;
  z-index: 4;
  background: #ffffff;
}

#tokenTable th:nth-child(1),
#tokenTable td:nth-child(1) {
  left: 0;
}

#tokenTable th:nth-child(2),
#tokenTable td:nth-child(2) {
  left: 44px;
}

#tokenTable th:nth-child(9),
#tokenTable td:nth-child(9) {
  right: 0;
}

#tokenTable thead th:nth-child(1),
#tokenTable thead th:nth-child(2),
#tokenTable thead th:nth-child(9) {
  z-index: 8;
  background: #f6f8fb;
}

#tokenTable th:nth-child(2),
#tokenTable td:nth-child(2) {
  box-shadow: 10px 0 14px -14px rgba(15, 23, 42, 0.55);
}

#tokenTable th:nth-child(9),
#tokenTable td:nth-child(9) {
  box-shadow: -10px 0 14px -14px rgba(15, 23, 42, 0.55);
}

#tokenTable tbody tr:nth-child(even) td:nth-child(1),
#tokenTable tbody tr:nth-child(even) td:nth-child(2),
#tokenTable tbody tr:nth-child(even) td:nth-child(9) {
  background: #fbfcfe;
}

#tokenTable tbody tr:hover td:nth-child(1),
#tokenTable tbody tr:hover td:nth-child(2),
#tokenTable tbody tr:hover td:nth-child(9) {
  background: #eff5ff;
}

.account-cell {
  color: #344054;
  font-size: 12px;
  line-height: 1.35;
}

.account-cell .account-name {
  color: var(--heading);
  font-weight: 700;
}

.account-cell .account-email {
  color: var(--muted);
  word-break: break-all;
}

.account-token {
  display: inline-block;
  margin-top: 4px;
  color: #475467;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.25;
  word-break: break-all;
}

.status-auto-cell {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

.status-meta-row {
  display: flex;
  max-width: 170px;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.refresh-status-tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 22px;
  border: 1px solid #dbe3eb;
  border-radius: 999px;
  background: #f8fafc;
  color: #475569;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.refresh-status-tag.enabled {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #047857;
}

.refresh-status-tag.paused {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}

.refresh-status-tag.manual {
  border-color: #e2e8f0;
  background: #f8fafc;
  color: #64748b;
}

.account-limit-cell {
  display: flex;
  width: 92px;
  flex-direction: column;
  gap: 6px;
}

.account-limit-trigger {
  width: 100%;
  min-height: 34px;
  justify-content: space-between;
  gap: 8px;
  border-color: #bfe4df;
  background: #ffffff;
  color: var(--heading);
  padding: 6px 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.account-limit-trigger:hover {
  border-color: #8fd8cd;
  background: var(--brand-soft);
  color: var(--heading);
}

.account-limit-value {
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.account-limit-edit {
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.account-limit-track {
  display: block;
  width: 100%;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.account-limit-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.today-usage-cell {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
}

.today-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}

.today-count strong {
  color: var(--heading);
  font-weight: 800;
}

.today-count.failed {
  color: var(--danger);
}

.upstream-cell {
  display: flex;
  min-width: 126px;
  flex-direction: column;
  gap: 4px;
}

.upstream-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
}

.upstream-badge.ok {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.upstream-badge.temporary {
  background: var(--warning-soft);
  color: var(--warning);
}

.upstream-badge.today {
  background: var(--danger-soft);
  color: var(--danger);
}

.upstream-detail,
.upstream-probe {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.audit-actions .input-select {
  width: auto;
  min-width: 116px;
}

.audit-search-input {
  width: min(280px, 32vw);
  min-width: 210px;
}

.audit-custom-range {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.audit-custom-range[hidden] {
  display: none;
}

.audit-time-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.audit-time-field .input-datetime {
  width: 176px;
}

.audit-file-cell {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
}

.audit-file-name {
  max-width: 220px;
  overflow: hidden;
  color: var(--heading);
  font-family: var(--mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audit-file-state {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.audit-file-state.exists {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.audit-file-state.missing {
  background: var(--danger-soft);
  color: var(--danger);
}

.audit-time-status-cell,
.audit-account-model-cell {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}

.audit-time-status-cell .log-state {
  width: fit-content;
}

.audit-account-model-cell .account-name,
.audit-account-model-cell .log-account-email,
.audit-account-model-cell .audit-model-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audit-model-name {
  color: var(--heading);
  font-family: var(--mono);
  font-size: 12px;
}

.audit-prompt-compact {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.audit-detail-dialog {
  width: min(1180px, 100%);
}

.audit-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.audit-detail-head h3 {
  margin: 0;
}

.audit-detail-content {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(360px, 1.15fr);
  gap: 14px;
  max-height: calc(100vh - 150px);
  overflow: auto;
}

.audit-detail-panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 12px;
}

.audit-detail-panel h4 {
  margin: 0 0 10px;
  color: var(--heading);
  font-size: 13px;
}

.audit-detail-preview {
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f172a;
  overflow: hidden;
}

.audit-detail-preview img,
.audit-detail-preview video {
  display: block;
  max-width: 100%;
  max-height: 420px;
}

.audit-detail-meta {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px 10px;
  margin-top: 12px;
  font-size: 12px;
}

.audit-detail-meta dt {
  color: var(--muted);
  font-weight: 800;
}

.audit-detail-meta dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.audit-raw-json {
  max-height: calc(100vh - 240px);
  margin: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  color: #344054;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.status-badge,
.log-state,
.file-kind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
  text-transform: none;
  white-space: nowrap;
}

.status-active,
.log-state.success,
.file-kind.image {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.status-exhausted {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-invalid,
.status-error,
.log-state.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-disabled,
.status-unknown {
  background: var(--surface-strong);
  color: var(--muted);
}

#tokenTable .token-status {
  min-height: 26px;
  border: 1px solid transparent;
  padding: 4px 10px;
  font-size: 12px;
}

#tokenTable .token-status.status-active {
  border-color: #16a34a;
  background: #dcfce7;
  color: #14532d;
  box-shadow: inset 0 0 0 1px rgba(22, 163, 74, 0.12);
}

#tokenTable .token-status.status-disabled,
#tokenTable .token-status.status-unknown {
  border-color: #cbd5e1;
  background: #f1f5f9;
  color: #334155;
}

#tokenTable .token-status.status-invalid,
#tokenTable .token-status.status-error {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #b91c1c;
}

#tokenTable .token-status.status-exhausted {
  border-color: #fbbf24;
  background: #fffbeb;
  color: #92400e;
}

.log-state.running,
.file-kind.video {
  background: var(--info-soft);
  color: var(--info);
}

.file-kind.file {
  background: var(--surface-strong);
  color: var(--muted);
}

.log-state-btn {
  border: 1px solid #f0b7bd;
  background: var(--danger-soft);
  color: var(--danger);
  cursor: pointer;
}

.log-state-btn:hover {
  background: #fddfe3;
}

.log-time-cell {
  color: #344054;
  line-height: 1.25;
}

.log-time-cell .date,
.log-time-cell .time {
  display: block;
}

.log-time-cell .time,
.log-account-email {
  color: var(--muted);
}

.log-account-cell {
  display: block;
  color: #344054;
  line-height: 1.35;
}

.log-account-email {
  word-break: break-all;
}

.log-model-cell,
.generated-file-name {
  color: #475467;
  font-size: 12px;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.log-prompt-cell {
  color: #475467;
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.log-row-running td {
  background: #f5f9ff;
}

.icon-spinner {
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.icon-check,
.icon-error {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
  font-size: 11px;
  line-height: 1;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 188px;
  min-width: 0;
  max-width: 188px;
}

.action-primary-row {
  display: grid;
  grid-template-columns: minmax(78px, 1fr) minmax(50px, 0.72fr) 32px;
  gap: 6px;
  min-width: 0;
  align-items: start;
}

.action-primary-row button,
.action-more-menu button {
  width: 100%;
  min-height: 28px;
  padding: 4px 6px;
  font-size: 11px;
}

.action-more {
  min-width: 0;
}

.action-more-trigger {
  display: flex;
  width: 32px;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.action-more-trigger span {
  display: block;
  margin-top: -4px;
  color: var(--heading);
  font-size: 18px;
  letter-spacing: 0;
  line-height: 1;
}

.action-more-trigger.is-open {
  border-color: #94a3b8;
  background: #f8fafc;
}

.action-more-menu {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  min-width: 176px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 6px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
}

.action-more-menu-template {
  display: none !important;
}

.action-more-menu-floating {
  position: fixed;
  z-index: 1400;
}

.action-more-field {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-width: 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.action-more-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
}

.action-more-menu .route-select {
  width: 100%;
  min-height: 28px;
  border-radius: 6px;
  font-size: 11px;
}

.generated-file-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.switch-wrap {
  display: inline-flex;
  align-items: center;
}

.switch-btn {
  width: 40px;
  height: 22px;
  min-height: 22px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  background: #e2e8f0;
  vertical-align: middle;
}

.switch-btn:hover {
  background: #d8e0ea;
}

.switch-btn.on {
  background: var(--brand);
  border-color: var(--brand);
}

.switch-btn.off {
  background: #e2e8f0;
}

.switch-btn:disabled {
  opacity: 0.6;
}

.switch-knob {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
  transform: translateX(0);
  transition: transform 0.15s ease;
}

.switch-btn.on .switch-knob {
  transform: translateX(18px);
}

.switch-text {
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.stat-card-live {
  border-color: #8fd8cd;
  background: var(--brand-soft);
}

.stat-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-value {
  color: var(--heading);
  font-size: 24px;
  line-height: 1.1;
  font-weight: 800;
}

.stat-value-live {
  color: var(--brand-strong);
}

.logs-pagination {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.logs-pagination.is-hidden {
  display: none;
}

.dialog-modal,
.preview-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  background: rgba(17, 24, 39, 0.58);
}

.dialog-modal.open,
.preview-modal.open {
  display: flex;
}

.dialog-card,
.preview-modal-dialog {
  width: min(780px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
  padding: 18px;
}

.account-concurrency-card {
  width: min(420px, 100%);
}

.account-concurrency-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.account-limit-current {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 11px 12px;
}

.account-limit-current span:first-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.account-limit-current strong {
  color: var(--heading);
  font-size: 15px;
  font-weight: 800;
  word-break: break-word;
}

.account-limit-key {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.35;
  word-break: break-all;
}

.account-stepper {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 8px;
}

.account-stepper button {
  min-height: 38px;
  padding: 0;
  font-size: 17px;
  font-weight: 800;
}

.account-stepper input {
  text-align: center;
  font-weight: 800;
}

.proxy-action-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  padding: 4px 6px;
}

.proxy-action-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.proxy-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
  border: 1px solid #dbeafe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.proxy-pill em {
  min-width: 0;
  overflow: hidden;
  color: #475569;
  font-style: normal;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.proxy-action-row .proxy-pill {
  justify-content: flex-start;
  width: 100%;
}

.proxy-action-row .proxy-pill em {
  display: none;
}

.route-action-row {
  grid-template-columns: auto minmax(0, 1fr) minmax(74px, auto);
}

.route-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
  border: 1px solid #dbeafe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.route-pill em {
  display: inline;
  min-width: 0;
  overflow: hidden;
  color: #475569;
  font-style: normal;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-pill.firefly {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #15803d;
}

.route-pill.express {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}

.route-select {
  width: 84px;
  min-height: 24px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 2px 5px;
  font-size: 11px;
  font-weight: 800;
}

.proxy-pill.custom {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #15803d;
}

.proxy-pill.direct {
  border-color: #e2e8f0;
  background: #f8fafc;
  color: #475569;
}

.proxy-pill.warn {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}

.account-proxy-trigger {
  min-height: 24px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.account-proxy-trigger:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.account-proxy-card {
  width: min(460px, 100%);
}

.account-proxy-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.account-proxy-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.account-proxy-fields.is-disabled {
  opacity: 0.58;
}

.proxy-port-field {
  max-width: 160px;
}

.proxy-clear-password {
  margin-top: 7px;
  font-size: 12px;
}

.proxy-preset-card {
  width: min(640px, 100%);
}

.proxy-preset-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.proxy-preset-form > .form-group,
.proxy-preset-form > .help,
.proxy-preset-form > .dialog-actions {
  grid-column: 1 / -1;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 2px;
}

.modal-head {
  margin-bottom: 10px;
}

/* ===== 订阅管理 / 取消订阅 ===== */
.subscription-card {
  width: min(560px, 100%);
}

.subscription-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.danger-help {
  color: var(--danger);
}

.subscription-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 52vh;
  overflow-y: auto;
}

.sub-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sub-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  word-break: break-all;
}

.sub-meta {
  color: var(--muted);
  font-size: 12px;
}

.sub-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sub-preview {
  border-top: 1px dashed var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub-preview-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 13px;
  align-items: baseline;
}

.sub-preview-grid span {
  color: var(--muted);
}

.sub-preview-grid strong {
  word-break: break-all;
}

.preview-modal-dialog {
  width: min(1120px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-close {
  align-self: flex-end;
}

.preview-content {
  min-height: 240px;
  max-height: calc(100vh - 150px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f172a;
  overflow: hidden;
}

.preview-content img,
.preview-content video {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 170px);
}

.preview-actions {
  display: flex;
  justify-content: flex-end;
}

.error-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.error-detail-content {
  max-height: calc(100vh - 220px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  padding: 12px;
}

.error-detail-content pre {
  margin: 0;
  color: #344054;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
  max-width: min(420px, calc(100vw - 40px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 18px 46px rgba(15, 23, 42, 0.18);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: #8fd8cd;
}

.toast.error {
  border-color: #e58a93;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  padding: 24px;
}

.auth-brand {
  margin-bottom: 22px;
}

.auth-card h1,
.auth-card .brand-text h1 {
  font-size: 22px;
}

.auth-card .form-group + .form-group {
  margin-top: 12px;
}

.auth-actions {
  margin-top: 16px;
}

@media (max-width: 980px) {
  .shell {
    padding: 18px;
  }

  .header {
    grid-template-columns: 1fr;
  }

  .header-meta {
    justify-content: flex-start;
  }

  .list-head {
    flex-direction: column;
  }

  .modal-head {
    flex-direction: row;
    align-items: center;
  }

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

  .token-list-actions {
    align-items: flex-start;
  }

  .config-cat-pane.active {
    grid-template-columns: 1fr;
  }

  .config-cat-pane .form-group {
    grid-column: auto;
  }

  .audit-detail-content {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 640px) {
  .shell {
    padding: 12px;
    gap: 12px;
  }

  .card,
  .dialog-card,
  .preview-modal-dialog {
    padding: 14px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-text h1,
  h1 {
    font-size: 19px;
  }

  .tabs {
    margin: 0 -4px;
  }

  .tab-btn {
    padding: 7px 10px;
    font-size: 13px;
  }

  .actions {
    width: 100%;
  }

  .actions button {
    flex: 1 1 auto;
  }

  .dialog-actions {
    flex-direction: column;
  }

  .dialog-actions button {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .logs-pagination {
    justify-content: space-between;
  }

  .config-category-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .proxy-port-field {
    max-width: none;
  }
}
