/* ============================================================
   Agent Registry — Components
   ============================================================ */

/* ============================================================
   BUTTON
   variants: primary | secondary | ghost | danger
   sizes:    md (default 28px) | sm (24px) | lg (32px)
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  font: var(--fw-medium) var(--fs-body)/1 var(--font-sans);
  letter-spacing: var(--tracking-tight);
  white-space: nowrap;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  transition:
    background var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out),
    box-shadow var(--motion-fast) var(--ease-out);
  user-select: none;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
/* Microsoft 4-square logo on the sign-in button — keep its own
   colours + a slightly larger footprint than monochrome btn icons. */
.btn svg.ms-logo { width: 16px; height: 16px; }

.btn--sm { height: 24px; padding: 0 var(--space-2); font-size: var(--fs-small); }
.btn--lg { height: 32px; padding: 0 var(--space-4); font-size: var(--fs-body); }

/* primary */
.btn--primary {
  background: var(--accent-solid);
  color: var(--accent-on-solid);
  border-color: var(--accent-solid);
}
.btn--primary:hover {
  background: var(--accent-solid-hover);
  border-color: var(--accent-solid-hover);
}
.btn--primary:active { background: var(--accent-solid-active); }

/* success — solid green; used for the high-emphasis admin-consent CTA */
.btn--success {
  background: var(--success-solid);
  border-color: var(--success-solid);
  color: #fff;
  font-weight: var(--fw-semibold);
}
.btn--success:hover {
  background: color-mix(in oklch, var(--success-solid) 88%, black);
  border-color: color-mix(in oklch, var(--success-solid) 88%, black);
}
.btn--success:active { background: color-mix(in oklch, var(--success-solid) 78%, black); }
.btn--success svg { width: 16px; height: 16px; }

/* secondary — bordered */
.btn--secondary {
  background: var(--bg-surface);
  border-color: var(--border-default);
  color: var(--text-primary);
}
.btn--secondary:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}
.btn--secondary:active { background: var(--bg-surface); }

/* ghost — no border, hover bg */
.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn--ghost:hover { background: var(--bg-surface); color: var(--text-primary); }
.btn--ghost:active { background: var(--bg-elevated); }

/* danger */
.btn--danger {
  background: var(--danger-solid);
  color: var(--danger-on-solid);
  border-color: var(--danger-solid);
}
.btn--danger:hover { background: var(--danger-solid-hover); border-color: var(--danger-solid-hover); }

/* icon-only — square */
.btn--icon {
  width: 28px;
  padding: 0;
}
.btn--icon.btn--sm { width: 24px; }
.btn--icon.btn--lg { width: 32px; }

/* ============================================================
   INPUT / SELECT / SEARCH
   ============================================================ */

.input,
.select {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 var(--space-3);
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font: var(--fw-regular) var(--fs-body)/1 var(--font-sans);
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
  min-width: 0;
}

.input::placeholder { color: var(--text-tertiary); }

.input:hover,
.select:hover { border-color: var(--border-strong); }

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px oklch(from var(--border-focus) l c h / 0.20);
}

.input--lg, .select--lg { height: 32px; }

/* Select pseudo (we render a button for the mockup) */
.select {
  gap: var(--space-2);
  cursor: pointer;
  background-image: linear-gradient(transparent, transparent),
                    linear-gradient(transparent, transparent);
}

/* Search input wrapper — icon left, clear right */
.search {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 240px;
}
.search__icon {
  position: absolute;
  left: var(--space-3);
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
  pointer-events: none;
}
.search .input {
  padding-left: 30px;
  padding-right: 28px;
  width: 100%;
}
.search__clear {
  position: absolute;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
}
.search__clear:hover { background: var(--bg-elevated); color: var(--text-primary); }
.search__clear svg { width: 10px; height: 10px; }

