:root, [data-theme="dark"] {
  --font-sans: "Segoe UI Variable Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --type-page: 24px;
  --type-title: 15px;
  --type-body: 14px;
  --type-lede: 13px;
  --type-label: 12.5px;
  --type-meta: 12px;
  --leading-tight: 1.25;
  --leading-title: 1.4;
  --leading-body: 1.5;
  --leading-lede: 1.55;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --card-pad: 22px 24px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --fast: 120ms;
  --bg: #151716;
  --bg-elev: #1d201e;
  --bg-elev2: #242825;
  --bg-soft: #191c1a;
  --bg-hover: #2b302c;
  --bg-active: #30332b;
  --sidebar-bg: #111412;
  --border: #343a35;
  --border-soft: #2b302c;
  --border-strong: #555e55;
  --text: #f0f1e9;
  --text-dim: #b0b7ad;
  --text-faint: #99a293;
  --accent: #c3cf9c;
  --accent-hover: #d3ddb5;
  --accent-text: #d0ddb0;
  --danger: #e06c6c;
  --warning: #d3a34f;
  --success: #6cab8d;
  --ok: #86efac;
  --scrollbar: #3a3a3a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--type-body);
  line-height: var(--leading-body);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--accent-text); text-decoration: none; }
code, pre { font-family: var(--font-mono); }
.muted { color: var(--text-dim); font-weight: 400; }
.ok { color: var(--ok); }
code {
  font-size: var(--type-label);
  line-height: var(--leading-body);
  color: var(--text-dim);
  word-break: break-all;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--r-md);
  background: var(--accent);
  color: #1b2414;
  font-size: var(--type-body);
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: scale(0.985); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }
a.primary-btn { color: #1b2414; text-decoration: none; min-height: 40px; }

.secondary-btn {
  min-height: 34px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: var(--type-lede);
  font-weight: 600;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.secondary-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.login-page-layer {
  min-height: 100dvh;
  padding: 24px 16px 48px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  background: var(--bg);
}
.login-page-shell {
  width: min(460px, calc(100% - 32px));
  padding: 36px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-elev);
  box-shadow: 0 24px 80px #0004;
  display: grid;
  gap: var(--space-6);
}
.login-page-heading h1 {
  margin: 0;
  color: var(--text);
  font-size: var(--type-page);
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
}
.login-page-heading p {
  margin: var(--space-2) 0 0;
  color: var(--text-dim);
  font-size: var(--type-lede);
  font-weight: 400;
  line-height: var(--leading-lede);
  max-width: 28em;
}
.login-page-form { display: grid; gap: var(--space-4); margin: 0; }
.login-field {
  display: grid;
  gap: var(--space-2);
  color: var(--text);
  font-size: var(--type-body);
  font-weight: 600;
  line-height: var(--leading-title);
}
.login-field span { letter-spacing: 0; }
.token-pool-input,
.login-page-form .token-pool-input,
input, textarea, select {
  width: 100%;
  height: 40px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--type-body);
  font-weight: 400;
  line-height: var(--leading-body);
}
textarea {
  height: auto;
  min-height: 160px;
  padding: 12px 15px;
  border-radius: 14px;
  font-family: var(--font-mono);
  font-size: var(--type-lede);
  line-height: var(--leading-body);
  resize: vertical;
}
input:hover, textarea:hover, select:hover,
input:focus, textarea:focus, select:focus {
  border-color: var(--border-strong);
  background: var(--bg-elev);
}
.login-page-form .primary-btn {
  min-height: 40px;
  margin-top: var(--space-1);
  border-radius: var(--r-pill);
  font-size: var(--type-body);
  font-weight: 600;
}
.login-page-status {
  min-height: 1.2em;
  margin: 0;
  color: var(--text-dim);
  font-size: var(--type-label);
  line-height: var(--leading-title);
}
.login-page-status.ok { color: var(--ok); }
.login-page-status.err { color: var(--danger); }

.admin-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.admin-header {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) auto;
  min-height: 76px;
  padding: 0 32px 0 0;
  align-items: center;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border-soft);
}
.settings-brand {
  min-width: 0;
  height: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-right: 1px solid var(--border-soft);
}
.settings-brand-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-text);
}
.settings-brand-mark img {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: block;
  object-fit: cover;
}
.login-brand {
  border-right: 0;
  height: auto;
  padding: 0;
  margin: 0 0 var(--space-4);
}
.settings-brand strong {
  display: block;
  font-size: var(--type-body);
  font-weight: 650;
  line-height: var(--leading-title);
}
.settings-brand span {
  color: var(--text-dim);
  font-size: var(--type-meta);
  line-height: var(--leading-title);
}

