/* ── Aperture Browser Layout ──────────────────────────────────
 * CSS-first layout driven by data attributes.
 * State changes = toggle a data attribute. CSS handles the rest.
 * No inline style surgery from JS.
 * ──────────────────────────────────────────────────────────── */

/* ── Viewport lock: prevent body/main scroll when workspace is active ── */
body:has(.ab-workspace) {
  overflow: hidden;
  height: 100vh;
}

body:has(.ab-workspace) main {
  overflow: hidden;
}

/* ── Workspace: topbar + three-column flex ─────────────────── */
.ab-workspace {
  display: flex;
  flex-direction: column;
  /* height set dynamically by JS via _applyLayout() */
  overflow: hidden;
  position: relative;
}

/* ── Topbar (always visible, workspace-level) ─────────────── */
.ab-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  padding: 0 12px;
  height: 26px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  background: var(--surface-overlay);
}

/* ── Columns wrapper (sources + center + inspector) ───────── */
.ab-columns {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sources (left column) ─────────────────────────────────── */
.ab-sources {
  width: 240px;
  flex-shrink: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 13px;
  display: none; /* hidden by default */
}

.ab-workspace[data-sources-visible] .ab-sources {
  display: block;
}

/* ── Inspector (right column) ──────────────────────────────── */
.ab-inspector {
  width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 1px solid var(--border);
  font-size: 13px;
  display: none; /* hidden by default */
}

.ab-workspace[data-inspector-visible] .ab-inspector {
  display: block;
}

/* ── Center column ─────────────────────────────────────────── */
.ab-center {
  flex: 1;
  min-width: 0;
  display: flex;
  overflow: hidden;
}

/* ── Center modes ──────────────────────────────────────────── */

/* Viewer only */
.ab-center[data-mode="viewer"] .ab-browser-pane { display: none; }
.ab-center[data-mode="viewer"] .ab-handle { display: none; }
.ab-center[data-mode="viewer"] .ab-viewer-pane {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Browser only */
.ab-center[data-mode="browser"] .ab-viewer-pane { display: none; }
.ab-center[data-mode="browser"] .ab-handle { display: none; }
.ab-center[data-mode="browser"] .ab-browser-pane {
  flex: 1;
}

/* Split mode */
.ab-center[data-mode="split"] .ab-viewer-pane {
  width: var(--split-offset, 50%);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.ab-center[data-mode="split"] .ab-browser-pane {
  flex: 1;
  min-width: 0;
}
.ab-center[data-mode="split"] .ab-handle {
  display: block;
}

/* Split directions */
.ab-center[data-mode="split"][data-split-dir="horizontal"] {
  flex-direction: row;
}
.ab-center[data-mode="split"][data-split-dir="vertical"] {
  flex-direction: column;
}
.ab-center[data-mode="split"][data-split-dir="vertical"] .ab-viewer-pane {
  width: auto;
  height: var(--split-offset, 50%);
  flex-shrink: 0;
}
.ab-center[data-mode="split"][data-split-dir="vertical"] .ab-browser-pane {
  flex: 1;
  min-height: 0;
}

/* Filmstrip split: browser pane shrinks to filmstrip height, viewer expands */
.ab-workspace[data-filmstrip-split] .ab-center[data-mode="split"] .ab-viewer-pane {
  flex: 1;
  width: auto;
  height: auto;
}
.ab-workspace[data-filmstrip-split] .ab-center[data-mode="split"] .ab-browser-pane {
  flex: none;
  height: var(--filmstrip-h, 240px);
  overflow: hidden;
}
.ab-workspace[data-filmstrip-split] .ab-center[data-mode="split"] .ab-handle {
  display: none;
}

/* ── Resize handle ─────────────────────────────────────────── */
.ab-handle {
  display: none;
  flex-shrink: 0;
  background: var(--border);
  transition: background 0.15s;
  position: relative;
  z-index: 5;
}

.ab-handle:hover,
.ab-handle.ab-handle--active {
  background: var(--session-color, #00b7f2);
}

.ab-center[data-split-dir="horizontal"] .ab-handle {
  width: 5px;
  cursor: col-resize;
  touch-action: none;
}

.ab-center[data-split-dir="vertical"] .ab-handle {
  height: 5px;
  cursor: row-resize;
  touch-action: none;
}

/* ── Viewer pane ───────────────────────────────────────────── */
.ab-viewer-pane {
  background: var(--surface-raised);
}

.ab-viewer-pane img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ── Browser pane ──────────────────────────────────────────── */
.ab-browser-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Toolbar ───────────────────────────────────────────────── */
.ab-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  position: relative;
  z-index: 51;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  background: var(--surface-overlay);
  min-height: 36px;
}

.ab-workspace:not([data-toolbar-visible]) .ab-toolbar {
  display: none;
}

.ab-toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ab-topbar-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  padding: 1px 4px 0 12px;
  display: flex;
  align-items: center;
  opacity: 0.6;
}

.ab-topbar-label:first-child {
  padding-left: 0;
}

.ab-toolbar-separator {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 0;
}

.ab-toolbar-btn {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}

.ab-toolbar-btn:hover {
  border-color: var(--text-muted);
  color: var(--text-secondary);
}

.ab-toolbar-btn--active {
  background: var(--session-color, #00b7f2);
  color: #fff;
  border-color: transparent;
}

.ab-toolbar-btn--icon {
  width: 26px;
  padding: 2px 0;
  text-align: center;
}

/* Thumb size slider */
.ab-thumb-slider {
  width: 106px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.ab-thumb-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--session-color, #00b7f2);
  cursor: pointer;
}

.ab-thumb-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: var(--session-color, #00b7f2);
  cursor: pointer;
}

.ab-toolbar-btn-group {
  display: flex;
  align-self: stretch;
}

.ab-toolbar-btn-group__btn:first-child {
  border-left: 1px solid var(--border);
}

.ab-toolbar-btn-group__btn {
  padding: 1px 8px 0;
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
  display: flex;
  align-items: center;
}

.ab-toolbar-btn-group__btn:last-child {
  border-right: none;
}

.ab-toolbar-btn-group__btn:hover {
  color: var(--text-secondary);
}

.ab-toolbar-btn-group__btn--active {
  background: var(--session-color, #00b7f2);
  color: #fff;
}

.ab-toolbar-btn-group__btn--disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Grid container: view modes ────────────────────────────── */
.ab-grid {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--grid-pad, 8px);
}

/* Grid view */
.ab-grid[data-view="grid"] {
  display: grid;
  gap: var(--grid-gap, 4px);
  grid-template-columns: repeat(var(--grid-cols, 6), 1fr);
  align-content: start;
}

/* Filmstrip view */
.ab-grid[data-view="filmstrip"] {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 2px;
  align-items: flex-start;
  padding: 4px;
}

/* Table view */
.ab-grid[data-view="table"] {
  display: grid;
  align-content: start;
  gap: 0;
  padding: 0;
}

/* ── Stack badge (count pill on pick card) ────────────────── */
.ab-stack-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 2;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  transition: background 0.15s;
}

.ab-stack-badge:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* Stack pick: subtle inset border like Aperture's highlight frame.
   Uses ::before pseudo-element so the border renders above the image content. */
.ab-card[data-stack-pick]::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: inherit;
  z-index: 1;
  pointer-events: none;
}

/* ── Cards ─────────────────────────────────────────────────── */
.ab-card {
  display: block;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  transition: opacity 0.15s, transform 0.15s;
}

.ab-card:hover {
  opacity: 0.85;
}

.ab-card img {
  width: 100%;
  display: block;
}

/* Grid card: explicit height makes cards square (width comes from grid column).
   No aspect-ratio needed — avoids grid-auto-rows sizing conflicts.
   Flex centers the contained image vertically. */
.ab-band-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 2px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.ab-band-header:first-child {
  padding-top: 0;
}

.ab-band-count {
  font-weight: 400;
  color: var(--text-tertiary);
}

.ab-grid[data-view="grid"] .ab-card {
  height: var(--grid-row-h, 200px);
  overflow: hidden;
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ab-grid[data-view="grid"] .ab-card img {
  width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.ab-grid[data-view="grid"][data-fit="cover"] .ab-card img {
  object-fit: cover;
}

/* Grid card overlay (title on hover) */
.ab-card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
  opacity: 0;
  transition: opacity 0.2s;
}

.ab-card:hover .ab-card-overlay {
  opacity: 1;
}

/* Filmstrip card */
.ab-grid[data-view="filmstrip"] .ab-card {
  flex-shrink: 0;
  height: var(--thumb-size, 200px);
  width: auto;
}

.ab-grid[data-view="filmstrip"] .ab-card img {
  height: 100%;
  width: auto;
  object-fit: cover;
}

/* Table card (row) — display: contents dissolves the box, so
   ::after selection overlay doesn't render. Table uses
   .ab-table-cell--selected background tint instead. */
.ab-grid[data-view="table"] .ab-card {
  display: contents;
  border-radius: 0;
}

.ab-grid[data-view="table"] .ab-card:hover {
  opacity: 1;
}

.ab-grid[data-view="table"] .ab-card:hover > .ab-table-cell {
  background: var(--surface-alt);
}

/* Table row keyboard selection */
.ab-table-cell--selected {
  background: color-mix(in srgb, var(--session-color, #00b7f2) 12%, transparent);
}

.ab-table-cell {
  padding: 0 8px;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  height: var(--table-row-h, 44px);
  line-height: var(--table-row-h, 44px);
}

.ab-table-cell--thumb {
  padding: 2px;
  display: flex;
  align-items: center;
  line-height: normal;
}

.ab-table-cell--thumb img {
  height: var(--table-thumb, 36px);
  width: var(--table-thumb, 36px);
  object-fit: cover;
  border-radius: 2px;
}

.ab-table-cell--thumb div {
  height: var(--table-thumb, 36px);
  width: var(--table-thumb, 36px);
  border-radius: 2px;
}

/* Table header */
.ab-table-header {
  display: contents;
}

.ab-table-header-cell {
  padding: 0 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 32px;
}

.ab-table-header-cell:hover {
  color: var(--text-secondary);
}

.ab-table-header-cell--sorted {
  color: var(--session-color, #00b7f2);
  border-bottom-color: var(--session-color, #00b7f2);
}

/* ── Sources panel ─────────────────────────────────────────── */

/* Collection type picker - compact horizontal row */
.ab-collection-row {
  display: flex;
  gap: 0;
  padding: 4px 6px;
}

.ab-collection-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 5px 2px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
  text-decoration: none;
  white-space: nowrap;
}

.ab-collection-btn:hover {
  color: var(--text-secondary);
  background: var(--hover-bg);
}

.ab-collection-btn--active {
  color: var(--text);
  font-weight: 600;
}

.ab-collection-btn--active .ab-collection-icon {
  color: var(--session-color, #00b7f2);
}

.ab-collection-icon {
  font-size: 9px;
  color: var(--border-strong);
  flex-shrink: 0;
}

/* Entity identity block */
.ab-entity-identity {
  padding: 12px 14px 10px;
  border-top: 1px solid var(--border-light);
}

.ab-entity-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  letter-spacing: -0.01em;
  margin: 0;
}

.ab-entity-artist {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
  margin-top: 2px;
  line-height: 1.3;
}

.ab-entity-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Source list - primary navigation */
.ab-source-section {
  padding: 0;
}

.ab-source-section-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  padding: 10px 14px 4px;
}

.ab-source-list {
  padding: 2px 0 6px;
}

.ab-source-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  color: var(--text-tertiary);
  font-size: 13px;
  text-decoration: none;
  border-left: 2px solid transparent;
}

.ab-source-item:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.ab-source-item--active {
  color: var(--text);
  font-weight: 600;
  background: var(--active-bg);
  border-left-color: var(--session-color, #00b7f2);
}

.ab-source-item--current {
  color: var(--text);
  font-weight: 600;
}

.ab-source-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-subtle);
  flex-shrink: 0;
}

.ab-source-item--active .ab-source-icon {
  color: var(--session-color, #00b7f2);
}

/* Zoom row - compact inline */
.ab-zoom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 8px;
}

.ab-zoom-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  flex-shrink: 0;
}

/* Subtle divider line */
.ab-source-divider {
  height: 1px;
  background: var(--border-light);
  margin: 0;
}

/* ── Catalog Tree ─────────────────────────────────────────── */

.ab-tree {
  padding: 2px 0;
  user-select: none;
}

/* Remove default disclosure marker */
.ab-tree details > summary {
  list-style: none;
}
.ab-tree details > summary::-webkit-details-marker {
  display: none;
}

/* Project level */
.ab-tree-project {
  margin-bottom: 0;
}

.ab-tree-project-summary {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px 5px 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  border-radius: 3px;
  transition: background 0.12s;
}

.ab-tree-project-summary:hover {
  background: var(--hover-bg);
}

.ab-tree-project-summary .ab-tree-arrow {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: var(--text-muted);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.ab-tree-project[open] > .ab-tree-project-summary .ab-tree-arrow {
  transform: rotate(90deg);
}

.ab-tree-project-summary .ab-tree-icon {
  font-size: 10px;
  color: var(--text-subtle);
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}

.ab-tree-project-summary .ab-tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ab-tree-project-summary .ab-tree-count {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-subtle);
  margin-left: auto;
  flex-shrink: 0;
}

/* Folder level */
.ab-tree-folder {
  margin-left: 14px;
  margin-bottom: 0;
}

.ab-tree-folder-summary {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px 3px 4px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-radius: 3px;
  transition: background 0.12s;
}

.ab-tree-folder-summary:hover {
  background: var(--hover-bg);
  color: var(--text-secondary);
}

.ab-tree-folder-summary .ab-tree-arrow {
  width: 12px;
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
  color: var(--text-subtle);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.ab-tree-folder[open] > .ab-tree-folder-summary .ab-tree-arrow {
  transform: rotate(90deg);
}

/* Leaf items (clickable albums) */
.ab-tree-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px 3px 20px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-tertiary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background 0.12s, color 0.12s;
  margin-left: 14px;
}

.ab-tree-item:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.ab-tree-item--active {
  color: var(--text);
  font-weight: 600;
  background: var(--active-bg);
  border-left-color: var(--session-color, #00b7f2);
}

.ab-tree-item .ab-tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ab-tree-item .ab-tree-count {
  font-size: 9px;
  font-weight: 400;
  color: var(--text-subtle);
  margin-left: auto;
  flex-shrink: 0;
}

.ab-tree-item--active .ab-tree-count {
  color: var(--text-muted);
}

/* Active project highlight */
.ab-tree-project--active > .ab-tree-project-summary .ab-tree-icon {
  color: var(--session-color, #00b7f2);
}

/* ── Inspector sections ────────────────────────────────────── */
.ab-inspector-content {
  padding: 16px 16px 24px;
  font-size: 13px;
  line-height: 1.4;
}

.ab-inspector-section {
  margin-bottom: 16px;
}

.ab-inspector-section + .ab-inspector-section {
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.ab-inspector-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.ab-inspector-value {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.ab-inspector-link {
  color: var(--session-color, #00b7f2);
  text-decoration: none;
  transition: text-decoration 0.15s;
}

.ab-inspector-link:hover {
  text-decoration: underline;
}

/* ── Loading overlay ───────────────────────────────────────── */
.ab-loading {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 50;
  align-items: center;
  justify-content: center;
}

.ab-browser-pane[data-loading] .ab-loading {
  display: flex;
}

.ab-loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--session-color, #00b7f2);
  border-radius: 50%;
  animation: ab-spin 0.6s linear infinite;
}

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

/* ── Grid-only loading (catalog navigation) ────────────────── */
.ab-grid-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  width: 100%;
}

/* ── Palette display ───────────────────────────────────────── */
.ab-palette {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.ab-palette-swatch {
  width: 24px;
  height: 24px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.08);
}

/* ── Zoom selector ─────────────────────────────────────────── */
.ab-zoom-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.ab-zoom-btn {
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-subtle);
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}

.ab-zoom-btn:first-child {
  border-left: none;
}

.ab-zoom-btn:hover {
  color: var(--text-secondary);
  background: var(--surface-alt);
}

.ab-zoom-btn--active {
  background: var(--session-color, #00b7f2);
  color: #fff;
}

/* ── Responsive: phone only (< 768px) ─────────────────────── */
@media (max-width: 767px) {
  .ab-columns {
    flex-direction: column;
  }

  .ab-sources,
  .ab-inspector {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border);
  }

  .ab-center {
    flex-direction: column !important;
  }

  .ab-center[data-mode="split"] .ab-viewer-pane {
    width: auto !important;
    height: 40vh;
  }

  .ab-handle {
    display: none !important;
  }
}

/* ── Mode toggle (Semantic / Catalog) ─────────────────────── */
.ab-mode-toggle {
  display: flex;
  align-items: stretch;
}

.ab-mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  transition: all 0.15s;
}

.ab-mode-btn--active {
  background: var(--session-color, #00b7f2);
  color: #fff;
}

.ab-mode-btn:not(.ab-mode-btn--active):hover {
  color: var(--text-secondary);
  background: var(--surface-alt);
}

/* ── Breadcrumb ───────────────────────────────────────────── */
.ab-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  grid-column: 1 / -1; /* span full width in table mode */
}

.ab-breadcrumb-sep {
  color: var(--border-strong);
}

.ab-breadcrumb-link {
  color: var(--session-color, #00b7f2);
  text-decoration: none;
}

.ab-breadcrumb-link:hover {
  text-decoration: underline;
}

.ab-breadcrumb-current {
  color: var(--text-secondary);
  font-weight: 600;
}

/* ── Catalog: department album card ───────────────────────── */
.ab-catalog-album {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  display: flex !important;
  flex-direction: column;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ab-catalog-album:hover {
  border-color: var(--text-muted);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  opacity: 1;
}

.ab-catalog-palette {
  display: flex;
  width: 100%;
  height: 6px;
}

.ab-catalog-album-body {
  padding: 12px;
}

/* Override grid card height for album cards */
.ab-grid[data-view="grid"] .ab-catalog-album {
  height: auto;
  min-height: var(--thumb-size, 120px);
  justify-content: flex-start;
}

/* ── Catalog: infinite scroll sentinel ─────────────────────── */
.ab-scroll-sentinel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 0;
  grid-column: 1 / -1;
  min-height: 60px;
  flex-shrink: 0; /* prevent collapse in filmstrip flex layout */
  min-width: 80px; /* visible sentinel in horizontal scroll */
}

/* ── Selected card overlay ───────────────────────────────────── */
/* Uses ::after pseudo-element so the highlight renders above image content.
   inset box-shadow paints behind content; images cover it entirely. */
.ab-card--selected::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid var(--session-color, #00b7f2);
  border-radius: inherit;
  z-index: 3;
  pointer-events: none;
}

/* When a card is both stack-pick and selected, hide the pick border */
.ab-card--selected.ab-card[data-stack-pick]::before {
  display: none;
}

/* ── Catalog: text-only fallback cards ────────────────────────── */
.ab-card--text {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 12px;
  background: var(--surface-raised);
  text-decoration: none;
  color: inherit;
  gap: 6px;
  overflow: hidden;
}

.ab-card--text:hover {
  background: var(--hover-bg);
}

.ab-card--text-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.ab-card--text-meta {
  font-size: 10px;
  color: var(--text-tertiary);
  line-height: 1.2;
}

/* ── Column picker popover ─────────────────────────────────── */
.ab-col-picker {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--surface-overlay);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 20;
  min-width: 160px;
  font-size: 12px;
}

.ab-col-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  cursor: pointer;
  transition: background 0.1s;
}

.ab-col-picker-item:hover {
  background: var(--hover-bg);
}

/* ── Help popover ──────────────────────────────────────────── */
.ab-help {
  display: none;
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--surface-overlay);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 100;
  font-size: 12px;
  max-width: 280px;
}

