/* ==========================================================================
   @agentu/ui  base.css
   Fonts, reset, type, focus, and the component set. Requires tokens.css
   first. Class names are BEM-ish and prefixed `ag-`:
     block          .ag-btn
     element        .ag-btn__spinner
     modifier       .ag-btn--primary
     state          .is-on / .is-loading / .is-invalid (or ARIA attributes)
   Light and dark both work from the same rules; only tokens change.
   ========================================================================== */

/* ---- fonts (self-hosted, see fonts/LICENSE-*.txt) ----------------------- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/inter-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/space-grotesk-latin-500-normal.woff2") format("woff2");
}
/* The website repo ships Space Grotesk 500 and 700 only; headings ask for 600
   and resolve to the 700 cut. font-synthesis is off so nothing is faux-bold. */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url("fonts/space-grotesk-latin-700-normal.woff2") format("woff2");
}
/* Metric-matched fallbacks: Arial (or Helvetica) scaled to the web fonts' advance widths and vertical metrics,
   computed from the woff2 files on 7 October 2026 (Inter 1984/-494 on 2048, Space Grotesk 984/-292 on 1000,
   lowercase advance 0.527 and 0.545 em against Arial's 0.482). Text set in the fallback occupies the same
   space as the web font, so the swap moves nothing (no layout shift while the fonts load). */
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Helvetica"), local("Liberation Sans");
  size-adjust: 109.4%;
  ascent-override: 88.5%;
  descent-override: 22.1%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Space Grotesk Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Helvetica"), local("Liberation Sans");
  size-adjust: 113.2%;
  ascent-override: 86.9%;
  descent-override: 25.8%;
  line-gap-override: 0%;
}

/* ---- reset -------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
ul,
ol,
dl,
dd,
pre {
  margin: 0;
}
ul,
ol {
  padding: 0;
  list-style: none;
}
img,
svg,
video {
  display: block;
  max-width: 100%;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}
button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: inherit;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
hr {
  border: 0;
}
[hidden] {
  display: none !important;
}

/* ---- type --------------------------------------------------------------- */
h1,
h2,
h3,
.ag-h1,
.ag-h2,
.ag-h3 {
  font-family: var(--display);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  letter-spacing: -0.01em;
  color: var(--text);
}
h1,
.ag-h1 {
  font-size: var(--fs-display);
}
h2,
.ag-h2 {
  font-size: var(--fs-xl);
}
h3,
.ag-h3 {
  font-size: var(--fs-lg);
  line-height: 1.3;
}
.ag-label,
label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.ag-muted {
  color: var(--text-muted);
}
.ag-small {
  font-size: var(--fs-sm);
}
.ag-mono {
  font-family: var(--mono);
  font-size: var(--fs-sm);
}
.ag-strong {
  font-weight: var(--fw-medium);
}
a,
.ag-link {
  color: var(--accent-text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}
a:hover,
.ag-link:hover {
  text-decoration: underline;
  text-decoration-color: currentColor;
}
/* an element focused by script after a screen change (tabindex="-1") shows no ring */
[tabindex="-1"]:focus {
  outline: none;
  box-shadow: none;
}
/* A link inside running text is underlined, so colour is never its only cue (WCAG 1.4.1). Buttons styled as
   links (.ag-btn) and navigation items keep their own look. */
p a:not(.ag-btn),
p .ag-link:not(.ag-btn),
li a:not(.ag-btn),
li .ag-link:not(.ag-btn),
td a:not(.ag-btn),
td .ag-link:not(.ag-btn),
.ag-small a:not(.ag-btn),
.ag-small .ag-link:not(.ag-btn),
.ag-muted a:not(.ag-btn),
.ag-muted .ag-link:not(.ag-btn),
.ag-empty__line a:not(.ag-btn),
.ag-crumb a:not(.ag-btn) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

/* ---- selection, scrollbars, focus ---------------------------------------- */
::selection {
  background: var(--accent);
  color: var(--accent-ink);
}
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: var(--radius-pill);
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-muted);
}
:focus {
  outline: none;
}
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  box-shadow: var(--focus-halo);
}

