/* Application layout: gate screen, console shell, panels, and views. */

.boot { height: 100vh; display: grid; place-items: center; background: var(--bg); }

/* ---------- login / setup ---------- */

.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  position: relative;
  isolation: isolate;
  overflow: hidden;
}
.gate-theme-toggle {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 2;
  border-color: var(--line);
  background: var(--bg-panel);
  box-shadow: var(--shadow-sm);
}
.gate::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .32), transparent 82%);
  opacity: .38;
  pointer-events: none;
}
.gate-card {
  width: 100%;
  max-width: 390px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
}
.gate-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--accent);
  position: relative;
  box-shadow: 0 10px 26px -14px var(--accent-glow);
}
.gate-mark::before, .brand-mark::before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid var(--accent-ink);
  border-top-color: transparent;
  border-left-color: transparent;
}
.gate-mark::after, .brand-mark::after {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent-ink);
}
.gate-card h1 { margin-top: 4px; font-size: 21px; }
.gate-card .btn-primary { margin-top: 3px; height: 38px; }
.gate-foot { font-size: 11.5px; margin-top: 2px; line-height: 1.5; }

/* ---------- shell ---------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--bg-raised);
  overflow: hidden;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  height: var(--topbar-h);
  padding: 0 17px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 7px;
  background: var(--accent);
  position: relative;
  box-shadow: 0 8px 18px -12px var(--accent-glow);
}
.brand-mark::before { width: 9px; height: 9px; }
.brand-mark::after { width: 3px; height: 3px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 13.5px; font-weight: 680; white-space: nowrap; }
.brand-text small { margin-top: 2px; font-size: 10.5px; color: var(--text-faint); }

.nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-group {
  padding: 15px 10px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-faint);
}
.nav-group:first-child { padding-top: 5px; }
.nav button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}
.nav button:hover { background: var(--bg-hover); color: var(--text); }
.nav button[aria-current="page"] {
  background: var(--accent-soft);
  background: linear-gradient(90deg, var(--accent-soft), color-mix(in srgb, var(--accent-soft) 28%, transparent));
  border-color: transparent;
  color: var(--accent-strong);
  font-weight: 600;
}
.nav button[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}
.nav button .icon { opacity: .82; }
.nav button[aria-current="page"] .icon { opacity: 1; }
.nav-badge {
  margin-left: auto;
  min-width: 19px;
  height: 18px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-faint);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.sidebar-foot {
  padding: 11px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: var(--bg-raised);
}
.endpoint {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
  transition: border-color .14s ease, background .14s ease;
}
.endpoint:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.endpoint-label { display: block; font-size: 10.5px; color: var(--text-faint); margin-bottom: 3px; }
.endpoint code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }

/* ---------- main ---------- */

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; background: var(--bg); }
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 22px;
  flex: none;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  z-index: 20;
}
.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 16px; }
.topbar-title p { font-size: 11.5px; margin-top: 1px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.theme-toggle { flex: none; border-color: var(--line); background: var(--bg-panel); }
.nav-toggle { display: none; flex: none; }
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(4, 6, 9, .68); backdrop-filter: blur(2px); }
.view {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-gutter: stable;
}