.ab-workspace[data-help-visible] .ab-help {
  display: block;
}

.ab-help-title {
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 13px;
}

.ab-help-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.ab-help-key {
  font-family: monospace;
  background: var(--surface-raised);
  padding: 0 4px;
  border-radius: 2px;
  font-size: 11px;
}

/* ── PhotoSwipe gallery overrides ─────────────────────────── */

/* Smooth image appearance — replaces the global fade-in system
   (which is excluded for .pswp__img) with a single clean fade */
.pswp__img {
  animation: img-fade-in 200ms ease both;
}

/* Hide navigation chrome — keep preloader visible for image loading */
.pswp__button--close,
.pswp__button--zoom,
.pswp__button--arrow--prev,
.pswp__button--arrow--next,
.pswp__counter {
  display: none !important;
}

/* Minimal close hint: thin top-edge bar, visible on hover/tap */
.pswp__top-bar {
  background: none !important;
  height: 44px;
}

.pswp__top-bar::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.25);
  transition: background 0.2s, width 0.2s;
}

.pswp__top-bar:hover::after {
  background: rgba(255, 255, 255, 0.6);
  width: 56px;
}

/* ── Gallery veil (seamless zoom transition) ──────────────── */
.ab-gallery-veil {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 1500001; /* above PhotoSwipe's z-index */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  opacity: 1;
  transition: opacity 0.35s ease;
}

