/*
 * Theatropolis web UI — single design system.
 *
 * Minimal warm "old playhouse" palette: parchment surfaces, oak-brown ink,
 * curtain burgundy as the one interactive accent, brass for kickers.
 * Standard system fonts only; nothing is downloaded.
 */

:root {
  color-scheme: light;

  /* Surfaces */
  --paper: #f3eddc;
  --surface: #fdfaf0;
  --surface-sunken: #f7f1e2;

  /* Ink (warm brown scale) */
  --ink-950: #211809;
  --ink-900: #2a2114;
  --ink-700: #4a3f2c;
  --ink-500: #77694e;
  --ink-400: #9a8c6f;
  --ink-300: #d8cdb4;
  --ink-200: #e6ddc7;
  --ink-100: #efe8d6;

  /* Accent (curtain burgundy) */
  --accent-800: #5c1f1f;
  --accent-700: #6e2626;
  --accent-600: #7f2d2d;
  --accent-100: #f4e3dc;

  /* Brass (kickers, small flourishes) */
  --brass-600: #96702a;

  /* Status */
  --green-700: #2e5f45;
  --green-100: #e0ebdd;
  --amber-700: #8a5c17;
  --amber-100: #f4e8cc;
  --red-700: #99372a;
  --red-100: #f6e0d8;
  --neutral-700: #5c5340;
  --neutral-100: #eae3d2;

  --shadow-sm: 0 1px 2px rgb(42 33 20 / 6%);
  --shadow-md: 0 10px 30px rgb(42 33 20 / 10%);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font-body: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --ease: 140ms ease;
}

/* Proxy Node manager */
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}

.resource-card {
  display: grid;
  gap: .5rem;
  color: var(--ink-900);
  text-decoration: none;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-lg);
  padding: 1rem;
  background: var(--surface);
  transition: border-color .15s ease, transform .15s ease;
}

.resource-card:not(.resource-card--static):hover {
  border-color: var(--accent-700);
  transform: translateY(-1px);
}

.resource-card strong { font-size: 1.08rem; }
.resource-card > span:not(.protocol-badge) { color: var(--ink-500); }
.resource-card__eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; }
.resource-card dl { display: flex; gap: 1.5rem; margin: .25rem 0; }
.resource-card dl div { display: grid; }
.resource-card dt { color: var(--ink-500); font-size: .72rem; }
.resource-card dd { margin: 0; font-weight: 700; }
.resource-card__actions { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: .5rem; }

.protocol-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  padding: .2rem .55rem;
  background: var(--accent-100);
  color: var(--accent-700);
  font-size: .72rem;
  font-weight: 700;
}

.proxy-tree-panel {
  overflow: hidden;
}

.proxy-tree__status {
  display: flex;
  padding: 0.85rem 1.25rem;
  align-items: center;
  gap: 0.75rem;
  color: var(--green-700);
  background: var(--green-100);
  border-top: 1px solid var(--green-700);
}

.proxy-tree__status > span:nth-child(2) {
  display: grid;
}

.proxy-tree__status small {
  color: var(--neutral-700);
}

.proxy-tree__status-icon {
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  flex: 0 0 auto;
  place-items: center;
  color: var(--surface);
  background: var(--green-700);
  border-radius: 999px;
  font-weight: 800;
}

.proxy-tree__warning {
  margin-left: auto;
  padding: 0.3rem 0.55rem;
  color: var(--amber-700);
  background: var(--amber-100);
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.proxy-tree__legend {
  display: flex;
  padding: 0.75rem 1.25rem 0;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  color: var(--ink-500);
  font-size: 0.76rem;
}

.proxy-tree__legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.proxy-tree__legend-mark {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 3px;
}

.proxy-tree__legend-mark--hop { background: var(--surface); border: 1px solid var(--ink-400); }
.proxy-tree__legend-mark--link { background: var(--accent-100); border: 1px solid var(--accent-600); }
.proxy-tree__legend-mark--direct { background: var(--green-100); border: 1px solid var(--green-700); }
.proxy-tree__legend-mark--reject { background: var(--red-100); border: 1px solid var(--red-700); }

.proxy-tree {
  padding: 1.25rem;
  overflow-x: auto;
}

.proxy-tree__canvas {
  display: grid;
  min-width: 46rem;
}

.proxy-tree__subtree,
.proxy-tree__branch {
  display: grid;
  gap: 0.7rem;
}

.proxy-tree__hop-card {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.proxy-tree__hop-header {
  display: flex;
  padding: 0.8rem 0.9rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface-sunken);
}

.proxy-tree__hop-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.75rem;
}

.proxy-tree__hop-title > span:last-child,
.proxy-tree__match,
.proxy-tree__target,
.proxy-tree__link-copy {
  display: grid;
  min-width: 0;
  gap: 0.05rem;
}

.proxy-tree__hop-title > span:last-child > strong {
  font-size: 1rem;
}

.proxy-tree__hop-title small,
.proxy-tree__match small,
.proxy-tree__target small,
.proxy-tree__link-copy small {
  overflow-wrap: anywhere;
  color: var(--ink-500);
  font-size: 0.75rem;
}

.proxy-tree__routes {
  display: grid;
}

.proxy-tree__route {
  display: grid;
  grid-template-columns: 4.75rem minmax(9rem, 1fr) auto minmax(11rem, 0.85fr);
  padding: 0.65rem 0.9rem;
  align-items: center;
  gap: 0.75rem;
  border-top: 1px solid var(--ink-200);
}

.proxy-tree__route:last-child {
  background: var(--surface-sunken);
}