.admin-origin:empty { display: none; }
.admin-origin {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
}
.admin-header-copy {
  min-width: 0;
  padding-left: 28px;
}
.admin-header-copy .admin-origin { max-width: 42em; }
.admin-header-copy h2 {
  margin: 0;
  font-size: var(--type-title);
  font-weight: 600;
  line-height: var(--leading-title);
  letter-spacing: 0;
}

.admin-body {
  flex: 1;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
}
.sheet-nav.settings-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
  max-height: 100%;
  padding: 20px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border-soft);
  background: var(--sidebar-bg);
}
.sheet-nav-btn {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--r-sm);
  font-size: var(--type-body);
  font-weight: 500;
  color: var(--text-dim);
  text-align: left;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.sheet-nav-btn svg { flex: 0 0 16px; color: var(--text-faint); }
.sheet-nav-btn:hover { color: var(--text); background: #ffffff06; }
.sheet-nav-btn.active,
.sheet-nav-btn.on {
  color: var(--accent-text);
  background: var(--bg-active);
  box-shadow: inset 2px 0 var(--accent);
}
.sheet-nav-btn.active svg,
.sheet-nav-btn.on svg { color: var(--accent-text); }
.sheet-nav-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-content {
  min-width: 0;
  padding: 28px clamp(20px, 2.8vw, 40px) 40px;
  overflow: auto;
}
.admin-view { min-width: 0; }
.admin-view .split { min-height: 0; }
.invite-list { list-style: none; padding: 0; margin: 10px 0 0; }
.invite-list li { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.invite-list code { font-family: var(--mono); letter-spacing: .08em; }
form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
form.inline input { width: auto; min-width: 6rem; flex: 1; }
.page-lede {
  margin: 0 0 var(--space-6);
  color: var(--text-dim);
  font-size: var(--type-lede);
  font-weight: 400;
  line-height: var(--leading-lede);
  max-width: 42em;
}
.split h2, .split-wide h2, .stack h2, .admin-view h2, .admin-view h3,
form.stack > h2, .group h3 {
  margin: 0 0 var(--space-4);
  color: var(--text);
  font-size: var(--type-title);
  font-weight: 600;
  line-height: var(--leading-title);
  letter-spacing: 0;
}
.lede, .stack > .muted, form .muted {
  margin: 0;
  color: var(--text-dim);
  font-size: var(--type-lede);
  font-weight: 400;
  line-height: var(--leading-lede);
  max-width: 46em;
}
.general-settings-group,
.split > div, .split > form, .split-wide > div, .split-wide > form,
.board, .provider-row, .group {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elev);
}
.split, .split-wide {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: var(--space-5);
}
.split > div, .split > form, .split-wide > div, .split-wide > form {
  padding: var(--card-pad);
}
.stack { display: grid; gap: var(--space-3); }
.stack > h2 + .lede,
.split > div > h2 + .lede,
.split-wide > div > h2 + .lede,
.admin-view > h2 + .lede {
  margin-top: calc(var(--space-4) * -1 + var(--space-2));
  margin-bottom: var(--space-4);
}
label { display: grid; gap: var(--space-2); font-size: var(--type-label); font-weight: 600; color: var(--text); line-height: var(--leading-title); }
label.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 500;
}
label.inline input { width: auto; height: auto; }
.form-error { color: var(--danger); font-size: var(--type-label); line-height: var(--leading-title); }
.form-error:empty { display: none; }
form.stack > button[type="submit"]:not(.tiny):not(.secondary-btn),
.row-actions > button[type="submit"]:not(.tiny) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #1b2414;
  font-size: var(--type-lede);
  font-weight: 600;
}
form.stack > button[type="submit"]:not(.tiny):not(.secondary-btn):hover,
.row-actions > button[type="submit"]:not(.tiny):hover { background: var(--accent-hover); }

.undo-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: var(--type-lede);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