/* ---------- panels ---------- */

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
}
.panel-head h2 { font-size: 13.5px; }
.panel-head .row { margin-left: auto; }
.panel-body { padding: 15px; }
.panel-body-tight { padding: 0; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric {
  position: relative;
  min-height: 104px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.metric::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: var(--accent);
  opacity: .8;
}
.metric:nth-child(4n + 2)::after { background: var(--info); }
.metric:nth-child(4n + 3)::after { background: var(--violet); }
.metric:nth-child(4n + 4)::after { background: var(--warn); }
.metric-label { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-muted); }
.metric-value {
  margin-top: 10px;
  font-size: 24px;
  font-weight: 670;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.metric-foot { margin-top: 7px; font-size: 11.5px; color: var(--text-faint); }
.overview-metrics, .analytics-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric.metric-ok::after { background: var(--ok); }
.metric.metric-info::after { background: var(--info); }
.metric.metric-warn::after { background: var(--warn); }
.metric.metric-danger::after { background: var(--danger); }
.metric.metric-idle::after { background: var(--text-faint); }
.metric-action {
  width: 100%;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  appearance: none;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.metric-action:hover { border-color: var(--line-strong); background: var(--bg-subtle); }
.metric-action:active { transform: translateY(1px); }
.metric-action:focus-visible { outline: none; box-shadow: var(--ring); }
.chart-legend { font-size: 11.5px; color: var(--text-faint); }
.panel-head .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.panel-head .seg::-webkit-scrollbar { display: none; }

.split { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; }
.split-even { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.chart {
  --chart-plot-height: 152px;
  width: 100%;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  grid-template-rows: var(--chart-plot-height) 26px;
  column-gap: 10px;
  padding: 2px 2px 0 0;
}
.chart-y-axis { grid-column: 1; grid-row: 1; position: relative; min-width: 0; }
.chart-plot { grid-column: 2; grid-row: 1; position: relative; min-width: 0; overflow: hidden; }
.chart-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-y-label {
  position: absolute;
  right: 0;
  transform: translateY(-50%);
  color: var(--text-faint);
  font: 10.5px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chart-y-label:first-child { transform: translateY(0); }
.chart-y-label:last-child { transform: translateY(-100%); }
.chart-x-axis { grid-column: 2; grid-row: 2; position: relative; height: 26px; }
.chart-x-label {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  color: var(--text-faint);
  font: 10.5px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chart-x-label.is-first { transform: none; }
.chart-x-label.is-last { transform: translateX(-100%); }
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  font-size: 12px;
}

.rank { display: flex; flex-direction: column; }
.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  transition: background .12s ease;
}
.rank-row:hover { background: var(--bg-subtle); }
.rank-row:last-child { border-bottom: 0; }
.rank-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.rank-row .bar { grid-column: 1 / -1; }

.attention-list { display: flex; flex-direction: column; }
.attention-row {
  display: grid;
  grid-template-columns: minmax(138px, .7fr) minmax(180px, 1fr) minmax(220px, 1.6fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 9px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .12s ease;
}
.attention-row:last-child { border-bottom: 0; }
.attention-row:hover { background: var(--bg-subtle); }
.attention-row:focus-visible { outline: none; box-shadow: inset var(--ring); }
.attention-row strong { font-size: 12.5px; }
.attention-route, .attention-error, .attention-time { font-size: 12px; color: var(--text-dim); min-width: 0; }
.attention-error { color: var(--text-muted); }
.attention-time { color: var(--text-faint); white-space: nowrap; font-variant-numeric: tabular-nums; }

.analytics-tabs { min-width: min(360px, 100%); }
.analytics-row { cursor: pointer; }
.analytics-row:focus-visible { outline: none; box-shadow: inset var(--ring); }
.analytics-name { display: block; font-size: 12.5px; font-weight: 620; white-space: nowrap; }
.analytics-hint { display: block; margin-top: 2px; color: var(--text-faint); font-size: 10.5px; white-space: nowrap; }

/* ---------- supplier and account cards ---------- */

.channels { display: flex; flex-direction: column; gap: 12px; }
.channel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.channel:hover { border-color: var(--line-strong); }
.channel-head { display: flex; align-items: center; gap: 13px; padding: 13px 15px; }
.channel-head.is-off { opacity: .58; }
.channel-id { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.channel-name { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 650; min-width: 0; }
.channel-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 11.5px; color: var(--text-faint); }
.channel-meta code { color: var(--text-dim); overflow-wrap: anywhere; }
.channel-stats { display: flex; gap: 22px; padding: 0 5px; }
.channel-stat { text-align: right; min-width: 54px; }
.channel-stat b { display: block; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.channel-stat span { font-size: 10.5px; color: var(--text-faint); }
.channel-actions { display: flex; align-items: center; gap: 3px; }
.channel-body {
  border-top: 1px solid var(--line);
  background: var(--bg-subtle);
  background: color-mix(in srgb, var(--bg-panel) 88%, var(--bg-subtle));
}
.channel-models { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.channel-models .tag { cursor: default; }
.channel-keyline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-subtle);
}
.channel-keyline .grow { flex: 1 1 auto; }

.accounts { width: 100%; border-collapse: collapse; font-size: 13px; }
.accounts th {
  padding: 8px 14px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 650;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--line);
  background: var(--bg-subtle);
}
.accounts td { padding: 9px 14px; border-bottom: 1px solid var(--line); }
.accounts tbody tr { transition: background .12s ease; }
.accounts tbody tr:hover { background: var(--bg-hover); }
.accounts tr:last-child td { border-bottom: 0; }
.accounts td.num { text-align: right; font-variant-numeric: tabular-nums; }
.account-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.account-name small { color: var(--text-faint); font-size: 11px; overflow-wrap: anywhere; }
.account-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* ---------- modal and editors ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 6, 9, .72);
  backdrop-filter: blur(4px);
  animation: overlay-in .14s ease;
}
.modal {
  width: 100%;
  max-width: 640px;
  max-height: calc(100vh - 54px);
  max-height: calc(100dvh - 54px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  animation: modal-in .16s ease;
}
.modal-lg { max-width: 820px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 17px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 15px; }
.modal-head .btn-icon { margin-left: auto; }
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 17px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 17px;
  border-top: 1px solid var(--line);
  background: var(--bg-subtle);
}
.modal-foot .grow { flex: 1; }
@keyframes overlay-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.editor-section { display: flex; flex-direction: column; gap: 10px; }
.editor-section + .editor-section { padding-top: 3px; }
.editor-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.editor-section-head h3 { font-size: 13px; }
.mapping-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.mapping-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto 30px;
  align-items: end;
  gap: 9px;
  padding: 10px;
  background: var(--bg-subtle);
}
.mapping-row + .mapping-row { border-top: 1px solid var(--line); }
.header-mapping-row { grid-template-columns: minmax(150px, .7fr) minmax(180px, 1.3fr) 30px; }
.mapping-cell { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.mapping-cell > span { color: var(--text-faint); font-size: 10.5px; }
.mapping-rewrite { min-height: 34px; padding-bottom: 5px; white-space: nowrap; }
.mapping-empty { padding: 16px; color: var(--text-faint); font-size: 12px; text-align: center; background: var(--bg-subtle); }
.key-mapping-row { grid-template-columns: minmax(160px, 1fr) auto auto; align-items: center; }
.key-mapping-row .mapping-actions { display: flex; gap: 2px; }
.key-mapping-row .span-all { grid-column: 1 / -1; padding-top: 2px; }
.current-provider { border-color: var(--line-strong); cursor: default; }

.tabs { display: flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-subtle); }
.tabs button {
  flex: 1;
  height: 30px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background .14s ease, color .14s ease, box-shadow .14s ease;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--bg-panel); color: var(--text); box-shadow: var(--shadow-sm); }