.proxy-tree__route-label {
  color: var(--ink-500);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.proxy-tree__arrow {
  color: var(--ink-400);
  font-weight: 800;
}

.proxy-tree__target {
  padding: 0.4rem 0.55rem;
  color: var(--ink-900);
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  text-decoration: none;
}

a.proxy-tree__target:hover {
  border-color: var(--accent-700);
}

.proxy-tree__target--direct {
  background: var(--green-100);
  border-color: var(--green-700);
}

.proxy-tree__target--reject {
  background: var(--red-100);
  border-color: var(--red-700);
}

.proxy-tree__target--link {
  background: var(--accent-100);
  border-color: var(--accent-700);
}

.proxy-tree__hop-summary {
  display: flex;
  padding: 0.45rem 0.9rem;
  justify-content: flex-end;
  gap: 1rem;
  color: var(--ink-500);
  background: var(--surface-sunken);
  border-top: 1px solid var(--ink-200);
  font-size: 0.72rem;
}

.proxy-tree__children {
  position: relative;
  display: grid;
  margin-left: 1.25rem;
  padding-left: 1.75rem;
  gap: 1.4rem;
}

.proxy-tree__children::before {
  position: absolute;
  top: 0;
  bottom: 1.75rem;
  left: 0;
  border-left: 2px solid var(--ink-300);
  content: "";
}

.proxy-tree__branch {
  position: relative;
}

.proxy-tree__branch::before {
  position: absolute;
  top: 1.15rem;
  left: -1.75rem;
  width: 1.75rem;
  border-top: 2px solid var(--ink-300);
  content: "";
}

.proxy-tree__link {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  padding: 0.55rem 0.7rem;
  align-items: center;
  gap: 0.65rem;
  background: var(--accent-100);
  border: 1px solid var(--accent-700);
  border-radius: var(--radius-md);
}

.proxy-tree__link--unused {
  background: var(--amber-100);
  border-color: var(--amber-700);
}

.proxy-tree__link-badge {
  padding: 0.2rem 0.45rem;
  color: var(--surface);
  background: var(--accent-700);
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.proxy-tree__link--unused .proxy-tree__link-badge {
  background: var(--amber-700);
}

.split-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.panel--danger { border-color: var(--red-700); }
.inline-form { display: flex; gap: .75rem; padding: 1.25rem; }
.inline-form input { flex: 1; }

.membership-list { display: grid; }
.membership-list > article,
.membership-list > a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1.25rem;
  border-top: 1px solid var(--ink-200);
  color: var(--ink-900);
  text-decoration: none;
}
.membership-list > :first-child { border-top: 0; }
.membership-list span { display: grid; gap: .2rem; }
.membership-list small { color: var(--ink-500); }

.rule-stack { display: grid; }
.rule-row {
  display: grid;
  grid-template-columns: 2rem minmax(12rem, 1fr) minmax(8rem, auto) auto;
  align-items: center;
  gap: 1rem;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--ink-200);
}
.rule-row:first-child { border-top: 0; }
.rule-row > span:nth-child(2) { display: grid; gap: .2rem; }
.rule-row small { color: var(--ink-500); }
.rule-row__position { display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 999px; background: var(--surface-sunken); font-weight: 700; }
.rule-row__target { font-weight: 600; }
.rule-row__actions, .rule-row__actions form { display: flex; align-items: center; gap: .35rem; }

.credential-list { display: grid; gap: 1rem; padding: 1.25rem; }
.credential-list article { border: 1px solid var(--ink-200); border-radius: var(--radius-md); overflow: hidden; }
.credential-list article > header { display: flex; justify-content: space-between; padding: .85rem 1rem; background: var(--surface-sunken); }
.credential-list article > header span { display: grid; gap: .2rem; }
.credential-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .75rem; padding: .7rem 1rem; border-top: 1px solid var(--ink-200); }
.credential-row code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deployment-agent-list { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-top: .5rem; }

@media (max-width: 760px) {
  .split-panels { grid-template-columns: 1fr; }
  .rule-row { grid-template-columns: 2rem 1fr; }
  .rule-row__target, .rule-row__actions { grid-column: 2; }
  .credential-row { grid-template-columns: auto 1fr; }
  .credential-row .button { grid-column: 2; }

  .proxy-tree__status {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .proxy-tree__warning {
    width: 100%;
    margin-left: 2.55rem;
    border-radius: var(--radius-sm);
  }

  .proxy-tree,
  .proxy-tree__legend {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }

  .proxy-tree__canvas {
    min-width: 0;
  }

  .proxy-tree__hop-header {
    align-items: flex-start;
  }

  .proxy-tree__route {
    grid-template-columns: 4.25rem minmax(0, 1fr);
    gap: 0.45rem 0.65rem;
  }

  .proxy-tree__arrow {
    display: none;
  }

  .proxy-tree__target {
    grid-column: 2;
  }

  .proxy-tree__hop-summary {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
  }

  .proxy-tree__children {
    margin-left: 0.4rem;
    padding-left: 0.85rem;
  }

  .proxy-tree__branch::before {
    left: -0.85rem;
    width: 0.85rem;
  }

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

  .proxy-tree__link .button-link {
    grid-column: 2;
    justify-self: start;
  }
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must win over component display rules such as
   `.field { display: flex }`, which otherwise override the UA default and
   keep "hidden" fields visible. */
[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink-900);
  background: var(--paper);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--ink-950);
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

p {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
summary {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--accent-700);
  text-decoration-color: rgb(127 45 45 / 35%);
  text-underline-offset: 2px;
  transition: color var(--ease), text-decoration-color var(--ease);
}

a:hover {
  color: var(--accent-800);
  text-decoration-color: currentColor;
}

code,
pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

svg {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.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;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.6rem 1rem;
  color: var(--surface);
  background: var(--ink-950);
  border-radius: var(--radius-sm);
  transform: translateY(-160%);
  transition: transform var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: 2px solid var(--accent-600);
  outline-offset: 2px;
}

.muted {
  color: var(--ink-500);
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--brass-600);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* ---------- Brand ---------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink-950);
  text-decoration: none;
}

.brand__mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: var(--surface);
  background: var(--accent-600);
  border-radius: var(--radius-sm);
}

.brand__mark svg {
  width: 18px;
  height: 18px;
}

