/* ============================================================
   Model Switcher — 设计令牌
   ============================================================ */
:root {
  /* 中性色 */
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #e9e9eb;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #a1a1aa;

  /* 品牌色 */
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-border: #bfdbfe;
  --on-accent: #ffffff;

  /* 语义色 */
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --success: #16a34a;
  --success-soft: #f0fdf4;

  /* 效果 */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .05);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .14), 0 4px 8px rgba(0, 0, 0, .06);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --header-blur: saturate(180%) blur(12px);
  --header-bg: rgba(250, 250, 250, .85);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --surface: #131316;
    --surface-2: #1c1c21;
    --surface-3: #26262c;
    --border: #26262c;
    --border-strong: #34343c;
    --text: #f4f4f5;
    --text-2: #a1a1aa;
    --text-3: #63636b;

    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft: rgba(59, 130, 246, .12);
    --accent-border: rgba(59, 130, 246, .35);
    --on-accent: #ffffff;

    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .1);
    --danger-border: rgba(248, 113, 113, .3);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, .1);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .5);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
    --header-bg: rgba(9, 9, 11, .8);
  }
}

/* ============================================================
   基础
   ============================================================ */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden { display: none !important; }

/* ============================================================
   顶部导航
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 max(20px, env(safe-area-inset-left));
  height: 60px;
  background: var(--header-bg);
  -webkit-backdrop-filter: var(--header-blur);
  backdrop-filter: var(--header-blur);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.brand-mark {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.brand-mark svg { width: 16px; height: 16px; }

.brand h1 {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -.01em;
  margin: 0;
  white-space: nowrap;
}

.brand .brand-sub {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

.current-banner {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  font-size: 12px;
  color: var(--text-3);
}
.current-banner::-webkit-scrollbar { display: none; }

.status-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.status-pill strong {
  color: var(--text);
  font-weight: 600;
}

/* ============================================================
   主体布局
   ============================================================ */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px max(20px, env(safe-area-inset-left)) 80px;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.toolbar-title {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.01em;
  margin-right: auto;
}

/* ============================================================
   按钮
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease,
    transform .08s ease, box-shadow .15s ease;
  box-shadow: var(--shadow-xs);
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: scale(.97); }

.btn svg { width: 14px; height: 14px; flex: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-danger {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}
.btn-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

/* ============================================================
   切换目标选择器 (分段控件)
   ============================================================ */
.target-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
}

.tp-group {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  gap: 2px;
}

.tp-item { position: relative; }

.tp-item input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}

.tp-item span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 550;
  color: var(--text-3);
  transition: all .15s ease;
  user-select: none;
}

.tp-item input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.tp-item span::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  transition: background .15s ease;
}

.tp-item input:checked + span::before { background: var(--success); }

.scope-select {
  padding: 6px 28px 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background-color: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 550;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

.target-picker.dimmed { opacity: .45; pointer-events: none; }

/* ============================================================
   供应商卡片
   ============================================================ */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow .2s ease, border-color .2s ease, transform .2s ease;
  animation: card-in .25s ease both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.card.active {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 1px var(--accent-border), var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.card-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 650;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
}

.card-title-wrap { min-width: 0; flex: 1; }

.card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-sub {
  font-size: 11.5px;
  color: var(--text-3);
  display: flex;
  gap: 6px;
  align-items: center;
}

.api-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 10.5px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--text-2);
}

.card-live-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--success);
  background: var(--success-soft);
}

.card-live-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.card-meta-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.meta-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  color: var(--text-2);
  min-width: 0;
}

.meta-row .meta-key {
  flex: none;
  width: 52px;
  color: var(--text-3);
  font-size: 11px;
}

.meta-row .meta-val {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  word-break: break-all;
}

/* ---------- 模型按钮 ---------- */
.model-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.chip {
  position: relative;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, opacity .15s ease,
    background .15s ease, border-color .15s ease, color .15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.chip:active { transform: scale(.93); }

.chip:disabled { opacity: .5; cursor: default; }

.chip.loading { padding-right: 30px; opacity: 1; }

.chip.loading::after {
  content: "";
  position: absolute;
  right: 9px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: chip-spin .6s linear infinite;
}

@keyframes chip-spin { to { transform: rotate(360deg); } }

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.chip.active:hover { color: var(--on-accent); }

.chip .chip-badge {
  font-size: 9.5px;
  opacity: .85;
  margin-left: 5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .22);
  vertical-align: 1px;
}

.chip.just-switched { animation: chip-pulse 1s ease-out 2; }

@keyframes chip-pulse {
  0% { box-shadow: 0 0 0 0 var(--accent); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ---------- 会话分流 ---------- */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 34px 0 6px;
}

.section-hint {
  font-size: 12px;
  color: var(--text-3);
  margin: 0 0 14px;
  line-height: 1.6;
}

.section-hint code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
}

.routes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.route-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  flex-wrap: wrap;
}

.route-where {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.route-channel {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
}

.route-peer {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-2);
  word-break: break-all;
}

.route-arrow { color: var(--text-3); font-size: 12px; }

.route-model {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.route-actions { margin-left: auto; display: flex; gap: 6px; }

.routes-empty {
  padding: 22px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-3);
  font-size: 12.5px;
  text-align: center;
}

/* ---------- 空状态 ---------- */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 24px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-3);
}

.empty-state .empty-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--text-3);
}

.empty-state p { margin: 0 0 16px; font-size: 13px; }

/* ============================================================
   弹窗
   ============================================================ */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in .15s ease;
}

@keyframes fade-in { from { opacity: 0; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 22px 18px;
  width: 100%;
  max-width: 480px;
  max-height: min(88vh, 88dvh);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in .18s cubic-bezier(.16, 1, .3, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: none; }
}

.modal h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -.01em;
}

.modal .modal-desc {
  margin: 0 0 16px;
  font-size: 12.5px;
  color: var(--text-3);
}

#profile-form label {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-2);
  margin-bottom: 13px;
}

#profile-form input,
#profile-form select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
  -webkit-appearance: none;
  appearance: none;
}

#profile-form select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 32px;
}

#profile-form input:focus,
#profile-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#profile-form input::placeholder { color: var(--text-3); }

.preset-hint {
  font-size: 12px;
  color: var(--text-2);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  margin: -5px 0 13px;
  line-height: 1.55;
}

.muted-note { font-size: 11px; font-weight: 400; color: var(--text-3); }

.models-block {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 16px;
}

.models-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 10px;
}

.model-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.model-row input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  transition: border-color .15s ease;
}

.model-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.model-row .btn { flex: none; padding: 4px 9px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(92vw, 480px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .22s cubic-bezier(.16, 1, .3, 1);
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 640px) {
  .brand .brand-sub { display: none; }
  .toolbar-title { width: 100%; }
  .target-picker { margin-left: 0; }
  main { padding-top: 18px; }
}