.pool-tabs { overflow-x: auto; scrollbar-width: thin; }
.pool-tabs button { flex: 0 0 auto; padding: 0 13px; white-space: nowrap; }
.pool-list { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.picker { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-subtle); overflow: hidden; }
.picker-search { padding: 9px; border-bottom: 1px solid var(--line); background: var(--bg-panel); }
.picker-list { max-height: 240px; overflow-y: auto; padding: 5px; }
.picker-item { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: var(--radius-xs); cursor: pointer; font-size: 13px; }
.picker-item:hover { background: var(--bg-hover); }
.picker-item input { width: auto; min-height: 0; margin: 0; accent-color: var(--accent); }
.picker-foot { display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-faint); background: var(--bg-panel); }

.provider-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); gap: 9px; }
.provider-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font: inherit;
  transition: border-color .14s ease, background .14s ease, box-shadow .14s ease;
}
.provider-card:hover { border-color: var(--line-strong); background: var(--bg-hover); }
.provider-card[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.provider-card b { font-size: 13px; font-weight: 650; }
.provider-card span { font-size: 11px; color: var(--text-faint); line-height: 1.4; }

.authbox { display: flex; flex-direction: column; gap: 11px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-subtle); }
.usercode {
  font-family: var(--mono);
  font-size: 22px;
  letter-spacing: 2px;
  padding: 10px 12px;
  border: 1px dashed var(--accent-line);
  border-radius: var(--radius-sm);
  text-align: center;
  color: var(--accent-strong);
  background: var(--accent-soft);
}
.authsteps { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; color: var(--text-dim); margin: 0; padding: 0; }
.authsteps li { list-style: none; display: flex; gap: 7px; }
.authsteps b { color: var(--accent-strong); font-variant-numeric: tabular-nums; }