/* ---- icons ---------------------------------------------------------------- */
.ag-icon {
  display: inline-block;
  vertical-align: -0.2em;
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ag-icon--s {
  width: 15px;
  height: 15px;
}
.ag-icon--l {
  width: 24px;
  height: 24px;
}

/* ---- buttons ------------------------------------------------------------ */
.ag-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 36px;
  padding: var(--s2) var(--s4);
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font-weight: var(--fw-medium);
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  text-decoration: none;
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    opacity var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
.ag-btn:hover {
  text-decoration: none;
}
.ag-btn:active {
  transform: translateY(1px);
}
.ag-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.ag-btn--primary:hover {
  filter: brightness(0.95);
}
.ag-btn--secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.ag-btn--secondary:hover {
  background: var(--surface-2);
}
.ag-btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text);
}
.ag-btn--ghost:hover {
  background: var(--surface-2);
}
.ag-btn--danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}
.ag-btn--danger:hover {
  filter: brightness(0.96);
}
.ag-btn--sm {
  min-height: 28px;
  padding: var(--s1) var(--s3);
  font-size: var(--fs-sm);
}
.ag-btn--lg {
  min-height: 44px;
  padding: var(--s3) var(--s5);
  font-size: var(--fs-lg);
}
.ag-btn--block {
  width: 100%;
  white-space: normal;   /* a full-width label wraps on a narrow phone instead of widening the page */
}
.ag-btn--icon {
  width: 36px;
  min-width: 36px;
  padding: 0;
  color: var(--text-muted);
  border-color: var(--border);
}
.ag-btn--icon:hover {
  color: var(--text);
  background: var(--surface-2);
}
.ag-btn--icon.ag-btn--sm {
  width: 28px;
  min-width: 28px;
}
.ag-btn[disabled],
.ag-btn.is-disabled,
.ag-btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
/* loading: keep the width, hide the label, show a spinner; set aria-busy */
.ag-btn[aria-busy="true"],
.ag-btn.is-loading {
  color: transparent !important;
  pointer-events: none;
}
.ag-btn[aria-busy="true"]::after,
.ag-btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: ag-spin 0.8s linear infinite;
}
.ag-btn--primary[aria-busy="true"]::after,
.ag-btn--primary.is-loading::after {
  border-color: var(--accent-ink);
  border-right-color: transparent;
}
.ag-btn--secondary[aria-busy="true"]::after,
.ag-btn--ghost[aria-busy="true"]::after,
.ag-btn--secondary.is-loading::after,
.ag-btn--ghost.is-loading::after {
  border-color: var(--text);
  border-right-color: transparent;
}
.ag-btn--danger[aria-busy="true"]::after,
.ag-btn--danger.is-loading::after {
  border-color: var(--danger);
  border-right-color: transparent;
}
@keyframes ag-spin {
  to {
    transform: rotate(360deg);
  }
}
.ag-btn-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

/* ---- forms -------------------------------------------------------------- */
.ag-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ag-field__label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.ag-field__hint {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.ag-field__error {
  font-size: var(--fs-sm);
  color: var(--danger);
}
.ag-input,
.ag-select,
.ag-textarea {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 9px var(--s3);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  transition:
    border-color var(--dur) var(--ease),
    background-color var(--dur) var(--ease);
}
.ag-input::placeholder,
.ag-textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}
.ag-input:hover,
.ag-select:hover,
.ag-textarea:hover {
  border-color: var(--text-muted);
}
.ag-input:focus-visible,
.ag-select:focus-visible,
.ag-textarea:focus-visible {
  border-color: var(--text);
}
.ag-input[disabled],
.ag-select[disabled],
.ag-textarea[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--surface);
}
.ag-input.is-invalid,
.ag-select.is-invalid,
.ag-textarea.is-invalid,
.ag-input[aria-invalid="true"],
.ag-select[aria-invalid="true"],
.ag-textarea[aria-invalid="true"] {
  border-color: var(--danger);
}
.ag-input--mono {
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.ag-textarea {
  min-height: 96px;
  resize: vertical;
  line-height: var(--lh-body);
}
.ag-select {
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237A7A86' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px 18px;
}
[data-theme="dark"] .ag-select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23A1A1AC' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ag-select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23A1A1AC' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  }
}
.ag-select option {
  background: var(--bg);
  color: var(--text);
}

