/* octoauth admin — component stylesheet.
   Tokens and rules per /DESIGN.md. This file is written with production intent:
   only .proto-* classes (in prototype.css) are throwaway. */

/* ---------- Tokens ---------- */

:root {
  --color-primary: #f54e00;
  --color-primary-active: #d04200;
  --color-ink: #26251e;
  --color-body: #5a5852;
  --color-muted: #807d72;
  --color-muted-soft: #a09c92;
  --color-hairline: #e6e5e0;
  --color-hairline-soft: #efeee8;
  --color-hairline-strong: #cfcdc4;
  --color-canvas: #f7f7f4;
  --color-canvas-soft: #fafaf7;
  --color-surface: #ffffff;
  --color-surface-strong: #e6e5e0;
  --color-on-primary: #ffffff;

  --color-status-pending: #dfa88f;
  --color-status-active: #9fc9a2;
  --color-status-info: #9fbbe0;
  --color-status-special: #c0a8dd;
  --color-status-warn: #c08532;
  --color-error: #cf2d56;
  --color-success: #1f8a65;

  --font-ui: "Inter", system-ui, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  --space-xxs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-base: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-page: 48px;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-canvas);
  color: var(--color-body);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; color: var(--color-ink); }

a { color: var(--color-ink); }

code, .mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* ---------- Typography ---------- */

.page-title {
  font-size: 26px;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.3px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}

.overline {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  color: var(--color-muted);
}

.help {
  font-size: 13px;
  color: var(--color-muted);
}

/* ---------- App shell ---------- */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--color-hairline);
  padding: var(--space-lg) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  transition: width 0.15s ease;
}

.sidebar.is-collapsed { width: 64px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  /* 2px nav-item border + 2px to center the 14px dot on the 18px nav icons */
  padding: 0 var(--space-lg) 0 calc(var(--space-lg) + 4px);
  font-size: 16px;
  font-weight: 600;
  color: var(--color-ink);
  letter-spacing: -0.2px;
}

.sidebar-brand .mono { color: var(--color-primary); }

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-primary);
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
}

.icon-btn:hover { color: var(--color-ink); background: var(--color-surface); }
.icon-btn .icon { vertical-align: 0; }

.sidebar-toggle { margin-left: auto; }
.sidebar-toggle .icon { transition: transform 0.15s ease; }
.sidebar:not(.is-collapsed) .sidebar-toggle .icon { transform: rotate(180deg); }

.sidebar.is-collapsed .sidebar-brand {
  flex-direction: column;
  gap: var(--space-sm);
  padding: 0;
}

.sidebar.is-collapsed .brand-dot { width: 16px; height: 16px; }
.sidebar.is-collapsed .sidebar-toggle { margin-left: 0; }

.sidebar.is-collapsed .nav-label,
.sidebar.is-collapsed .badge-count,
.sidebar.is-collapsed .user-text,
.sidebar.is-collapsed .sidebar-signout { display: none; }

.sidebar.is-collapsed .sidebar-footer { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar.is-collapsed .user-card { flex: 0 0 auto; }

.sidebar.is-collapsed .nav-item { justify-content: center; padding: 9px 0; }

.nav { display: flex; flex-direction: column; }

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
  padding: 9px var(--space-lg);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-body);
  text-decoration: none;
  border-left: 2px solid transparent;
}

.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; vertical-align: 0; }
.nav-item .nav-label { flex: 1; min-width: 0; }

.nav-item:hover { color: var(--color-ink); }

.nav-item.is-active {
  color: var(--color-ink);
  border-left-color: var(--color-primary);
  background: var(--color-surface);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-top: auto;
  padding: var(--space-sm) var(--space-base) 0;
  border-top: 1px solid var(--color-hairline);
}

.sidebar-signout { display: flex; }

.user-card {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex: 1;
  min-width: 0;
  padding: 4px;
  border-radius: var(--radius-md);
  text-decoration: none;
}

.user-card:hover, .user-card.is-active { background: var(--color-surface); }

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(245, 78, 0, 0.12);
  color: var(--color-primary-active);
  font-size: 12px;
  font-weight: 600;
}

.user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.35;
}

.user-name, .user-tenant {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-name { font-size: 13px; color: var(--color-ink); }
.user-tenant { font-size: 12px; color: var(--color-muted); }

.main {
  flex: 1;
  min-width: 0;
  max-width: 1100px;
  padding: var(--space-page);
}

/* Map-style pages take the room they can use, but stop short of ultrawide
   sprawl; centering splits any leftover width instead of piling it up on
   one side. */
.main-wide { max-width: 1920px; margin-inline: auto; }

@media (min-width: 769px) {
  .sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    height: 100dvh;
  }
  .sidebar-brand, .sidebar-footer { flex-shrink: 0; }
  .sidebar .nav { min-height: 0; overflow-y: auto; }
}

@media (max-width: 768px) {
  .shell { flex-direction: column; }
  .sidebar, .sidebar.is-collapsed {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    border-right: 0;
    border-bottom: 1px solid var(--color-hairline);
    padding: var(--space-sm) var(--space-base);
  }
  .sidebar-brand, .sidebar.is-collapsed .sidebar-brand { flex-direction: row; padding: 0; }
  .sidebar.is-collapsed .brand-dot { width: 14px; height: 14px; }
  .sidebar.is-collapsed .nav-label { display: inline; }
  .sidebar.is-collapsed .badge-count { display: inline-flex; }
  .sidebar.is-collapsed .user-text { display: flex; }
  .sidebar.is-collapsed .sidebar-signout { display: flex; }
  .nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; order: 3; }
  .nav-item, .sidebar.is-collapsed .nav-item {
    justify-content: flex-start;
    padding: 6px var(--space-xs);
    border-left: 0;
    border-bottom: 2px solid transparent;
  }
  .nav-item.is-active, .sidebar.is-collapsed .nav-item.is-active {
    background: none;
    border-bottom-color: var(--color-primary);
  }
  .nav-item .nav-label { flex: 0 0 auto; }
  .sidebar-footer, .sidebar.is-collapsed .sidebar-footer {
    justify-content: flex-start;
    margin-top: 0;
    margin-left: auto;
    padding: 0;
    border-top: 0;
  }
  .sidebar.is-collapsed .user-card { flex: 0 0 auto; }
  .sidebar-toggle { display: none; }
  .main { padding: var(--space-lg); }
}