.keyline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.keyline code {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-detail { display: flex; flex-direction: column; gap: 11px; }
.kv { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 7px 12px; font-size: 13px; }
.kv dt { color: var(--text-faint); font-size: 12px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
pre.block {
  margin: 0;
  padding: 11px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-dim);
}

.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; min-width: 138px; }
.token-split { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.usage-line { white-space: nowrap; overflow-x: auto; font-variant-numeric: tabular-nums; }

/* ---------- playground ---------- */

.playground { display: grid; grid-template-columns: minmax(0, 330px) minmax(0, 1fr); gap: 16px; align-items: start; }
.pg-output {
  min-height: 310px;
  max-height: 480px;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
}
.pg-section-label { color: var(--text-muted); font-size: 11.5px; font-weight: 650; }
.pg-reasoning-wrap:has(.pg-reasoning[hidden]) { display: none; }
.pg-reasoning {
  max-height: 230px;
  overflow: auto;
  padding: 12px 14px;
  border-left: 2px solid var(--info);
  background: var(--info-soft);
  color: var(--text-muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
}

/* ---------- toasts ---------- */

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  min-width: 250px;
  max-width: 390px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in .18s ease;
  pointer-events: auto;
}
.toast-ok { border-left: 3px solid var(--ok); }
.toast-err { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--info); }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

/* ---------- responsive ---------- */

@media (min-width: 1560px) {
  .view { padding: 26px 30px; }
}