/* checkbox and radio: ag-check wraps an input + text */
.ag-check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-md);
  font-weight: var(--fw-regular);
  cursor: pointer;
}
.ag-check__input {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  flex: none;
  margin: 0;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--bg);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}
.ag-check__input[type="radio"] {
  border-radius: 50%;
}
.ag-check__input::before {
  content: "";
  width: 10px;
  height: 6px;
  border: 2px solid var(--accent-ink);
  border-top: 0;
  border-right: 0;
  transform: translateY(-1px) rotate(-45deg) scale(0);
  transition: transform var(--dur) var(--ease);
}
.ag-check__input[type="radio"]::before {
  width: 8px;
  height: 8px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-ink);
  transform: scale(0);
}
.ag-check__input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.ag-check__input:checked::before {
  transform: translateY(-1px) rotate(-45deg) scale(1);
}
.ag-check__input[type="radio"]:checked::before {
  transform: scale(1);
}
.ag-check__input[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.ag-check__input[disabled] + * {
  opacity: 0.5;
}

/* switch: <button class="ag-switch" role="switch" aria-checked="true"> */
.ag-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex: none;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  border: 0;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.ag-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  transition:
    transform var(--dur) var(--ease),
    background-color var(--dur) var(--ease);
}
.ag-switch[aria-checked="true"],
.ag-switch.is-on {
  background: var(--accent);
}
.ag-switch[aria-checked="true"]::after,
.ag-switch.is-on::after {
  transform: translateX(18px);
  background: var(--accent-ink);
}
.ag-switch[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.ag-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

/* search box (topbar and lists) */
.ag-search {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 240px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  color: var(--text-muted);
  transition: border-color var(--dur) var(--ease);
}
.ag-search:focus-within {
  border-color: var(--border-strong);
}
.ag-search__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--text);
  outline: none;
}
.ag-search__input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}
.ag-search__input:focus-visible {
  outline: none;
  box-shadow: none;
}

/* ---- cards ---------------------------------------------------------------- */
.ag-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s5);
  box-shadow: var(--shadow);
  min-width: 0;
}
.ag-card--pad-s {
  padding: var(--s3);
}
.ag-card--flush {
  padding: 0;
  overflow: hidden;
}
.ag-card--accent {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.ag-card__title {
  margin-bottom: 6px;
}
.ag-card__lead {
  color: var(--text-muted);
}
.ag-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

/* ---- pills (status) and chips (filters) ----------------------------------- */
.ag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: var(--fw-medium);
  line-height: 1.5;
  white-space: nowrap;
}
.ag-pill--ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.ag-pill--warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.ag-pill--danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.ag-pill--info {
  background: var(--info-soft);
  color: var(--info);
}
.ag-pill--accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.ag-pill__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.ag-chip {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--s1) 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}
.ag-chip:hover {
  background: var(--surface-2);
}
.ag-chip.is-on,
.ag-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: var(--fw-medium);
}
.ag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

/* ---- tabs ---------------------------------------------------------------- */
.ag-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--s4);
  overflow-x: auto;
}
.ag-tab {
  text-decoration: none;
  padding: 10px var(--s3);
  margin-bottom: -1px;
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  cursor: pointer;
  transition:
    color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}