/* Date-range trigger — looks like a select with a divider */
.daterange {
  display: inline-flex;
  align-items: center;
  height: 28px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: var(--fs-body);
  color: var(--text-primary);
  overflow: hidden;
}
.daterange:hover { border-color: var(--border-strong); }
.daterange__seg { padding: 0 var(--space-3); display: flex; align-items: center; gap: 6px; height: 100%; }
.daterange__seg svg { width: 12px; height: 12px; color: var(--text-tertiary); }
.daterange__divider { width: 1px; height: 16px; background: var(--border-subtle); }

/* ============================================================
   FILTER CHIP — toggleable, with count
   ============================================================ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-default);
  background: var(--bg-input);
  color: var(--text-secondary);
  font: var(--fw-medium) var(--fs-small)/1 var(--font-sans);
  transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
  white-space: nowrap;
}
.chip:hover { background: var(--bg-elevated); color: var(--text-primary); }

.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: oklch(from var(--accent-soft) calc(l + 0.06) c h);
  color: var(--accent-text);
}

.chip__swatch {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.chip__count {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: oklch(from currentColor l c h / 0.18);
  color: inherit;
}

/* ============================================================
   BADGE — source + status
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  font: var(--fw-medium) 11px/1 var(--font-sans);
  letter-spacing: var(--tracking-wide);
  white-space: nowrap;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}

/* sources */
.badge--teams   { background: var(--src-teams-soft);   color: var(--src-teams-text); }
.badge--pplat   { background: var(--src-pplat-soft);   color: var(--src-pplat-text); }
.badge--foundry { background: var(--src-foundry-soft); color: var(--src-foundry-text); }
.badge--agentid { background: var(--src-agentid-soft); color: var(--src-agentid-text); }
.badge--securitycopilot { background: var(--src-securitycopilot-soft); color: var(--src-securitycopilot-text); }
.badge--mdapp { background: var(--src-pplat-soft); color: var(--src-pplat-text); }

/* statuses */
.badge--success { background: var(--success-soft); color: var(--success-text); }
.badge--warn    { background: var(--warn-soft);    color: var(--warn-text); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger-text); }
.badge--info    { background: var(--info-soft);    color: var(--info-text); }
.badge--muted   { background: var(--bg-elevated);  color: var(--text-tertiary); }
.badge--new     { background: var(--info-soft);    color: var(--info-text); font-weight: 600; letter-spacing: 0.02em; }
.badge--reviewed { background: var(--success-soft); color: var(--success-text); font-weight: 600; }
/* Reviewed agents render their name in green so the triage state
   reads at a glance, in the table row and the side-panel title. */
.tbl__name-text--reviewed { color: var(--success-text); }
.side-panel__title--reviewed { color: var(--success-text); }
.reviewed-note {
  background: var(--success-soft);
  color: var(--success-text);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-small);
  margin-bottom: var(--space-3);
}

.badge--ghost {
  background: transparent;
  color: var(--text-tertiary);
  border: 1px solid var(--border-subtle);
  padding: 0 7px;
}

/* ============================================================
   BANNER — info, warn, danger
   ============================================================ */

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-3) 0 0;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  font-size: var(--fs-body);
}

.banner__icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex-shrink: 0;
}

.banner__body { flex: 1; min-width: 0; }

.banner__title {
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}

.banner__msg {
  color: var(--text-secondary);
  margin-top: 2px;
}

.banner__msg a, .banner__action {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: oklch(from currentColor l c h / 0.4);
  text-underline-offset: 2px;
  font-weight: var(--fw-medium);
  background: none;
  cursor: pointer;
}

.banner__actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  margin-left: var(--space-3);
  flex-shrink: 0;
}

.banner--warn {
  background: oklch(from var(--warn-soft) l c h / 0.45);
  border-color: oklch(from var(--warn-solid) l c h / 0.30);
  color: var(--warn-text);
}
.banner--warn .banner__icon { color: var(--warn-text); }

