/* ============================================================
   AI Hub — Scoped styles
   All aih-* classes live here. Loaded only when the AI Hub
   portal is active. Design tokens from css/variables.css apply
   globally; only the three AI-Hub-specific tint gaps are defined
   as scoped vars below.
   ============================================================ */

/* ── AI Hub scoped colour vars (the 3 token-gap tints) ── */
:root {
  /* Watermark / approval tints — E3 full implementation */
  --aih-watermark-valid-bg:     rgba(34, 197, 94, 0.14);
  --aih-watermark-valid-border: rgba(34, 197, 94, 0.35);
  --aih-watermark-outdated-bg:  rgba(95, 103, 117, 0.16);
  --aih-watermark-outdated-border: rgba(95, 103, 117, 0.32);
  --aih-watermark-pending-bg:   rgba(245, 158, 11, 0.14);
  --aih-watermark-pending-border: rgba(245, 158, 11, 0.40);

  /* Diff view tints (add / delete) */
  --aih-diff-add-bg:      rgba(34, 197, 94, 0.12);
  --aih-diff-add-swatch:  rgba(34, 197, 94, 0.22);
  --aih-diff-add-border:  rgba(34, 197, 94, 0.40);
  --aih-diff-ins-bg:      rgba(34, 197, 94, 0.35);
  --aih-diff-del-bg:      rgba(239, 68, 68, 0.12);
  --aih-diff-del-swatch:  rgba(239, 68, 68, 0.22);
  --aih-diff-del-border:  rgba(239, 68, 68, 0.40);
  --aih-diff-del-ins-bg:  rgba(239, 68, 68, 0.35);

  /* Doc-type badge hues (background tints + light-mode overrides) */
  --aih-badge-claude-md-bg:    rgba(124, 58, 237, 0.14);
  --aih-badge-agents-md-bg:    rgba(109, 40, 217, 0.14);
  --aih-badge-rules-bg:        rgba(91, 33, 182, 0.14);
  --aih-badge-output-style-bg: rgba(139, 92, 246, 0.14);
  --aih-badge-skill-bg:        rgba(37, 99, 235, 0.14);
  --aih-badge-agent-bg:        rgba(8, 145, 178, 0.14);
  --aih-badge-command-bg:      rgba(217, 119, 6, 0.14);
  --aih-badge-spec-bg:         rgba(79, 70, 229, 0.14);
  --aih-badge-design-bg:       rgba(6, 182, 212, 0.14);
  --aih-badge-prd-bg:          rgba(16, 185, 129, 0.14);
  --aih-badge-adr-bg:          rgba(234, 88, 12, 0.14);
  --aih-badge-runbook-bg:      rgba(220, 38, 38, 0.14);
  --aih-badge-doc-bg:          rgba(52, 211, 153, 0.14);
  --aih-badge-personal-bg:     rgba(107, 114, 128, 0.14);

  /* Document lifecycle stage tints */
  --aih-stage-draft-bg:              rgba(107, 114, 128, 0.14);
  --aih-stage-draft-border:          rgba(107, 114, 128, 0.32);
  --aih-stage-spec-bg:               rgba(99, 102, 241, 0.14);
  --aih-stage-spec-border:           rgba(99, 102, 241, 0.35);
  --aih-stage-design-bg:             rgba(37, 99, 235, 0.14);
  --aih-stage-design-border:         rgba(37, 99, 235, 0.35);
  --aih-stage-in-impl-bg:            rgba(245, 158, 11, 0.14);
  --aih-stage-in-impl-border:        rgba(245, 158, 11, 0.40);
  --aih-stage-shipped-bg:            rgba(34, 197, 94, 0.14);
  --aih-stage-shipped-border:        rgba(34, 197, 94, 0.35);
  --aih-stage-archived-bg:           rgba(95, 103, 117, 0.10);
  --aih-stage-archived-border:       rgba(95, 103, 117, 0.25);
}


/* ── Main content wrapper ── */
.aih-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ── */
.aih-topbar {
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  padding: 0 var(--space-8);
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 10;
}

.aih-topbar__title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3);
  font-weight: 700;
}

.aih-topbar__breadcrumb { font-size: var(--font-small); color: var(--text-secondary); }
.aih-topbar__breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.aih-topbar__breadcrumb a:hover { color: var(--color-action); }
.aih-topbar__sep { color: var(--text-tertiary); }
.aih-topbar__current { color: var(--text-primary); font-weight: 600; }

.aih-topbar__search {
  flex: 1;
  max-width: 480px;
  margin-left: auto;
}

.aih-topbar__actions { display: flex; gap: var(--space-2); align-items: center; margin-left: auto; }

/* ── Search ── */
.aih-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.aih-search-wrap svg {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
}
.aih-search-input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 36px;
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: 'Lato', sans-serif;
  font-size: var(--font-body);
  color: var(--text-primary);
  outline: none;
  box-sizing: border-box;
}
.aih-search-input::placeholder { color: var(--text-tertiary); }
.aih-search-input:focus {
  border-color: var(--color-action);
  box-shadow: 0 0 0 3px var(--color-action-muted);
}

/* ── Content area ── */
.aih-content {
  padding: var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

/* ── Feed section ── */
.aih-feed-section {}

.aih-feed-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.aih-feed-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h2);
  font-weight: 700;
}

.aih-phase-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(95, 103, 117, 0.14);
  color: var(--text-tertiary);
  border: 1px solid rgba(95, 103, 117, 0.25);
  white-space: nowrap;
}

.aih-feed-count {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

.aih-doc-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

/* ── Doc card ── */
.aih-doc-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.aih-doc-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.aih-doc-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: var(--space-2);
}

/* Leading type icon (coloured by type family) — replaces the old type pill */
.aih-doc-card__kind { flex-shrink: 0; display: inline-flex; align-items: center; margin-top: 2px; }
.aih-doc-card__kind > svg { display: block; }

.aih-doc-card__title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
}

