/* 令牌：唯一依据为《界面主题规范》第二节。 */
:root {
  color-scheme: light;
  --canvas: #F4F0E6;
  --surface: #FFFCF6;
  --raised: #FFFFFF;
  --sunken: #EBE5D8;
  --ink: #1C1915;
  --muted: #615A4F;
  --faint: #8C8374;
  --border: #DCD2C0;
  --border-strong: #C3B7A1;
  --primary: #1F3D34;
  --primary-hover: #295147;
  --on-primary: #F7F4EE;
  --tint: #E6EEE8;
  --success: #2C6A4A;
  --success-bg: #E7F1EA;
  --warning: #8A5A12;
  --warning-bg: #F6EBD8;
  --danger: #A13B32;
  --danger-bg: #F8E7E4;
  --info: #2F5D7A;
  --brass: #A67C3D;

  --font-ui: "Segoe UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --canvas: #171512;
    --surface: #1F1C17;
    --raised: #272319;
    --sunken: #131110;
    --ink: #F3EDE1;
    --muted: #B7AD9C;
    --faint: #7E7565;
    --border: #3A342A;
    --border-strong: #4C4436;
    --primary: #8FC7AA;
    --primary-hover: #A5D8BC;
    --on-primary: #10231B;
    --tint: #24342B;
    --success: #7FC49B;
    --success-bg: #1E2E25;
    --warning: #E0B36A;
    --warning-bg: #332A1B;
    --danger: #E58C82;
    --danger-bg: #3A2320;
    --info: #8CB8D6;
    --brass: #D0A45E;
  }
}

/* 基础 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
}

h1, h2, h3, h4, p, ul, ol, figure {
  margin: 0;
}

ul, ol {
  padding: 0;
}

a {
  color: var(--info);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
  word-break: break-all;
}

button {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  display: inline-block;
  vertical-align: -2px;
}

.icon-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* 外壳布局 */
.app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2);
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
}

.brand-mark {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 3px;
  background: var(--brass);
}

.brand-name {
  line-height: 1.3;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-md);
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  transition: background 100ms ease, color 100ms ease;
}

.nav-link:hover {
  background: var(--tint);
  color: var(--ink);
  text-decoration: none;
}

.nav-link[aria-current="page"] {
  background: var(--tint);
  color: var(--primary);
  font-weight: 500;
}

.nav-link .icon {
  color: currentColor;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.access-open {
  width: 100%;
}

.access-panel {
  display: flex;
  flex-direction: column;
}

.access-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-bottom: var(--space-1);
}

.access-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 0 var(--space-2);
  align-items: center;
  padding: var(--space-1) 0;
}

.access-label {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--muted);
}

.access-value {
  grid-column: 1;
  grid-row: 2;
  font-size: 12px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.access-row .btn {
  grid-column: 2;
  grid-row: 2;
}

.access-hint {
  margin-top: var(--space-2);
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  width: 100%;
  max-width: 1600px;
  margin-inline: auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) 24px 0;
}

.topbar-titles {
  min-width: 0;
}

#view-title {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.3;
}

.topbar-sub {
  margin-top: var(--space-1);
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  flex: none;
}

.content {
  width: 100%;
  max-width: 1600px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) 24px var(--space-7);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  animation: fade-in 120ms ease-out;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.banner-root {
  width: 100%;
  max-width: 1600px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) 24px 0;
}

.banner-root:empty {
  display: none;
}

.banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

/* 通用区块 */
.section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.section-title {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
}

.section-head-hint .field-hint {
  margin: 0 0 0 auto;
  text-align: right;
}

.section-head-hint .field-hint:empty {
  display: none;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2);
}

.toolbar-spacer {
  flex: 1 1 auto;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-3);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3);
}

.stat-tabs {
  margin-bottom: var(--space-3);
  align-self: flex-start;
  width: fit-content;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: var(--space-3);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--space-3);
  align-items: start;
}

.accounts-split {
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
}

.master-detail {
  display: grid;
  grid-template-columns: clamp(360px, 26vw, 440px) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}

.master,
.detail {
  min-width: 0;
}

.is-dirty {
  color: var(--warning);
  font-size: 12px;
}