/* ---------- Page header ---------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-base);
  padding-bottom: var(--space-base);
  border-bottom: 1px solid var(--color-hairline);
  margin-bottom: var(--space-lg);
}

.page-header .help { margin-top: var(--space-xxs); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  height: 40px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.btn-primary:hover, .btn-primary:active { background: var(--color-primary-active); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-ink);
  border-color: var(--color-hairline-strong);
}
.btn-secondary:hover { border-color: var(--color-muted-soft); }

.btn-danger {
  background: var(--color-surface);
  color: var(--color-error);
  border-color: var(--color-error);
}

.btn-ghost {
  background: transparent;
  color: var(--color-ink);
  border: 0;
  padding: 6px 8px;
  height: auto;
}
.btn-ghost:hover { text-decoration: underline; }

.btn-sm {
  height: 32px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.btn:disabled {
  background: var(--color-surface-strong);
  color: var(--color-muted-soft);
  border-color: transparent;
  cursor: not-allowed;
}

/* ---------- Cards ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-base);
  margin-bottom: var(--space-base);
}

.card + .card { margin-top: var(--space-base); }

/* ---------- Tables ---------- */

.table-card {
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

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

.table th {
  background: var(--color-canvas-soft);
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-hairline);
}

.table td {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--color-ink);
  border-bottom: 1px solid var(--color-hairline-soft);
  vertical-align: middle;
}

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

.table tbody tr:hover { background: var(--color-canvas-soft); }

/* bot rows carry a subtle lavender tint */
.table tbody tr.row-bot { background: rgba(192, 168, 221, 0.08); }
.table tbody tr.row-bot:hover { background: rgba(192, 168, 221, 0.16); }

.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table .cell-sub {
  display: block;
  font-size: 13px;
  color: var(--color-muted);
  font-weight: 400;
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-sm);
  font-size: 13px;
  color: var(--color-muted);
}

/* ---------- Pills, tags, badges ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  color: var(--color-ink);
  white-space: nowrap;
}

.pill-active { background: var(--color-status-active); }
.pill-pending { background: var(--color-status-pending); }
.pill-info { background: var(--color-status-info); }
.pill-special { background: var(--color-status-special); }
.pill-warn { background: var(--color-status-warn); color: var(--color-on-primary); }
.pill-revoked { background: var(--color-surface-strong); color: var(--color-muted); }
.pill-error { background: rgba(207, 45, 86, 0.12); color: var(--color-error); }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  background: var(--color-surface-strong);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-ink);
  white-space: nowrap;
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-strong);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-ink);
}

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

.field { margin-bottom: var(--space-base); }

.field > label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-ink);
  margin-bottom: var(--space-xxs);
}

.field .required { color: var(--color-error); }

.input, .select, .textarea {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline-strong);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  height: 40px;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--color-ink);
}

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23807d72' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.select:hover { border-color: var(--color-muted-soft); }

.textarea { height: auto; min-height: 80px; resize: vertical; }

.input.mono { font-family: var(--font-mono); font-size: 13px; }

.input::placeholder, .textarea::placeholder { color: var(--color-muted-soft); }

.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
  border-color: var(--color-primary);
}

.field.is-invalid .input { border-color: var(--color-error); }

.field-error {
  font-size: 13px;
  color: var(--color-error);
  margin-top: var(--space-xxs);
}

.field .help { margin-top: var(--space-xxs); }

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-base);
  border-bottom: 1px solid var(--color-hairline-soft);
  cursor: pointer;
}

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

.checkbox-row:hover { background: var(--color-canvas-soft); }

.checkbox-row input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--color-primary);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.checkbox-row .row-title {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--color-ink);
}

.checkbox-row .row-desc {
  font-size: 13px;
  color: var(--color-muted);
}

.form-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-base);
  padding-top: var(--space-base);
  border-top: 1px solid var(--color-hairline);
  margin-top: var(--space-lg);
}

.tools-section-header {
  padding: var(--space-base);
}

.tools-section-header .help {
  margin: var(--space-xxs) 0 0;
}

.tools-section-header + .table,
.tools-empty {
  border-top: 1px solid var(--color-hairline-soft);
}

.tools-empty {
  margin: 0;
  padding: var(--space-lg) var(--space-base);
}

.tools-provider-name {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--color-ink);
}

.connect-dialog {
  width: min(520px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 32px);
  padding: 0;
  color: var(--color-body);
  background: var(--color-surface);
  border: 1px solid var(--color-hairline-strong);
  border-radius: var(--radius-lg);
}

.connect-dialog::backdrop {
  background: rgba(38, 37, 30, 0.4);
}

.connect-dialog form {
  padding: var(--space-lg);
}

.connect-dialog-header {
  padding-bottom: var(--space-base);
  margin-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-hairline);
}

.connect-dialog-header .help {
  margin: var(--space-xxs) 0 0;
}

.connect-error {
  margin-top: var(--space-base);
}

.connect-error[hidden] {
  display: none;
}

/* ---------- Users & bots ---------- */

.users-page-error,
.users-secret {
  margin-bottom: var(--space-base);
}

.users-page-error[hidden],
.users-secret[hidden] {
  display: none;
}

.users-secret .help {
  margin: var(--space-xxs) 0 0;
}

.users-secret-value {
  display: block;
  margin-top: var(--space-base);
  overflow-wrap: anywhere;
  user-select: all;
}

.users-table-card {
  overflow-x: auto;
}

.users-who-name {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--color-ink);
}