/* Meta line: type-as-text + scope-as-icon (no pills) */
.aih-doc-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--font-small);
}
.aih-doc-card__typelabel { font-weight: 600; color: var(--text-secondary); }
.aih-doc-card__metasep { color: var(--text-tertiary); }
.aih-doc-card__scope { display: inline-flex; align-items: center; gap: 4px; color: var(--text-tertiary); }
.aih-doc-card__scope > svg { display: block; }

.aih-doc-card__tags { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.aih-doc-tag {
  font-size: 10px;
  font-family: 'Geist Mono', monospace;
  color: var(--text-tertiary);
  background: var(--bg-inset);
  padding: 1px 6px;
  border-radius: 4px;
}

.aih-doc-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
}

.aih-doc-card__last-edit {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
}

.aih-doc-card__version {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: var(--font-xs);
  color: var(--text-tertiary);
}

/* ── Doc type badges ── */
.aih-type-badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.aih-type-badge--claude-md { background: var(--aih-badge-claude-md-bg); color: #7C3AED; }
[data-theme="dark"] .aih-type-badge--claude-md { color: #A78BFA; }
.aih-type-badge--skill     { background: var(--aih-badge-skill-bg);     color: var(--color-action); }
.aih-type-badge--agent     { background: var(--aih-badge-agent-bg);     color: #0891B2; }
[data-theme="dark"] .aih-type-badge--agent { color: #22D3EE; }
.aih-type-badge--command   { background: var(--aih-badge-command-bg);   color: #D97706; }
[data-theme="dark"] .aih-type-badge--command { color: #FCD34D; }
.aih-type-badge--personal  { background: var(--aih-badge-personal-bg);  color: var(--text-secondary); }

/* ── Share-state pills ── */
.aih-share-pill {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 var(--space-2);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid transparent;
}
.aih-share-pill--private { background: rgba(95, 103, 117, 0.12); color: var(--text-tertiary); border-color: rgba(95, 103, 117, 0.25); }
.aih-share-pill--shared  { background: var(--color-action-muted); color: var(--color-action); border-color: var(--border-action); }
.aih-share-pill--public  { background: rgba(34, 197, 94, 0.14); color: var(--color-success); border-color: rgba(34, 197, 94, 0.35); }
[data-theme="light"] .aih-share-pill--public { color: #0E8A65; }
.aih-share-pill--pending { background: rgba(245, 158, 11, 0.14); color: var(--color-warning); border-color: rgba(245, 158, 11, 0.40); }
[data-theme="light"] .aih-share-pill--pending { color: #B45309; }

/* Sign-off badge on the initiative card header — FILLED (solid bg), distinct from the
   outlined status/risk pills, sits above the title. */
.aih-signoff-badge { font-weight: 700; border: none !important; letter-spacing: .02em; }
.aih-signoff-badge.aih-share-pill--public  { background: var(--color-success); color: #fff; }
.aih-signoff-badge.aih-share-pill--pending { background: var(--color-warning); color: #3a2705; }
.aih-signoff-badge.aih-share-pill--private { background: var(--bg-active);     color: var(--text-secondary); }

/* ── Watermark pills (E3 — inert in E1) ── */
.aih-watermark {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid transparent;
}
.aih-watermark--valid   { background: var(--aih-watermark-valid-bg);   color: var(--color-success);  border-color: var(--aih-watermark-valid-border); }
[data-theme="light"] .aih-watermark--valid { color: #0E8A65; }
.aih-watermark--outdated { background: var(--aih-watermark-outdated-bg); color: var(--text-secondary); border-color: var(--aih-watermark-outdated-border); }
.aih-watermark--pending  { background: var(--aih-watermark-pending-bg);  color: var(--color-warning);  border-color: var(--aih-watermark-pending-border); }
[data-theme="light"] .aih-watermark--pending { color: #B45309; }

/* ── Mono utility ── */
.aih-mono { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; }

/* ── Divider ── */
.aih-divider {
  border: none;
  border-top: 1px solid var(--border-default);
  margin: 0;
}

/* ── Later-phase faded section ── */
.aih-feed-section--later { opacity: 0.65; }
.aih-feed-section--later .aih-doc-list { pointer-events: none; }

/* ── Empty state mini ── */
.aih-empty-mini {
  padding: var(--space-8);
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--font-small);
  background: var(--bg-surface);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md);
}

/* ── Section label ── */
.aih-section-label {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin: var(--space-6) 0 var(--space-3);
}
.aih-section-label:first-child { margin-top: 0; }

/* ── Folder tree (workspace sidebar rail) ── */
.aih-folder-tree { padding: var(--space-3) 0; }
.aih-tree-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-5);
  font-size: var(--font-small);
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.aih-tree-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.aih-tree-item.active { color: var(--color-action); background: var(--color-action-ghost); }
.aih-tree-item__icon { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-tertiary); }
.aih-tree-item.active .aih-tree-item__icon { color: var(--color-action); }
.aih-tree-item--child { padding-left: calc(var(--space-5) + 18px); }
.aih-tree-item__count {
  margin-left: auto;
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* ── Workspace layout ── */
.aih-workspace-body { display: flex; flex: 1; min-height: 0; }

/* Folder rail */
.aih-folder-rail {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 56px);
}
.aih-folder-rail__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.aih-folder-rail__title {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Doc grid area */
.aih-doc-area { flex: 1; padding: var(--space-6) var(--space-8); min-width: 0; }

.aih-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}
.aih-toolbar__breadcrumb {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3);
  font-weight: 700;
  color: var(--text-primary);
}
.aih-toolbar__breadcrumb-sep { color: var(--text-tertiary); margin: 0 var(--space-1); }
.aih-toolbar__count {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.aih-sort-select {
  height: 32px;
  padding: 0 var(--space-3);
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: 'Lato', sans-serif;
  font-size: var(--font-small);
  color: var(--text-secondary);
  cursor: pointer;
  margin-left: auto;
}

/* Tag filter chips */
.aih-tag-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
.aih-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 26px;
  padding: 0 var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 999px;
  font-size: var(--font-xs);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.aih-tag-chip:hover { background: var(--bg-hover); color: var(--text-primary); }
.aih-tag-chip.active {
  background: var(--color-action-muted);
  border-color: var(--border-action);
  color: var(--color-action);
  font-weight: 600;
}
.aih-tag-label {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* Doc grid */
.aih-doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}

/* Folder card */
.aih-folder-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.aih-folder-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.aih-folder-card__icon { color: var(--color-warning); flex-shrink: 0; }
.aih-folder-card__name {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3);
  font-weight: 600;
}
.aih-folder-card__count {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
  font-variant-numeric: tabular-nums;
}

/* ── Doc page layout ── */
.aih-doc-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 0;
  flex: 1;
  min-height: 0;
}

.aih-doc-content {
  padding: var(--space-8);
  min-width: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
}

.aih-doc-header { margin-bottom: var(--space-6); }
.aih-doc-header__top {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.aih-doc-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h1);
  font-weight: 800;
  flex: 1;
  line-height: 1.25;
}

.aih-doc-header__meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
}

/* Read-only marker for imported packaged skills (source_kind='bundle') */
.aih-readonly-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full, 999px);
  padding: 2px 9px;
  white-space: nowrap;
}
.aih-readonly-pill svg { flex-shrink: 0; }

.aih-doc-last-edit { font-size: var(--font-small); color: var(--text-tertiary); }
.aih-doc-last-edit strong { color: var(--text-secondary); font-weight: 600; }

/* Rendered markdown */
.aih-md-body {
  font-size: var(--font-body);
  line-height: 1.7;
  color: var(--text-primary);
  max-width: 720px;
}
.aih-md-body h1 { font-family: 'Plus Jakarta Sans', sans-serif; font-size: 1.5rem; font-weight: 700; margin: var(--space-6) 0 var(--space-3); }
.aih-md-body h2 { font-family: 'Plus Jakarta Sans', sans-serif; font-size: 1.125rem; font-weight: 700; margin: var(--space-5) 0 var(--space-2); padding-bottom: var(--space-2); border-bottom: 1px solid var(--border-subtle); }
.aih-md-body h3 { font-family: 'Plus Jakarta Sans', sans-serif; font-size: 0.9375rem; font-weight: 700; margin: var(--space-4) 0 var(--space-2); }
.aih-md-body p  { margin: 0 0 var(--space-3); color: var(--text-primary); }
.aih-md-body code { font-family: 'Geist Mono', monospace; font-size: 0.8125rem; background: var(--bg-inset); padding: 2px 6px; border-radius: 4px; color: var(--text-primary); border: 1px solid var(--border-subtle); }
.aih-md-body pre { background: var(--bg-inset); border: 1px solid var(--border-default); border-radius: var(--radius-md); padding: var(--space-4); overflow-x: auto; margin: var(--space-4) 0; }
.aih-md-body pre code { background: none; border: none; padding: 0; font-size: 0.8125rem; }
.aih-md-body ul, .aih-md-body ol { padding-left: var(--space-6); margin: 0 0 var(--space-3); color: var(--text-primary); }
.aih-md-body li  { margin-bottom: var(--space-1); }
.aih-md-body strong { color: var(--text-primary); font-weight: 700; }
.aih-md-body blockquote { border-left: 3px solid var(--color-action-muted); padding-left: var(--space-4); color: var(--text-tertiary); margin: var(--space-4) 0; }
.aih-md-body hr  { border: none; border-top: 1px solid var(--border-default); margin: var(--space-6) 0; }

/* ── Edit mode ── */
.aih-edit-mode {
  margin-top: var(--space-8);
  padding-top: var(--space-8);
  border-top: 3px solid var(--border-default);
}
.aih-edit-mode__label {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-action);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.aih-edit-toolbar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.aih-edit-toolbar-btn {
  height: 28px;
  padding: 0 var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.aih-edit-toolbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-strong); }
.aih-md-textarea {
  width: 100%;
  min-height: 360px;
  box-sizing: border-box;
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  font-family: 'Geist Mono', monospace;
  font-size: 0.8125rem;
  color: var(--text-primary);
  line-height: 1.7;
  resize: vertical;
  outline: none;
}
.aih-md-textarea:focus { border-color: var(--color-action); box-shadow: 0 0 0 3px var(--color-action-muted); }
.aih-edit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
}
.aih-edit-footer__note { font-size: var(--font-xs); color: var(--text-tertiary); }
.aih-edit-footer__actions { display: flex; gap: var(--space-2); }