@media (min-width: 1900px) {
  .metrics { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .overview-metrics, .analytics-metrics { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (max-width: 1080px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .playground { grid-template-columns: minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attention-row { grid-template-columns: minmax(138px, .7fr) minmax(160px, 1fr) minmax(0, 1.3fr); }
  .attention-time { display: none; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    z-index: 50;
    inset: 0 auto 0 0;
    width: min(286px, 84vw);
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: var(--shadow);
  }
  .drawer-open .sidebar { transform: translateX(0); }
  .nav-toggle { display: inline-flex; }
  .topbar {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) 32px;
    grid-template-rows: auto auto;
    padding: 9px 14px;
    gap: 8px 10px;
    height: auto;
    min-height: var(--topbar-h);
  }
  .nav-toggle { grid-column: 1; grid-row: 1; }
  .topbar-title { grid-column: 2; grid-row: 1; align-self: center; }
  .topbar > .theme-toggle { grid-column: 3; grid-row: 1; }
  .topbar-title h1 { font-size: 16px; }
  .topbar-title p { display: none; }
  .topbar-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    margin-left: 0;
    gap: 6px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .topbar-actions:empty { display: none; }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .topbar-actions .seg button { padding: 0 8px; }
  .filters select, .filters input { min-width: 0; flex: 1 1 132px; }
  .channel-head { flex-wrap: wrap; }
  .channel-id { flex: 1 1 100%; }
  .channel-name { flex-wrap: wrap; }
  .channel-meta code { overflow-wrap: anywhere; }
  .channel-stats { order: 3; width: 100%; justify-content: flex-start; gap: 24px; padding: 2px 0; }
  .channel-stat { text-align: left; min-width: 0; }
  .channel-actions { order: 4; width: 100%; flex-wrap: wrap; padding-top: 7px; border-top: 1px solid var(--line); }

  .accounts thead { display: none; }
  .accounts, .accounts tbody, .accounts tr, .accounts td { display: block; width: auto; }
  .accounts tr { padding: 11px 14px; border-bottom: 1px solid var(--line); }
  .accounts tr:last-child { border-bottom: 0; }
  .accounts td { padding: 3px 0; border: 0; }
  .accounts td[data-label]:not([data-label="账号"]) { display: flex; align-items: center; gap: 10px; }
  .accounts td[data-label]:not([data-label="账号"])::before {
    content: attr(data-label);
    flex: none;
    min-width: 74px;
    font-size: 11.5px;
    color: var(--text-faint);
  }
  .accounts td.num { text-align: left; }
  .accounts td[data-label="账号"] { padding-bottom: 7px; }
  .account-cell-actions { padding-top: 8px; }
  .account-actions { justify-content: flex-start; flex-wrap: wrap; }

  .table-wrap table.grid td, .table-wrap table.grid th { white-space: nowrap; }
  .table-wrap table.grid td.truncate { max-width: 180px; }
  .view { padding: 14px; gap: 13px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric { min-height: 96px; padding: 13px; }
  .metric-value { font-size: 20px; }
  .attention-row { grid-template-columns: minmax(130px, .75fr) minmax(0, 1.25fr); gap: 5px 10px; }
  .attention-error { grid-column: 1 / -1; padding-left: 14px; }
  .analytics-tabs { min-width: 0; width: 100%; overflow-x: auto; }
  .analytics-tabs button { min-width: 76px; }
  .split-even { gap: 12px; }
  .overlay { padding: 0; align-items: stretch; }
  .modal {
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
    animation: none;
  }
  .modal-head { flex: none; padding-top: max(14px, env(safe-area-inset-top)); }
  .modal-body { padding: 15px; }
  .modal-foot { flex-wrap: wrap; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal-foot .grow { display: none; }
  .modal-foot .btn-primary { margin-left: auto; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-section-head { align-items: flex-start; }
  .mapping-row, .header-mapping-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
  .model-mapping-row .mapping-rewrite { grid-column: 1 / 3; }
  .key-mapping-row { grid-template-columns: minmax(0, 1fr) auto; }
  .key-mapping-row .mapping-actions { grid-column: 2; grid-row: 1; justify-self: end; }
  .provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; min-width: 0; }
}

@media (max-width: 520px) {
  .gate { padding: 16px; align-items: center; }
  .gate-card { padding: 25px 20px; }
  .metrics { grid-template-columns: minmax(0, 1fr); }
  .metric { min-height: 90px; }
  .attention-row { grid-template-columns: minmax(0, 1fr); padding: 11px 13px; }
  .attention-error { grid-column: 1; padding-left: 14px; }
  .chart { grid-template-columns: 30px minmax(0, 1fr); column-gap: 7px; }
  .chart-y-label, .chart-x-label { font-size: 9.5px; }
  .panel-head { align-items: flex-start; flex-wrap: wrap; }
  .panel-head .row { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .provider-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-section-head { flex-direction: column; }
  .mapping-row, .header-mapping-row { grid-template-columns: minmax(0, 1fr) 32px; }
  .mapping-row .mapping-cell { grid-column: 1 / -1; }
  .key-mapping-row .mapping-actions { grid-column: 1 / -1; grid-row: auto; justify-self: start; }
  .model-mapping-row .mapping-rewrite { grid-column: 1; }
  .mapping-row > .btn-icon { grid-column: 2; grid-row: 1; justify-self: end; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd + dt { margin-top: 7px; }
}