.users-bots-link {
  color: var(--color-ink);
  text-decoration-color: var(--color-hairline-strong);
  text-underline-offset: 3px;
}

.users-bots-link:hover {
  color: var(--color-primary-active);
}

.table tbody tr.users-token-row,
.table tbody tr.users-token-row:hover {
  background: var(--color-canvas-soft);
}

.users-token-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-base);
  padding: var(--space-base) 0;
  border-bottom: 1px solid var(--color-hairline-soft);
}

.users-token-item:last-child {
  border-bottom: 0;
}

.users-token-scopes {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xxs);
  margin-top: var(--space-xs);
}

.table td.users-empty {
  padding: var(--space-xl);
  text-align: center;
}

/* ---------- Wells & description lists ---------- */

.well {
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-md);
  padding: var(--space-base);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--color-ink);
  overflow-x: auto;
}

.dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  margin: 0;
}

.dl dt {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  color: var(--color-muted);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-hairline-soft);
}

.dl dd {
  margin: 0;
  padding: var(--space-sm) 0;
  font-size: 14px;
  color: var(--color-ink);
  border-bottom: 1px solid var(--color-hairline-soft);
}

.dl dt:last-of-type, .dl dd:last-of-type { border-bottom: 0; }

/* ---------- Alerts & flash ---------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-sm) var(--space-base);
  font-size: 13.5px;
  line-height: 1.5;
}

.alert-success {
  background: color-mix(in srgb, var(--color-success) 7%, transparent);
  border-color: color-mix(in srgb, var(--color-success) 30%, transparent);
}

.alert-error {
  background: color-mix(in srgb, var(--color-error) 6%, transparent);
  border-color: color-mix(in srgb, var(--color-error) 28%, transparent);
  color: color-mix(in srgb, var(--color-error) 72%, var(--color-ink));
}

.alert-warn {
  background: color-mix(in srgb, var(--color-status-warn) 8%, transparent);
  border-color: color-mix(in srgb, var(--color-status-warn) 32%, transparent);
}

.alert .alert-title {
  font-weight: 600;
  color: var(--color-ink);
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: var(--space-lg);
  border-bottom: 1px solid var(--color-hairline);
  margin-bottom: var(--space-lg);
}

.tab {
  padding: var(--space-xs) 0 var(--space-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.is-active {
  color: var(--color-ink);
  border-bottom-color: var(--color-primary);
}

/* ---------- Stepper (wizard flows) ---------- */

.stepper {
  display: flex;
  gap: var(--space-xs);
  margin-bottom: var(--space-lg);
}

.step {
  flex: 1;
  padding: var(--space-sm) var(--space-base);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-hairline);
  background: var(--color-surface);
  font-size: 13px;
  color: var(--color-muted);
}

.step .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-strong);
  color: var(--color-ink);
  font-size: 11px;
  font-weight: 600;
  margin-right: var(--space-xs);
}

.step.is-active {
  border-color: var(--color-ink);
  color: var(--color-ink);
  font-weight: 500;
}

.step.is-active .step-num {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.step.is-done { color: var(--color-body); }

.step.is-done .step-num {
  background: var(--color-status-active);
}

/* ---------- Icons (Lucide sprite) ---------- */

.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  vertical-align: -3px;
}

.icon-sm { width: 14px; height: 14px; }

/* ---------- Segmented switch ---------- */

.seg {
  display: inline-flex;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline-strong);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.seg button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-muted);
  cursor: pointer;
}

.seg button.is-active {
  background: var(--color-ink);
  color: var(--color-canvas);
}

/* ---------- Access-level chips ---------- */

.lvl {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.lvl-view { background: var(--color-hairline-soft); color: var(--color-body); }
.lvl-edit { background: var(--color-ink); color: var(--color-canvas); }
.lvl-none { color: var(--color-muted-soft); font-weight: 400; }

/* icon-only compact chip — perfect circle, subtle fill; "ends soon" is a corner dot */
.lvl-ico {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  padding: 0;
}

.lvl-ico .icon { width: 17px; height: 17px; vertical-align: 0; }

.lvl-dot::after {
  background: var(--color-error);
}

.lvl-ico .icon { vertical-align: 0; }

.lvl-dot::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-surface);
}

.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.matrix td { padding: 8px 12px; }
.matrix .who-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--color-ink);
}
.matrix .who-cell .icon { color: var(--color-muted); }

/* ---------- Graph view ---------- */

.graph-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(360px, 34vw, 520px);
  gap: var(--space-base);
  align-items: start;
}