/* ── Version rail (doc page) ── */
.aih-version-rail {
  background: var(--bg-surface);
  padding: var(--space-6) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: calc(100vh - 56px);
}
.aih-rail-title {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}
.aih-version-entry {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-base);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.aih-version-entry:hover { border-color: var(--border-default); background: var(--bg-hover); }
.aih-version-entry.current { border-color: var(--border-action); background: var(--color-action-ghost); }
.aih-version-entry__top { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.aih-version-num {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
}
.aih-version-entry.current .aih-version-num { color: var(--color-action); }
.aih-version-entry__author { font-size: var(--font-xs); color: var(--text-tertiary); }
.aih-version-entry__date {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  margin-left: auto;
}
.aih-version-entry__note { font-size: var(--font-xs); color: var(--text-secondary); line-height: 1.4; }
.aih-rail-actions { display: flex; flex-direction: column; gap: var(--space-2); padding-top: var(--space-4); border-top: 1px solid var(--border-subtle); }

/* ── Share dialog ── */
.aih-share-dialog {
  max-width: 580px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
}
.aih-share-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-6);
  border-bottom: 1px solid var(--border-default);
}
.aih-share-dialog__title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h2);
  font-weight: 700;
}
.aih-share-dialog__body { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); }
.aih-share-dialog__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-default);
}
.aih-share-section__label {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}
.aih-share-scope {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.aih-share-scope:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.aih-share-scope.selected { border-color: var(--border-action); background: var(--color-action-ghost); }
.aih-share-scope__radio {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.aih-share-scope.selected .aih-share-scope__radio { border-color: var(--color-action); background: var(--color-action); }
.aih-share-scope.selected .aih-share-scope__radio::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.aih-share-scope__content { flex: 1; min-width: 0; }
.aih-share-scope__title { font-family: 'Plus Jakarta Sans', sans-serif; font-size: var(--font-body); font-weight: 600; margin-bottom: var(--space-1); }
.aih-share-scope__desc { font-size: var(--font-xs); color: var(--text-tertiary); line-height: 1.4; }
.aih-share-scope__approval { font-size: var(--font-xs); color: var(--color-warning); margin-top: var(--space-1); }
.aih-share-perm { display: flex; gap: var(--space-2); }
.aih-perm-btn {
  flex: 1;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  font-size: var(--font-xs);
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.aih-perm-btn.active { background: var(--color-action-muted); border-color: var(--border-action); color: var(--color-action); }
.aih-user-search-input {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-4);
  box-sizing: border-box;
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: 'Lato', sans-serif;
  font-size: var(--font-body);
  color: var(--text-primary);
  outline: none;
}
.aih-user-search-input::placeholder { color: var(--text-tertiary); }
.aih-current-share {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}
.aih-current-share__avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--color-action-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-action);
  flex-shrink: 0;
}
.aih-current-share__name { font-size: var(--font-small); color: var(--text-primary); flex: 1; }
.aih-current-share__perm { font-family: 'Geist Mono', monospace; font-size: var(--font-xs); color: var(--text-tertiary); }