/* Post-sign-in consent-gap banner: lists every scope whose token
   acquisition failed, with a one-click re-consent action.  Lives
   in the same #bannerSlot as the partial-visibility banner. */
/* Consent focus-lock: when the consent banner is showing on the
   Overview, hide every other direct child of #mainOverview so the
   admin focuses on consenting first.  The banner slot + the banner
   itself stay visible.  Released by either dismissing the banner
   (button) or by the gaps clearing after a successful consent. */
#mainOverview[data-consent-lock="on"] > *:not(#overviewBannerSlot) { display: none; }
#mainOverview[data-consent-lock="on"] > #overviewBannerSlot { margin-top: var(--space-5); }

.consent-banner__list {
  margin: var(--space-2) 0 var(--space-3);
  padding-left: var(--space-5);
  font-size: var(--fs-small);
  line-height: 1.6;
  color: var(--text-secondary);
}
.consent-banner__list li { margin-bottom: 4px; }
.consent-banner__list code {
  font-size: 10px;
  background: var(--bg-app);
  padding: 1px 4px;
  border-radius: 3px;
}
.consent-banner__actions { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-3); }
/* Make the primary consent CTA stand out — taller + roomier than a
   standard btn--lg, with the green success palette. */
#consentBannerGrantBtn, [id^="consentBannerGrantBtn_"] {
  height: 40px;
  padding: 0 var(--space-5);
  font-size: var(--fs-body);
  gap: var(--space-2);
}
/* Expandable "What will be added?" section enumerating every scope
   the chained admin-consent flow requests, grouped by resource. */
.consent-banner__details { margin: var(--space-2) 0; }
.consent-banner__details > summary {
  cursor: pointer;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  padding: 4px 0;
  list-style: revert;
}
.consent-banner__details[open] > summary { color: var(--text-primary); }
.consent-banner__lead {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: var(--space-2) 0 var(--space-3);
}
.consent-banner__resource {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
}
.consent-banner__resource-h {
  font-size: 11px;
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.consent-banner__scopes {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 11px;
  line-height: 1.7;
}
.consent-banner__scopes code {
  font-size: 10px;
  background: var(--bg-elevated);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--text-primary);
}
.consent-banner__scopes .muted { color: var(--text-tertiary); }

.banner--info {
  background: oklch(from var(--info-soft) l c h / 0.45);
  border-color: oklch(from var(--info-solid) l c h / 0.30);
  color: var(--info-text);
}
.banner--info .banner__icon { color: var(--info-text); }

.banner--danger {
  background: oklch(from var(--danger-soft) l c h / 0.55);
  border-color: oklch(from var(--danger-solid) l c h / 0.35);
  color: var(--danger-text);
}
.banner--danger .banner__icon { color: var(--danger-text); }

/* ============================================================
   VIRTUALIZED TABLE
   role="grid" with row & cell roles; sticky header.
   ============================================================ */

.tbl {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--bg-app);
  font-size: var(--fs-body);
  min-height: 0;
}

.tbl__head,
.tbl__row {
  display: grid;
  /* columns: select | name | source | publisher | type | env | created | modified | canDelete | actions
     Source col is 180px to fit the longest badge label "SharePoint Agents"
     (17 chars) plus leading dot + padding. Narrower clipped the badge
     under .tbl__cell's overflow: hidden + text-overflow: ellipsis. */
  grid-template-columns:
    36px
    minmax(220px, 1.8fr)
    180px
    minmax(180px, 1.3fr)
    120px
    minmax(160px, 1fr)
    120px
    120px
    72px
    44px;
  align-items: center;
}

.tbl__head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border-subtle);
  height: 36px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.tbl__hcell {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-3);
  height: 100%;
  user-select: none;
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tbl__hcell--sortable { cursor: pointer; }
.tbl__hcell--sortable:hover { color: var(--text-secondary); }
.tbl__hcell[aria-sort="ascending"],
.tbl__hcell[aria-sort="descending"] { color: var(--text-secondary); }
.tbl__hcell svg { width: 10px; height: 10px; opacity: 0.7; }

