:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e6;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --danger: #d70015;
  --ok: #1d8a45;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

.boot { padding: 40px; color: var(--muted); }

/* ── login ─────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}
.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.02em; }
.login-card p { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  background: #fbfbfd;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}
.btn {
  border: none;
  border-radius: 980px;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 500;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 6px 14px; font-size: 13px; }
.btn.danger { background: transparent; color: var(--danger); }
.error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ── shell ─────────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
}
.brand { font-size: 17px; font-weight: 600; padding: 0 10px 18px; letter-spacing: -0.02em; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav button {
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 14px;
  transition: background 0.12s;
}
.nav button:hover { background: #f0f0f2; }
.nav button.active { background: #e8f0fe; color: var(--accent); font-weight: 500; }
.who { font-size: 12px; color: var(--muted); padding: 12px 10px 8px; border-top: 1px solid var(--line); }
.who b { color: var(--text); font-weight: 600; }

.main { padding: 32px 36px; overflow: auto; }
.main h2 { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.main .sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }

/* ── cards / stats ─────────────────────────────────────────────────────── */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 30px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }
.section-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 28px 0 12px; }

/* ── table ─────────────────────────────────────────────────────────────── */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: 920px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
td .row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 980px; font-size: 12px; font-weight: 500; }
.tag.root { background: #e8f0fe; color: var(--accent); }
.tag.user { background: #f0f0f2; color: var(--muted); }
.tag.active, .tag.approved, .tag.completed, .tag.success { background: #e3f5e9; color: var(--ok); }
.tag.inactive, .tag.rejected { background: #fdeaea; color: var(--danger); }
.tag.pending, .tag.processing { background: #fff4e0; color: #b15c00; }
.tag.idle { background: #f0f0f2; color: var(--muted); }
.muted { color: var(--muted); }
.empty, .loading { padding: 40px; text-align: center; color: var(--muted); }
.banner { background: #fdeaea; color: var(--danger); padding: 10px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }

/* ── article + COS administration ──────────────────────────────────────── */
.article-filters, .cos-browser-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px;
  margin-bottom: 18px;
  overflow: visible;
}
.article-filters input { min-width: 210px; flex: 1; }
.article-filters input, .article-filters select, .cos-browser-toolbar input,
.article-editor input, .article-editor select, .article-editor textarea,
.cos-config input, .cos-config select, .speech-config input, .speech-config select {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font: inherit;
  background: #fbfbfd;
}
.article-filters input:focus, .article-filters select:focus,
.article-editor input:focus, .article-editor select:focus, .article-editor textarea:focus,
.cos-browser-toolbar input:focus, .cos-config input:focus, .cos-config select:focus,
.speech-config input:focus, .speech-config select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}
.article-editor, .cos-config, .speech-config { padding: 20px; margin-bottom: 20px; overflow: visible; }
.article-editor h3 { margin: 0 0 2px; }
.article-editor p { margin: 0 0 16px; }
.article-editor .field input, .article-editor .field select,
.article-editor .field textarea, .cos-config .field input, .cos-config .field select,
.speech-config .field input, .speech-config .field select { width: 100%; }
.article-editor textarea { resize: vertical; }
.result-count { margin-bottom: 10px !important; }
.cos-browser-toolbar input { min-width: 260px; flex: 1; }
.cos-pagination { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 10px; }
.cos-status-guide { margin-bottom: 14px; line-height: 1.45; }
.cos-object-cell { min-width: 390px; }
.cos-object-cell code { overflow-wrap: anywhere; }
.cos-object-summary { margin-top: 7px; line-height: 1.45; }
.cos-object-summary strong { font-size: 13px; font-weight: 600; }
.cos-status-counts { margin-top: 5px; }
code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12px; }

/* ── model provider ────────────────────────────────────────────────────── */
.small { font-size: 12px; }
.ai-section-nav {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin: 0 0 20px;
  border-radius: 11px;
  background: #e9e9ed;
}
.ai-section-nav button {
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 500;
}
.ai-section-nav button.active { color: var(--text); background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }
.speech-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.speech-card-head h3 { margin: 0 0 4px; font-size: 18px; }
.speech-card-head p { margin: 0; }
.speech-divider { border-top: 1px solid var(--line); margin: 24px -20px; }
.speech-result { margin-top: 14px; line-height: 1.6; }
.speech-result audio { width: min(100%, 460px); margin-top: 8px; }
.paid-warning { margin-top: 16px; }
.automation-config { max-width: 760px; }
.switch-row { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 500; }
.switch-row input { width: auto; }
.restore-field { min-height: 24px; margin-top: 4px; }
.provider-title { align-items: flex-start; }
.provider-title .sub { margin-bottom: 0; }
.provider-title-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.revision { color: var(--muted); font-size: 12px; }
.provider-message:empty { display: none; }
.provider-message { margin-bottom: 16px; }
.endpoint-message { margin: 10px 0 0; }
.success-banner { background: #e3f5e9; color: var(--ok); padding: 10px 16px; border-radius: 10px; font-size: 13px; }
.routing-guide { background: #fff4e0; color: #8a4b08; border-radius: 10px; padding: 11px 16px; margin-bottom: 16px; font-size: 13px; }
.provider-layout { display: grid; grid-template-columns: minmax(240px, 310px) minmax(0, 1fr); gap: 16px; align-items: start; }
.endpoint-column { min-width: 0; }
.column-head, .provider-detail-head, .binding-toolbar, .call-plan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.column-head { padding: 18px; border-bottom: 1px solid var(--line); }
.column-head h3, .provider-detail-head h3, .binding-toolbar h3, .call-plan-head h3 {
  margin: 0 0 3px;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.column-head p, .provider-detail-head p, .binding-toolbar p, .call-plan-head p { margin: 0; }
.endpoint-list { padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.endpoint-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  text-align: left;
}
.endpoint-item:hover { background: #f5f5f7; }
.endpoint-item.selected { background: #e8f0fe; border-color: #c8ddfa; }
.endpoint-name { font-size: 14px; font-weight: 600; }
.endpoint-url { display: block; width: 100%; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.endpoint-badges { margin-top: 3px; }
.provider-editor { min-width: 0; padding: 22px; }
.provider-detail-head { margin-bottom: 18px; }
.provider-form .field { margin: 0; }
.provider-form .field input, .catalog-actions input, .call-plan-actions select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font-size: 14px;
  background: #fbfbfd;
}
.provider-form .field input:focus, .catalog-actions input:focus, .call-plan-actions select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.field-help { color: var(--muted); font-size: 12px; line-height: 1.35; margin-top: 4px; }
.check-field { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; min-height: 36px; }
.check-field input { margin: 0; }
.form-actions { display: flex; align-items: center; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.dirty-hint { min-height: 17px; margin-top: 6px; color: #b15c00; font-size: 12px; }
.provider-empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.provider-empty h3 { margin: 0 0 6px; color: var(--text); font-size: 17px; }
.provider-empty p { margin: 0; }
.provider-empty.compact { padding: 24px 16px; font-size: 13px; }
.bindings-section { margin: 24px -22px -22px; padding: 22px; border-top: 1px solid var(--line); background: #fbfbfd; }
.binding-toolbar { align-items: flex-start; margin-bottom: 14px; }
.catalog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.catalog-actions input { width: 190px; padding: 7px 10px; font-size: 13px; }
.catalog-summary { margin: -4px 0 12px; padding: 8px 10px; border-radius: 8px; background: #eef6ff; color: #315f8c; font-size: 12px; }
.catalog-models { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.catalog-models-head, .catalog-model-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.catalog-models-head { padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f5f5f7; }
.catalog-model-list { max-height: 280px; overflow-y: auto; }
.catalog-model-row { min-height: 43px; padding: 7px 10px 7px 12px; border-bottom: 1px solid var(--line); }
.catalog-model-row:last-child { border-bottom: none; }
.catalog-model-id { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.binding-list { display: flex; flex-direction: column; gap: 12px; }
.binding-card { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.binding-summary { display: flex; align-items: center; gap: 8px; padding: 13px 16px; cursor: pointer; list-style: none; }
.binding-summary::-webkit-details-marker { display: none; }
.binding-summary::before { content: "›"; color: var(--muted); font-size: 18px; line-height: 1; transition: transform 0.15s ease; }
.binding-card[open] .binding-summary::before { transform: rotate(90deg); }
.binding-summary strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.binding-summary:hover { background: #f8f8fa; }
.binding-card[open] .binding-summary { border-bottom: 1px solid var(--line); }
.binding-form { padding: 16px; }
.model-test-result { margin-top: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; }
.model-test-result.passed { border-color: #b9dec5; background: #f5fbf7; }
.model-test-result.failed { border-color: #f1b8bd; background: #fff7f7; }
.model-test-result.failed > p { margin: 8px 0; line-height: 1.45; }
.model-test-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.model-test-text { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.model-test-text > div { padding: 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.model-test-text span, .model-test-metrics span { display: block; color: var(--muted); font-size: 11px; }
.model-test-text p { margin: 4px 0 0; line-height: 1.5; }
.model-test-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(95px, 1fr)); gap: 8px; margin-top: 10px; }
.model-test-metrics > div { padding: 8px 9px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.model-test-metrics strong { display: block; margin-top: 3px; font-size: 12px; overflow-wrap: anywhere; }
.model-test-warning { margin-top: 10px; padding: 9px 10px; border-radius: 8px; background: #fff4e0; color: #8a4b08; line-height: 1.4; }
.model-test-warning.strong { background: #ffebdf; color: #9b2c00; border: 1px solid #f3b18f; }
.model-test-streaming-action { margin-top: 10px; }
.pricing { margin-top: 15px; border-top: 1px solid var(--line); padding-top: 12px; }
.pricing summary { color: var(--accent); cursor: pointer; font-size: 13px; }
.pricing-grid { margin-top: 13px; }
.call-plan { padding: 20px; }
.call-plan-head { margin-bottom: 14px; }
.call-plan-list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.call-plan-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) 100px auto; align-items: center; gap: 12px; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.call-plan-row:last-child { border-bottom: none; }
.call-position { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #f0f0f2; color: var(--muted); font-size: 12px; font-weight: 600; }
.call-model { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.call-model strong, .call-model span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-model strong { font-size: 14px; }
.call-model span { color: var(--muted); font-size: 11px; }
.route-role { color: var(--muted); font-size: 12px; }
.call-plan-row .row-actions { display: flex; justify-content: flex-end; gap: 3px; }
.call-plan-actions { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; gap: 8px; margin-top: 14px; }
.call-plan-actions select { min-width: 0; }

@media (max-width: 900px) {
  .provider-layout { grid-template-columns: 1fr; }
  .endpoint-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
  .provider-editor { min-width: 0; }
}

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .who { border: none; }
  .main { padding: 20px; }
  .provider-title, .binding-toolbar { align-items: stretch; flex-direction: column; }
  .provider-title-actions, .catalog-actions { justify-content: flex-start; }
  .catalog-actions input { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .model-test-text { grid-template-columns: 1fr; }
  .call-plan-row { grid-template-columns: 30px minmax(0, 1fr); }
  .call-plan-row .route-role, .call-plan-row .row-actions { grid-column: 2; }
  .call-plan-row .row-actions { justify-content: flex-start; }
  .call-plan-actions { grid-template-columns: 1fr; }
  .article-filters, .cos-browser-toolbar { align-items: stretch; flex-direction: column; }
  .article-filters input, .article-filters select, .cos-browser-toolbar input { width: 100%; }
}
