:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #111827;
  --muted: #667085;
  --line: #e3e8ef;
  --line-strong: #cbd5e1;
  --brand: #0f172a;
  --accent: #168ac4;
  --accent-strong: #0c6f9f;
  --danger: #b42318;
  --warning: #a15c07;
  --ok: #16703c;
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.07);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }

h1,
h2,
h3,
p { margin-top: 0; }

h1 {
  margin-bottom: 6px;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: 0;
}

small,
.muted { color: var(--muted); }

button,
.button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.button:hover {
  border-color: #94a3b8;
  background: var(--surface-soft);
}

button.primary,
.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover,
.button.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

button.danger,
.button.danger {
  border-color: #efb4ad;
  color: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button.compact {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.fill { width: 100%; }

input,
textarea,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 138, 196, 0.16);
  outline: none;
}

textarea { resize: vertical; }

code {
  border-radius: 5px;
  background: #edf5f9;
  color: #16445a;
  padding: 2px 6px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-word;
}

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 100vh;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
  padding: 28px 18px 18px;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 14px;
  margin-bottom: 34px;
  color: var(--brand);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 13px;
  background: var(--brand);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.brand strong {
  display: block;
  font-size: 22px;
  line-height: 1.1;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: #667085;
  font-size: 17px;
}

.nav {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 10px;
}

.nav-link {
  display: flex;
  min-height: 48px;
  align-items: center;
  border-radius: 8px;
  color: #667085;
  padding: 0 16px;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
}

.nav-link:hover {
  background: #eef3f8;
  color: var(--text);
}

.nav-link.is-active {
  background: #e9f1f7;
  color: var(--text);
}

.signed-in {
  display: grid;
  gap: 7px;
  margin-top: auto;
  border-top: 1px solid var(--line-strong);
  padding-top: 18px;
}

.signed-in span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.signed-in strong {
  color: var(--text);
  overflow-wrap: anywhere;
}

.signed-in small { font-size: 12px; }

.signed-in button {
  width: 100%;
  margin-top: 4px;
}

.main {
  min-width: 0;
  padding: 34px 38px 42px;
}

.page-header,
.page-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-copy {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.page-actions form { margin: 0; }

.summary-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-row > div {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 15px 16px;
  box-shadow: var(--shadow);
}

.summary-row span,
.summary-row small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-row strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  line-height: 1;
}

.status-summary > div {
  min-height: 126px;
}

.status-summary small {
  margin-top: 8px;
  font-weight: 500;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.lower-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.main-panel,
.side-panel,
.panel:not(.main-panel):not(.side-panel) {
  padding: 18px;
}

.panel-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-head.stacked {
  display: block;
}

.panel-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 136px auto;
  gap: 8px;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tr:last-child td { border-bottom: 0; }

td small {
  display: block;
  color: var(--muted);
}

.users-table td:first-child {
  min-width: 180px;
}

.users-table code {
  white-space: nowrap;
}

.policy-cell {
  max-width: 280px;
  overflow-wrap: anywhere;
}

.usage span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9eef5;
}

.bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status.active,
.status.accepted,
.status.relayed {
  background: #e8f5ed;
  color: var(--ok);
}

.status.disabled,
.status.rejected,
.status.rejected_policy {
  background: #fceceb;
  color: var(--danger);
}

.status.rate_limited {
  background: #fff4dd;
  color: var(--warning);
}

.text-link {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.text-link:hover { text-decoration: underline; }

.form-stack {
  display: grid;
  gap: 13px;
}

.form-stack label span,
.policy-test label span {
  display: block;
  margin-bottom: 5px;
  color: #475467;
  font-size: 12px;
  font-weight: 800;
}

.form-stack small {
  display: block;
  margin-top: 5px;
}

.empty-state {
  display: grid;
  gap: 7px;
  align-items: start;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 20px;
}

.empty-state p {
  margin-bottom: 0;
  color: var(--muted);
}

.empty-state .button {
  justify-self: start;
  margin-top: 4px;
}

.compact-empty {
  padding: 14px;
}

.detail-header {
  align-items: center;
}

.title-with-back {
  display: flex;
  min-width: 0;
  gap: 12px;
  align-items: flex-start;
}

.back-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: #667085;
  font-size: 20px;
  line-height: 1;
  text-decoration: none;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: start;
}

.tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  padding: 0 18px;
}