.tbl__body {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  /* Reserve the scrollbar gutter so filtering between row counts that fit /
     don't fit the viewport doesn't shift columns horizontally. */
  scrollbar-gutter: stable;
}

.tbl__row {
  height: var(--row-h);
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--motion-fast);
  cursor: pointer;
  color: var(--text-secondary);
}

.tbl__row:hover {
  background: var(--bg-row-hover);
  color: var(--text-primary);
}

.tbl__row[aria-selected="true"] {
  background: var(--bg-row-selected);
  color: var(--text-primary);
  box-shadow: inset 2px 0 0 var(--accent-solid);
}

.tbl__cell {
  padding: 0 var(--space-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.tbl__cell--primary {
  color: var(--text-primary);
  font-weight: var(--fw-medium);
}

.tbl__cell--mono {
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.tbl__cell--num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  justify-content: flex-end;
}

.tbl__cell--center { justify-content: center; }

.tbl__name {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.tbl__name-mark {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: var(--fw-semibold);
  flex-shrink: 0;
}

.tbl__name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tbl__checkbox {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: 3px;
  background: var(--bg-input);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color var(--motion-fast), background var(--motion-fast);
}
.tbl__checkbox:hover { border-color: var(--accent-solid); }
.tbl__checkbox[aria-checked="true"] {
  background: var(--accent-solid);
  border-color: var(--accent-solid);
}
.tbl__checkbox[aria-checked="true"]::after {
  content: "";
  width: 7px;
  height: 4px;
  border-left: 1.5px solid var(--accent-on-solid);
  border-bottom: 1.5px solid var(--accent-on-solid);
  transform: rotate(-45deg) translate(1px, -1px);
}

.tbl__row-actions {
  opacity: 0;
  transition: opacity var(--motion-fast);
}
.tbl__row:hover .tbl__row-actions,
.tbl__row[aria-selected="true"] .tbl__row-actions { opacity: 1; }

/* ============================================================
   SIDE PANEL — right-sliding, ESC to close
   ============================================================ */

.side-panel {
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  position: relative;
  /* Always-on z-index + isolation creates a stacking context, so
     the sticky table headers (z-index: 2) inside the adjacent grid
     column can't bleed through the panel.  z-index alone wasn't
     enough at wide viewports where the panel sits in a grid cell
     without its own stacking context. */
  z-index: 10;
  isolation: isolate;
  animation: slideInFromRight var(--motion-panel) var(--ease-out);
}

/* Drag handle on the left edge — 8px hit zone for easier grabbing,
   with a faint always-visible vertical line so users discover it,
   and a stronger accent line on hover / drag.  Cursor flips to
   col-resize.  Width is persisted via localStorage in app.js. */
.side-panel__resize {
  position: absolute;
  top: 0; bottom: 0;
  left: -4px;
  width: 8px;
  cursor: col-resize;
  z-index: 30;
  /* Always-visible faint line in the center of the hit zone so the
     handle is discoverable without hovering. */
  background: linear-gradient(to right,
    transparent 0,
    transparent calc(50% - 1px),
    var(--border-default) calc(50% - 1px),
    var(--border-default) calc(50% + 1px),
    transparent calc(50% + 1px),
    transparent 100%);
}
.side-panel__resize:hover, .side-panel__resize:active,
.side-panel.is-resizing .side-panel__resize {
  background: linear-gradient(to right,
    transparent 0,
    transparent calc(50% - 1.5px),
    var(--accent-solid) calc(50% - 1.5px),
    var(--accent-solid) calc(50% + 1.5px),
    transparent calc(50% + 1.5px),
    transparent 100%);
}
.side-panel.is-resizing {
  /* Disable transitions / animations while dragging so the panel
     follows the cursor 1:1 — even a 120ms transition feels laggy
     against a drag. */
  animation: none !important;
  transition: none !important;
}
.side-panel.is-resizing,
.side-panel.is-resizing * {
  user-select: none;
}

@keyframes slideInFromRight {
  from { transform: translateX(16px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.side-panel__header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  /* Explicit opaque background so the agent display name is never
     visually overlapped by anything painting underneath — table
     headers especially.  The panel root also creates a stacking
     context (above) so this is belt-and-braces. */
  background: var(--bg-surface);
  position: relative;
  z-index: 2;
}

.side-panel__title-wrap {
  flex: 1;
  min-width: 0;
}

.side-panel__title {
  margin: 0;
  font-size: var(--fs-h2);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--lh-tight);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-panel__meta {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-2);
  font-size: var(--fs-small);
  color: var(--text-tertiary);
}

.side-panel__close {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  transition: background var(--motion-fast);
}
.side-panel__close:hover { background: var(--bg-elevated); color: var(--text-primary); }
.side-panel__close svg { width: 14px; height: 14px; }

.side-panel__actions {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-app);
}

.side-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.side-panel__section-label {
  font-size: 11px;
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin: 0 0 var(--space-3);
}

/* Key/value grid */
.kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: var(--space-2) var(--space-4);
  font-size: var(--fs-body);
}
.kv dt {
  color: var(--text-tertiary);
  padding-top: 2px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.kv__icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  color: var(--text-tertiary);
  opacity: 0.85;
}
.kv dd {
  margin: 0;
  color: var(--text-primary);
  word-break: break-word;
}
.kv dd.mono {
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  color: var(--text-secondary);
}

/* Inline limited-visibility state in detail panel */
.panel-empty {
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  gap: var(--space-3);
  background: oklch(from var(--warn-soft) l c h / 0.18);
}
.panel-empty__icon {
  width: 20px;
  height: 20px;
  color: var(--warn-text);
  flex-shrink: 0;
  margin-top: 2px;
}
.panel-empty__title {
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  margin: 0 0 var(--space-2);
  font-size: var(--fs-body);
}
.panel-empty__msg {
  color: var(--text-secondary);
  font-size: var(--fs-body);
  margin: 0 0 var(--space-3);
}
.panel-empty__link {
  font-size: var(--fs-small);
  color: var(--accent-text);
  font-weight: var(--fw-medium);
}

/* ============================================================
   JSON viewer (read-only)
   ============================================================ */

.json {
  position: relative;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  line-height: 1.55;
  color: var(--text-secondary);
  overflow: auto;
  max-height: 240px;
}
.json__copy {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: color var(--motion-fast), background var(--motion-fast);
}
.json__copy:hover { color: var(--text-primary); background: var(--bg-elevated); }
.json__copy svg { width: 12px; height: 12px; }
.json .k { color: var(--accent-text); }
.json .s { color: var(--success-text); }
.json .n { color: var(--warn-text); }
.json .b { color: var(--info-text); }

/* ============================================================
   TOAST — top-right, auto-dismiss (styling only)
   ============================================================ */

.toast-stack {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  align-items: flex-end;     /* keep each toast right-aligned, never centered */
  gap: 10px;                 /* explicit, slightly wider than space-2 so the stack reads as distinct rows */
  z-index: 80;
  pointer-events: none;
  max-height: calc(100vh - var(--space-5) * 2);
  overflow-y: auto;
  scrollbar-width: thin;
}
/* Shove the toast stack to the LEFT of the side panel when it's
   open — otherwise the toasts cover the panel header (title +
   close button), which is the bug the user kept hitting where the
   agent's name disappeared after expanding the panel.  Drives off
   the same --panel-w variable JS writes during resize, so the
   offset always tracks the real panel width. */
.content[data-panel="open"] ~ .toast-stack,
body:has(.content[data-panel="open"]) .toast-stack {
  right: calc(var(--panel-w, 440px) + var(--space-5));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  /* Fixed width — every toast renders at the same size regardless of
     content length, so a stack of enrichment toasts reads as a uniform
     column instead of a jagged ladder of widths. Long messages wrap;
     short ones still occupy the full chip. */
  width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-body);
  color: var(--text-primary);
  pointer-events: auto;
  /* Slide-in from the right so multiple toasts firing close together
     visibly arrive one-by-one instead of appearing as a wall. */
  animation: toast-in 220ms var(--ease-out);
  flex-shrink: 0;            /* never compress when the stack overflows */
  box-sizing: border-box;
}
.toast__body { min-width: 0; }              /* allow .toast__msg to wrap properly */
.toast__msg  { word-break: break-word; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast__icon { width: 16px; height: 16px; margin-top: 2px; flex-shrink: 0; color: var(--success-text); }
.toast__body { flex: 1; }
.toast__title { font-weight: var(--fw-medium); }
.toast__msg { color: var(--text-secondary); margin-top: 2px; font-size: var(--fs-small); }

/* ============================================================
   CONFIRM DIALOG — destructive only
   ============================================================ */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: grid;
  place-items: center;
  z-index: 90;
  animation: fadeIn var(--motion-base) var(--ease-out);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dialog {
  width: min(420px, calc(100vw - var(--space-7)));
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: var(--space-5);
  animation: dialogIn var(--motion-base) var(--ease-out);
}
@keyframes dialogIn {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
.dialog__title {
  font-size: var(--fs-h2);
  font-weight: var(--fw-semibold);
  margin: 0 0 var(--space-2);
}
.dialog__body { color: var(--text-secondary); font-size: var(--fs-body); margin: 0 0 var(--space-5); }
.dialog__actions { display: flex; gap: var(--space-2); justify-content: flex-end; }

/* ============================================================
   AUTH GATE CARD
   ============================================================ */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-7);
}
.auth-card {
  width: min(520px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-7);
  max-height: calc(100vh - var(--space-7) * 2);
  overflow-y: auto;
  box-shadow: var(--shadow-1);
}
.auth-card__brand { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-5); }
.auth-card__title { font-size: var(--fs-h1); font-weight: var(--fw-semibold); margin: 0 0 var(--space-2); }
.auth-card__msg   { color: var(--text-secondary); margin: 0 0 var(--space-5); font-size: var(--fs-body); }
.auth-card__field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-3); }
.auth-card__label { font-size: var(--fs-small); color: var(--text-secondary); font-weight: var(--fw-medium); }
.auth-card .input { height: 32px; width: 100%; font-family: var(--font-mono); font-size: var(--fs-mono); }
.auth-card__hint { color: var(--text-tertiary); font-size: 11px; line-height: 1.4; margin: 6px 0 0; }
.auth-card__hint a { color: inherit; text-decoration: underline; }
.auth-card__hint-details { margin-top: 6px; }
.auth-card__hint-details > summary {
  cursor: pointer;
  font-size: 11px;
  color: var(--text-tertiary);
  list-style: revert;
  padding: 2px 0;
}
.auth-card__hint-details[open] > summary { color: var(--text-secondary); margin-bottom: var(--space-2); }
.auth-card__hint-body {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.auth-card__hint-body p { margin: 0 0 var(--space-2); }
.auth-card__hint-body ol { margin: 0 0 var(--space-2); padding-left: var(--space-5); }
.auth-card__hint-body ol > li { margin-bottom: 6px; }
.auth-card__hint-body ol > li:last-child { margin-bottom: 0; }
.auth-card__hint-body a { color: var(--accent); text-decoration: underline; }
.auth-card__hint-body code { font-size: 11px; background: var(--bg-app); padding: 1px 4px; border-radius: 3px; }
.auth-card__hint-callout {
  background: var(--info-soft);
  color: var(--info-text);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-2);
  font-size: 12px;
}
.auth-card__hint-callout strong { color: inherit; }
.auth-card__hint-code {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-3);
  font-size: 11px;
  font-family: var(--font-mono);
  overflow-x: auto;
  white-space: pre;
  color: var(--text-primary);
}
.auth-card__hint-code code { background: none; padding: 0; border-radius: 0; }
.auth-card__hint-foot { color: var(--text-tertiary); font-size: 11px; margin: var(--space-2) 0 0; }
.auth-card__note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin: 0 0 var(--space-4);
}
.auth-card__note strong { color: var(--text-primary); }
.auth-card__note code { font-size: 11px; }
.auth-advanced { margin-top: var(--space-4); border-top: 1px solid var(--border-subtle); padding-top: var(--space-3); }
.auth-advanced > summary { cursor: pointer; font-size: var(--fs-small); color: var(--text-tertiary); padding: var(--space-1) 0; list-style: revert; }
.auth-advanced[open] > summary { color: var(--text-secondary); margin-bottom: var(--space-2); }
.auth-advanced__msg { color: var(--text-tertiary); font-size: var(--fs-small); margin: 0 0 var(--space-3); line-height: 1.4; }