table { width: 100%; border-collapse: collapse; font-size: var(--type-body); }
th, td {
  text-align: left;
  padding: 16px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
  line-height: var(--leading-title);
}
th {
  color: var(--text-faint);
  font-size: var(--type-meta);
  font-weight: 600;
  letter-spacing: 0.01em;
}
td { color: var(--text); font-weight: 500; }
td .muted {
  display: inline-block;
  margin-top: 2px;
  font-size: var(--type-meta);
  font-weight: 400;
  line-height: var(--leading-title);
}
td:nth-child(n+2) { font-variant-numeric: tabular-nums; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
button.tiny, .tiny {
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--bg-soft);
  color: var(--text);
  font-size: var(--type-label);
  font-weight: 600;
}
button.tiny:hover, .tiny:hover { background: var(--bg-hover); border-color: var(--border-strong); }
button.tiny:disabled { opacity: 0.45; cursor: not-allowed; }
button.linkish {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
button.linkish:hover { color: var(--accent); }
button.danger { background: var(--danger); color: #fff; border-color: transparent; }

.badge {
  display: inline-block;
  font-size: var(--type-meta);
  font-weight: 600;
  line-height: var(--leading-title);
  padding: 1px 7px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  margin-left: .3rem;
  color: var(--text-dim);
  vertical-align: 1px;
}
.badge.on { color: var(--success); border-color: var(--success); }
.badge.off { color: var(--text-faint); }
.note {
  color: var(--text-dim);
  font-size: var(--type-meta);
  font-weight: 400;
  line-height: var(--leading-body);
  margin-top: var(--space-1);
}

.board { padding: 0; border: 0; background: transparent; overflow: visible; }
.banner {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  font-size: var(--type-lede);
  font-weight: 400;
  line-height: var(--leading-lede);
  color: var(--text-dim);
}
.banner.ok { box-shadow: inset 3px 0 0 var(--success); }
.banner.warn { box-shadow: inset 3px 0 0 var(--warning); }
.banner.danger { box-shadow: inset 3px 0 0 var(--danger); color: #f0c4c4; }
.banner:empty { display: none; }
.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.metric {
  padding: 24px 24px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  min-width: 0;
}
.metric:last-child { border-right: 1px solid var(--border); }
.metric span, .metric small { display: block; color: var(--text-dim); }
.metric span { font-size: var(--type-label); font-weight: 600; line-height: var(--leading-title); }
.metric small { font-size: var(--type-meta); font-weight: 400; line-height: var(--leading-title); }
.metric b {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: clamp(28px, 2.8vw, 40px);
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--text);
  margin: 14px 0 10px;
  line-height: 1.1;
}
.spark { width: 100%; height: 56px; display: block; color: var(--accent); }
.spark-fill { fill: color-mix(in srgb, currentColor 16%, transparent); }
.spark-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.board-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(260px, 1fr); gap: 24px; }
.quota-panel { min-width: 0; padding: 24px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); }
.quota-head { display: flex; justify-content: space-between; gap: 1rem; align-items: end; margin-bottom: .85rem; }
.quota-head span { color: var(--text-dim); font-size: var(--type-label); font-weight: 600; }
.quota-head b {
  display: block;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.03em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.quota-side { text-align: right; color: var(--text-dim); font-size: var(--type-meta); line-height: var(--leading-title); display: grid; gap: 2px; }
.side-stack { min-width: 0; display: grid; align-content: start; gap: 16px; }
.side-stack section { padding: 22px 24px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); }
.side-stack h3 {
  color: var(--text-faint);
  font-size: var(--type-meta);
  font-weight: 600;
  line-height: var(--leading-title);
  margin: 0 0 var(--space-2);
  letter-spacing: 0;
}
.kv { display: grid; gap: 6px; margin: var(--space-2) 0 0; }
.kv div { display: flex; justify-content: space-between; gap: var(--space-4); font-size: var(--type-lede); line-height: var(--leading-title); }
.kv span { color: var(--text-dim); font-weight: 400; }
.kv b { font-weight: 600; font-size: var(--type-lede); color: var(--text); overflow-wrap: anywhere; text-align: right; }
.op-list, .hist-list { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; gap: var(--space-2); }
.op-list li, .hist-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--type-lede);
  line-height: var(--leading-title);
}
.op-list li > span:first-child,
.hist-list li > span:first-child {
  min-width: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.op-list .muted, .hist-list .muted {
  flex: 0 0 auto;
  font-size: var(--type-meta);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.count-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin-top: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  overflow: hidden;
}
.count-strip button {
  text-align: left;
  border-right: 1px solid var(--border-soft);
  padding: 20px 24px;
}
.count-strip button:hover { background: var(--bg-hover); }
.count-strip span { display: block; color: var(--text-dim); font-size: var(--type-meta); font-weight: 600; line-height: var(--leading-title); }
.count-strip b { font-size: 18px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: 0 0 var(--space-4); }
.toolbar input[type="search"] { max-width: 320px; }
.template-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0 0 var(--space-4); }
.provider-list { display: grid; gap: var(--space-3); }
.provider-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: .75rem;
  align-items: start;
  padding: .75rem .8rem;
}
.provider-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev2);
  color: var(--accent-text);
}
.provider-title { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.provider-title strong { font-size: var(--type-body); font-weight: 650; line-height: var(--leading-title); }
.preview-box, .session-json {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: var(--type-label);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .7rem;
  max-height: 360px;
  overflow: auto;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: content-box;
}

@media (max-width: 1100px) {
  .split, .split-wide, .board-grid { grid-template-columns: 1fr; }
  .quota-panel { border-right: 0; border-bottom: 1px solid var(--border-soft); }
}
@media (max-width: 900px) {
  .admin-header { grid-template-columns: 1fr auto; padding-right: 16px; min-height: 68px; }
  .admin-header-copy { display: none; }
  .admin-body { grid-template-columns: 1fr; }
  .settings-brand { border-right: 0; }
  .sheet-nav.settings-sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }
  .sheet-nav-btn { flex: 0 0 auto; width: auto; }
  .metric-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.drop-zone {
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
  padding: 22px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  background: var(--bg-elev);
  color: var(--text-dim);
  cursor: pointer;
}
.drop-zone input { display: none; }
.drop-zone:hover,
.drop-zone.is-over {
  border-color: var(--accent-text);
  color: var(--accent-text);
}
.drop-zone.is-busy { cursor: progress; }
.drop-title {
  font-size: var(--type-lede);
  font-weight: 600;
  color: var(--text);
  line-height: var(--leading-title);
}
.drop-zone:hover .drop-title,
.drop-zone.is-over .drop-title { color: var(--accent-text); }
.drop-status {
  font-size: var(--type-meta);
  font-weight: 400;
  color: var(--text-dim);
}
.drop-status:empty { display: none; }
.drop-error {
  margin: 0;
  color: var(--danger);
  font-size: var(--type-label);
  font-weight: 400;
  line-height: var(--leading-title);
}
.drop-error:empty { display: none; }

.catalog-table th,
.catalog-table td {
  padding: 14px 12px;
  vertical-align: middle;
}
.catalog-table th:last-child,
.catalog-table td:last-child { text-align: right; }
.catalog-table td.row-actions { justify-content: flex-end; white-space: nowrap; }
.catalog-table td:nth-child(2) { font-variant-numeric: normal; }
.catalog-name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-weight: 600;
  line-height: var(--leading-title);
}
.catalog-name .badge { margin-left: 0; vertical-align: 0; }
.catalog-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
  color: var(--text-dim);
  font-size: var(--type-meta);
  font-weight: 400;
  line-height: var(--leading-title);
}
.catalog-meta {
  width: 7.2rem;
  max-width: 28%;
  color: var(--text-dim);
  font-size: var(--type-meta);
  font-weight: 400;
}
.catalog-empty {
  color: var(--text-dim);
  font-weight: 400;
}