.graph-card {
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.graph-svg { display: block; width: 100%; height: clamp(560px, 74vh, 920px); cursor: grab; }

.graph-node { cursor: pointer; }
.graph-node circle, .graph-node rect { stroke-width: 1.5; }
.graph-shape.is-tool { fill: var(--color-canvas-soft); stroke: var(--color-hairline-strong); }
.graph-shape.is-app { fill: rgba(159, 187, 224, 0.18); stroke: var(--color-status-info); }
.graph-shape.is-person { fill: var(--color-surface); stroke: var(--color-hairline-strong); }
.graph-shape.is-bot { fill: rgba(192, 168, 221, 0.35); stroke: var(--color-status-special); }

.graph-node circle, .graph-node rect, .graph-node use, .graph-node text {
  transition: transform 0.25s ease;
}

.graph-node.is-selected circle,
.graph-node.is-selected rect {
  stroke: var(--color-ink);
  stroke-width: 2.5;
  transform: scale(1.3);
}

/* The selected node sits on top of edges, so its fill must be fully opaque:
   these are the translucent type tints pre-composited onto white. */
.graph-node.is-selected .graph-shape.is-bot { fill: #e9e1f3; }
.graph-node.is-selected .graph-shape.is-app { fill: #eef3f9; }
.graph-node.is-selected .graph-shape.is-person { fill: #ffffff; }
.graph-node.is-selected .graph-shape.is-tool { fill: var(--color-canvas-soft); }

.graph-node.is-selected use { transform: scale(1.3); }

.graph-node.is-selected text {
  font-size: 15px;
  font-weight: 600;
  transform: translateY(12px);
}
.graph-node text {
  font-family: var(--font-ui);
  font-size: 12px;
  fill: var(--color-ink);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--color-surface);
  stroke-width: 3px;
}
.graph-node .node-icon { color: var(--color-ink); pointer-events: none; }

.graph-link { stroke-linecap: round; fill: none; }
.graph-link.is-view { stroke: var(--color-hairline-strong); stroke-width: 1.5; stroke-dasharray: 5 6; }
.graph-link.is-edit { stroke: rgba(38, 37, 30, 0.6); stroke-width: 3; }
.graph-link.is-use { stroke: rgba(192, 168, 221, 0.8); stroke-width: 2; }
.graph-link.is-identity { stroke: rgba(159, 187, 224, 0.9); stroke-width: 2.5; }

/* With nothing selected the map is an overview: every wire fades to a whisper
   and thins out. Hovering or picking a wire restores its full weight. */
.graph-svg.is-idle .graph-link:not(.is-hover):not(.is-picked) { stroke-opacity: 0.3; }
.graph-svg.is-idle .graph-link:not(.is-hover):not(.is-picked).is-edit { stroke-width: 1.75; }
.graph-svg.is-idle .graph-link:not(.is-hover):not(.is-picked).is-use { stroke-width: 1.5; }
.graph-svg.is-idle .graph-link:not(.is-hover):not(.is-picked).is-identity { stroke-width: 1.5; }

.lvl-use { background: rgba(192, 168, 221, 0.28); color: #5b4a75; }
.lvl-linked { background: rgba(159, 187, 224, 0.28); color: #3d5877; }

/* An invisible wide stroke makes thin connection curves clickable. */
.graph-link-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18;
  pointer-events: stroke;
  cursor: pointer;
}

/* The canvas-colored halo keeps the count legible where edges cross.
   Counts whisper until their edge is hovered or picked. */
.graph-link-count {
  font-size: 11px;
  font-weight: 600;
  fill: var(--color-muted);
  paint-order: stroke;
  stroke: var(--color-canvas);
  stroke-width: 4;
  stroke-linejoin: round;
  cursor: pointer;
  user-select: none;
  opacity: 0.22;
  transition: opacity 0.15s;
}

.graph-link-count.is-hover,
.graph-link-count.is-picked { opacity: 1; }

.graph-link-count.is-picked { fill: var(--color-primary); font-weight: 700; }

.graph-link.is-hover { stroke-opacity: 1; }

/* The connection open in the panel reads as the one live wire on the map. */
.graph-link.is-picked {
  stroke: var(--color-primary);
  stroke-width: 4.5;
  stroke-dasharray: none;
  opacity: 1;
}

.lvl-config {
  border: 0;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-hairline-soft);
  color: var(--color-body);
}

.lvl-config:hover { background: var(--color-ink); color: var(--color-canvas); }

/* ---------- Connection panel ---------- */

.conn-header {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 10px;
}

.conn-back { padding: 2px 8px; flex-shrink: 0; }

/* Who → what, spelled out; names wrap rather than truncate. */
.conn-pair {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-width: 0;
}

.conn-end {
  all: unset;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-ink);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.conn-end:hover { text-decoration: underline; }

.conn-verb { color: var(--color-muted); font-size: 13px; font-weight: 400; }

.conn-bulk { margin-bottom: 8px; }

.conn-bulk-buttons { gap: 6px; }

.conn-count { font-size: 12px; font-weight: 600; color: var(--color-body); }

/* No inner scroll: tooltips must escape the list, so the page scrolls instead. */
.conn-tools {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-md);
}

.conn-tool {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--color-hairline-soft);
}

.conn-tool:last-child { border-bottom: 0; }
.conn-tool:hover { background: var(--color-canvas-soft); }

.conn-tool-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.conn-tool-name { font-size: 12.5px; font-weight: 600; overflow-wrap: anywhere; }

.conn-tool-desc {
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--color-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.conn-tool-info {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--color-muted-soft);
  cursor: help;
}

.conn-tool:hover .conn-tool-info { color: var(--color-ink); }

/* ---------- Toggle switch ---------- */

.switch {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  width: 30px;
  height: 17px;
  margin-top: 1px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-pill);
  background: var(--color-hairline-strong);
  transition: background 0.15s;
  pointer-events: none;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--color-canvas);
  transition: transform 0.15s;
}

.switch input:checked + .switch-track { background: var(--color-primary); }
.switch input:checked + .switch-track::after { transform: translateX(13px); }
.switch input:disabled + .switch-track { opacity: 0.5; }

/* ---------- Schema tooltip ---------- */

.tip { position: relative; display: inline-flex; }

.tip-card {
  display: none;
  position: absolute;
  top: -6px;
  right: calc(100% + 10px);
  z-index: 30;
  width: 300px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--color-ink);
  color: var(--color-canvas);
}

.tip:hover .tip-card,
.tip.is-open .tip-card { display: block; }

.tip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.tip-title { font-size: 12.5px; font-weight: 700; }

.tip-flag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
}

.tip-flag.is-read { background: rgba(255, 255, 255, 0.16); }
.tip-flag.is-write { background: var(--color-primary); }

.tip-empty { margin: 0; font-size: 12px; opacity: 0.7; }

.tip-params {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.tip-param { display: flex; flex-direction: column; gap: 1px; }

.tip-param-head { display: flex; align-items: baseline; gap: 8px; }

.tip-param-name { font-size: 12px; font-weight: 600; }

.tip-param-type { font-size: 11px; opacity: 0.65; }

.tip-param-desc { font-size: 11px; line-height: 1.4; opacity: 0.75; }

/* ---------- Accordion ---------- */

.acc-item {
  border-top: 1px solid var(--color-hairline-soft);
  margin: 0 -10px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  transition: background-color 0.2s ease;
}

.acc-item:first-of-type { border-top: 0; }

.acc-item.is-open {
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-md);
  margin-top: 6px;
  margin-bottom: 6px;
}

