:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #5f6f65;
  --line: #d7dfda;
  --line-strong: #bcc8c0;
  --paper: #f5f7f5;
  --card: #ffffff;
  --accent: #17633f;
  --accent-hover: #0f5032;
  --accent-soft: #e4f2e9;
  --danger: #a22d2a;
  --danger-soft: #fff0ef;
  --warning: #875908;
  --warning-soft: #fff4d9;
  --info: #285f8f;
  --info-soft: #eaf3fb;
  --shadow: 0 8px 28px rgba(27, 47, 35, .06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, select, dialog { font: inherit; }
button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 15px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}
button:hover { background: var(--accent-hover); }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(23, 99, 63, .26);
  outline-offset: 2px;
}
button:disabled { cursor: progress; opacity: .62; }
button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}
button.secondary:hover, .ghost-button:hover { background: #eef2ef; }
.ghost-button, .icon-button {
  background: transparent;
  color: var(--muted);
}
.icon-button {
  min-width: 40px;
  padding: 4px 10px;
  font-size: 1.6rem;
  line-height: 1;
}
.danger-button {
  border-color: #e8b6b3;
  background: #fff;
  color: var(--danger);
}
.danger-button:hover { background: var(--danger-soft); }
.app-shell { width: min(1500px, 100%); margin: 0 auto; padding: 24px 32px 48px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: 1.28rem; letter-spacing: -.02em; }
h2 { margin-bottom: 7px; font-size: clamp(1.65rem, 3vw, 2.15rem); letter-spacing: -.035em; }
h3 { margin: 0 0 8px; font-size: 1.08rem; letter-spacing: -.015em; }
small { line-height: 1.4; }
.eyebrow {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: .68rem;
  font-weight: 850;
  letter-spacing: .14em;
}
.muted { margin-bottom: 0; color: var(--muted); line-height: 1.55; }
.error, .form-error { color: var(--danger); }
.error { min-height: 1.4em; }
.form-error { min-height: 1.25em; margin: 8px 0 0; font-size: .86rem; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.login-shell { min-height: calc(100vh - 48px); display: grid; place-items: center; }
.login-card { width: min(420px, 100%); padding: 36px; }
.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 22px;
}
label {
  display: grid;
  gap: 7px;
  margin: 15px 0;
  color: #3d4c43;
  font-size: .86rem;
  font-weight: 700;
}
label small { color: var(--muted); font-weight: 500; }
label.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
label.checkbox-row input { width: auto; min-height: auto; }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
}
fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 18px 0;
  padding: 10px 14px;
}
legend { padding: 0 6px; color: #3d4c43; font-size: .86rem; font-weight: 700; }
fieldset label { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
fieldset input { width: auto; min-height: auto; }
.topbar, .section-title, .page-heading, .header-actions, .product-name, .dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar {
  min-height: 66px;
  border-bottom: 1px solid var(--line);
}
.product-name { justify-content: flex-start; }
.product-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 850;
}
.header-actions { justify-content: flex-end; }
.pill, .status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .76rem;
  font-weight: 800;
  white-space: nowrap;
}
.status::before {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}
.status.frozen, .status.offline, .status.expired, .status.over_quota, .status.failed, .status.error {
  background: var(--danger-soft);
  color: var(--danger);
}
.status.maintenance, .status.pending, .status.awaiting_contact {
  background: var(--warning-soft);
  color: var(--warning);
}
.status.draft, .status.hidden, .status.not_configured, .status.configured {
  background: #edf0ee;
  color: #526058;
}
.tabs {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  gap: 3px;
  margin: 0 0 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 245, .96);
  backdrop-filter: blur(10px);
}
.tabs button {
  min-height: 46px;
  border-radius: 0;
  padding-inline: 17px;
  background: transparent;
  color: var(--muted);
}
.tabs button:hover { background: #e9eeeb; color: var(--ink); }
.tabs button.active {
  box-shadow: inset 0 -3px var(--accent);
  color: var(--accent);
}
.view { display: grid; gap: 20px; }
.page-heading { align-items: flex-end; margin-bottom: 2px; }
.page-heading > div { max-width: 760px; }
.section-title { align-items: flex-start; }
.section-title > div { max-width: 850px; }
.notice {
  position: sticky;
  z-index: 15;
  top: 54px;
  margin-bottom: 18px;
  border: 1px solid #b7dac5;
  border-radius: 8px;
  padding: 12px 15px;
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 5px 20px rgba(27, 47, 35, .08);
}
.notice.error { border-color: #e8b6b3; background: var(--danger-soft); color: var(--danger); }
.metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.metric {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  background: var(--card);
}
.metric strong { display: block; margin-top: 15px; font-size: 1.9rem; letter-spacing: -.04em; }
.metric span { color: var(--muted); font-size: .82rem; font-weight: 650; }
.overview-grid { display: grid; grid-template-columns: minmax(320px, .72fr) minmax(600px, 1.28fr); gap: 20px; align-items: stretch; }
.definition-grid { display: grid; grid-template-columns: max-content 1fr; gap: 12px 20px; margin: 0; }
.definition-grid dt { color: var(--muted); }
.definition-grid dd { margin: 0; overflow-wrap: anywhere; font-weight: 620; }
.model-card { overflow: hidden; }
.model-lanes { display: grid; gap: 13px; margin-top: 18px; }
.model-lane {
  display: grid;
  grid-template-columns: 70px minmax(130px, 1fr) 24px minmax(120px, 1fr) 24px minmax(130px, 1fr);
  gap: 8px;
  align-items: center;
}
.lane-label { color: var(--muted); font-size: .76rem; font-weight: 800; }
.entity-chip {
  display: grid;
  gap: 3px;
  min-height: 64px;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f9fbf9;
}
.entity-chip small { color: var(--muted); }
.arrow, .plus { color: var(--line-strong); text-align: center; font-size: 1.15rem; font-weight: 800; }
.relationship-callout {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 12px;
  margin-left: 78px;
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  background: var(--accent-soft);
  font-size: .86rem;
}
.relationship-callout span { color: #3f5749; }
.table-card { padding: 0; overflow: hidden; }
.table-card > .section-title { padding: 20px 22px 15px; }
.table-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  background: #fbfcfb;
}
.search-field { width: min(420px, 100%); margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th {
  background: #f8faf8;
  color: var(--muted);
  font-size: .72rem;
  letter-spacing: .04em;
  white-space: nowrap;
}
tbody tr:hover { background: #f6faf7; }
tr:last-child td { border-bottom: 0; }
td small { color: var(--muted); }
.link-button {
  min-height: 34px;
  background: transparent;
  color: var(--accent);
  padding: 5px 8px;
}
.link-button:hover { background: var(--accent-soft); }
.empty-cell { padding: 32px 16px; text-align: center; color: var(--muted); }
.setup-guide {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 24px;
  align-items: center;
  border: 1px solid #bfd2c6;
  border-radius: 12px;
  padding: 20px 22px;
  background: #edf6f0;
}
.setup-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}
.setup-steps li {
  position: relative;
  display: grid;
  grid-template-columns: 30px 1fr;
  column-gap: 9px;
  align-items: center;
  padding-right: 22px;
}
.setup-steps li:not(:last-child)::after {
  position: absolute;
  right: 7px;
  color: #88a394;
  content: "→";
}
.setup-steps li > span {
  display: grid;
  grid-row: 1 / 3;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .78rem;
  font-weight: 800;
}
.setup-steps strong { font-size: .84rem; }
.setup-steps small { color: var(--muted); }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.checkbox-label { display: flex; align-items: center; align-self: end; gap: 8px; min-height: 42px; }
.checkbox-label input { width: auto; min-height: auto; }
.user-detail { padding: 0; overflow: hidden; }
.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 20px 22px;
}
.detail-heading h2 { font-size: 1.45rem; }
.detail-kicker { margin-bottom: 7px; color: var(--muted); font-size: .78rem; }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}
.summary-item { min-height: 86px; padding: 16px 20px; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-item span { display: block; margin-bottom: 8px; color: var(--muted); font-size: .76rem; }
.summary-item strong { font-size: .96rem; overflow-wrap: anywhere; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.detail-section { padding: 22px; border-bottom: 1px solid var(--line); }
.detail-section:nth-child(odd) { border-right: 1px solid var(--line); }
.detail-section.full-width { grid-column: 1 / -1; border-right: 0; }
.section-copy { margin-bottom: 16px; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.membership-editor {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: end;
}
.membership-editor label { margin: 0; }
.membership-editor small { grid-column: 1 / -1; color: var(--muted); }
.membership-profile-editor { grid-template-columns: minmax(180px, 1fr) auto auto; }
.account-action-reason { margin: 15px 0 10px; }
.quota-progress {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--paper);
  font-size: .84rem;
}
.quota-progress span { color: var(--muted); }
.routing-profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.routing-section-title { margin-top: 8px; }
.routing-rule-set-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.routing-profile-card { padding: 20px; }
.routing-profile-card > header, .routing-rule-set-card > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.routing-rule-set-card { padding: 20px; }
.rule-set-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}
.rule-set-summary span {
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--paper);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
}
.routing-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.routing-meta div { padding: 10px 12px; }
.routing-meta div + div { border-left: 1px solid var(--line); }
.routing-meta dt { color: var(--muted); font-size: .72rem; }
.routing-meta dd { margin: 4px 0 0; font-weight: 750; }
.routing-rule-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.routing-rule-list li {
  display: grid;
  grid-template-columns: 28px 84px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 35px;
  border-bottom: 1px solid var(--line);
  font-size: .78rem;
}
.routing-rule-list li > span { color: var(--muted); }
.routing-rule-set-card .routing-rule-list li {
  grid-template-columns: 28px 84px minmax(0, 1fr) auto auto;
}
.routing-rule-list .empty-rule-set {
  display: block;
  padding: 12px 0;
  color: var(--muted);
}
.routing-rule-list code, .user-route-rule code {
  overflow-wrap: anywhere;
  font-size: .74rem;
}
.route-action {
  border-radius: 999px;
  padding: 3px 7px;
  font-size: .7rem;
  font-style: normal;
  font-weight: 800;
}
.route-action.direct { color: #17633e; background: #e5f3ea; }
.route-action.proxy { color: #315d8a; background: #e8f1f9; }
.route-action.block { color: #9f332e; background: #f9e8e6; }
.user-route-rules {
  display: grid;
  gap: 6px;
  margin: 16px 0 10px;
}
.user-route-rule {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: .78rem;
}
.route-rule-editor {
  display: grid;
  grid-template-columns: 105px minmax(0, 1fr) 82px auto;
  gap: 7px;
  align-items: end;
}
.rule-set-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: .78rem;
}
.route-set-rule-form { margin-top: 14px; }
.routing-set-picker { margin: 16px 0 10px; }
.routing-set-picker label {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding: 7px 0;
}
.routing-set-picker label:last-child { border-bottom: 0; }
.routing-set-picker label span { display: grid; gap: 2px; }
.routing-set-picker label small { color: var(--muted); font-weight: 500; }
.routing-set-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.routing-set-actions small { color: var(--muted); }
.user-actions, .grant-editor, .stack-actions, .dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.user-actions { margin-top: 14px; }
.grant-editor { align-items: end; margin-top: 14px; }
.grant-editor select { min-width: 230px; }
.subscription-list { display: grid; gap: 8px; }
.subscription-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.subscription-row code {
  overflow: hidden;
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--paper);
  font-size: .76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grant-list { display: grid; gap: 8px; }
.grant-item {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(280px, 1.4fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}
.grant-item p { margin: 3px 0 0; color: var(--muted); font-size: .82rem; }
.danger-zone {
  border: 1px solid #e5b7b4;
  border-radius: 8px;
  padding: 16px;
  background: #fffafa;
}
.danger-zone h3 { color: var(--danger); }
.danger-actions { display: grid; grid-template-columns: 1fr 1.2fr; gap: 14px; margin-top: 15px; }
.danger-action { border-top: 1px solid #efd4d2; padding-top: 13px; }
.danger-action:first-child { border-top: 0; padding-top: 0; }
.danger-action p { margin-bottom: 10px; color: var(--muted); font-size: .82rem; line-height: 1.5; }
.danger-action label { margin: 0 0 9px; }
.backup-card { max-width: 900px; }
.backup-status { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.editor-dialog {
  width: min(620px, calc(100% - 28px));
  max-height: calc(100vh - 40px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 24px 90px rgba(18, 35, 25, .24);
}
.wide-dialog { width: min(760px, calc(100% - 28px)); }
.editor-dialog::backdrop { background: rgba(18, 30, 23, .54); }
.dialog-form { padding: 24px; }
.dialog-heading { align-items: flex-start; }
.dialog-actions {
  position: sticky;
  bottom: 0;
  justify-content: flex-end;
  margin: 20px -24px -24px;
  border-top: 1px solid var(--line);
  padding: 14px 24px;
  background: rgba(255, 255, 255, .97);
}
.token-dialog { padding: 24px; }
.token-dialog .dialog-actions { margin-bottom: -24px; }
.token-value {
  display: block;
  margin: 18px 0;
  border-radius: 7px;
  padding: 14px;
  background: var(--paper);
  overflow-wrap: anywhere;
  user-select: all;
}

@media (max-width: 1000px) {
  .overview-grid { grid-template-columns: 1fr; }
  .setup-guide { grid-template-columns: 1fr; }
  .setup-steps { grid-template-columns: 1fr 1fr; gap: 16px; }
  .setup-steps li:nth-child(2)::after { content: ""; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-item:nth-child(2) { border-right: 0; }
  .summary-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-section:nth-child(odd) { border-right: 0; }
  .routing-profile-grid { grid-template-columns: 1fr; }
  .routing-rule-set-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { padding: 16px; }
  .topbar { align-items: flex-start; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .tabs { overflow-x: auto; }
  .tabs button { flex: 0 0 auto; padding-inline: 13px; }
  .page-heading, .section-title { align-items: flex-start; flex-direction: column; }
  .page-heading > button, .section-title > button { width: 100%; }
  .model-lane { grid-template-columns: 1fr; }
  .lane-label { margin-top: 5px; }
  .arrow, .plus { transform: rotate(90deg); }
  .relationship-callout { grid-template-columns: 1fr; margin-left: 0; }
  .setup-steps { grid-template-columns: 1fr; }
  .setup-steps li::after { content: "" !important; }
  .inline-fields, .danger-actions { grid-template-columns: 1fr; gap: 0; }
  .membership-editor { grid-template-columns: 1fr; }
  .membership-editor small { grid-column: auto; }
  .subscription-row, .grant-item { grid-template-columns: 1fr; }
  .route-rule-editor, .user-route-rule { grid-template-columns: 1fr; }
  .routing-rule-set-card .routing-rule-list li { grid-template-columns: 28px 1fr; }
  .routing-rule-set-card .routing-rule-list li code { grid-column: 2; }
  .routing-rule-set-card .routing-rule-list li em,
  .routing-rule-set-card .routing-rule-list li button { justify-self: start; }
  .routing-set-actions { align-items: stretch; flex-direction: column; }
  .subscription-row code { white-space: normal; overflow-wrap: anywhere; }
  .grant-editor { align-items: stretch; flex-direction: column; }
  .grant-editor select { min-width: 0; }
}

@media (max-width: 480px) {
  .metrics, .summary-grid { grid-template-columns: 1fr; }
  .summary-item { border-right: 0; border-bottom: 1px solid var(--line); }
  .summary-item:last-child { border-bottom: 0; }
  .header-actions { align-items: flex-end; flex-direction: column; gap: 4px; }
  .table-toolbar { align-items: stretch; flex-direction: column; }
  .table-toolbar button { width: 100%; }
}