.ag-tab:hover {
  color: var(--text);
}
.ag-tab.is-on,
.ag-tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.ag-tab__n {
  margin-left: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---- app shell: sidebar + topbar + content --------------------------------- */
.ag-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.ag-sidebar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px var(--s3);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  min-height: 0;
}
.ag-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px var(--s2) var(--s3);
}
.ag-sidebar__brand b {
  font-family: var(--display);
  font-weight: var(--fw-semibold);
  font-size: 16px;
}
.ag-logo {
  width: 28px;
  height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font: var(--fw-semibold) 15px var(--display);
}
/* workspace switcher slot */
.ag-ws {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: var(--s2) 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease);
}
.ag-ws:hover {
  border-color: var(--border-strong);
}
.ag-ws__badge {
  width: 26px;
  height: 26px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--info-soft);
  color: var(--info);
  font: var(--fw-semibold) 12px var(--display);
}
.ag-ws__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--fw-medium);
}
.ag-ws__sub {
  display: block;
  font-size: 12px;
  font-weight: var(--fw-regular);
  color: var(--text-muted);
}
.ag-ws .ag-icon {
  margin-left: auto;
  color: var(--text-muted);
}
.ag-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--s2);
}
.ag-nav__label {
  padding: var(--s3) 10px var(--s1);
  font-size: 11px;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.ag-nav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: var(--s2) 10px;
  border-radius: var(--radius-s);
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.ag-nav__item:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.ag-nav__item.is-on,
.ag-nav__item[aria-current="page"] {
  background: var(--surface-3);
  font-weight: var(--fw-medium);
}
.ag-nav__item .ag-icon {
  color: var(--text-muted);
}
.ag-nav__item.is-on .ag-icon,
.ag-nav__item[aria-current="page"] .ag-icon {
  color: var(--accent-text);
}
.ag-nav__count {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12px;
}
.ag-sidebar__footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.ag-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.ag-topbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: var(--topbar-h);
  padding: var(--s3) var(--s6);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.ag-topbar__title {
  font-size: 18px;
  font-family: var(--display);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ag-crumb {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ag-crumb h1 {
  display: inline;
  font: inherit;
  color: var(--text);
  font-weight: var(--fw-medium);
  letter-spacing: 0;
}
.ag-crumb b,
.ag-crumb h1 {
  display: inline;
  margin: 0;
  color: var(--text);
  font: inherit;
  font-weight: var(--fw-medium);
}
.ag-spacer {
  flex: 1;
}
.ag-content {
  flex: 1;
  min-height: 0;
  padding: var(--s6);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.ag-content--narrow > * {
  max-width: 1180px;
}
.ag-menu-btn {
  display: none;
}

@media (max-width: 980px) {
  .ag-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .ag-sidebar {
    display: none;
  }
  .ag-menu-btn {
    display: inline-flex;
  }
}

/* under 720 px the sidebar becomes a bottom nav */
@media (max-width: 720px) {
  .ag-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .ag-main {
    order: 0;
  }
  .ag-sidebar {
    order: 1;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    padding: 6px var(--s1) calc(6px + env(safe-area-inset-bottom));
    min-height: var(--bottom-nav-h);
    border-right: 0;
    border-top: 1px solid var(--border);
    overflow: hidden;
    z-index: var(--z-nav);
  }
  .ag-sidebar__brand,
  .ag-ws,
  .ag-nav__label,
  .ag-nav__count,
  .ag-sidebar__footer,
  .ag-sidebar > :not(.ag-nav) {
    display: none;
  }
  /* more items than fit (the Professional portal has ten): the bar scrolls sideways, the page never does */
  .ag-nav {
    flex: 1;
    flex-direction: row;
    justify-content: space-around;
    margin: 0;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .ag-nav::-webkit-scrollbar {
    display: none;
  }
  .ag-nav__item {
    flex: 1 0 64px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: var(--s1) 2px;
    font-size: 10.5px;
    color: var(--text-muted);
    text-align: center;
  }
  .ag-nav__item .ag-icon {
    width: 22px;
    height: 22px;
  }
  .ag-nav__item.is-on,
  .ag-nav__item[aria-current="page"] {
    background: none;
    color: var(--accent-text);
    font-weight: var(--fw-semibold);
  }
  .ag-menu-btn {
    display: none;
  }
  .ag-topbar {
    padding: 10px var(--s4);
    min-height: 52px;
  }
  /* the title keeps its words; a long status pill next to it is what gets shortened */
  .ag-topbar__title {
    flex: 0 0 auto;
    max-width: 60%;
  }
  .ag-topbar > .ag-pill {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ag-content {
    padding: var(--s4);
  }
  .ag-row__trailing {
    white-space: normal;
    max-width: 50%;
  }
}

/* ---- list rows ------------------------------------------------------------ */
.ag-list {
  display: flex;
  flex-direction: column;
}
.ag-row {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  width: 100%;
  padding: var(--s3) var(--s1);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  text-decoration: none;
  transition: background-color var(--dur) var(--ease);
}
.ag-row:last-child {
  border-bottom: 0;
}
.ag-row--link {
  cursor: pointer;
  border-radius: var(--radius-s);
}
.ag-row--link:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.ag-row__icon {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.ag-row__icon--ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.ag-row__icon--warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.ag-row__icon--danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.ag-row__icon--accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.ag-row__body {
  flex: 1;
  min-width: 0;
}
.ag-row__title {
  font-weight: var(--fw-medium);
  overflow: hidden;
  text-overflow: ellipsis;
}
.ag-row__meta {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.ag-row__trailing {
  margin-left: auto;
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text-muted);
  font-size: 12.5px;
  text-align: right;
  white-space: nowrap;
}

/* ---- table ------------------------------------------------------------------ */
.ag-table-wrap {
  width: 100%;
  overflow-x: auto;
  /* layout containment: Chrome on a phone otherwise widens the layout viewport to the table's intrinsic width
     (the People directory laid out at 820 px on a 390 px device) although the wrap clips and scrolls it */
  contain: layout;
}
.ag-table {
  width: 100%;
  font-size: 14px;
}
.ag-table th {
  padding: var(--s2) var(--s3);
  text-align: left;
  font-size: 12.5px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.02em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ag-table td {
  padding: 11px var(--s3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ag-table tbody tr:last-child td {
  border-bottom: 0;
}
.ag-table--hover tbody tr {
  cursor: pointer;
}
.ag-table--hover tbody tr:hover td {
  background: var(--surface-2);
}
.ag-table td.ag-table__num,
.ag-table th.ag-table__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---- modal ------------------------------------------------------------------ */
.ag-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  background: var(--scrim);
}
.ag-scrim.is-on {
  display: flex;
}
.ag-modal {
  width: min(640px, 100%);
  max-height: 92vh;
  max-height: 92dvh;
  overflow: auto;
  padding: var(--s6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-pop);
  color: var(--text);
}
.ag-modal--sm {
  width: min(440px, 100%);
}
.ag-modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s4);
}
.ag-modal__title {
  font-size: var(--fs-xl);
}
.ag-modal__body > * + * {
  margin-top: var(--s3);
}
.ag-modal__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s2);
  margin-top: var(--s5);
}
.ag-modal__foot .ag-spacer {
  flex: 1;
}
/* native <dialog class="ag-modal"> support */
dialog.ag-modal {
  margin: auto;
}
dialog.ag-modal::backdrop {
  background: rgba(11, 11, 13, 0.55);
}
@media (max-width: 720px) {
  .ag-scrim {
    align-items: flex-end;
    padding: 0;
  }
  .ag-modal {
    width: 100%;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding-bottom: calc(var(--s6) + env(safe-area-inset-bottom));
  }
}

/* ---- toast ------------------------------------------------------------------ */
.ag-toasts {
  position: fixed;
  left: 50%;
  bottom: var(--s6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 2 * var(--s4));   /* a long message wraps inside the viewport instead of widening the page */
  max-width: calc(100vw - var(--s7));
  pointer-events: none;
}
.ag-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px var(--s4);
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
.ag-toast.is-on {
  opacity: 1;
  transform: none;
}
.ag-toast--static {
  opacity: 1;
  transform: none;
}
.ag-toast .ag-icon {
  width: 16px;
  height: 16px;
}
.ag-toast--ok .ag-icon {
  color: var(--accent);
}
.ag-toast--danger .ag-icon {
  color: var(--danger);
}
.ag-toast__action {
  margin-left: var(--s1);
  color: inherit;
  font-weight: var(--fw-medium);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
[data-theme="dark"] .ag-toast--danger .ag-icon {
  color: #ffb4b4;
}

/* ---- skeleton (loading state: never a spinner) --------------------------------- */
.ag-skeleton {
  position: relative;
  overflow: hidden;
  display: block;
  height: 12px;
  border-radius: 6px;
  background: var(--surface-2);
}
.ag-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--surface-3), transparent);
  animation: ag-shimmer 1.4s var(--ease) infinite;
}
.ag-skeleton--text {
  height: 12px;
  margin: 6px 0;
}
.ag-skeleton--title {
  height: 18px;
  width: 40%;
  margin: 6px 0 10px;
}
.ag-skeleton--circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
}
.ag-skeleton--block {
  height: 96px;
  border-radius: var(--radius-s);
}
.ag-skeleton--w40 {
  width: 40%;
}
.ag-skeleton--w60 {
  width: 60%;
}
.ag-skeleton--w80 {
  width: 80%;
}
@keyframes ag-shimmer {
  to {
    transform: translateX(100%);
  }
}

/* ---- empty state --------------------------------------------------------------- */
.ag-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: var(--s8) var(--s6);
  text-align: center;
  color: var(--text-muted);
}
.ag-empty__icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text-muted);
  margin-bottom: var(--s1);
}
.ag-empty__icon .ag-icon {
  width: 24px;
  height: 24px;
}
.ag-empty__title {
  color: var(--text);
  font-weight: var(--fw-medium);
}
.ag-empty__line {
  max-width: 36em;
}
.ag-empty__action {
  margin-top: var(--s2);
}
.ag-empty--danger .ag-empty__icon {
  background: var(--danger-soft);
  color: var(--danger);
}
.ag-empty--ok .ag-empty__icon {
  background: var(--ok-soft);
  color: var(--ok);
}