.acc-item.is-open + .acc-item { border-top-color: transparent; }

.acc-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: var(--font-ui);
}

.acc-head:hover .overline { color: var(--color-ink); }

.acc-item.is-open .overline { color: var(--color-ink); }

.acc-item.is-open .badge-count { background: var(--color-ink); color: var(--color-canvas); }

.acc-chev {
  color: var(--color-muted-soft);
  font-size: 10px;
  transition: transform 0.25s ease;
}

.acc-item.is-open .acc-chev { transform: rotate(180deg); color: var(--color-ink); }

/* animated expand/collapse via the grid-rows trick */
.acc-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}

.acc-body > div {
  overflow: hidden;
  min-height: 0;
}

.acc-item.is-open .acc-body { grid-template-rows: 1fr; }

/* after the expand animation, allow popups (comboboxes) to overflow */
.acc-item.is-open .acc-body > div {
  overflow: visible;
  animation: acc-settle 0.3s;
}

@keyframes acc-settle {
  from { overflow: hidden; }
  to { overflow: hidden; }
}

.acc-body .stack-sm { padding: 2px 0 14px; }

/* panel rows */
.prow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  margin: 0 -8px;
  border-radius: var(--radius-sm);
}

.prow:hover { background: var(--color-surface); }

.prow-name {
  all: unset;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--color-ink);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button.prow-name:hover { text-decoration: underline; }

/* per-user resource config block inside the panel */
.cfg {
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  margin: 6px 0 2px;
}

.cfg label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--color-ink);
  padding: 4px 2px;
  cursor: pointer;
}

.cfg input[type="checkbox"] { accent-color: var(--color-ink); }

.is-dim { opacity: 0.15; }

.graph-legend {
  display: flex;
  gap: var(--space-base);
  padding: var(--space-sm) var(--space-base);
  border-top: 1px solid var(--color-hairline-soft);
  font-size: 12px;
  color: var(--color-muted);
  align-items: center;
  flex-wrap: wrap;
}

.legend-swatch { display: inline-block; width: 18px; height: 3px; border-radius: 2px; vertical-align: middle; }
.legend-swatch.is-edit { background: rgba(38, 37, 30, 0.6); }
.legend-swatch.is-view { background: repeating-linear-gradient(90deg, var(--color-hairline-strong) 0 5px, transparent 5px 10px); }
.legend-swatch.is-use { background: rgba(192, 168, 221, 0.8); }
.legend-swatch.is-identity { background: rgba(159, 187, 224, 0.9); }

.graph-search { min-width: 240px; }
.panel-header { margin-bottom: 14px; }
.panel-header.has-type { margin-bottom: 2px; }
.panel-heading { gap: 8px; min-width: 0; }
.panel-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-type { margin: 0 0 6px 24px; }
.panel-summary { margin: 0 0 12px 24px; }
.panel-note { margin: 12px 0 0; }
.panel-more { margin: 4px 0 0; }
.panel-name-row { gap: 6px; min-width: 0; }
.panel-sub { font-size: 11px; }
.panel-controls { gap: 2px; flex-shrink: 0; }
.panel-level-button { all: unset; cursor: pointer; }
.panel-remove { padding: 2px 6px; color: var(--color-muted); }
.panel-acc-meta { gap: 8px; }
.panel-error { margin-bottom: 12px; }
.give-header { margin-bottom: 14px; }
.give-step { margin: 0 0 8px; }
.give-step.is-next { margin: 12px 0 8px; }
.give-principal { margin-top: 12px; }

@media (max-width: 960px) {
  .graph-wrap { grid-template-columns: 1fr; }
}

/* ---------- Stat strip ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-base);
  margin-bottom: var(--space-lg);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-base) var(--space-lg);
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 400;
  color: var(--color-ink);
  letter-spacing: -0.3px;
}

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

.home-stats {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.home-stats .stat-card {
  text-decoration: none;
}

.home-section {
  padding: 0;
  overflow: hidden;
}

.home-section .card-header {
  margin: 0;
  padding: 20px var(--space-lg) var(--space-base);
  border-bottom: 1px solid var(--color-hairline-soft);
}

.home-row {
  justify-content: space-between;
}

.home-attention-row {
  text-decoration: none;
}

.home-copy {
  margin: 0;
  color: var(--color-ink);
  font-size: 14px;
}

.home-copy .icon {
  color: var(--color-muted);
}

.home-list-empty {
  margin: 0;
  padding: 18px var(--space-lg);
}

@media (max-width: 768px) {
  .home-stats { grid-template-columns: 1fr; }
}

.docs-main {
  max-width: 760px;
}

.docs-card .section-title {
  margin-bottom: var(--space-xxs);
}

.docs-card > .help {
  margin: 0 0 var(--space-sm);
}

/* ---------- Combobox (oa-combobox) ---------- */

.combo {
  position: relative;
  display: block;
}

.combo-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-muted-soft);
  pointer-events: none;
}

.combo-input {
  height: 36px;
  font-size: 14px;
  padding-left: 34px;
}

.combo-list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline-strong);
  border-radius: var(--radius-md);
  max-height: 240px;
  overflow-y: auto;
}

.combo-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--color-ink);
  cursor: pointer;
}

.combo-list li .icon { color: var(--color-muted); }

.combo-hint {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--color-muted-soft);
}

/* ---------- Identity link builder: member, confirm, person ---------- */

.link-builder {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-hairline);
}

.link-step {
  margin: 0;
  color: var(--color-muted);
}

.link-join {
  display: flex;
  justify-content: center;
  padding: 2px 0;
}

.link-chosen {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  font-size: 13px;
}