.ab-gallery-veil--out {
  opacity: 0;
  pointer-events: none;
}

.ab-gallery-veil-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.75);
}

.ab-gallery-veil-dots {
  display: flex;
  gap: 10px;
}

.ab-gallery-veil-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  transition: background 0.3s, transform 0.3s;
}

.ab-gallery-veil-dot--active {
  background: var(--session-color, #00b7f2);
  transform: scale(1.6);
}

/* ── Shared lightbox info bar — always on dark overlay, not theme-dependent ── */
.moma-lb-bar { position: absolute; bottom: 0; left: 0; right: 0; padding: 12px 16px; background: rgba(0,0,0,0.85); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); z-index: 1; }
.moma-lb-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.moma-lb-left { min-width: 0; overflow: hidden; }
.moma-lb-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.moma-lb-title { font-size: 15px; font-weight: 700; margin: 0; line-height: 1.3; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.moma-lb-sub { font-size: 13px; color: rgba(255,255,255,0.6); margin: 2px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.moma-lb-counter { font-size: 11px; color: rgba(255,255,255,0.5); }
.moma-lb-link { font-size: 12px; font-weight: 600; color: var(--session-color, #e91e8c); text-decoration: none; white-space: nowrap; }
.moma-lb-star { background: none; border: none; cursor: pointer; padding: 0; font-size: 18px; line-height: 1; color: rgba(255,255,255,0.5); transition: color 0.15s; }
.moma-lb-star:hover { color: rgba(255,255,255,0.8); }
.moma-lb-star--active { color: var(--session-color, #00b7f2); }
.moma-lb-star--active:hover { opacity: 0.8; }

/* Viewer image cursor hint for gallery */
.ab-viewer-pane img {
  cursor: zoom-in;
}

/* ── Search results ───────────────────────────────────────── */

/* Viewer: full-bleed mosaic behind query text */
.ab-search-mosaic {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  grid-auto-rows: 120px;
  gap: 2px;
  overflow: hidden;
}

.ab-search-mosaic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.3;
  transition: opacity 0.6s ease;
}

.ab-search-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    180deg,
    var(--glass-bg) 0%,
    var(--glass-bg) 35%,
    var(--glass-bg) 65%,
    var(--glass-bg) 100%
  );
  z-index: 1;
  padding: 32px;
  text-align: center;
}

.ab-search-kicker {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.ab-search-query {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
  max-width: 420px;
}

.ab-search-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 10px;
}

/* Search facet pills */
.ab-search-facets {
  display: flex;
  gap: 0.375rem;
  padding: 0.5rem 0;
  justify-content: center;
}

.ab-search-facet-pill {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
}

.ab-search-facet-pill:hover {
  border-color: var(--text-secondary);
  color: var(--text);
}

.ab-search-facet-pill.active {
  border-color: var(--session-color, #00b7f2);
  color: var(--session-color, #00b7f2);
}

/* Sources: search result section links */
.ab-search-source-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  color: var(--text-secondary);
  font-size: 13px;
  text-decoration: none;
  border-left: 2px solid transparent;
}

.ab-search-source-item:hover {
  background: var(--hover-bg);
  border-left-color: var(--session-color, #00b7f2);
}

.ab-search-source-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-raised);
  padding: 1px 8px;
  border-radius: 99px;
}

.ab-search-source-item:hover .ab-search-source-count {
  color: var(--session-color, #00b7f2);
  background: var(--surface);
}

/* Grid: section headers (museum wall label style) */
.ab-search-section-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 4px 10px;
}

.ab-search-section-header:first-child {
  padding-top: 8px;
}

.ab-search-section-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  background: var(--surface-raised);
  color: var(--text-tertiary);
}

.ab-search-section-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.ab-search-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.ab-search-section-count {
  font-size: 10px;
  color: var(--text-muted);
}

.ab-search-section-rule {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Inspector: search breakdown */
.ab-search-inspector {
  padding: 20px 16px;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.5;
}

.ab-search-inspector-heading {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.ab-search-inspector-query {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text);
  margin-bottom: 16px;
}

.ab-search-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-tertiary);
}

.ab-search-stat-value {
  font-weight: 700;
  color: var(--text-secondary);
}

.ab-search-divider {
  height: 1px;
  background: var(--border-light);
  margin: 12px 0;
}

/* Search: term cards */
.ab-search-term-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.ab-search-term-card:hover {
  border-color: var(--text-muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  opacity: 1;
}

.ab-search-term-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.ab-search-term-def {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ab-search-term-sim {
  font-size: 10px;
  font-weight: 600;
  color: var(--session-color, #00b7f2);
  margin-top: 2px;
}

/* Search: artist cards */
.ab-search-artist-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.ab-search-artist-card:hover {
  border-color: var(--text-muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  opacity: 1;
}

.ab-search-artist-card .ab-search-artist-portrait {
  width: 36px;
  height: 36px;
  min-width: 36px;
  max-width: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.ab-search-artist-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--border-strong);
  flex-shrink: 0;
}

.ab-search-artist-info {
  flex: 1;
  min-width: 0;
}

.ab-search-artist-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ab-search-artist-meta {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
  margin-top: 2px;
}

/* Search: exhibition cards */
.ab-search-exh-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.ab-search-exh-card:hover {
  border-color: var(--text-muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  opacity: 1;
}

.ab-search-exh-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.ab-search-exh-date {
  font-size: 11px;
  color: var(--text-muted);
}

.ab-search-exh-sim {
  font-size: 10px;
  font-weight: 600;
  color: var(--session-color, #00b7f2);
  margin-top: 2px;
}

/* ── Star button (inspector) ──────────────────────────────── */
.ab-star-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  padding: 4px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
}

.ab-star-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text-secondary);
}

.ab-star-btn--active {
  color: var(--session-color, #00b7f2);
  border-color: var(--session-color, #00b7f2);
}

.ab-star-btn--active:hover {
  opacity: 0.8;
}

/* ── Card star indicator ─────────────────────────────────── */
.ab-card-star {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  font-size: 14px;
  color: var(--session-color, #00b7f2);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  line-height: 1;
}

/* Grid-height override: search entity cards need auto height */
.ab-grid[data-view="grid"] .ab-search-term-card,
.ab-grid[data-view="grid"] .ab-search-exh-card,
.ab-grid[data-view="grid"] .ab-search-artist-card {
  height: auto;
  min-height: 80px;
}