.admin-header-copy h2#crumb { letter-spacing: 0.08em; }
.session-toolbar { gap: 12px; margin-bottom: var(--space-5); }
.session-group { margin-bottom: var(--space-5); }
.session-group h3 { margin: 0 0 var(--space-3); }
.session-table th, .session-table td,
.usage-table th, .usage-table td {
  padding: 14px 12px;
  vertical-align: middle;
}
.session-table th:last-child,
.session-table td.row-actions { font-variant-numeric: tabular-nums; }
.usage-table th:nth-child(4),
.usage-table th:nth-child(5),
.usage-table th:nth-child(6),
.usage-table th:nth-child(7),
.usage-table th:nth-child(8),
.usage-table td:nth-child(4),
.usage-table td:nth-child(5),
.usage-table td:nth-child(6),
.usage-table td:nth-child(7),
.usage-table td:nth-child(8) {
  min-width: 5.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.usage-table th:nth-child(6),
.usage-table td:nth-child(6),
.usage-table th:nth-child(7),
.usage-table td:nth-child(7) { min-width: 4.5rem; }
.usage-table th:nth-child(9),
.usage-table td:nth-child(9) {
  text-align: center;
  white-space: nowrap;
}
.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 var(--space-4);
}
.page-head h2 { margin: 0; }
.kind-section {
  margin: 0 0 var(--space-5);
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}
.kind-section h3 {
  margin: 0 0 var(--space-3);
  font-size: var(--type-title);
}
.model-card {
  margin: 0 0 var(--space-3);
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-elev);
}
.model-card.current { border-color: var(--border-strong); }
.model-card-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}
.model-card .row-actions { margin-top: 10px; }
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}
.template-card {
  display: grid;
  gap: 6px;
  justify-items: start;
  text-align: left;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
}
.template-card:hover { border-color: var(--accent-text); }
.template-card strong { font-size: var(--type-body); }
.model-form { width: 100%; max-width: 1100px; }