/* Permissions panel on the sign-in card — collapsible by default so
   the primary action (Sign in with Microsoft) stays the focal point.
   Expanded, it walks the user through every scope + role required. */
.auth-perms { margin-top: var(--space-4); }
/* Render the disclosure trigger as a plain text link. */
.auth-perms > summary {
  cursor: pointer;
  font-size: var(--fs-small);
  color: var(--accent-text);
  text-decoration: underline;
  padding: var(--space-1) 0;
  list-style: none;
  width: fit-content;
}
.auth-perms > summary::-webkit-details-marker { display: none; }
.auth-perms > summary:hover { opacity: 0.8; }
.auth-perms[open] > summary { margin-bottom: var(--space-3); }
.auth-perms__hint { color: var(--text-tertiary); font-size: 11px; font-weight: var(--fw-normal); margin-left: auto; }
.auth-perms__lead { color: var(--text-secondary); font-size: var(--fs-small); line-height: 1.5; margin: 0 0 var(--space-3); }
.auth-perms__lead--tight { margin-top: var(--space-2); }
.auth-perms__h { font-size: 12px; font-weight: var(--fw-semibold); color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin: var(--space-3) 0 var(--space-2); }
/* table-layout:fixed + wrapping keeps both columns inside the card
   (long scope / role names previously forced horizontal overflow
   and a scrollbar; the right column got clipped). */