.link-chosen .icon { width: 14px; height: 14px; color: var(--color-muted); }
.link-chosen-name { font-weight: 600; }
.link-chosen-hint { font-size: 11px; color: var(--color-muted); }

.link-clear {
  all: unset;
  cursor: pointer;
  margin-left: auto;
  padding: 0 4px;
  color: var(--color-muted);
  font-size: 15px;
  line-height: 1;
}

.link-clear:hover { color: var(--color-ink); }

.link-loading,
.link-fallback { margin: 0; }

.combo-list li[aria-selected="true"],
.combo-list li[data-combobox-option-default]:hover,
.combo-list li:hover {
  background: var(--color-canvas-soft);
}

.combo-list li[aria-selected="true"] {
  background: var(--color-hairline-soft);
}

.combo-list .combo-none {
  color: var(--color-muted-soft);
  cursor: default;
}

/* ---------- Activity traces (graph paths in event rows) ---------- */

.activity-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-hairline-soft);
}

.activity-row:last-child { border-bottom: 0; }
.activity-row:hover { background: var(--color-canvas-soft); }
.activity-row[hidden] { display: none; }

.activity-row .when {
  flex-shrink: 0;
  width: 84px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-muted);
}

.activity-row > .pill { flex-shrink: 0; }

.activity-toolbar .activity-search {
  flex: 1;
  min-width: 220px;
}

.activity-filter {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding-left: var(--space-sm);
  border-left: 1px solid var(--color-hairline);
  color: var(--color-muted);
  font-size: 13px;
}

.activity-empty {
  display: grid;
  justify-items: center;
  gap: var(--space-xs);
  padding: var(--space-xl);
  color: var(--color-muted);
  text-align: center;
}

.activity-empty .icon {
  width: 22px;
  height: 22px;
  color: var(--color-muted-soft);
}

.activity-empty p { margin: 0; }

.activity-row.is-new { animation: row-in 0.35s ease; }

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

.trace {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.tnode {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-hairline);
  background: var(--color-surface);
  font-size: 12.5px;
  color: var(--color-ink);
  white-space: nowrap;
  text-decoration: none;
}

a.tnode:hover { border-color: var(--color-muted-soft); }

.activity-row .meta {
  flex-shrink: 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-muted-soft);
  line-height: 1.5;
}

.tnode .icon { width: 13px; height: 13px; color: var(--color-muted); }

.tnode-bot { background: rgba(192, 168, 221, 0.22); border-color: rgba(192, 168, 221, 0.6); }
.tnode-app { background: rgba(159, 187, 224, 0.18); border-color: rgba(159, 187, 224, 0.6); }
.tnode-res { background: var(--color-canvas-soft); border-radius: var(--radius-sm); }

.thop {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--color-muted);
  white-space: nowrap;
}

.thop::after { content: "→"; color: var(--color-muted-soft); }

.thop.is-write { color: #7d5620; font-weight: 600; }
.thop.is-deny { color: var(--color-error); font-weight: 600; }

@media (max-width: 768px) {
  .activity-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .activity-row .when {
    width: 100%;
  }
}

/* ---------- Live tail ---------- */

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  animation: live-pulse 1.4s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---------- Utility layout ---------- */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: var(--space-base);
  align-items: start;
}

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

.stack-sm > * + * { margin-top: var(--space-sm); }
.stack-base > * + * { margin-top: var(--space-base); }
.stack-lg > * + * { margin-top: var(--space-lg); }

.row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.sticky-panel {
  position: sticky;
  top: var(--space-lg);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-base);
  flex-wrap: wrap;
}

.toolbar .input, .toolbar .select { width: auto; }

/* ---------- Login ---------- */
/* No inline styles: the CSP (style-src 'self') drops them silently. */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  background:
    radial-gradient(ellipse 60% 45% at 50% 0%, #fdf0e9 0%, transparent 70%),
    var(--color-canvas);
}

.login-panel { width: 100%; max-width: 380px; }

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  color: var(--color-ink);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.login-brand .mono { color: var(--color-primary); }

.login-tenant {
  margin: var(--space-xxs) 0 0;
  text-align: center;
  color: var(--color-muted);
  font-size: 13px;
}

.login-card {
  margin-top: var(--space-lg);
  padding: var(--space-xl);
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
}

.login-card .btn { width: 100%; height: 44px; }

/* Google's branded sign-in button, light variant per the official branding
   guidelines: white fill, #747775 hairline, #1F1F1F label, and the standard
   multicolor G logo, which must never be recolored. */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #ffffff;
  border: 1px solid #747775;
  color: #1f1f1f;
  font-size: 14px;
  font-weight: 500;
}

.btn-google:hover { background: #f8f9fa; border-color: #747775; }

.btn-google-logo { flex: 0 0 auto; }

.login-divider {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: var(--space-base) 0;
  color: var(--color-muted-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-divider::before, .login-divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--color-hairline);
}

.login-field { display: block; }
.login-field + .login-field { margin-top: var(--space-sm); }

.login-field .help {
  display: block;
  margin-bottom: var(--space-xxs);
}

.login-form .btn { margin-top: var(--space-base); }

.login-foot {
  margin: var(--space-lg) 0 0;
  text-align: center;
  color: var(--color-muted-soft);
  font-size: 13px;
}

/* ---------- Activity forensic console ---------- */

/* A labelled row around the house .switch, which is the track only. */
.switch-row {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 13px;
  color: var(--color-body);
  cursor: pointer;
}

.forensic {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  gap: var(--space-base);
  align-items: start;
}

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

/* The dot hover card has to escape the card, so this one cannot clip. */
.forensic-feed {
  padding: 0;
  overflow: visible;
}

.feed-head {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-base);
  border-bottom: 1px solid var(--color-hairline);
  background: var(--color-canvas-soft);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.feed-head .overline { flex: 1; }

.feed-body { overflow: visible; }

.trail-note {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px var(--space-base);
  border-bottom: 1px solid var(--color-hairline-soft);
  background: rgba(223, 168, 143, 0.14);
  font-size: 12.5px;
  color: var(--color-ink);
}

.trail-note .icon { width: 14px; height: 14px; color: var(--color-status-warn); }

.live-toggle .live-dot { margin-right: 6px; }

/* ---------- One turn per row ---------- */

.chain-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-base) 0 var(--space-sm);
  border-bottom: 1px solid var(--color-hairline-soft);
  border-left: 2px solid transparent;
}