.tabs a {
  display: flex;
  min-height: 52px;
  align-items: center;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  padding: 0 16px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.tabs a:hover,
.tabs a.is-active {
  border-bottom-color: var(--accent);
  color: var(--accent-strong);
}

.settings-form {
  display: grid;
}

.form-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.form-row > label {
  padding-top: 8px;
  color: #475467;
  font-weight: 800;
}

.field-control {
  display: grid;
  gap: 7px;
}

.password-control {
  grid-template-columns: minmax(0, 1fr) auto;
}

.password-control small {
  grid-column: 1 / -1;
}

.rate-control {
  grid-template-columns: minmax(120px, 170px) minmax(150px, 1fr);
  align-items: center;
}

.rate-control .check-inline {
  grid-column: 1 / -1;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #475467;
  font-weight: 650;
  white-space: nowrap;
}

.check-inline input {
  width: auto;
  min-height: 0;
}

.form-actions {
  display: flex;
  gap: 8px;
  padding: 16px 18px;
}

.tab-panel {
  padding: 18px;
}

.policy-test {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.side-stack {
  display: grid;
  gap: 18px;
}

.definition-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.definition-list.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.definition-list div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.warning-note {
  margin: 14px 0 0;
  border-left: 3px solid var(--warning);
  border-radius: 6px;
  background: #fff7ed;
  color: #7c2d12;
  padding: 10px 12px;
  font-size: 13px;
}

.usage-large strong {
  display: block;
  font-size: 34px;
  line-height: 1;
}

.usage-large span {
  display: block;
  margin: 4px 0 12px;
  color: var(--muted);
}

.secret-banner {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  border: 1px solid #a7d7cc;
  border-radius: 8px;
  background: #ecfdf7;
  padding: 16px 18px;
}

.secret-banner span,
.secret-banner small {
  display: block;
  color: var(--muted);
}

.secret-banner strong {
  display: block;
  margin: 4px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  word-break: break-all;
}

.decision {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 13px 14px;
}

.decision span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.decision strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.decision p {
  margin-bottom: 0;
}

.decision.accepted,
.decision.relayed { border-left-color: var(--ok); }

.decision.rejected,
.decision.rejected_policy { border-left-color: var(--danger); }

.decision.rate_limited { border-left-color: var(--warning); }

.activity-list,
.audit-list {
  display: grid;
  gap: 0;
}

.separated {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.activity-row {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.activity-row .status {
  align-self: start;
  justify-self: start;
}

.activity-row:first-child { padding-top: 0; }
.activity-row:last-child { border-bottom: 0; padding-bottom: 0; }

.activity-row p {
  margin-bottom: 4px;
}

.audit-row {
  display: grid;
  grid-template-columns: 138px 190px minmax(160px, 220px) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.audit-row.simple {
  grid-template-columns: 138px 170px minmax(0, 1fr);
}

.audit-row:last-child {
  border-bottom: 0;
}

.audit-row span,
.audit-row p {
  color: var(--muted);
}

.audit-row p {
  margin-bottom: 0;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.details-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 13px 14px;
}

.details-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.details-grid strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

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

.auth-shell {
  width: min(100%, 480px);
  padding: 24px;
}

.auth-panel {
  display: grid;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 26px;
}

.auth-copy {
  margin-bottom: 0;
  color: var(--muted);
}

.auth-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
}

.mode-pill.is-on {
  border-color: #a7d7cc;
  background: #ecfdf7;
  color: var(--accent-strong);
}

.form-alert {
  border: 1px solid #f0b8b2;
  border-radius: 6px;
  background: #fceceb;
  color: var(--danger);
  padding: 10px 12px;
}

.oidc-block {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.oidc-block p {
  margin-bottom: 0;
  color: var(--muted);
}

.auth-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.auth-meta div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

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

  .main-panel .panel-head {
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
    grid-template-columns: minmax(260px, 1fr) 150px auto;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    padding: 14px 18px;
  }

  .brand {
    margin-bottom: 14px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    font-size: 16px;
  }

  .brand strong {
    font-size: 20px;
  }

  .brand small {
    font-size: 14px;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-link {
    min-height: 40px;
    white-space: nowrap;
  }

  .signed-in {
    display: none;
  }

  .main {
    padding: 24px 20px 34px;
  }

  .detail-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .page-header,
  .page-head,
  .secret-banner,
  .panel-head,
  .detail-header {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-row,
  .lower-grid,
  .toolbar,
  .policy-test,
  .form-row,
  .rate-control,
  .password-control,
  .definition-list.two-column,
  .details-grid,
  .auth-meta,
  .activity-row,
  .audit-row,
  .audit-row.simple {
    grid-template-columns: 1fr;
  }

  .page-actions,
  .page-actions form,
  .page-actions button,
  .page-actions .button {
    width: 100%;
  }

  .main {
    padding: 18px 14px 28px;
  }

  .main-panel,
  .side-panel,
  .panel:not(.main-panel):not(.side-panel) {
    padding: 14px;
  }

  .tabs {
    padding: 0 12px;
  }

  .tabs a {
    min-height: 46px;
    padding: 0 12px;
  }

  .form-row {
    gap: 8px;
    padding: 14px;
  }

  .form-row > label {
    padding-top: 0;
  }

  h1 {
    font-size: 24px;
  }
}