.auth-perms__tbl { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 12px; margin-bottom: var(--space-2); }
.auth-perms__tbl th { text-align: left; font-weight: var(--fw-medium); color: var(--text-tertiary); padding: 4px 10px 4px 0; border-bottom: 1px solid var(--border-subtle); font-size: 11px; }
.auth-perms__tbl td { padding: 6px 10px 6px 0; vertical-align: top; color: var(--text-secondary); border-bottom: 1px solid var(--border-subtle); overflow-wrap: anywhere; word-break: break-word; }
.auth-perms__tbl tr:last-child td { border-bottom: none; }
/* First column ~45% (scope / role), second column takes the rest. */
.auth-perms__tbl td:first-child, .auth-perms__tbl th:first-child { width: 45%; }
.auth-perms__tbl td:first-child { font-family: var(--font-mono); font-size: 11px; color: var(--text-primary); white-space: normal; }
.auth-perms__tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-family: var(--font-sans);
  background: var(--bg-elevated);
  color: var(--text-tertiary);
  border-radius: var(--radius-pill);
  vertical-align: 1px;
}
/* Opt-in ReadWrite scopes — warn-tinted so the elevated-privilege
   tag stands apart from the neutral "preview" tag. */
.auth-perms__tag--warn {
  background: var(--warn-soft);
  color: var(--warn-text);
}
.auth-perms__foot { color: var(--text-tertiary); font-size: 11px; line-height: 1.5; margin: var(--space-3) 0 0; }