.chain-row:last-child { border-bottom: 0; }
.chain-row:hover { background: var(--color-canvas-soft); }

.chain-row.is-selected {
  background: var(--color-canvas-soft);
  border-left-color: var(--color-primary);
}

.chain-row.is-denied { border-left-color: var(--color-error); }
.chain-row.is-new { animation: row-in 0.35s ease; }

.chain-when {
  flex-shrink: 0;
  width: 76px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-muted);
}

.chain-surface {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--color-muted);
}

.chain-dots {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: 152px;
  flex-wrap: nowrap;
}

.chain-more {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-muted-soft);
}

.chain-open {
  all: unset;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 7px 0;
  cursor: pointer;
  font-family: var(--font-ui);
}

/* Chips shrink inside the table so a full Derek → Slack → Hermes path fits one
   row. A path too long for the row fades out instead of cutting a chip mid-word. */
.chain-open .trace {
  flex-wrap: nowrap;
  overflow: hidden;
  gap: 5px;
  mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
}

.chain-open .tnode {
  font-size: 11.5px;
  padding: 2px 8px;
  gap: 4px;
}

.chain-open .tnode .icon { width: 11px; height: 11px; }
.chain-open .thop { font-size: 10.5px; }

.chain-who {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  max-width: 150px;
  font-size: 13px;
  color: var(--color-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chain-who .icon { width: 13px; height: 13px; color: var(--color-muted); }
.chain-who.is-bot .icon { color: var(--color-status-special); }

.chain-caps {
  flex: 1;
  min-width: 0;
  font-size: 11.5px;
  color: var(--color-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chain-tally {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--color-muted-soft);
}

.chain-tally .is-deny { color: var(--color-error); }

/* ---------- Decision dots: the shape of a turn at a glance ---------- */

.cdot {
  all: unset;
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-status-active);
  cursor: pointer;
}

.cdot.is-deny { background: var(--color-error); }
.cdot.is-write { border-radius: 2px; }
.cdot:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.chain-dots .tip:hover .cdot, .chain-dots .tip.is-open .cdot { transform: scale(1.45); }

/* The Access schema card opens dark and to the left. A step card carries a
   payload block, so it opens above the dot on a light surface. Scoped here so
   Access keeps its own geometry. */
.chain-dots .tip-card {
  top: auto;
  right: auto;
  bottom: calc(100% + 9px);
  left: -10px;
  z-index: 40;
  width: 340px;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline-strong);
  color: var(--color-ink);
  text-align: left;
}

.chain-row:first-child .chain-dots .tip-card,
.chain-row:nth-child(2) .chain-dots .tip-card {
  bottom: auto;
  top: calc(100% + 9px);
}

.chain-dots .tip.is-open .tip-card { border-color: var(--color-primary); }

.chain-dots .tip-cap {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--color-ink);
  overflow: hidden;
  text-overflow: ellipsis;
}

.chain-dots .tip-reason {
  margin: 0 0 var(--space-xs);
  font-size: 12px;
  color: var(--color-body);
}

.chain-dots .tip-pin { color: var(--color-muted-soft); visibility: hidden; }
.chain-dots .tip-pin .icon { width: 12px; height: 12px; }
.chain-dots .tip.is-open .tip-pin { visibility: visible; color: var(--color-primary); }

/* ---------- Payload rendering: full fidelity, admin only ---------- */

.payload {
  margin: 0;
  padding: var(--space-xs) 10px;
  max-height: 240px;
  overflow: auto;
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--color-ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.payload-none {
  margin: 0;
  font-size: 12px;
  color: var(--color-muted-soft);
}

.payload-label {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
}

.payload-label .icon { width: 12px; height: 12px; }

.pill-truncated {
  background: rgba(223, 168, 143, 0.34);
  color: #7d5620;
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--font-mono);
  padding: 2px 8px;
}

/* ---------- Inspector: the anatomy of one turn ---------- */

.inspector {
  position: sticky;
  top: var(--space-lg);
  padding: 0;
}

.inspector-empty {
  display: grid;
  justify-items: center;
  gap: var(--space-xs);
  padding: var(--space-xl) var(--space-lg);
  color: var(--color-muted);
  text-align: center;
}

.inspector-empty .icon { width: 22px; height: 22px; color: var(--color-muted-soft); }
.inspector-empty p { margin: 0; }

.inspector-head {
  padding: var(--space-base) var(--space-base) var(--space-sm);
  border-bottom: 1px solid var(--color-hairline);
}

.inspector-path { margin-top: 6px; }

.inspector-story {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.story-copy {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--color-ink);
}

.inspector-meta {
  margin: 6px 0 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-muted);
  word-break: break-all;
}

.inspector-tally {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* Trail steps. Named apart from .step so the wizard stepper keeps its rules. */

.tsteps {
  list-style: none;
  margin: 0;
  padding: var(--space-xs) 0 var(--space-sm);
  max-height: 56vh;
  overflow-y: auto;
}

.tstep {
  position: relative;
  padding-left: var(--space-lg);
  margin-left: var(--space-base);
  border-left: 1px solid var(--color-hairline);
}

.tstep:last-child { border-left-color: transparent; }

.tstep::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 13px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-status-active);
}

.tstep.is-deny::before { background: var(--color-error); }

.tstep-head {
  all: unset;
  /* all: unset also resets box-sizing, so the right padding would land outside
     the 100% width and push the decision pill past the card edge. */
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  width: 100%;
  padding: 6px var(--space-base) 6px 0;
  cursor: pointer;
  font-family: var(--font-ui);
}