/* ── History layout ── */
.aih-history-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  flex: 1;
}

/* Version list panel */
.aih-version-list {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 56px);
}
.aih-version-list__header {
  padding: var(--space-5) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.aih-version-list__title {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}
.aih-version-list__hint { font-size: var(--font-xs); color: var(--text-tertiary); }
.aih-version-list__body { flex: 1; overflow-y: auto; }

.aih-vl-entry {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.aih-vl-entry:hover { background: var(--bg-hover); }
.aih-vl-entry.selected-a { background: rgba(37, 99, 235, 0.06); border-left: 3px solid var(--color-action); padding-left: calc(var(--space-5) - 3px); }
.aih-vl-entry.selected-b { background: rgba(139, 92, 246, 0.06); border-left: 3px solid #7C3AED; padding-left: calc(var(--space-5) - 3px); }
.aih-vl-entry__checkbox { flex-shrink: 0; margin-top: 2px; }
.aih-vl-entry__checkbox input { cursor: pointer; accent-color: var(--color-action); width: 14px; height: 14px; }
.aih-vl-entry__body { flex: 1; min-width: 0; }
.aih-vl-entry__top { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-1); }
.aih-vl-version {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  font-weight: 700;
}
.aih-vl-date {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  margin-left: auto;
}
.aih-vl-author { font-size: var(--font-xs); color: var(--text-secondary); }
.aih-vl-note { font-size: var(--font-xs); color: var(--text-tertiary); margin-top: var(--space-1); line-height: 1.4; }
.aih-vl-entry__action { margin-top: var(--space-2); }

/* Diff area */
.aih-diff-area { padding: var(--space-6) var(--space-8); }
.aih-diff-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.aih-diff-header__comparing {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3);
  font-weight: 700;
}
.aih-diff-legend { display: flex; align-items: center; gap: var(--space-4); margin-left: auto; }
.aih-diff-legend__item { display: flex; align-items: center; gap: var(--space-2); font-size: var(--font-xs); color: var(--text-secondary); }
.aih-diff-legend__swatch { width: 16px; height: 10px; border-radius: 2px; }
.aih-diff-legend__swatch--add { background: var(--aih-diff-add-swatch); border: 1px solid var(--aih-diff-add-border); }
.aih-diff-legend__swatch--del { background: var(--aih-diff-del-swatch); border: 1px solid var(--aih-diff-del-border); }

.aih-diff-meta {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--font-xs);
}
.aih-diff-meta__side { flex: 1; }
.aih-diff-meta__label { font-family: 'Geist Mono', monospace; font-weight: 600; color: var(--text-tertiary); margin-bottom: var(--space-1); text-transform: uppercase; letter-spacing: 0.08em; font-size: 9px; }
.aih-diff-meta__val { color: var(--text-primary); font-weight: 600; }
.aih-diff-meta__sub { color: var(--text-tertiary); margin-top: 2px; }
.aih-diff-meta__divider { width: 1px; background: var(--border-default); }

.aih-diff-view {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-family: 'Geist Mono', monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
}
.aih-diff-view__toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border-default);
}
.aih-diff-view__toolbar-label { font-size: var(--font-xs); color: var(--text-tertiary); font-family: 'Lato', sans-serif; }
.aih-diff-mode-btn {
  height: 24px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  cursor: pointer;
  color: var(--text-secondary);
}
.aih-diff-mode-btn.active { background: var(--color-action-muted); border-color: var(--border-action); color: var(--color-action); font-weight: 700; }
.aih-diff-body { padding: var(--space-2) 0; }
.aih-diff-line { display: flex; align-items: stretch; min-height: 22px; }
.aih-diff-line__num {
  min-width: 40px;
  padding: 0 var(--space-3);
  text-align: right;
  font-size: 11px;
  color: var(--text-tertiary);
  user-select: none;
  border-right: 1px solid var(--border-subtle);
  flex-shrink: 0;
  line-height: 22px;
}
.aih-diff-line__sign { width: 20px; padding: 0 var(--space-1); font-weight: 700; line-height: 22px; flex-shrink: 0; text-align: center; }
.aih-diff-line__content { flex: 1; padding: 0 var(--space-3); line-height: 22px; white-space: pre-wrap; word-break: break-all; }