/* ============================================================
   SKELETON LOADING ROW
   ============================================================ */
.skel {
  display: inline-block;
  /* Three-stop gradient with a brighter accent-tinted highlight, so the
     shimmer is actually visible against the dark surface. */
  background: linear-gradient(90deg,
    var(--bg-elevated) 0%,
    oklch(from var(--bg-elevated) calc(l + 0.05) c h) 40%,
    oklch(from var(--accent-solid) l c h / 0.18) 50%,
    oklch(from var(--bg-elevated) calc(l + 0.05) c h) 60%,
    var(--bg-elevated) 100%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  height: 10px;
  animation: shimmer 1.6s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

/* ----- Loading: spinner + topbar pill ----- */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  position: relative;
  /* Conic gradient that fades to transparent — looks like a comet trail
     rather than a single bright tick. Masked into a ring with a thicker
     stroke so it reads at a glance. */
  background: conic-gradient(from 0deg, transparent 0deg, var(--accent-solid) 320deg, var(--accent-solid-hover) 360deg);
  mask: radial-gradient(circle, transparent 5px, #000 6px);
  -webkit-mask: radial-gradient(circle, transparent 5px, #000 6px);
  animation: spin 0.9s cubic-bezier(0.5, 0.1, 0.5, 0.9) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#refreshBtn .spinner { display: none; margin-right: 6px; vertical-align: -3px; }
#refreshBtn.is-loading .spinner { display: inline-block; }

/* Always-visible loading pill in the topbar.
   Subtle gradient bg, a soft accent glow, and a slow breathing pulse so it
   reads as 'alive and working' without being noisy. */
.topbar__loading {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: var(--space-4);
  padding: 6px 14px 6px 12px;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  background: linear-gradient(135deg,
    oklch(from var(--accent-solid) l c h / 0.10),
    oklch(from var(--accent-solid) l c h / 0.04));
  border: 1px solid oklch(from var(--accent-solid) l c h / 0.28);
  border-radius: var(--radius-pill);
  box-shadow: 0 0 0 0 oklch(from var(--accent-solid) l c h / 0.45);
  animation: pill-pulse 2.2s ease-in-out infinite;
  position: relative;
  overflow: hidden;
}
.topbar__loading[hidden] { display: none; }

/* Sheen that sweeps across the pill, reinforcing the 'progress' feel. */
.topbar__loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg,
    transparent 30%,
    oklch(from var(--accent-solid) l c h / 0.18) 50%,
    transparent 70%);
  transform: translateX(-100%);
  animation: pill-sheen 2.2s ease-in-out infinite;
  pointer-events: none;
}
.topbar__loading > * { position: relative; z-index: 1; }

@keyframes pill-pulse {
  0%, 100% { box-shadow: 0 0 0 0 oklch(from var(--accent-solid) l c h / 0.35); }
  50%      { box-shadow: 0 0 0 6px oklch(from var(--accent-solid) l c h / 0); }
}
@keyframes pill-sheen {
  0%   { transform: translateX(-100%); }
  60%  { transform: translateX(100%); }
  100% { transform: translateX(100%); }
}

/* Respect reduced-motion: drop the sweeping/pulsing decorations, keep the
   spinner barely rotating so users still see *something* is happening. */
@media (prefers-reduced-motion: reduce) {
  .spinner            { animation-duration: 2s; animation-timing-function: linear; }
  .topbar__loading    { animation: none; }
  .topbar__loading::after { animation: none; display: none; }
}

/* ============================================================
   UTILS
   ============================================================ */
.muted { color: var(--text-tertiary); }
.mono  { font-family: var(--font-mono); font-size: var(--fs-mono); font-variant-numeric: tabular-nums; }
.row   { display: flex; align-items: center; gap: var(--space-2); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