.brand strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

/* ---------- Header / navigation ---------- */

.global-header {
  position: sticky;
  z-index: 40;
  top: 0;
  background: rgb(253 250 240 / 92%);
  border-bottom: 1px solid var(--ink-200);
  backdrop-filter: blur(10px);
}

.global-header__inner {
  display: flex;
  width: min(100% - 2rem, 1200px);
  min-height: 60px;
  margin: 0 auto;
  align-items: center;
  gap: 1.5rem;
}

.global-nav {
  display: flex;
  margin-right: auto;
  align-items: center;
  gap: 0.25rem;
}

.global-nav a {
  padding: 0.5rem 0.75rem;
  color: var(--ink-500);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: color var(--ease), background-color var(--ease);
}

.global-nav a:hover {
  color: var(--ink-900);
  background: var(--ink-100);
}

.global-nav a.is-active {
  color: var(--accent-700);
  background: var(--accent-100);
}

/* ---------- Layout ---------- */

.main {
  width: min(100% - 2rem, 1200px);
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.main--narrow {
  width: min(100% - 2rem, 920px);
}

.main--wide {
  width: min(100% - 2rem, 1360px);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  color: var(--ink-400);
  font-size: 0.85rem;
}

.breadcrumbs a {
  color: var(--ink-500);
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--accent-700);
}