.aih-diff-line--added   { background: var(--aih-diff-add-bg); }
.aih-diff-line--added .aih-diff-line__sign   { color: var(--color-success); }
.aih-diff-line--added .aih-diff-line__content { color: var(--text-primary); }
.aih-diff-line--deleted { background: var(--aih-diff-del-bg); }
.aih-diff-line--deleted .aih-diff-line__sign { color: var(--color-danger); }
.aih-diff-line--deleted .aih-diff-line__content { color: var(--text-primary); }
.aih-diff-line--context .aih-diff-line__sign  { color: transparent; }
.aih-diff-line--context .aih-diff-line__content { color: var(--text-secondary); }
.aih-diff-line--hunk {
  background: var(--bg-inset);
  padding: var(--space-1) var(--space-4);
  font-size: 11px;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.aih-diff-ins { background: var(--aih-diff-ins-bg);     border-radius: 2px; padding: 0 2px; }
.aih-diff-del { background: var(--aih-diff-del-ins-bg); border-radius: 2px; padding: 0 2px; text-decoration: line-through; }

.aih-restore-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
}
.aih-restore-bar__note { font-size: var(--font-small); color: var(--text-secondary); }
.aih-restore-bar__note strong { color: var(--text-primary); }

/* ── Static section (mockup-only render helpers, harmless in prod) ── */
.aih-static-section { margin-top: var(--space-12); padding-top: var(--space-8); border-top: 3px dashed var(--border-default); }
.aih-static-section__label {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.aih-static-badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(95, 103, 117, 0.14);
  font-size: 10px;
  color: var(--text-tertiary);
  border: 1px solid rgba(95, 103, 117, 0.25);
}

/* ── Shared / Search page (ai-shared) ── */
.aih-shared-search-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-8);
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-surface);
}
.aih-shared-search-wrap--query   { flex: 1 1 320px; min-width: 220px; }
.aih-shared-search-wrap--creator { flex: 0 1 240px; min-width: 180px; }

.aih-shared-tag-input-wrap {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
  flex: 1 1 200px;
  min-width: 160px;
  min-height: 36px;
  padding: 3px var(--space-2);
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
}
.aih-shared-tag-input {
  flex: 1;
  min-width: 90px;
  height: 28px;
  border: none;
  background: transparent;
  outline: none;
  font-family: 'Lato', sans-serif;
  font-size: var(--font-body);
  color: var(--text-primary);
}
.aih-shared-tag-input::placeholder { color: var(--text-tertiary); }

.aih-shared-results-header { margin-bottom: var(--space-2); }

/* Empty / loading / error state card (used by ai-shared) */
.aih-state-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-8);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}
.aih-state-card--centered { align-items: center; text-align: center; }
.aih-state-card__icon { color: var(--text-tertiary); }
.aih-state-card__title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3);
  font-weight: 600;
  color: var(--text-primary);
}
.aih-state-card__sub {
  font-size: var(--font-body);
  color: var(--text-secondary);
  max-width: 480px;
  line-height: 1.5;
}

/* ── Toast (approvals / admin feedback; mirrors the inline toast in ai-hub-doc.js) ── */
.aih-toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-5);
  font-size: var(--font-small);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

/* ── Loading shimmer (search skeleton) ── */
@keyframes aih-shimmer-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.aih-shimmer {
  background: var(--bg-inset);
  border-radius: var(--radius-xs);
  animation: aih-shimmer-pulse 1.2s ease-in-out infinite;
}
.aih-doc-card--shimmer { pointer-events: none; }

/* ── Tag chip remove button (search filter chips) ── */
.aih-tag-chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  padding: 0;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-xs);
  color: var(--text-tertiary);
  background: transparent;
}
.aih-tag-chip__remove:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ── Individual tag chip on doc cards (search / workspace results) ── */
.aih-doc-card__tag {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 1px 6px;
}

/* ── Shared menu item (overflow + context menus) ── */
.aih-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: none;
  border: none;
  border-radius: var(--radius-xs);
  font-family: 'Lato', sans-serif;
  font-size: var(--font-small);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.aih-menu-item:hover { background: var(--bg-hover); }
.aih-menu-item svg { flex-shrink: 0; color: var(--text-tertiary); }
.aih-menu-item--danger { color: var(--color-danger); }
.aih-menu-item--danger svg { color: var(--color-danger); }
.aih-menu-item--danger:hover { background: rgba(239, 68, 68, 0.10); }
.aih-menu-sep { height: 1px; background: var(--border-subtle); margin: var(--space-1) 0; }

/* ── Overflow action menu (doc toolbar ⋯) ── */
.aih-overflow { position: relative; display: inline-flex; }
.aih-overflow__backdrop { position: fixed; inset: 0; z-index: 90; }
.aih-overflow__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 95;
  min-width: 188px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  display: flex;
  flex-direction: column;
}

/* ── Right-click context menu (home / workspace cards) ── */
.aih-ctx-backdrop { position: fixed; inset: 0; z-index: 140; }
.aih-ctx-menu {
  position: fixed;
  z-index: 145;
  min-width: 176px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  display: flex;
  flex-direction: column;
}

/* ── Inline restore confirm (version row) ── */
.aih-vl-restore-confirm { display: flex; flex-direction: column; gap: var(--space-2); }
.aih-vl-restore-confirm__q { font-size: var(--font-xs); color: var(--text-secondary); }
.aih-vl-restore-confirm__actions { display: flex; gap: var(--space-2); }
.aih-vl-restore-confirm__err { font-size: var(--font-xs); color: var(--color-danger); }

/* ── Route-scoped layout overrides ── */
/* aih-main is full-bleed; the page-content wrapper padding creates a grey gap above the topbar. */
body[data-page^="ai-"] .page-content { padding: 0; }
/* The inline .content-area uses calc(sidebar-width + --space-4) which leaves a 16px grey strip
   between the sidebar edge and the topbar. Flush it to the sidebar on AI Hub routes. */
body[data-page^="ai-"] .content-area { margin-left: var(--sidebar-width); }
body[data-page^="ai-"] .sidebar.collapsed ~ .content-area,
body[data-page^="ai-"] .content-area--collapsed { margin-left: var(--sidebar-collapsed); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .aih-folder-rail { display: none; }
  .aih-doc-layout  { grid-template-columns: 1fr; }
  .aih-history-layout { grid-template-columns: 1fr; }
  .aih-version-list { min-height: auto; }
  .aih-version-rail { min-height: auto; }
  .aih-content { padding: var(--space-4); }
  .aih-topbar { padding: 0 var(--space-4); }
  .aih-doc-content { padding: var(--space-4); }
  .aih-diff-area { padding: var(--space-4); }
  .aih-doc-area { padding: var(--space-4); }
}