.tstep-head .icon {
  width: 13px;
  height: 13px;
  color: var(--color-muted-soft);
  transition: transform 0.2s ease;
}

.tstep.is-open .tstep-head .icon { transform: rotate(90deg); color: var(--color-ink); }
.tstep-head:hover .tstep-cap { color: var(--color-primary); }

.tstep-index {
  font-size: 10px;
  color: var(--color-muted-soft);
}

.tstep-cap {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--color-ink);
  overflow: hidden;
  text-overflow: ellipsis;
}

.tstep-delta {
  font-size: 10.5px;
  color: var(--color-muted-soft);
}

.tstep-body { padding: 0 var(--space-base) var(--space-sm) 0; }

.kv {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 2px var(--space-xs);
  margin: 0 0 var(--space-xs);
  font-size: 12px;
}

.kv dt { color: var(--color-muted-soft); }
.kv dd { margin: 0; color: var(--color-body); word-break: break-word; }

/* ---------- Your setup: granted tools, grouped by toolset ---------- */

.toolset {
  border-top: 1px solid var(--color-hairline-soft);
}

.toolset:first-child { border-top: 0; }
.toolset[open]:last-child .toolset-grid,
.toolset[open]:last-child .toolset-other { padding-bottom: 0; }

.toolset-header {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-xs);
  margin: var(--space-xxs) calc(-1 * var(--space-xs));
  border-radius: var(--radius-sm);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.toolset-header::-webkit-details-marker { display: none; }
.toolset-header:hover { background: var(--color-canvas-soft); }
.toolset-header .icon { color: var(--color-muted); }

.toolset-chevron {
  display: inline-flex;
  color: var(--color-muted-soft);
}

.toolset-chevron .icon { transition: transform 0.15s ease; }
.toolset[open] .toolset-chevron .icon { transform: rotate(90deg); }

.toolset-name {
  font-weight: 600;
  color: var(--color-ink);
}

.toolset-header .help { margin-left: auto; }

.toolset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-sm) var(--space-base);
  padding: var(--space-xxs) 0 var(--space-base);
}

@media (max-width: 900px) {
  .toolset-grid { grid-template-columns: minmax(0, 1fr); }
}

.toolset-other {
  flex-wrap: wrap;
  gap: var(--space-xxs);
  padding: var(--space-xxs) 0 var(--space-base);
}

.tool-entry {
  min-width: 0;
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-md);
}

.tool-entry-name {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 14px;
  color: var(--color-ink);
}

.tool-entry-desc {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--color-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tool-entry-cap {
  display: block;
  margin-top: var(--space-xxs);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-muted-soft);
  word-break: break-all;
}

.pill-level {
  padding: 1px 7px;
  font-size: 10px;
  letter-spacing: 0.6px;
}

.pill-level-view { background: var(--color-surface-strong); color: var(--color-muted); }
.pill-level-edit { background: rgba(245, 78, 0, 0.12); color: var(--color-primary-active); }

.tag-text {
  font-family: inherit;
  font-size: 12px;
  color: var(--color-body);
}

/* The hidden attribute must win over component display rules. */
[hidden] { display: none !important; }

/* ---------- Delegation (agent → subagent) ---------- */

.graph-link.is-delegate { stroke: rgba(137, 112, 168, 0.62); stroke-width: 2; }

.graph-svg.is-idle .graph-link:not(.is-hover):not(.is-picked).is-delegate { stroke-width: 1.5; }

/* Drawn mid-edge chevrons rather than markers: the arrow belongs in the middle
   of the curve, and a reciprocal pair needs two of them on one path. */
.graph-delegation-arrow {
  fill: none;
  stroke: rgba(106, 82, 137, 0.88);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.graph-svg.is-idle .graph-delegation-arrow:not(.is-hover):not(.is-picked) { stroke-opacity: 0.45; }

.graph-delegation-arrow.is-hover { stroke-opacity: 1; }
.graph-delegation-arrow.is-picked { stroke: var(--color-primary); stroke-width: 2; }

.legend-arrow { width: 22px; height: 8px; vertical-align: middle; overflow: visible; }

.lvl-delegate { background: rgba(137, 112, 168, 0.24); color: #4f4171; }

.delegate-switch-label { font-size: 13px; color: var(--color-ink); }

/* ---------- Effective access (person panel) ---------- */

.person-tabs {
  gap: var(--space-base);
  margin-bottom: var(--space-base);
}

.person-tabs .tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  font-family: var(--font-ui);
  cursor: pointer;
}

/* The button reset above re-declares the border shorthand, so the active
   underline has to be restated at higher specificity. */
.person-tabs .tab.is-active { border-bottom-color: var(--color-primary); }

.person-tabs .tab-secondary { color: var(--color-muted-soft); font-weight: 400; }

.person-tabs .tab-secondary.is-active { color: var(--color-body); font-weight: 500; }

.eff-provider { margin: 10px 0 2px; }

/* Long capability codes and multi-chip provenance must never widen the row:
   the code ellipsizes and the chips wrap, so the widest row cannot push every
   right-aligned chip past the card edge. */
.prow.eff-row .panel-name-row { flex: 1 1 auto; }

.prow.eff-row .prow-name { flex-shrink: 0; }

.prow.eff-row .panel-sub {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prow.eff-row .panel-controls {
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  row-gap: 2px;
}

.lvl-direct { background: var(--color-hairline-soft); color: var(--color-body); }

.lvl-via {
  background: rgba(137, 112, 168, 0.18);
  color: #4f4171;
  font-weight: 500;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
}

/* A capability the person cannot reach directly: present so an admin can see
   what delegation exposes, whispered so it never reads as their own access. */
.prow.is-agent-only { opacity: 0.55; }

.lvl-agent-only {
  background: none;
  border: 1px dashed var(--color-hairline-strong);
  color: var(--color-muted);
  font-weight: 500;
}