.page-header {
  display: flex;
  margin-bottom: 1.75rem;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header--compact {
  margin-bottom: 1.25rem;
}

.page-header h1 {
  font-size: clamp(1.6rem, 3.5vw, 2.1rem);
}

.page-header__description {
  margin-top: 0.35rem;
  color: var(--ink-500);
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-header__actions form {
  display: contents;
}

/* ---------- Buttons ---------- */

.button {
  display: inline-flex;
  min-height: 40px;
  padding: 0.55rem 1rem;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  transition:
    background-color var(--ease),
    border-color var(--ease),
    color var(--ease),
    box-shadow var(--ease);
}

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

.button--primary {
  color: var(--surface);
  background: var(--accent-600);
  border-color: var(--accent-600);
}

.button--primary:hover:not(:disabled) {
  background: var(--accent-700);
  border-color: var(--accent-700);
}

.button--primary:active:not(:disabled) {
  background: var(--accent-800);
  border-color: var(--accent-800);
}

.button--secondary {
  color: var(--ink-700);
  background: var(--surface);
  border-color: var(--ink-300);
}

.button--secondary:hover:not(:disabled) {
  color: var(--ink-900);
  background: var(--surface-sunken);
  border-color: var(--ink-400);
}

.button--danger {
  color: var(--surface);
  background: var(--red-700);
  border-color: var(--red-700);
}

.button--danger:hover:not(:disabled) {
  background: #822b20;
  border-color: #822b20;
}

.button--small {
  min-height: 32px;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

.button--full {
  width: 100%;
}

.button--icon svg {
  width: 1rem;
  height: 1rem;
}

.button--icon-only {
  width: 40px;
  padding: 0;
}

.button--icon-only svg {
  width: 1.15rem;
  height: 1.15rem;
}

.button-link {
  padding: 0;
  color: var(--accent-700);
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: rgb(127 45 45 / 35%);
  text-underline-offset: 2px;
}

.button-link:hover {
  color: var(--accent-800);
  text-decoration-color: currentColor;
}

.button-link--danger {
  color: var(--red-700);
  text-decoration-color: rgb(153 55 42 / 35%);
}

.button-link--danger:hover {
  color: #822b20;
}

/* ---------- Cards and panels ---------- */

.panel,
.metric-card,
.summary-card,
.form-card,
.context-card,
.result-card {
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.panel {
  padding: 1.25rem;
}

.panel__header {
  display: flex;
  margin-bottom: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.panel__header h2 {
  font-size: 1.15rem;
}

.panel__header p {
  margin-top: 0.2rem;
  color: var(--ink-500);
  font-size: 0.88rem;
}

.panel__count,
.resource-summary__count {
  font-variant-numeric: lining-nums tabular-nums;
}

.panel__count {
  padding: 0.2rem 0.6rem;
  color: var(--ink-500);
  background: var(--ink-100);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.panel__empty {
  padding: 1rem;
  color: var(--ink-500);
  background: var(--surface-sunken);
  border: 1px dashed var(--ink-300);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

/* ---------- Metric / summary cards ---------- */

.metric-grid {
  display: grid;
  margin-bottom: 1.5rem;
  gap: 0.75rem;
  grid-template-columns: repeat(4, 1fr);
}

.metric-card {
  display: flex;
  padding: 0.9rem 1rem;
  flex-direction: column;
  gap: 0.15rem;
  border-top: 3px solid var(--ink-300);
}

.metric-card strong {
  color: var(--ink-950);
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-variant-numeric: lining-nums;
  line-height: 1.1;
}

.metric-card__label {
  color: var(--ink-500);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.metric-card__hint {
  color: var(--ink-400);
  font-size: 0.8rem;
}

.metric-card--positive {
  border-top-color: var(--green-700);
}

.metric-card--pending {
  border-top-color: var(--amber-700);
}

.metric-card--attention {
  border-top-color: var(--red-700);
}

.server-summary {
  display: grid;
  margin-bottom: 1.5rem;
  gap: 0.75rem;
  grid-template-columns: repeat(4, 1fr);
}

.summary-card {
  display: flex;
  padding: 0.9rem 1rem;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-start;
}

.summary-card__label {
  color: var(--ink-500);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.summary-card__value {
  color: var(--ink-950);
  font-size: 1.05rem;
}

.summary-card__value--positive {
  color: var(--green-700);
}

.summary-card small {
  color: var(--ink-400);
  font-size: 0.8rem;
}

/* ---------- Status pills ---------- */

.status {
  display: inline-flex;
  padding: 0.22rem 0.6rem;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.status > span[aria-hidden="true"] {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status--pending {
  color: var(--amber-700);
  background: var(--amber-100);
}

.status--online,
.status--enrolled {
  color: var(--green-700);
  background: var(--green-100);
}

.status--offline {
  color: var(--neutral-700);
  background: var(--neutral-100);
}

.status--expired,
.status--failed {
  color: var(--red-700);
  background: var(--red-100);
}

/* ---------- Fleet table ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  padding: 0.6rem 0.9rem;
  color: var(--ink-500);
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--ink-200);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--ink-100);
  vertical-align: middle;
}

tbody tr {
  transition: background-color var(--ease);
}

tbody tr:hover {
  background: var(--surface-sunken);
}

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

.server-link {
  color: var(--ink-900);
  text-decoration: none;
}

.server-link:hover {
  color: var(--accent-700);
  text-decoration: underline;
}

/* ---------- Empty state ---------- */

.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
}

.empty-state h3 {
  margin: 0.35rem 0 0.5rem;
  font-size: 1.25rem;
}

.empty-state p:not(.eyebrow) {
  max-width: 40ch;
  margin: 0 auto 1.25rem;
  color: var(--ink-500);
}

.empty-state .eyebrow {
  margin: 0;
}

/* ---------- Asynchronous sections ---------- */

.async-region {
  min-height: 5rem;
}

.loading-state {
  display: flex;
  min-height: 5rem;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  color: var(--ink-500);
  font-size: 0.88rem;
}

.loading-spinner {
  width: 1rem;
  height: 1rem;
  flex: none;
  border: 2px solid var(--ink-200);
  border-top-color: var(--accent-700);
  border-radius: 50%;
  animation: loading-spin 700ms linear infinite;
}

.loading-spinner--small {
  width: 0.75rem;
  height: 0.75rem;
}

.inline-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.async-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
    border-color: var(--accent-700);
  }
}

/* ---------- Forms ---------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stack--compact {
  gap: 0.65rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field > span,
.field > label,
.field legend {
  color: var(--ink-700);
  font-size: 0.85rem;
  font-weight: 600;
}

.field small {
  color: var(--ink-400);
  font-size: 0.78rem;
}

.field-warning {
  color: var(--red-700) !important;
}

input:not([type]),
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-400);
}

input:hover:not(:disabled):not([readonly]),
select:hover:not(:disabled),
textarea:hover:not(:disabled):not([readonly]) {
  border-color: var(--ink-400);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-600);
  box-shadow: 0 0 0 3px rgb(127 45 45 / 14%);
  outline: none;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--ink-100);
  cursor: not-allowed;
  opacity: 0.7;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--red-700);
}

input[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgb(153 55 42 / 14%);
}

.select-box {
  position: relative;
  display: block;
  width: 100%;
}

.select-box__native {
  position: absolute !important;
  width: 1px !important;
  height: 1px;
  padding: 0 !important;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  border: 0 !important;
  white-space: nowrap;
}

.select-box__trigger {
  display: flex;
  width: 100%;
  min-height: 2.55rem;
  align-items: center;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  cursor: text;
  transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}

.select-box__trigger:hover:not(:disabled) {
  border-color: var(--ink-400);
}

.select-box:focus-within .select-box__trigger,
.select-box.is-open .select-box__trigger {
  border-color: var(--accent-600);
  box-shadow: 0 0 0 3px rgb(127 45 45 / 14%);
  outline: none;
}

.select-box.is-invalid .select-box__trigger {
  border-color: var(--red-700);
}

.select-box.is-invalid:focus-within .select-box__trigger {
  box-shadow: 0 0 0 3px rgb(153 55 42 / 14%);
}

.select-box.is-disabled .select-box__trigger {
  background: var(--ink-100);
  cursor: not-allowed;
  opacity: 0.7;
}

.select-box__input,
.select-box__input:hover:not(:disabled):not([readonly]),
.select-box__input:focus {
  width: 100%;
  min-width: 0;
  min-height: calc(2.55rem - 2px);
  padding: 0.55rem 0.7rem;
  flex: 1;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: inherit;
  box-shadow: none;
  outline: none;
}

.select-box__input:disabled {
  background: transparent;
  cursor: not-allowed;
  opacity: 1;
}

.select-box__chevron,
.route-match-chevron {
  display: inline-flex;
  width: 2.55rem;
  min-height: calc(2.55rem - 2px);
  align-self: stretch;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  color: var(--ink-500);
  background: var(--surface-sunken);
  border-left: 1px solid var(--ink-300);
  border-radius: 0 calc(var(--radius-sm) - 1px) calc(var(--radius-sm) - 1px) 0;
  pointer-events: none;
  transition: color var(--ease), background-color var(--ease), border-color var(--ease);
}

.select-box__chevron svg,
.route-match-chevron svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  transition: transform var(--ease);
}

.select-box.is-open .select-box__chevron {
  color: var(--accent-700);
  background: var(--accent-100);
  border-left-color: var(--accent-600);
}

.select-box.is-open .select-box__chevron svg {
  transform: rotate(180deg);
}

.select-box__menu {
  position: fixed;
  z-index: 100;
  box-sizing: border-box;
  max-width: calc(100dvw - 1rem);
  max-height: min(20rem, calc(100dvh - 1.5rem));
  margin: 0;
  padding: 0.35rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-md);
  box-shadow: 0 14px 36px rgb(42 33 20 / 18%);
  animation: select-menu-enter 110ms ease-out;
}

.select-box__menu::backdrop {
  background: transparent;
}

.select-box__option {
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 2.35rem;
  padding: 0.5rem 2rem 0.5rem 0.65rem;
  position: relative;
  align-items: center;
  color: var(--ink-700);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  overflow-wrap: anywhere;
  white-space: normal;
}

.select-box__option:hover:not(:disabled),
.select-box__option:focus-visible {
  color: var(--ink-950);
  background: var(--ink-100);
  outline: none;
}

.select-box__option[aria-selected="true"] {
  color: var(--accent-800);
  background: var(--accent-100);
  font-weight: 650;
}

.select-box__option[aria-selected="true"]::after {
  content: "";
  width: 0.55rem;
  height: 0.3rem;
  position: absolute;
  right: 0.75rem;
  border-bottom: 2px solid currentColor;
  border-left: 2px solid currentColor;
  transform: rotate(-45deg) translateY(-1px);
}

.select-box__option:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.select-box__empty {
  display: block;
  padding: 0.65rem;
  color: var(--ink-400);
  font-size: 0.82rem;
  text-align: center;
}

@keyframes select-menu-enter {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .select-box__menu {
    animation: none;
  }
}

textarea {
  line-height: 1.5;
  resize: vertical;
}

.field--editor textarea,
textarea[data-outbound-field="json"],
textarea[data-route-field="match_values"] {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.field--editor textarea {
  min-height: 24rem;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.secret-input,
.field-with-action {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
}

.secret-input input,
.field-with-action input {
  flex: 1;
  min-width: 0;
}

.secret-input button {
  flex: none;
  padding: 0 0.7rem;
  color: var(--ink-500);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: color var(--ease), border-color var(--ease), background-color var(--ease);
}

.secret-input button:hover {
  color: var(--ink-900);
  background: var(--surface-sunken);
  border-color: var(--ink-400);
}

.danger-confirm {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  font-size: 0.88rem;
}

.danger-confirm input {
  margin-top: 0.2rem;
  accent-color: var(--red-700);
}

/* ---------- Notices ---------- */

.notice {
  padding: 0.75rem 0.9rem;
  color: var(--ink-700);
  background: var(--ink-100);
  border: 1px solid var(--ink-200);
  border-left: 3px solid var(--ink-400);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.notice--warning {
  color: var(--amber-700);
  background: var(--amber-100);
  border-color: rgb(138 92 23 / 25%);
  border-left-color: var(--amber-700);
}

.notice--success {
  color: var(--green-700);
  background: var(--green-100);
  border-color: rgb(46 95 69 / 25%);
  border-left-color: var(--green-700);
}

.notice--error {
  color: var(--red-700);
  background: var(--red-100);
  border-color: rgb(153 55 42 / 25%);
  border-left-color: var(--red-700);
}

/* ---------- Forms layout / cards ---------- */

.form-layout {
  display: grid;
  align-items: start;
  gap: 1rem;
  grid-template-columns: 1fr 300px;
}

.form-card {
  padding: 1.5rem;
}

.form-card__header {
  display: flex;
  margin-bottom: 1.25rem;
  align-items: center;
  gap: 0.85rem;
}

.form-card__header h2 {
  font-size: 1.2rem;
}

.form-card__header p {
  margin-top: 0.2rem;
  color: var(--ink-500);
  font-size: 0.88rem;
}

.form-card .notice {
  margin-bottom: 1rem;
}

.form-card__actions {
  display: flex;
  margin-top: 1.5rem;
  justify-content: flex-end;
  gap: 0.5rem;
}

.step-number {
  display: grid;
  width: 34px;
  height: 34px;
  flex: none;
  place-items: center;
  color: var(--accent-700);
  background: var(--accent-100);
  border-radius: 50%;
  font-family: var(--font-display);
  font-weight: 700;
}

.context-card {
  padding: 1.25rem;
}

.context-card h2 {
  margin: 0.2rem 0 0.5rem;
  font-size: 1.05rem;
  word-break: break-all;
}

.context-card > p:not(.eyebrow) {
  margin-bottom: 1rem;
  color: var(--ink-500);
  font-size: 0.85rem;
}

.context-card dl {
  display: flex;
  margin: 0;
  flex-direction: column;
  gap: 0.5rem;
}

.context-card dl > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.context-card dt {
  color: var(--ink-500);
  font-size: 0.82rem;
}

.context-card dd {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ---------- Result / enrollment ---------- */

.result-card {
  padding: 2rem;
  text-align: center;
}

.result-card__success {
  display: grid;
  width: 52px;
  height: 52px;
  margin: 0 auto 1rem;
  place-items: center;
  color: var(--green-700);
  background: var(--green-100);
  border-radius: 50%;
}

.result-card__success svg {
  width: 1.6rem;
  height: 1.6rem;
  stroke-width: 2.2;
}

.result-card h1 {
  margin: 0.25rem 0 0.5rem;
  font-size: 1.7rem;
}

.result-card__lead {
  max-width: 46ch;
  margin: 0 auto 1.5rem;
  color: var(--ink-500);
}

.copy-section {
  margin-bottom: 1.25rem;
  text-align: left;
}

.command-card {
  overflow: hidden;
  background: var(--ink-950);
  border-radius: var(--radius-md);
}

.command-card__header {
  display: flex;
  padding: 0.55rem 0.55rem 0.55rem 1rem;
  align-items: center;
  justify-content: space-between;
  color: rgb(253 250 240 / 65%);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.command-card pre {
  margin: 0;
  padding: 0.9rem 1rem 1.1rem;
  overflow-x: auto;
  color: #f3e9d2;
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.copy-button {
  display: inline-flex;
  padding: 0.35rem 0.7rem;
  align-items: center;
  gap: 0.4rem;
  color: #f3e9d2;
  background: rgb(253 250 240 / 10%);
  border: 1px solid rgb(253 250 240 / 22%);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background-color var(--ease), border-color var(--ease);
}

.copy-button:hover {
  background: rgb(253 250 240 / 18%);
  border-color: rgb(253 250 240 / 35%);
}

.copy-button svg {
  width: 0.95rem;
  height: 0.95rem;
}

.copy-status {
  min-height: 1.2rem;
  margin-top: 0.5rem;
  color: var(--green-700);
  font-size: 0.82rem;
}

.next-step {
  display: flex;
  margin: 1.25rem 0;
  padding: 1rem;
  align-items: center;
  gap: 0.85rem;
  background: var(--surface-sunken);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
  text-align: left;
}

.next-step h2 {
  font-size: 1rem;
}

.next-step p {
  margin-top: 0.2rem;
  color: var(--ink-500);
  font-size: 0.85rem;
}

.result-card__actions {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ---------- Modals ---------- */

dialog.modal {
  width: min(100% - 2rem, 720px);
  max-height: min(85vh, 900px);
  padding: 0;
  background: transparent;
  border: 0;
}

dialog.modal::backdrop {
  background: rgb(33 24 9 / 45%);
}

dialog.modal[open] {
  animation: modal-in 160ms ease;
}

dialog.modal[open]::backdrop {
  animation: backdrop-in 160ms ease;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

body:has(dialog[open]) {
  overflow: hidden;
}

.modal__surface {
  display: flex;
  max-height: inherit;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.modal__header {
  display: flex;
  padding: 1.25rem 1.25rem 1rem;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--ink-100);
}

.modal__header h2 {
  font-size: 1.2rem;
}

.modal__header p:not(.eyebrow) {
  margin-top: 0.25rem;
  color: var(--ink-500);
  font-size: 0.88rem;
}

.modal__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 1.25rem;
  overflow-y: auto;
}

.modal__footer {
  display: flex;
  padding: 1rem 1.25rem;
  justify-content: flex-end;
  gap: 0.5rem;
  background: var(--surface-sunken);
  border-top: 1px solid var(--ink-100);
}

.resource-modal {
  width: min(100% - 2rem, 860px);
  height: min(85vh, 900px);
}

.resource-modal .modal__surface {
  height: 100%;
}

/* ---------- Action sections (details/summary) ---------- */

.actions-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.action-section {
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
}

.action-section summary {
  display: flex;
  padding: 0.85rem 1rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  list-style: none;
  border-radius: var(--radius-md);
  transition: background-color var(--ease);
}

.action-section summary::-webkit-details-marker {
  display: none;
}

.action-section summary::after {
  width: 0.5rem;
  height: 0.5rem;
  flex: none;
  border-right: 2px solid var(--ink-400);
  border-bottom: 2px solid var(--ink-400);
  content: "";
  transform: rotate(45deg);
  transition: transform var(--ease);
}

.action-section[open] summary::after {
  transform: rotate(225deg);
}

.action-section summary:hover {
  background: var(--surface-sunken);
}

.action-section summary strong {
  display: block;
  color: var(--ink-900);
  font-size: 0.95rem;
}

.action-section summary small {
  color: var(--ink-400);
  font-size: 0.8rem;
}

.action-section--danger {
  border-color: rgb(153 55 42 / 35%);
}

.action-section--danger summary strong {
  color: var(--red-700);
}

.action-section__body {
  padding: 0 1rem 1rem;
}

.action-section__body > p {
  margin-bottom: 0.75rem;
  color: var(--ink-500);
  font-size: 0.88rem;
}

.action-section__body .stack {
  margin-top: 0.75rem;
}

/* ---------- Detail lists / diagnostics ---------- */

.detail-list {
  display: grid;
  margin: 0 0 1rem;
  gap: 0.55rem;
}

.detail-list > div {
  display: grid;
  align-items: baseline;
  gap: 1rem;
  grid-template-columns: 140px 1fr;
}

.detail-list dt {
  color: var(--ink-500);
  font-size: 0.82rem;
}

.detail-list dd {
  margin: 0;
  min-width: 0;
  font-size: 0.88rem;
}

.detail-list dd code {
  word-break: break-all;
}

.detail-list--compact {
  padding: 0.75rem 0.9rem;
  background: var(--surface-sunken);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-sm);
}

.diagnostic {
  margin-bottom: 1rem;
}

.diagnostic strong {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--red-700);
  font-size: 0.82rem;
}

.diagnostic pre {
  max-height: 16rem;
  margin: 0;
  padding: 0.75rem 0.9rem;
  overflow: auto;
  color: var(--red-700);
  background: var(--red-100);
  border: 1px solid rgb(153 55 42 / 20%);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Configuration editor ---------- */

.configuration-panel {
  padding: 1.25rem;
}

.configuration-form .notice {
  margin-bottom: 1rem;
}

.config-mode-tabs {
  display: flex;
  width: fit-content;
  margin-bottom: 1.25rem;
  padding: 3px;
  gap: 2px;
  background: var(--ink-100);
  border-radius: var(--radius-sm);
}

.config-mode-tab {
  padding: 0.45rem 0.9rem;
  color: var(--ink-500);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: color var(--ease), background-color var(--ease), box-shadow var(--ease);
}

.config-mode-tab:hover {
  color: var(--ink-900);
}

.config-mode-tab.is-active {
  color: var(--ink-900);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.guided-config {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.guided-config__notice {
  margin-bottom: 0.25rem;
}

.builder-section {
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
}

.resource-summary {
  display: flex;
  padding: 0.9rem 1rem;
  align-items: center;
  gap: 1rem;
}

.resource-summary > div {
  margin-right: auto;
}

.resource-summary h3 {
  font-size: 1rem;
}

.resource-summary p {
  margin-top: 0.15rem;
  color: var(--ink-500);
  font-size: 0.82rem;
}

.resource-summary__count {
  padding: 0.2rem 0.6rem;
  color: var(--ink-500);
  background: var(--ink-100);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.configuration-form__actions {
  display: flex;
  margin-top: 1.25rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.configuration-form__actions .muted {
  font-size: 0.82rem;
}

/* ---------- Builder cards ---------- */

.builder-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.builder-list:empty::before {
  display: block;
  padding: 1rem;
  color: var(--ink-400);
  border: 1px dashed var(--ink-300);
  border-radius: var(--radius-sm);
  content: "Nothing configured yet.";
  font-size: 0.85rem;
  text-align: center;
}

.builder-card {
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
  transition: border-color var(--ease), box-shadow var(--ease);
}

.builder-card.is-editing {
  border-color: var(--accent-600);
  box-shadow: 0 0 0 3px rgb(127 45 45 / 10%);
}

.builder-card__header {
  display: flex;
  padding: 0.7rem 0.9rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.builder-card__identity strong {
  display: block;
  font-size: 0.92rem;
}

.builder-card__identity small {
  color: var(--ink-400);
  font-size: 0.78rem;
}

.builder-card__editor {
  padding: 0 0.9rem 0.9rem;
  border-top: 1px solid var(--ink-100);
}

.builder-card__editor > *:first-child {
  margin-top: 0.9rem;
}

.builder-card__actions {
  display: flex;
  margin-top: 0.75rem;
  justify-content: flex-end;
}

.route-rule-card {
  position: relative;
}

.route-rule-card.is-dragging {
  opacity: 0.55;
  border-color: var(--accent-600);
  box-shadow: var(--shadow-md);
}

.route-rule-card__header {
  justify-content: flex-start;
}

.route-rule-card__header .builder-card__identity {
  min-width: 0;
  flex: 1;
}

.route-rule-card__header .builder-card__identity small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-rule-card__actions {
  display: flex;
  gap: 0.35rem;
}

.route-rule-card__actions .button {
  width: 2rem;
  height: 2rem;
}

.route-drag-handle {
  display: inline-flex;
  width: 2rem;
  height: 2rem;
  padding: 0;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  color: var(--ink-400);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: grab;
}

.route-drag-handle:hover,
.route-drag-handle:focus-visible {
  color: var(--accent-700);
  background: var(--accent-100);
  outline: none;
}

.route-drag-handle:active {
  cursor: grabbing;
}

.route-drag-handle svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}

.route-rule-card__editor {
  padding-top: 0.9rem;
}

.route-rule-card__editor > *:first-child {
  margin-top: 0;
}

.route-match-combobox {
  grid-column: span 2;
}

.builder-fields {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, 1fr);
}

.builder-fields--three {
  grid-template-columns: repeat(3, 1fr);
}

.builder-subsection {
  margin: 0.75rem 0 0;
  padding: 0.9rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
}

.builder-subsection legend,
.builder-subsection__header legend {
  padding: 0 0.35rem;
  color: var(--ink-700);
  font-size: 0.85rem;
  font-weight: 600;
}

.builder-subsection > small {
  display: block;
  margin-top: 0.6rem;
  color: var(--ink-400);
  font-size: 0.78rem;
}

.form-help {
  margin: 0 0 0.75rem;
  color: var(--ink-400);
  font-size: 0.82rem;
}

.builder-subsection__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.builder-final-outbound {
  margin-bottom: 0.9rem;
}

.user-list {
  display: flex;
  margin-top: 0.6rem;
  flex-direction: column;
  gap: 0.5rem;
}

.user-row {
  display: grid;
  padding: 0.6rem;
  align-items: end;
  gap: 0.6rem;
  background: var(--surface-sunken);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-sm);
  grid-template-columns: 1fr 1fr minmax(11rem, auto) auto;
}

.user-row__actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.user-row .field {
  gap: 0.25rem;
}

.user-row .field > span {
  font-size: 0.75rem;
}

/* ---------- Geo rule set combobox (routing rules) ---------- */

.geo-combobox {
  position: relative;
}

.route-match-control {
  position: relative;
}

.route-match-trigger {
  display: flex;
  width: 100%;
  min-height: 2.55rem;
  align-items: stretch;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}

.route-match-trigger:hover {
  border-color: var(--ink-400);
}

.route-match-control:focus-within .route-match-trigger,
.route-match-control.is-open .route-match-trigger {
  border-color: var(--accent-600);
  box-shadow: 0 0 0 3px rgb(127 45 45 / 14%);
  outline: none;
}

.route-match-trigger input,
.route-match-trigger input:hover:not(:disabled):not([readonly]),
.route-match-trigger input:focus {
  min-width: 0;
  min-height: calc(2.55rem - 2px);
  padding: 0.55rem 0.7rem;
  flex: 1;
  background: transparent;
  border: 0;
  border-radius: inherit;
  box-shadow: none;
  outline: none;
}

.route-match-control.is-open .route-match-trigger {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.route-match-control.is-open .route-match-chevron {
  color: var(--accent-700);
  background: var(--accent-100);
  border-left-color: var(--accent-600);
  border-bottom-right-radius: 0;
}

.route-match-control.is-open .route-match-chevron svg {
  transform: rotate(180deg);
}

.geo-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.geo-chips:empty {
  display: none;
}

.geo-chip {
  display: inline-flex;
  padding: 0.15rem 0.5rem;
  align-items: center;
  gap: 0.3rem;
  color: var(--accent-800);
  background: var(--accent-100);
  border: 1px solid rgb(127 45 45 / 25%);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  transition: color var(--ease), border-color var(--ease), background-color var(--ease);
}

.geo-chip:hover {
  color: var(--red-700);
  background: var(--red-100);
  border-color: var(--red-700);
}

.geo-options {
  position: fixed;
  z-index: 200;
  box-sizing: border-box;
  max-width: calc(100dvw - 1rem);
  max-height: 14rem;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--accent-600);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: var(--shadow-md);
}

.geo-options::backdrop {
  background: transparent;
}

.geo-option {
  display: block;
  width: 100%;
  padding: 0.45rem 0.7rem;
  color: var(--ink-900);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
  text-align: left;
  transition: background-color var(--ease);
}

.geo-option:hover {
  background: var(--surface-sunken);
}

.geo-option.is-selected {
  color: var(--ink-400);
  background: var(--surface-sunken);
}

.geo-option.is-unavailable {
  color: var(--ink-400);
}

.geo-option.is-unavailable:hover {
  color: var(--ink-900);
}

.geo-option--empty {
  color: var(--ink-400);
  cursor: default;
}

.geo-option--empty:hover {
  background: transparent;
}

/* ---------- Fleet outbound pool ---------- */

.pool-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 0.85rem;
}

.pool-summary-card {
  display: flex;
  min-width: 0;
  padding: 1rem;
  flex-direction: column;
  gap: 0.9rem;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}

.pool-summary-card:hover {
  border-color: var(--accent-500);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.pool-summary-card:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.pool-summary-card__heading {
  display: flex;
  min-width: 0;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.pool-summary-card__heading code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pool-summary-card__facts,
.pool-address-grid,
.field-grid--two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.pool-summary-card__facts > span,
.pool-address-grid > span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.15rem;
}

.pool-summary-card__facts small,
.pool-address-grid small {
  color: var(--ink-400);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pool-summary-card__facts code,
.pool-address-grid code {
  overflow-wrap: anywhere;
}

.pool-summary-card__action {
  color: var(--accent-700);
  font-size: 0.82rem;
  font-weight: 700;
}

.pool-user-list {
  display: flex;
  margin: 0.65rem 0 0.35rem;
  flex-direction: column;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
}

.pool-user {
  display: flex;
  min-width: 0;
  padding: 0.7rem 0.8rem;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.pool-user + .pool-user {
  border-top: 1px solid var(--ink-100);
}

.pool-user code {
  overflow-wrap: anywhere;
  text-align: right;
}

.modal__body section > h3 {
  margin-bottom: 0.55rem;
}

.pool-delete-form {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.pool-delete-form .danger-confirm {
  margin-bottom: 0;
}

.pool-outbound-json {
  display: inline-block;
  max-width: 26rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.pool-address-line {
  display: block;
}

/* Segmented control (pool address family switch in the guided editor) */

.segmented {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
}

.segmented__option {
  min-height: 32px;
  padding: 0.35rem 0.7rem;
  color: var(--ink-700);
  background: var(--surface);
  border: none;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: color var(--ease), background-color var(--ease);
}

.segmented__option + .segmented__option {
  border-left: 1px solid var(--ink-300);
}

.segmented__option:hover:not(:disabled) {
  background: var(--surface-sunken);
}

.segmented__option[aria-pressed="true"] {
  color: var(--surface);
  background: var(--accent-700);
}

.segmented__option:disabled {
  color: var(--ink-400);
  cursor: not-allowed;
}

.pool-probe {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.4rem;
}

/* ---------- Settings / update progress ---------- */

.settings-panel form {
  margin-top: 1rem;
}

.settings-version-list {
  margin-bottom: 0;
}

.settings-version-list + [data-master-version-refresh] {
  margin-top: 0.75rem;
}

.update-progress {
  max-width: 560px;
  margin: 3rem auto 0;
  padding: 2rem;
  text-align: center;
}

.update-progress h1 {
  margin: 0.25rem 0 0.5rem;
  font-size: 1.5rem;
}

.update-progress > p:not(.eyebrow) {
  color: var(--ink-500);
}

.update-progress code {
  display: inline-block;
  margin-top: 1rem;
  color: var(--ink-400);
  font-size: 0.75rem;
}

.update-progress .button {
  margin-top: 1rem;
}

.update-progress__bar {
  height: 6px;
  margin-top: 1.5rem;
  overflow: hidden;
  background: var(--ink-100);
  border-radius: 999px;
}

.update-progress__bar span {
  display: block;
  width: 40%;
  height: 100%;
  background: var(--accent-600);
  border-radius: 999px;
  animation: progress-slide 1.4s ease-in-out infinite;
}

@keyframes progress-slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(350%);
  }
}

/* ---------- Auth page (centered card) ---------- */

.auth-page {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

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

.auth-card {
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.auth-card .brand {
  margin-bottom: 1.5rem;
}

.auth-card__heading {
  margin-bottom: 1.25rem;
}

.auth-card__heading h1 {
  margin: 0.2rem 0 0.4rem;
  font-size: 1.5rem;
}

.auth-card__heading p:not(.eyebrow) {
  color: var(--ink-500);
  font-size: 0.9rem;
}

.auth-card .notice {
  margin-bottom: 1rem;
}

.auth-help {
  margin-top: 1.25rem;
  color: var(--ink-400);
  font-size: 0.8rem;
  text-align: center;
}

.auth-panel__foot {
  margin-top: 1rem;
  color: var(--ink-400);
  font-size: 0.78rem;
  text-align: center;
}

/* ---------- Responsive ---------- */

@media (max-width: 1050px) {
  .metric-grid,
  .server-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .builder-fields--three {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 820px) {
  .form-layout {
    grid-template-columns: 1fr;
  }

  .context-card {
    order: -1;
  }

  .user-row {
    grid-template-columns: 1fr 1fr;
  }

  .user-row__actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

@media (max-width: 650px) {
  .global-header__inner {
    min-height: 54px;
    gap: 0.75rem;
  }

  .brand strong {
    display: none;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .server-summary,
  .builder-fields,
  .builder-fields--three,
  .field-grid--two {
    grid-template-columns: 1fr;
  }

  .route-match-combobox {
    grid-column: auto;
  }

  .pool-user {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.25rem;
  }

  .pool-user code {
    text-align: left;
  }

  /* Fleet table becomes stacked cards */
  .table-wrap {
    border: 0;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  tbody tr {
    margin-bottom: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
  }

  tbody tr:hover {
    background: var(--surface);
  }

  td {
    display: flex;
    padding: 0.55rem 0.9rem;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--ink-100);
  }

  td::before {
    color: var(--ink-500);
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

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

  .result-card,
  .form-card,
  .auth-card {
    padding: 1.25rem;
  }

  .modal__header,
  .modal__body {
    padding: 1rem;
  }
}

@media (max-width: 420px) {
  .page-header__actions {
    width: 100%;
  }

  .page-header__actions .button {
    flex: 1;
  }

  .configuration-form__actions {
    align-items: stretch;
    flex-direction: column;
  }

  .result-card__actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-card__actions {
    flex-direction: column-reverse;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