/* ============================================================
   AI Value editor (migs 267/268)
   Scoped to .aiv-* — zero bleed into other aih-* components
   ============================================================ */

/* Card wrapper for each value section */
.aiv-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* Card header row */
.aiv-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border-default);
}
.aiv-card__title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3);
  font-weight: 600;
  color: var(--text-primary);
}

/* Read-only banner */
.aiv-readonly-banner {
  padding: var(--space-3) var(--space-4);
  background: rgba(245, 158, 11, 0.10);
  border: 1px solid rgba(245, 158, 11, 0.30);
  border-radius: var(--radius-sm);
  font-size: var(--font-small);
  color: var(--color-warning);
  margin-bottom: var(--space-4);
}
[data-theme="light"] .aiv-readonly-banner { color: #B45309; }

/* 6-month data grid table */
.aiv-grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-small);
  min-width: 520px;
}

/* Table header cells */
.aiv-th {
  padding: var(--space-2) var(--space-3);
  text-align: right;
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}
.aiv-th.aiv-th--left { text-align: left; }

/* Table body cells */
.aiv-tr { border-bottom: 1px solid var(--border-subtle); }
.aiv-tr:last-child { border-bottom: none; }

.aiv-td {
  padding: var(--space-2) var(--space-3);
  text-align: right;
  vertical-align: middle;
  font-size: var(--font-small);
  color: var(--text-primary);
}
.aiv-td.aiv-td--label {
  text-align: left;
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: var(--font-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 600;
}
/* Computed/preview cells */
.aiv-td.aiv-td--computed {
  color: var(--text-secondary);
  background: var(--bg-inset);
}
.aiv-td.aiv-td--money {
  background: var(--bg-inset);
  font-variant-numeric: tabular-nums;
}
.aiv-td.aiv-td--positive {
  color: var(--color-success);
}
/* Total row */
.aiv-tr--total .aiv-td {
  background: color-mix(in srgb, var(--text-primary) 4%, transparent);
  border-top: 1px solid var(--border-default);
  font-weight: 600;
}
.aiv-td.aiv-td--total {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: var(--font-small);
}

/* Numeric input inside grid — right-aligned, tabular */
.aiv-num-input {
  width: 100px;
  box-sizing: border-box;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 4px var(--space-2);
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  text-align: right;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.aiv-num-input:focus {
  border-color: var(--color-action);
  box-shadow: 0 0 0 2px var(--color-action-muted);
}
.aiv-num-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.aiv-num-input--wide { width: 140px; }

/* Mono utility — applied in template as a class */
.aiv-mono {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* Baseline inputs grid (Cost-of-Error section) */
.aiv-baseline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.aiv-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.aiv-label {
  font-size: var(--font-small);
  color: var(--text-secondary);
  font-weight: 600;
}
.aiv-label--hint {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  font-weight: 400;
  margin-left: var(--space-1);
}

/* Responsive — stack grid on narrow viewports */
@media (max-width: 768px) {
  .aiv-baseline-grid { grid-template-columns: 1fr; }
  .aiv-grid-table { min-width: 400px; }
  .aiv-num-input { width: 80px; }
}

/* ── Value & ROI chart grid ──────────────────────────────── */
/* 3 charts side-by-side on wide screens; stack on narrow.   */
.aiv-charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-5);
}

.aiv-chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.aiv-chart-card__title {
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.aiv-chart-card__body {
  flex: 1;
  min-width: 0;
  min-height: 80px;
}

/* Legend dots in the composition chart — theme-safe colour swatch */
.aiv-chart-card .aiv-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Horizontal bar track inside Chart 1 */
.aiv-hbar__label {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .aiv-charts-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   Doc-type badge expansions (9 new types — appended)
   Agent-instruction family: purple hues (near claude-md)
   Delivery-doc family: distinct indigo/teal/green/orange/red
   ============================================================ */

/* Agent-instruction types */
.aih-type-badge--agents-md    { background: var(--aih-badge-agents-md-bg);    color: #6D28D9; }
[data-theme="dark"] .aih-type-badge--agents-md    { color: #C4B5FD; }

.aih-type-badge--rules        { background: var(--aih-badge-rules-bg);        color: #5B21B6; }
[data-theme="dark"] .aih-type-badge--rules        { color: #DDD6FE; }

.aih-type-badge--output-style { background: var(--aih-badge-output-style-bg); color: #7C3AED; }
[data-theme="dark"] .aih-type-badge--output-style { color: #A78BFA; }

/* Delivery-doc types */
.aih-type-badge--spec    { background: var(--aih-badge-spec-bg);    color: #4338CA; }
[data-theme="dark"] .aih-type-badge--spec    { color: #A5B4FC; }

.aih-type-badge--design  { background: var(--aih-badge-design-bg);  color: #0E7490; }
[data-theme="dark"] .aih-type-badge--design  { color: #67E8F9; }

.aih-type-badge--prd     { background: var(--aih-badge-prd-bg);     color: #047857; }
[data-theme="dark"] .aih-type-badge--prd     { color: #6EE7B7; }

.aih-type-badge--adr     { background: var(--aih-badge-adr-bg);     color: #C2410C; }
[data-theme="dark"] .aih-type-badge--adr     { color: #FDBA74; }

.aih-type-badge--runbook { background: var(--aih-badge-runbook-bg); color: #B91C1C; }
[data-theme="dark"] .aih-type-badge--runbook { color: #FCA5A5; }

.aih-type-badge--doc     { background: var(--aih-badge-doc-bg);     color: #065F46; }
[data-theme="dark"] .aih-type-badge--doc     { color: #34D399; }

/* ============================================================
   Document lifecycle stage badges
   Classes: .aih-stage--<stage>
   draft=grey, spec=indigo, design=blue, in_implementation=amber,
   shipped=green, archived=muted
   ============================================================ */
.aih-stage-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 var(--space-3);
  border-radius: 999px;
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.aih-stage--draft {
  background: var(--aih-stage-draft-bg);
  border-color: var(--aih-stage-draft-border);
  color: var(--text-secondary);
}

.aih-stage--spec {
  background: var(--aih-stage-spec-bg);
  border-color: var(--aih-stage-spec-border);
  color: #4338CA;
}
[data-theme="dark"] .aih-stage--spec { color: #A5B4FC; }

.aih-stage--design {
  background: var(--aih-stage-design-bg);
  border-color: var(--aih-stage-design-border);
  color: var(--color-action);
}

.aih-stage--in_implementation {
  background: var(--aih-stage-in-impl-bg);
  border-color: var(--aih-stage-in-impl-border);
  color: var(--color-warning);
}
[data-theme="light"] .aih-stage--in_implementation { color: #B45309; }

.aih-stage--shipped {
  background: var(--aih-stage-shipped-bg);
  border-color: var(--aih-stage-shipped-border);
  color: var(--color-success);
}
[data-theme="light"] .aih-stage--shipped { color: #0E8A65; }

.aih-stage--archived {
  background: var(--aih-stage-archived-bg);
  border-color: var(--aih-stage-archived-border);
  color: var(--text-tertiary);
  opacity: 0.85;
}

/* Stage select — compact inline control */
.aih-stage-select {
  height: 24px;
  padding: 0 var(--space-2);
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: 'Geist Mono', monospace;
  font-size: var(--font-xs);
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
}
.aih-stage-select:focus { border-color: var(--color-action); box-shadow: 0 0 0 2px var(--color-action-muted); }

/* ============================================================
   Getting Started — guided tour modal + guide page (FE onboarding)
   ============================================================ */

/* ── Welcome tour modal + spotlight ── */
.aih-tour__layer { position: fixed; inset: 0; z-index: 300; }
/* Centered mode: dim the whole screen, click-outside closes */
.aih-tour__backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
/* Anchored mode: transparent layer that blocks page interaction (no close) */
.aih-tour__catch { position: absolute; inset: 0; }
/* The lit "hole" — its huge box-shadow dims everything except the cut-out */
.aih-tour__hole {
  position: fixed;
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  outline: 2px solid rgba(255, 255, 255, 0.9);
  outline-offset: 0;
  pointer-events: none;
  z-index: 1;
  transition: top 0.22s ease, left 0.22s ease, width 0.22s ease, height 0.22s ease;
}
.aih-tour {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 2;
  width: calc(100% - 2 * var(--space-4)); max-width: 460px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg, 14px);
  box-shadow: var(--shadow-lg);
  /* NB: --space-7 does not exist in the token scale (…6=24px, 8=32px). Using it
     made the whole padding shorthand invalid → collapsed to 0, so the modal hugged
     its edges. Use defined tokens: 32px top/sides, 24px bottom. */
  padding: var(--space-8) var(--space-8) var(--space-6);
  text-align: center;
}
/* Anchored callout: positioned via inline top/left next to the spotlight */
.aih-tour--anchored {
  transform: none;
  width: 360px; max-width: calc(100vw - 24px);
  text-align: left;
  padding: var(--space-6) var(--space-6) var(--space-4);
}
.aih-tour--anchored .aih-tour__icon { margin-left: 0; margin-right: auto; }
.aih-tour--anchored .aih-tour__body { margin-left: 0; max-width: none; }
.aih-tour--anchored .aih-tour__dots { justify-content: flex-start; }
.aih-tour__close {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--text-tertiary); cursor: pointer;
}
.aih-tour__close:hover { background: var(--bg-hover); color: var(--text-primary); }
.aih-tour__icon {
  width: 56px; height: 56px; margin: 0 auto var(--space-4);
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.aih-tour__step-count {
  font-size: var(--font-small); color: var(--text-tertiary);
  letter-spacing: 0.04em; margin-bottom: var(--space-2);
}
.aih-tour__title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h2); font-weight: 700; margin: 0 0 var(--space-3);
  color: var(--text-primary);
}
.aih-tour__body {
  font-size: var(--font-body); line-height: 1.6;
  color: var(--text-secondary); margin: 0 auto var(--space-5);
  max-width: 38ch;
}
.aih-tour__dots {
  display: flex; gap: 7px; justify-content: center; margin-bottom: var(--space-5);
}
.aih-tour__dot {
  width: 7px; height: 7px; padding: 0; border: none; border-radius: 50%;
  background: var(--border-strong); cursor: pointer; transition: all 0.15s ease;
}
.aih-tour__dot.is-active { background: var(--color-action); transform: scale(1.35); }
.aih-tour__footer {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.aih-tour__footer-right { display: flex; gap: var(--space-2); }

/* ── Guide page ── */
.aih-guide { max-width: 1080px; }

.aih-guide__hero {
  display: flex; gap: var(--space-5); align-items: flex-start;
  padding: var(--space-6);
  background: linear-gradient(135deg, var(--color-action-ghost, rgba(59,130,246,0.08)), transparent 70%);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md, 12px);
}
.aih-guide__hero-mark {
  flex-shrink: 0; width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px;
  background: var(--color-action); color: #fff;
}
.aih-guide__hero-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h1); font-weight: 800; margin: 0 0 var(--space-2);
  color: var(--text-primary);
}
.aih-guide__hero-sub {
  font-size: var(--font-body); line-height: 1.6; color: var(--text-secondary);
  margin: 0 0 var(--space-4); max-width: 70ch;
}
.aih-guide__hero-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }

.aih-guide__section { }
.aih-guide__h2 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h2); font-weight: 700; margin: 0 0 var(--space-2);
  color: var(--text-primary);
}
.aih-guide__lead {
  font-size: var(--font-body); color: var(--text-secondary);
  margin: 0 0 var(--space-5); max-width: 70ch;
}

/* Checklist */
.aih-guide__checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.aih-guide__check {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-sm); cursor: pointer; transition: all 0.12s ease;
}
.aih-guide__check:hover { border-color: var(--border-action); background: var(--bg-hover); }
.aih-guide__check-num {
  flex-shrink: 0; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--font-small); font-weight: 700;
  color: var(--color-action); background: var(--color-action-muted);
  border-radius: 50%;
}
.aih-guide__check-icon { flex-shrink: 0; color: var(--text-tertiary); display: flex; }
.aih-guide__check-text { flex: 1; font-size: var(--font-body); color: var(--text-primary); }
.aih-guide__check-go { color: var(--text-tertiary); font-weight: 700; }
.aih-guide__check:hover .aih-guide__check-go { color: var(--color-action); }

/* Feature areas + cards */
.aih-guide__area { margin-bottom: var(--space-6); }
.aih-guide__area-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.aih-guide__area-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.aih-guide__area-label {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3); font-weight: 700; margin: 0; color: var(--text-primary);
}
.aih-guide__cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-4);
}
.aih-guide__card {
  display: flex; flex-direction: column;
  padding: var(--space-5);
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-md, 12px); cursor: pointer; transition: all 0.14s ease;
}
.aih-guide__card:hover { border-color: var(--border-action); box-shadow: var(--shadow-md, 0 4px 12px rgba(0,0,0,0.08)); transform: translateY(-1px); }
.aih-guide__card-top { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.aih-guide__card-icon {
  flex-shrink: 0; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center; border-radius: 9px;
}
.aih-guide__card-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: var(--font-h3); font-weight: 700; color: var(--text-primary);
}
.aih-guide__card-role {
  margin-left: auto; flex-shrink: 0;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 999px;
  color: var(--text-secondary); background: var(--bg-inset); border: 1px solid var(--border-default);
}
.aih-guide__card-what { font-size: var(--font-body); color: var(--text-secondary); line-height: 1.55; margin: 0 0 var(--space-3); }
.aih-guide__card-how { margin: 0 0 var(--space-4); padding-left: 1.15em; display: flex; flex-direction: column; gap: 5px; }
.aih-guide__card-how li { font-size: var(--font-small); color: var(--text-secondary); line-height: 1.5; }
.aih-guide__card-cta { margin-top: auto; font-size: var(--font-small); font-weight: 700; color: var(--color-action); }

/* Concepts */
.aih-guide__concepts { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: var(--space-4); }
.aih-guide__concept {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4);
  background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-sm);
}
.aih-guide__concept-icon {
  flex-shrink: 0; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center; border-radius: 8px;
  color: var(--color-action); background: var(--color-action-muted);
}
.aih-guide__concept-title { font-family: 'Plus Jakarta Sans', sans-serif; font-size: var(--font-body); font-weight: 700; margin: 0 0 4px; color: var(--text-primary); }
.aih-guide__concept-body { font-size: var(--font-small); color: var(--text-secondary); line-height: 1.55; margin: 0; }

/* Footer CTA */
.aih-guide__cta-row {
  display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap;
  padding: var(--space-5) var(--space-6);
  background: var(--bg-inset); border: 1px solid var(--border-default); border-radius: var(--radius-md, 12px);
  font-size: var(--font-body); color: var(--text-secondary);
}

@media (max-width: 720px) {
  .aih-guide__hero { flex-direction: column; }
  .aih-guide__cards, .aih-guide__concepts { grid-template-columns: 1fr; }
}

/* ── Live progress: guide checklist + Home banner (mig 277) ── */
.aih-guide__progress { margin: 0 0 var(--space-4); max-width: 560px; }
.aih-guide__progress-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.aih-guide__progress-label { font-size: var(--font-small); font-weight: 600; color: var(--text-secondary); }
.aih-guide__progress-count { font-size: var(--font-small); color: var(--text-tertiary); }
.aih-guide__progress-track { height: 7px; border-radius: 999px; background: var(--bg-inset); overflow: hidden; }
.aih-guide__progress-fill { height: 100%; border-radius: 999px; background: var(--color-success); transition: width 0.4s ease; }

.aih-guide__check.is-done { background: color-mix(in srgb, var(--color-success) 7%, var(--bg-surface)); border-color: color-mix(in srgb, var(--color-success) 28%, var(--border-default)); }
.aih-guide__check-tick {
  flex-shrink: 0; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; background: var(--color-success); border-radius: 50%;
}
.aih-guide__check.is-done .aih-guide__check-text { color: var(--text-secondary); }
.aih-guide__check-done-tag {
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--color-success);
}

/* Home onboarding banner */
.aih-onboard-banner {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: linear-gradient(135deg, var(--color-action-ghost, rgba(59,130,246,0.08)), transparent 70%);
  border: 1px solid var(--border-action);
  border-radius: var(--radius-md, 12px);
  position: relative;
}
.aih-onboard-banner__icon {
  flex-shrink: 0; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center; border-radius: 9px;
  color: var(--color-action); background: var(--color-action-muted);
}
.aih-onboard-banner__body { flex: 1; min-width: 0; }
.aih-onboard-banner__top { display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; margin-bottom: 7px; }
.aih-onboard-banner__title { font-size: var(--font-body); font-weight: 700; color: var(--text-primary); }
.aih-onboard-banner__guide { margin-left: auto; font-size: var(--font-small); font-weight: 600; color: var(--color-action); }
.aih-onboard-banner__track { height: 6px; border-radius: 999px; background: var(--bg-inset); overflow: hidden; margin-bottom: var(--space-3); max-width: 420px; }
.aih-onboard-banner__fill { height: 100%; border-radius: 999px; background: var(--color-action); transition: width 0.4s ease; }
.aih-onboard-banner__next { display: flex; align-items: center; gap: var(--space-2); font-size: var(--font-small); color: var(--text-secondary); }
.aih-onboard-banner__close {
  position: absolute; top: 10px; right: 10px;
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--text-tertiary); cursor: pointer;
}
.aih-onboard-banner__close:hover { background: var(--bg-hover); color: var(--text-primary); }