/* ---- steps (numbered progress 1-4) ---------------------------------------------- */
.ag-steps {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s6);
}
/* narrow: only the current step keeps its label (the others stay in the accessible name) */
.ag-steps--compact .ag-step:not(.is-on) .ag-step__t {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.ag-step {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.ag-step__n {
  width: 24px;
  height: 24px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: 12px;
  font-weight: var(--fw-semibold);
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}
.ag-step__n .ag-icon {
  width: 14px;
  height: 14px;
}
.ag-step.is-done .ag-step__n {
  background: var(--ok-soft);
  border-color: transparent;
  color: var(--ok);
}
.ag-step.is-on {
  color: var(--text);
  font-weight: var(--fw-medium);
}
.ag-step.is-on .ag-step__n {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.ag-step__line {
  width: 28px;
  height: 1px;
  flex: none;
  background: var(--border-strong);
}
@media (max-width: 720px) {
  .ag-steps {
    gap: 5px;
  }
  .ag-step {
    font-size: 11px;
  }
  .ag-step__n {
    width: 20px;
    height: 20px;
    font-size: 10.5px;
  }
  .ag-step__line {
    width: 12px;
  }
  .ag-step:not(.is-on) .ag-step__t {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* ---- code box, copy box, kbd ------------------------------------------------------ */
.ag-code {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--text);
  overflow-wrap: anywhere;
}
.ag-code pre {
  font: inherit;
  white-space: pre-wrap;
}
.ag-code__group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ag-code__group + .ag-code__group {
  padding-top: var(--s3);
  border-top: 1px solid var(--border);
}
.ag-code__label {
  font-family: var(--font);
  font-size: 11px;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.ag-code__line {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
}
.ag-code__line > pre,
.ag-code__line > code {
  flex: 1;
  min-width: 0;
}
.ag-code--inline,
code.ag-code {
  display: inline;
  padding: 2px 6px;
  border: 0;
  border-radius: var(--radius-xs);
  font-size: 12.5px;
  overflow-wrap: anywhere;      /* a long path wraps on a 320 px screen instead of widening the page */
}
.ag-copybox {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s1) var(--s1) var(--s1) var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--bg);
  min-height: 40px;
}
.ag-copybox__value {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
  -webkit-user-select: all;
}
.ag-copybox__btn {
  flex: none;
}
.ag-copybox--secret .ag-copybox__value {
  font-size: 18px;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.06em;
  text-align: center;
  white-space: normal;
}
/* recovery code block (prototype .rc) */
.ag-recovery {
  margin: 10px 0 14px;
  padding: var(--s4);
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: var(--bg);
  font: var(--fw-semibold) 22px/1.4 var(--mono);
  letter-spacing: 0.06em;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
  -webkit-user-select: all;
}
@media (max-width: 720px) {
  .ag-recovery {
    font-size: 18px;
    letter-spacing: 0.04em;
    padding: var(--s3);
  }
  .ag-copybox--secret .ag-copybox__value {
    font-size: 15px;
  }
}
.ag-kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: var(--fw-medium);
  line-height: 1.4;
  text-align: center;
}

/* ---- divider, note, progress, avatar, sr ------------------------------------------- */
.ag-divider {
  height: 1px;
  margin: 14px 0;
  background: var(--border);
  border: 0;
}
.ag-divider--v {
  width: 1px;
  height: auto;
  align-self: stretch;
  margin: 0 var(--s2);
}
.ag-note {
  padding: 10px var(--s3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-s);
  color: var(--text-muted);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}
.ag-progress {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}
.ag-progress__bar {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width var(--dur-slow) var(--ease);
}
.ag-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--surface-3);
  color: var(--text);
  font: var(--fw-semibold) 12px var(--display);
}
.ag-avatar--lg {
  width: 40px;
  height: 40px;
  font-size: 14px;
}
.ag-avatar--ext {
  background: var(--info-soft);
  color: var(--info);
}
.ag-avatar--ai {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.ag-sr {
  position: absolute !important;
  top: 0;                     /* at the containing block's origin: a hidden label in a scrolled table cell never widens the page */
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- layout helpers ------------------------------------------------------------------ */
.ag-hstack {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ag-hstack--wrap {
  flex-wrap: wrap;
}
.ag-hstack--between {
  justify-content: space-between;
}
.ag-vstack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ag-stack > * + * {
  margin-top: var(--s3);
}
.ag-grid {
  display: grid;
  gap: var(--s4);
}
.ag-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ag-grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.ag-grid--4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.ag-grid--main {
  grid-template-columns: minmax(0, 1fr) 320px;
}
@media (max-width: 980px) {
  .ag-grid--2,
  .ag-grid--3,
  .ag-grid--main {
    grid-template-columns: minmax(0, 1fr);
  }
  .ag-grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---- motion: no animation on page load, none when reduced ---------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0ms !important;
    scroll-behavior: auto !important;
  }
  .ag-skeleton::after {
    animation: none;
    transform: none;
    opacity: 0.5;
  }
}

/* ---- reduced motion ------------------------------------------------------------- */
/* tokens.css already sets --dur and --dur-slow to 0 here; the shimmer has its own duration, so it stops too.
   The button spinner stays: it is the one piece of motion that carries information. */
@media (prefers-reduced-motion: reduce) {
  .ag-skeleton::after {
    animation: none;
  }
  html {
    scroll-behavior: auto;
  }
}