/* 按钮六态 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background 100ms ease, border-color 100ms ease, color 100ms ease;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--primary);
}

.btn-secondary:hover {
  background: var(--tint);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--tint);
  color: var(--ink);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-bg);
}

.confirm-dialog .btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
}

.btn-sm {
  min-height: 28px;
  padding: 0 var(--space-2);
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn-icon {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  justify-content: center;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn:disabled:active {
  transform: none;
}

.btn.is-loading {
  pointer-events: none;
  opacity: 0.8;
}

.btn.is-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 表单 */
.field,
.field-inline,
.visually-inline {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.field-inline {
  width: auto;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
}

.field-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.field-group-head .field-label {
  margin: 0;
}

.field-group-head .btn {
  flex: none;
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.field-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.field-error {
  font-size: 12px;
  color: var(--danger);
  line-height: 1.5;
}

.req {
  color: var(--danger);
  font-size: 12px;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 36px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--sunken);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.4;
}

.textarea {
  min-height: 76px;
  padding: var(--space-2);
  resize: vertical;
  line-height: 1.5;
}

.input.mono,
.textarea.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--faint);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  color: var(--faint);
  cursor: not-allowed;
}

.input-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.input-group .input {
  flex: 1 1 auto;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.checkbox-row input[type="radio"],
.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.errors-summary {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.errors-summary:empty {
  display: none;
}

/* 开关 */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  min-height: 28px;
  position: relative;
}

.switch-input {
  position: absolute;
  width: 36px;
  height: 20px;
  margin: 0;
  opacity: 0;
}

.switch-track {
  width: 36px;
  height: 20px;
  flex: none;
  position: relative;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 100ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform 100ms ease;
}

.switch-input:checked + .switch-track {
  background: var(--primary);
}

.switch-input:checked + .switch-track::after {
  transform: translateX(16px);
  background: var(--on-primary);
}

.switch-input:focus-visible + .switch-track {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

/* 分段 tab */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.seg-btn {
  min-height: 30px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease;
}

.seg-btn:hover:not(.is-on) {
  background: var(--tint);
  color: var(--ink);
}

.seg-btn.is-on,
.seg-btn[aria-selected="true"] {
  background: var(--primary);
  color: var(--on-primary);
}

/* 标签与 chip */
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 22px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.tag-neutral {
  background: var(--sunken);
  color: var(--muted);
  border-color: var(--border);
}

.tag-success {
  background: var(--success-bg);
  color: var(--success);
}

.tag-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.tag-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.tag-brass {
  background: transparent;
  color: var(--brass);
  border-color: var(--brass);
}

/* 兜底卡片：两列下拉与保存按钮同一行 */
.fallback-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* 关联页模型行的兜底标记前的小红点：这条模型当前没有可用通道 */
.dot-warning {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: var(--space-1);
  border-radius: 50%;
  background: var(--danger);
  vertical-align: middle;
}

.tag-current {
  background: var(--primary);
  color: var(--on-primary);
}

.tag-spent {
  background: var(--sunken);
  color: var(--faint);
  border-color: var(--border);
}

.tag-unknown {
  background: var(--warning-bg);
  color: var(--warning);
}

.tag-ready {
  background: var(--success-bg);
  color: var(--success);
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip-list .chip {
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

.chip-more {
  border-style: dashed;
  background: transparent;
  color: var(--info);
  cursor: pointer;
}

/* 卡片与指标 */
.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.card.current {
  border-color: var(--primary);
}

.card.spent {
  background: var(--sunken);
}

.card.spent .card-title {
  color: var(--muted);
}

.card.unknown {
  border-color: var(--warning);
}

.card.ready {
  border-color: var(--border);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.card-title {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.card-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  align-items: center;
}

.provider-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.provider-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.provider-link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.provider-tags {
  flex: none;
}

.provider-url {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-key-btn {
  gap: var(--space-1);
}

.provider-key-btn.is-empty {
  color: var(--faint);
}

.provider-models-btn {
  margin-left: auto;
  color: var(--info);
}

.provider-models-btn:hover {
  color: var(--primary);
}

.provider-fetch {
  margin-left: auto;
}

/* 同地址多 Key 分组卡片 */
.provider-group {
  display: flex;
  flex-direction: column;
}

.provider-group .provider-key-list {
  margin-top: var(--space-2);
  border-top: 1px solid var(--border);
}

.provider-key-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.provider-key-list .provider-key-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}

.provider-key-list .provider-key-row:first-child {
  border-top: 0;
}

.provider-key-main {
  display: flex;
  flex: 1 1 220px;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  min-width: 0;
}

.provider-key-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-key-mask {
  color: var(--muted);
  font-size: 12px;
}

.provider-key-models {
  flex: none;
}

.provider-key-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

.provider-group-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.provider-metric {
  color: var(--muted);
  font-size: 12px;
}

.provider-card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.provider-card-actions .provider-fetch {
  margin-left: 0;
}

.provider-card-actions .provider-manage-keys {
  margin-left: auto;
}

.provider-group-note {
  margin: var(--space-2) 0 0;
  color: var(--warning);
  font-size: 12px;
}

/* 单 Key 编辑弹层 */
.dialog-key-edit {
  width: min(460px, calc(100vw - 32px));
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.dialog-form .dialog-body {
  margin: 0;
}

.dialog-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* 抽屉内多 Key 列表：一个带边界的容器，行与行之间只用分隔线 */
.key-input-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.key-input-row.provider-key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    'main side'
    'error error';
  align-items: center;
  gap: 2px var(--space-2);
  min-height: 58px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: transparent;
}

.key-input-row.provider-key-row:first-child {
  border-top: 0;
}

.key-input-row.provider-key-row:hover {
  background: var(--tint);
}

.key-input-row.is-removed {
  background: var(--tint);
  opacity: 0.7;
}

.key-row-main {
  grid-area: main;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
}

.key-row-status {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 46px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.key-row-status-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
}

.key-row-status.is-on {
  color: var(--ink);
}

.key-row-status.is-on .key-row-status-dot {
  background: var(--success);
}

.key-row-name {
  flex: 1 1 80px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.key-row-copy {
  flex: none;
  min-height: 28px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.key-row-meta {
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

/* 固定文字块宽度：模型/绑定数无论一位还是两位数，复制Key 都落在同一条竖线上。 */
.key-row-meta-text {
  flex: 0 0 176px;
  width: 176px;
  max-width: 176px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-row-side {
  grid-area: side;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 104px;
  flex: none;
}

.key-row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  width: 100%;
  flex: none;
}

.key-input-row.is-removed .key-row-side {
  width: auto;
}

.key-row-actions .btn {
  width: auto;
  min-height: 28px;
  padding: 0 6px;
  font-size: 12px;
}

.key-row-actions .key-row-remove:hover {
  color: var(--danger);
}

.key-row-error {
  grid-area: error;
}

.key-list-empty {
  margin: 0;
  padding: 18px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

/* 模型清单：一张满宽竖向卡片，标签自适应平铺 */
.model-source-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
  max-height: 55vh;
  overflow-y: auto;
  padding: var(--space-1) 0;
}

.model-source-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
  min-width: 0;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.model-source-note {
  margin: 0;
}

.model-source-card.is-error {
  border-color: var(--danger);
}

.model-source-card.is-skipped {
  opacity: 0.72;
}

.model-source-card.is-unlabeled {
  border-style: dashed;
}

.model-source-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  min-width: 0;
}

.model-source-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.model-source-mask {
  color: var(--muted);
  font-size: 12px;
}

.model-source-head .list-meta {
  margin-left: auto;
  white-space: nowrap;
}

.model-source-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.model-source-empty,
.model-source-error {
  margin: 0;
}

/* 模型关联页骨架：由 body[data-view="routes"] 的 flex 链占满可视高度，
   不写死像素；外层不滚动，列表和匹配结果在各自区域内滚动。 */
@media (min-width: 901px) {
body[data-view="routes"] {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body[data-view="routes"] .app {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body[data-view="routes"] .main {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body[data-view="routes"] .content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 0;
}

body[data-view="routes"] #panel-routes {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

body[data-view="routes"] .routes-layout {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  overflow: hidden;
  align-items: stretch;
  grid-template-columns: clamp(360px, 26vw, 440px) minmax(0, 1fr);
}

body[data-view="routes"] .routes-master,
body[data-view="routes"] .routes-detail,
body[data-view="routes"] .routes-master .section,
body[data-view="routes"] #route-editor {
  min-height: 0;
  overflow: hidden;
}

body[data-view="routes"] #catalog-list,
body[data-view="routes"] #route-hits {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
}

/* 模型列表：名称行（右端启用开关）+ 数据行（上下文紧邻统计、右端三点菜单） */
.catalog-name-row {
  width: 100%;
}

.catalog-name-row .visually-inline {
  flex: 1 1 260px;
  min-width: 0;
}

.model-row {
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-1);
}

/* .list-row 在后面还会设 align-items:center，这里用复合选择器压过它，
   让两行内容都撑满整行，开关和三点菜单才能贴到最右侧。 */
.list-row.model-row {
  align-items: stretch;
}

.model-row-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.model-row-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-enabled-switch {
  flex: none;
}

.model-row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  min-width: 0;
}

.model-row-meta .model-context,
.model-row-meta .tag {
  white-space: nowrap;
}

.model-row-meta .toolbar-spacer {
  flex: 1 1 auto;
}

.model-row .menu {
  align-self: flex-start;
}

/* 未匹配模型浮层：原生 popover 进 top layer，避免被卡片或滚动区裁掉 */
.route-no-match {
  margin: 0;
}

.route-others {
  display: flex;
  justify-content: flex-start;
}

.route-others-toggle {
  margin-top: var(--space-1);
}

.route-others-popover {
  position: fixed;
  inset: auto;
  display: none;
  margin: 0;
  padding: var(--space-2);
  width: max-content;
  min-width: min(420px, calc(100vw - 16px));
  max-width: min(520px, calc(100vw - 16px));
  max-height: min(70vh, 560px);
  overflow: auto;
  background: var(--raised);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  z-index: 60;
}

.route-others-popover:popover-open,
.route-others-popover.is-open {
  display: block;
}

.route-others-popover .list {
  border: 0;
  overflow: visible;
}

.route-others-popover .binding-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  min-width: 0;
  min-height: 40px;
  white-space: normal;
}

.route-others-popover .binding-row > input[type="checkbox"] {
  flex: none;
}

.route-others-popover .toolbar-spacer {
  display: none;
}

.route-others-popover .binding-name {
  flex: 1 1 150px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-others-popover .binding-tags,
.route-others-popover .binding-health,
.route-others-popover .binding-weight,
.route-others-popover .binding-probe,
.route-others-popover .binding-context-probe {
  flex: none;
}

.route-others-popover .binding-health {
  min-width: 0;
}

.route-others-popover .binding-context {
  flex: 1 1 160px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-others-popover .context-tiers {
  flex: 1 0 100%;
}

.routes-master,
.routes-detail {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.routes-master .section,
#route-editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

#catalog-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

#route-hits {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

/* sr-only 是绝对定位；没有定位祖先时会以初始包含块为基准，把根滚动高度撑大。
   两个滚动容器各自成为包含块，绝对定位的辅助文本就随内容一起被裁剪。 */
#catalog-list,
#route-hits {
  position: relative;
}

/* 保存/放弃单独占搜索框上面一行，固定在滚动区之外，按钮始终可见 */
.route-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  min-height: 36px;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.route-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  padding-top: var(--space-2);
}

.route-search {
  flex: 1 1 320px;
}

.route-actions .is-dirty:empty {
  display: none;
}

.catalog-context {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
}

.catalog-context .field-inline {
  flex: 1 1 auto;
  min-width: 0;
}

.catalog-context > .list-meta {
  flex: none;
}

.model-context {
  white-space: nowrap;
}

.route-hits-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  align-items: stretch;
}

.route-hits-grid > .card {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.route-hits-grid .card .list {
  flex: 1 1 auto;
}

.route-hits-grid .binding-row {
  flex-wrap: wrap;
  row-gap: 4px;
}

@media (max-width: 1200px) {
  .route-hits-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.chip-copy {
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease;
}

.chip-copy:hover {
  background: var(--tint);
  border-color: var(--border-strong);
  color: var(--primary);
}

.chip-copy.is-copied {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}

.account-use-row,
.account-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.account-meta-row .card-sub {
  margin: 0;
}

.account-credits {
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
}

.metric {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.metric-label {
  font-size: 12px;
  color: var(--muted);
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.metric-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* 列表 */
.list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border-top: 1px solid var(--border);
  text-align: left;
}

.list-row:first-child {
  border-top: 0;
}

.list-row:hover {
  background: var(--tint);
}

.list-row.is-selected {
  background: var(--tint);
  box-shadow: inset 3px 0 0 var(--primary);
}

.list-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-main .mono {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-meta {
  font-size: 12px;
  color: var(--muted);
}

.list-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
}

/* 表格 */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.4;
}

.table caption {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.table th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: var(--space-2) var(--space-3);
  background: var(--sunken);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
  vertical-align: top;
}

.table th:first-child,
.table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
}

.table th:first-child {
  z-index: 3;
  background: var(--sunken);
}

.table tbody tr:hover td {
  background: var(--tint);
}

.table tr:hover td:first-child {
  background: var(--tint);
}

.table-compact th,
.table-compact td {
  padding: var(--space-1) var(--space-2);
  font-size: 13px;
}

.cell-num {
  text-align: right;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.cell-mono {
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

.row-toggle {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  min-height: 24px;
  min-width: 24px;
  cursor: pointer;
}

.row-toggle:hover {
  background: var(--tint);
  color: var(--ink);
}

.row-detail td {
  background: var(--sunken);
}

.is-ok {
  color: var(--success);
}

.is-fail {
  color: var(--danger);
}

/* 上传进度 */
.progress {
  display: block;
  width: 100%;
  height: 8px;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  overflow: hidden;
}

.progress[hidden] {
  display: none;
}

.progress::-webkit-progress-bar {
  background: var(--sunken);
}

.progress::-webkit-progress-value {
  background: var(--brass);
  transition: width 80ms linear;
}

.progress::-moz-progress-bar {
  background: var(--brass);
}

/* 状态与反馈 */
.status {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  min-height: 1.2em;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-5);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.empty-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
}

.empty-hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  max-width: 60ch;
}

.skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.skeleton-line {
  height: 14px;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  animation: breathe 1.8s ease-in-out infinite;
}

.skeleton-line[data-width="wide"] {
  width: 92%;
}

.skeleton-line[data-width="mid"] {
  width: 74%;
}

.skeleton-line[data-width="short"] {
  width: 52%;
}

@keyframes breathe {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}

.error-card {
  padding: var(--space-3);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.is-refreshing {
  opacity: 0.6;
  pointer-events: none;
}

.toast-root {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--raised);
  color: var(--ink);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
  pointer-events: auto;
}

.toast.is-error {
  border-color: var(--danger);
  color: var(--danger);
}

.toast-msg {
  flex: 1 1 auto;
  margin: 0;
}

.toast-close {
  flex: none;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

/* 图表 */
.chart {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.chart-title {
  font-size: 16px;
  font-weight: 500;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(72px, 120px) minmax(0, 1fr) 56px;
  gap: var(--space-2);
  align-items: center;
  font-size: 12px;
}

.bar-label {
  font-family: var(--font-mono);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  display: flex;
  height: 20px;
  border-radius: 3px;
  background: var(--sunken);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
}

.bar-fill-ok {
  background: var(--primary);
}

.bar-fill-fail {
  background: var(--danger);
}

.bar-value {
  font-family: var(--font-mono);
  text-align: right;
  color: var(--muted);
  white-space: nowrap;
}

.chart-wide {
  grid-column: 1 / -1;
}

.provider-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.provider-toolbar-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.provider-toolbar .field-hint {
  margin: 0;
}

.provider-rule {
  color: var(--faint);
}

.provider-chart {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.provider-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.provider-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.provider-main {
  display: grid;
  grid-template-columns: minmax(96px, 180px) minmax(0, 1fr) 64px 96px auto;
  gap: var(--space-2);
  align-items: center;
  font-size: 12px;
}

.provider-name {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-name .tag {
  flex: none;
}

.provider-track {
  min-width: 0;
}

.provider-rate,
.provider-count {
  font-family: var(--font-mono);
  text-align: right;
  white-space: nowrap;
}

.rate-danger {
  color: var(--danger);
}

.rate-warn {
  color: var(--warning);
}

.rate-muted {
  color: var(--muted);
}

.provider-reasons {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--muted);
}

.provider-reasons .cell-mono {
  white-space: nowrap;
}

.provider-reasons .provider-link {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.provider-toggle-spacer {
  width: 40px;
}

.provider-models {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--space-1);
  padding: var(--space-2);
  background: var(--sunken);
  border-radius: var(--radius-sm);
}

.provider-model-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: var(--space-3);
  align-items: center;
  font-size: 12px;
}

.provider-model-name {
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-chart {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-row {
  padding: var(--space-2);
  border-radius: var(--radius-sm);
}

.score-row:nth-child(odd) {
  background: var(--sunken);
}

.score-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: var(--space-3);
  align-items: center;
}

.score-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.score-total {
  font-weight: 600;
}

.score-good {
  color: var(--success);
}

.score-mid {
  color: var(--warning);
}

.score-bad {
  color: var(--danger);
}

.score-none {
  color: var(--muted);
}

.score-models {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.score-model {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) auto minmax(0, 2fr);
  gap: var(--space-3);
  align-items: center;
  font-size: 12px;
}

.score-dims {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.score-dim {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;
}

.score-dim-label {
  color: var(--muted);
}

.score-dim-track {
  width: 48px;
}

.score-facts {
  grid-column: 1 / -1;
}

.donut {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}

.donut-plot {
  position: relative;
  width: 140px;
  height: 140px;
  flex: none;
}

.donut svg {
  width: 140px;
  height: 140px;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 1.2;
}

.donut-center small {
  display: block;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 12px;
  color: var(--muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 2px;
  background: var(--muted);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* 菜单 */
.menu {
  display: flex;
  flex-direction: column;
  min-width: 140px;
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--raised);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--tint);
}

.menu-item.is-danger {
  color: var(--danger);
}

/* 抽屉与弹层 */
dialog {
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--border);
  background: var(--raised);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
}

.drawer[open] {
  display: flex;
  flex-direction: column;
}

.drawer-form {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.drawer-title {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
}

.drawer-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
}

.drawer-actions {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--raised);
}

.confirm-dialog {
  margin: auto;
  width: 400px;
  max-width: calc(100vw - 32px);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--raised);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
}

.confirm-title {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
  margin-bottom: var(--space-2);
}

.confirm-body {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: var(--space-4);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* 响应式 */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  .brand {
    padding: 0;
    flex: none;
  }

  .brand-name {
    white-space: nowrap;
  }

  .nav {
    flex-direction: row;
    gap: var(--space-1);
    overflow-x: auto;
    flex: 1 1 auto;
    min-width: 0;
  }

  .nav-link {
    min-height: 32px;
    padding: 0 var(--space-2);
    white-space: nowrap;
    flex: none;
  }

  .sidebar-foot {
    margin: 0 0 0 auto;
    flex-direction: row;
    align-items: center;
    flex: none;
  }

  .topbar {
    padding: var(--space-3) var(--space-4) 0;
  }

  .banner-root {
    padding: var(--space-2) var(--space-4) 0;
  }

  .content {
    padding: var(--space-3) var(--space-4) var(--space-6);
  }

  .master-detail,
  .split,
  .accounts-split {
    grid-template-columns: minmax(0, 1fr);
  }

  .routes-layout {
    height: auto;
    min-height: 0;
  }

  #catalog-list,
  #route-hits {
    overflow: visible;
  }

  .drawer {
    width: 100%;
    max-width: 100vw;
    border-left: 0;
  }

  .card-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .bar-row {
    grid-template-columns: minmax(60px, 88px) minmax(0, 1fr) 48px;
  }

  .provider-main {
    grid-template-columns: minmax(72px, 110px) minmax(0, 1fr) 52px auto;
  }

  .provider-name,
  .provider-track,
  .provider-rate {
    grid-row: 1;
  }

  .provider-toggle-spacer,
  .provider-main > .row-toggle {
    grid-column: 4;
    grid-row: 1;
  }

  .provider-count {
    grid-column: 2 / 5;
    grid-row: 2;
    text-align: left;
  }

  .donut {
    flex-direction: column;
    align-items: flex-start;
  }

  .table th,
  .table td {
    padding: var(--space-1) var(--space-2);
  }

  .toast-root {
    left: var(--space-4);
    right: var(--space-4);
    width: auto;
  }
}

@media (max-width: 360px) {
  body {
    font-size: 13px;
  }

  #view-title {
    font-size: 20px;
  }

  .sidebar {
    gap: var(--space-2);
  }

  .brand-name {
    display: none;
  }

  .content {
    padding: var(--space-3) var(--space-2) var(--space-5);
  }

  .topbar,
  .banner-root {
    padding-left: var(--space-2);
    padding-right: var(--space-2);
  }

  .stat-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .btn,
  .toolbar .input,
  .toolbar .select,
  .field-inline,
  .visually-inline {
    width: 100%;
  }

  .seg {
    width: 100%;
  }

  .provider-meta {
    flex-direction: column;
    align-items: stretch;
  }

  .provider-meta .btn,
  .provider-fetch {
    margin-left: 0;
    width: 100%;
  }

  .provider-card-actions {
    align-items: stretch;
  }

  .provider-card-actions .btn,
  .provider-card-actions .provider-manage-keys {
    margin-left: 0;
    width: 100%;
  }

  .key-input-row.provider-key-row {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      'main'
      'side'
      'error';
  }

  .key-row-side {
    justify-content: flex-end;
  }

  .key-row-meta-text {
    flex-basis: 150px;
    width: 150px;
    max-width: 150px;
  }


  .seg-btn {
    flex: 1 1 auto;
    padding: 0 var(--space-2);
  }

  .bar-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }

  .bar-value {
    text-align: left;
  }

  .confirm-dialog {
    width: calc(100vw - 16px);
    padding: var(--space-4);
  }

  .drawer-body,
  .drawer-head,
  .drawer-actions {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 运行时由 ui.js/app.js 生成的节点样式 */
.toast-success {
  border-color: var(--border);
}

.toast-error {
  border-color: var(--danger);
  color: var(--danger);
}

.toast-message {
  flex: 1 1 auto;
  margin: 0;
  line-height: 1.5;
  word-break: break-word;
}

.banner-error {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
}

.btn-danger-solid:hover {
  background: var(--danger);
  filter: brightness(1.06);
}

.btn-label {
  display: inline-flex;
  align-items: center;
}

.error-card-message {
  margin: 0;
  line-height: 1.55;
  word-break: break-word;
}

.clipboard-buffer {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dialog {
  width: min(420px, calc(100vw - 32px));
  margin: auto;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--raised);
  color: var(--ink);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
}

.dialog::backdrop {
  background: rgba(16, 14, 11, 0.45);
}

.dialog-title {
  margin: 0 0 var(--space-2);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
}

.dialog-body {
  margin: 0 0 var(--space-4);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

.dialog-models {
  width: min(860px, calc(100vw - 32px));
}

.dialog-models-body {
  min-height: 0;
}

.dialog-models[open] {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.dialog-models .dialog-title {
  margin: 0;
}

.dialog-models .field-hint {
  margin: 0;
}

.dialog-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  max-height: 50vh;
  overflow-y: auto;
  padding: var(--space-2);
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.dialog-confirm .btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
}

@media (max-width: 640px) {
  .dialog {
    width: calc(100vw - 16px);
    padding: var(--space-4) var(--space-3);
  }
}

/* 模型关联绑定行 */
.binding-row {
  gap: var(--space-2);
  flex-wrap: wrap;
  cursor: pointer;
}

.binding-row .input.priority {
  width: 72px;
  min-height: 28px;
  padding: 0 var(--space-2);
  font-size: 12px;
}

.binding-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex: none;
  accent-color: var(--primary);
}

.binding-row .list-meta {
  max-width: 20ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.binding-row .context-values,
.binding-row .context-tiers {
  max-width: none;
  overflow: visible;
  white-space: normal;
}

.binding-row .context-tiers {
  flex-basis: 100%;
}

.switch {
  color: var(--ink);
}

.switch-text {
  font-size: 13px;
  color: var(--ink);
}

@media (max-width: 640px) {
  .binding-row .list-meta {
    max-width: 12ch;
  }
}

/* 账号区局部刷新时的进度提示 */
#panel-accounts {
  position: relative;
}

#panel-accounts.is-refreshing {
  opacity: 1;
  pointer-events: auto;
}

#panel-accounts.is-refreshing > * {
  opacity: 0.45;
  pointer-events: none;
}

#panel-accounts.is-refreshing::after {
  content: "正在刷新账号…";
  position: absolute;
  top: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--raised);
  color: var(--muted);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}

/* 登录页 */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.login-card .brand {
  padding: 0;
}

.login-title {
  margin: var(--space-2) 0 0;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
}

.login-card .btn {
  margin-top: var(--space-2);
}

/* 用户页 */
.user-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  white-space: nowrap;
}