.barrel-table th, .barrel-table td,
.account-table th, .account-table td,
.company-table th, .company-table td {
  vertical-align: middle;
}
.barrel-table th:nth-child(2),
.barrel-table th:nth-child(3),
.barrel-table td:nth-child(2),
.barrel-table td:nth-child(3),
.company-table th:nth-child(2),
.company-table th:nth-child(3),
.company-table th:nth-child(4),
.company-table td:nth-child(2),
.company-table td:nth-child(3),
.company-table td:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 4.5rem;
}
.company-table th:nth-child(5),
.company-table td:nth-child(5),
.account-table th:last-child,
.account-table td.row-actions {
  text-align: right;
}

.ledger-table th:nth-child(4),
.ledger-table td:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ledger-table td:nth-child(5) {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-list li > div:first-child { min-width: 0; }
.stack-page {
  display: grid;
  gap: var(--space-5);
}
.stack-page > .panel,
.stack-page > form.panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elev);
  padding: var(--card-pad);
}
.stack-page > .panel > p:first-child { margin: 0 0 var(--space-3); }
.company-metrics { grid-template-columns: 1fr 1fr; border-bottom: 0; }
.company-metrics .metric { padding: 18px 20px; }
.detail-block h3 { margin: 0 0 var(--space-3); }
.detail-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.detail-row input { width: auto; min-width: 8rem; flex: 1; }

.detail-row select { width: auto; min-width: 10rem; flex: 1; }
.account-group { margin-bottom: var(--space-5); }
.account-group .page-head { margin-bottom: var(--space-2); }
.account-group h3 { margin: 0; }
.account-preview { margin: 0; }
.invite-list .badge { letter-spacing: 0; font-variant-numeric: normal; }
.session-toolbar { align-items: center; }

.thread-view { margin-top: var(--space-4); }
.thread-head { margin-bottom: var(--space-3); }
.thread-head h3 { margin: 0; }
.thread-log { display: grid; gap: 12px; }
.thread-msg {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
}
.thread-msg.user { background: transparent; }
.thread-msg header {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: var(--type-small, 12px);
}
.thread-md p, .thread-md ul, .thread-md ol, .thread-md pre, .thread-md h1, .thread-md h2, .thread-md h3 {
  margin: 0 0 8px;
}
.thread-md p:last-child, .thread-md ul:last-child, .thread-md ol:last-child, .thread-md pre:last-child {
  margin-bottom: 0;
}
.thread-md pre {
  overflow: auto;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
}
.thread-md code { font-family: var(--mono); font-size: 0.92em; }

#session-company-list .session-group .page-head,
#session-user-list .session-group .page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  min-height: 36px;
}
#session-company-list .session-group .page-head > h3,
#session-user-list .session-group .page-head > h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  font-weight: 650;
}
#session-company-list .session-group .page-head > h3 .muted,
#session-user-list .session-group .page-head > h3 .muted {
  margin-left: 0.35em;
  font-size: 13px;
  font-weight: 500;
}
#session-company-list .session-group .page-head > .tiny,
#session-user-list .session-group .page-head > .tiny {
  flex-shrink: 0;
  align-self: center;
}

/* Shared workspace chrome and responsive content surfaces. */
.admin-shell { height: 100dvh; min-height: 0; overflow: hidden; }
.admin-header { flex-shrink: 0; }
.admin-content { scrollbar-gutter: stable; }
.admin-view, .content-heading { width: 100%; max-width: 1520px; margin-inline: auto; }
.content-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-eyebrow { color: var(--accent-text); font-size: 11px; letter-spacing: .14em; }
.content-heading h1 { margin: 8px 0 6px; font-size: 28px; font-weight: 600; letter-spacing: -.03em; line-height: 1.3; overflow-wrap: anywhere; }
.content-heading p { margin: 0; color: var(--text-dim); line-height: 1.7; }
.workspace-label { color: var(--text-dim); font-size: 12px; }
.workspace-label > span { color: var(--text-faint); padding: 0 12px; }
.admin-header-actions { display: flex; align-items: center; gap: 16px; }
.admin-role { color: var(--text-dim); font-size: 12px; }
.nav-section { padding: 16px 14px 8px; color: var(--text-faint); font-size: 10px; letter-spacing: .12em; }
.nav-section:first-child { padding-top: 4px; }
.nav-footer { display: grid; gap: 4px; margin: 12px 14px 8px; padding-top: 12px; color: var(--text-faint); font-size: 11px; }
.nav-footer strong { color: var(--text-dim); font-size: 12px; letter-spacing: .05em; font-weight: 500; }
.settings-sidebar-nav { min-height: 0; overflow-y: auto; }
.metric-link { display: inline-flex; gap: 14px; margin-top: 26px; font-size: 12px; }
.metric-link span { color: inherit; }
.metric:nth-child(2) .spark { color: #98b5aa; }
.banner { margin-bottom: 20px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elev); }
.count-strip button:last-child { border-right: 0; }
.count-strip b { display: block; margin-top: 8px; font-size: 24px; }
.quota-head { align-items: center; }
.quota-head span { color: var(--text); font-size: var(--type-title); }
.table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.table-scroll:focus-visible { outline-offset: -2px; }
.table-scroll table { min-width: 480px; }
.table-scroll .barrel-table { min-width: 320px; }
.table-scroll .usage-table { min-width: 1080px; table-layout: fixed; }
.usage-table th:first-child { width: 12%; }
.usage-table th:nth-child(2) { width: 18%; }
.usage-table th:nth-child(3) { width: 16%; }
.usage-table th:nth-child(n+4) { width: 9%; }
thead { background: var(--bg-soft); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #ffffff03; }
.catalog-empty { padding: 40px 16px !important; text-align: center !important; }
td.row-actions { display: table-cell; white-space: nowrap; }
td.row-actions > button + button { margin-left: 6px; }
.usage-table td { white-space: nowrap; }
.usage-table td:is(:nth-child(2), :nth-child(3), :nth-child(9)) {
  white-space: normal;
  overflow-wrap: anywhere;
}
.usage-table .catalog-name { display: block; }
.usage-table td:nth-child(9) .badge { max-width: 100%; margin-left: 0; }
.stack-page > *, .session-group, .split > div, .split-wide > div { min-width: 0; }
.detail-row > button, form.inline > button {
  min-height: 40px; padding: 8px 18px; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); background: var(--bg-elev2); font-weight: 600; white-space: nowrap;
}
.detail-row > button:hover, form.inline > button:hover { background: var(--bg-hover); }
.detail-row > button[data-sign="add"], .detail-row > button[type="submit"] {
  background: var(--accent); color: #1b2414; border-color: transparent;
}
.detail-row > button[data-sign="sub"] { color: #efa0a0; }
.detail-row > label { flex: 1; min-width: 140px; color: var(--text-dim); font-weight: 400; }
.detail-row > label :is(input, select) { width: 100%; min-width: 0; }
.detail-row:has(> label) { align-items: end; }
button:disabled { cursor: not-allowed; opacity: .5; }
.badge { padding: 3px 8px; }
.badge.on { background: #6cab8d12; }
.model-card { padding: 22px 24px; }
.model-card.current { border-color: #73805c; }
.drop-zone { min-height: 160px; border-color: var(--border-strong); background: var(--bg-soft); }
.drop-zone input { display: block; width: 100%; height: auto; padding: 8px; font-size: 12px; border: 0; }
.drop-zone input::file-selector-button { margin-right: 12px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-elev2); color: var(--text); cursor: pointer; }
select { background-color: var(--bg-soft); color-scheme: dark; }
:is(button, a, input, select, textarea, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.skip-link { position: fixed; top: -80px; left: 16px; z-index: 100; padding: 10px 16px; background: var(--accent); color: #1b2414; border-radius: 6px; }
.skip-link:focus { top: 12px; }
.login-brand { padding: 0; margin-bottom: 32px; }
.login-page-heading h1 { font-size: 26px; }
.login-page-form .primary-btn { border-radius: var(--r-sm); min-height: 44px; justify-content: space-between; }
.login-page-form .token-pool-input { background: var(--bg-soft); border-radius: var(--r-sm); }
.login-page-heading .admin-origin { font-family: var(--font-mono); font-size: 11px; overflow-wrap: anywhere; }

#page-breadcrumb { font-size: 12px; color: var(--text-dim); display: flex; gap: 10px; }
.page-tools { flex: 0 0 auto; display: grid; gap: 8px; justify-items: end; }
#page-state { font-size: 11px; color: var(--text-faint); }
.page-loading, .page-error { min-height: 220px; display: flex; align-items: center; justify-content: center; gap: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); color: var(--text-dim); }
.page-error { flex-direction: column; padding: 24px; overflow-wrap: anywhere; }
.page-error h2, .page-error p { margin: 0; }
.loading-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.section-heading h2, .section-heading h3 { margin: 0; }
.section-heading > a { font-size: 12px; white-space: nowrap; }
.list-hint { margin: 0 0 16px; color: var(--text-dim); font-size: 12px; line-height: 1.7; }
.form-feedback { margin: 12px 0 0; color: var(--accent-text); font-size: 12px; }
.form-feedback:empty { display: none; }
.record-summary { display: flex; flex-wrap: wrap; gap: 20px 32px; margin-bottom: 16px; padding: 18px 22px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elev); color: var(--text-dim); font-size: 12px; }
.record-summary strong { margin-left: 8px; color: var(--text); font-size: 20px; font-variant-numeric: tabular-nums; }
.admin-list-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 16px; }
.admin-list-search { flex: 1; min-width: 180px; max-width: 380px; }
.admin-list-status { width: 138px; }
.admin-list-toolbar label { gap: 6px; color: var(--text-dim); font-weight: 400; font-size: 12px; }
.admin-list-toolbar input { background: var(--bg-soft); }
.admin-list-count { margin-left: auto; padding-bottom: 10px; color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.admin-list-empty { padding: 40px 20px; text-align: center; color: var(--text-dim); border: 1px dashed var(--border); border-radius: 10px; }
.admin-list-pagination { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: end; padding-top: 16px; color: var(--text-dim); font-size: 12px; }
.admin-list-size { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.admin-list-size select { width: auto; height: 34px; }
.admin-list-page { min-width: 80px; text-align: center; }
.resource-workspace { display: grid; gap: 20px; }
.resource-workspace > div, .billing-workspace > .panel { padding: var(--card-pad); border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); min-width: 0; }
.editor-disclosure { min-width: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elev); }
.editor-disclosure > summary { cursor: pointer; padding: 16px 20px; color: var(--accent-text); font-weight: 600; }
.editor-disclosure > summary span { margin-left: 16px; color: var(--text-dim); font-weight: 400; font-size: 12px; }
.editor-disclosure > :not(summary) { margin: 0; padding: 4px 20px 20px; }
.editor-disclosure > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.resource-workspace > .editor-disclosure { order: -1; }
.editor-disclosure form.stack { max-width: 600px; }
.directory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.directory-grid > .session-group { padding: 20px; margin: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-soft); }
.directory-grid > .session-group:hover { border-color: var(--border-strong); }
.directory-grid .page-head { align-items: start; justify-content: space-between; }
.directory-grid .page-head h3 { font-size: 16px !important; overflow-wrap: anywhere; }
.directory-grid .account-preview { margin-top: 12px; line-height: 1.7; }
.directory-grid .tiny { flex-shrink: 0; }
.billing-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.company-list-panel { grid-column: 1; grid-row: 1 / 3; }
.recharge-panel { grid-column: 2; }
.recharge-panel .detail-row > label { flex-basis: 100%; }
.company-create { grid-column: 2; }
.ledger-panel { grid-column: 1 / -1; }
.company-detail-grid { grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr); align-items: start; }
.company-detail-grid > .panel:first-child { grid-column: 1 / -1; }
.company-detail-grid > .ledger-panel { grid-row: 3; }
.company-detail-grid > .invite-panel { grid-column: 2; grid-row: 2; }
.company-metrics { margin: 0; }
.company-metrics .metric b { font-size: 30px; }
.model-form-group { min-width: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 20px 24px 24px; margin: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elev); }
.model-form-group legend { padding: 0 8px; font-weight: 600; }
.model-form-group .full-width { grid-column: 1 / -1; }
.model-visibility { grid-template-columns: 1fr; }
.sticky-actions { position: sticky; bottom: -1px; z-index: 2; padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elev); box-shadow: 0 -8px 24px #0002; }
.sticky-actions #model-save { margin-left: auto; }
.sticky-actions #model-msg { flex-basis: 100%; margin: 4px 0 0; overflow-wrap: anywhere; }
.kind-section:has(.model-card):not(:has(.model-card:not([hidden]))) { display: none; }
.model-card .row-actions { border-top: 1px solid var(--border-soft); padding-top: 14px; }
.model-card .row-actions .danger { margin-left: auto; }
button.tiny.danger { background: transparent; color: #efa0a0; border-color: #744848; }
button.tiny.danger:hover { background: #e06c6c16; }
.thread-view { padding: 24px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-soft); scroll-margin-top: 20px; }
.thread-view .thread-head { flex-wrap: wrap; }
.thread-head h3 { flex: 1; }
.thread-log { max-width: 920px; margin: 24px auto 0; }
.thread-md { line-height: 1.85; overflow-wrap: anywhere; }
.thread-msg { min-width: 0; padding: 20px 24px; }
.thread-msg.user { border-left: 3px solid var(--accent); }
.thread-msg header { font-size: 12px; }
tr.is-selected td { background: #c3cf9c0c; }
.table-scroll .row-actions { white-space: nowrap; }
.table-scroll th { white-space: nowrap; }
.table-scroll td { line-height: 1.6; }
@media (min-height: 820px) {
  .login-page-layer { align-items: center; }
}
@media (max-width: 1100px) {
  .board-grid { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: 1fr 1fr; }
  .metric { padding: 20px 18px 12px; }
  .billing-workspace { grid-template-columns: 1fr; }
  .billing-workspace > * { grid-column: auto; grid-row: auto; }
  .recharge-panel .detail-row > label { flex-basis: auto; }
}
@media (max-width: 900px) {
  .nav-section, .nav-footer { display: none; }
  .sheet-nav.settings-sidebar-nav { padding: 10px 16px; }
  .admin-body { grid-template-rows: auto minmax(0, 1fr); }
  .count-strip button { padding: 18px 14px; }
  .content-heading h1 { font-size: 26px; }
}
@media (max-width: 600px) {
  .admin-content { padding: 24px 16px 36px; }
  .admin-role { display: none; }
  .metric-row { grid-template-columns: 1fr; gap: 12px; }
  .metric { position: relative; padding: 20px; }
  .metric b { font-size: 34px; }
  .spark { position: absolute; right: 20px; top: 32px; width: 28%; height: 48px; }
  .metric-link { margin-top: 16px; }
  .side-stack { grid-template-columns: 1fr; }
  .count-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .count-strip button { border-bottom: 1px solid var(--border-soft); }
  .quota-panel, .stack-page > .panel, .split > div, .split-wide > div { padding: 18px; }
  .page-head { flex-wrap: wrap; }
  .detail-row { gap: 10px; }
  .detail-row input, .detail-row select { min-width: 100%; }
  .detail-row > label { flex-basis: 100%; }
  .login-page-shell { padding: 28px; }
  .content-heading { align-items: start; }
  .page-tools .secondary-btn { padding: 7px 10px; font-size: 12px; }
  .content-heading p { font-size: 12px; }
  #page-state { max-width: 90px; }
  .admin-list-search { max-width: none; min-width: 100%; }
  .admin-list-count { padding-bottom: 10px; }
  .directory-grid, .company-detail-grid, .model-form-group { grid-template-columns: 1fr; }
  .company-detail-grid > * { grid-column: 1 !important; grid-row: auto !important; }
  .model-form-group, .thread-view { padding: 18px; }
  .editor-disclosure > summary span { display: block; margin: 6px 0 0 16px; }
  .table-scroll .company-table { min-width: 580px; }
  .record-summary { gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
