/**
 * Project Hub — gallery + table over all projects.
 *
 * Reuses Studio gallery vocabulary (sg-toolbar, sg-grid, sg-card, sg-card-info).
 * Project-specific styles use the .ph- prefix and only extend / override Studio.
 *
 * Defensive token fallbacks mirror project-workspace.css — scilence tokens
 * sometimes resolve to empty string at runtime in current build.
 */

.ph-page {
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100%;
  min-height: 0;
}

/* ── toolbar overrides ─────────────────────────────────────── */

.ph-toolbar-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--s-space-1);
  flex-shrink: 0;
}

.ph-toolbar {
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-space-2);
}

/* Tag chip row — unfurls underneath the local toolbar. Hidden entirely when
 * collapsed (no header, no border — the chevron is in row 1). */
.ph-toolbar-tags {
  display: flex;
  align-items: center;
  gap: var(--s-space-2);
  flex-wrap: wrap;
  padding: var(--s-space-1) 0 var(--s-space-2);
}

.ph-toolbar-tags--collapsed {
  display: none;
}

.ph-toolbar-tags .ph-tag-filters {
  flex: 1;
  min-width: 0;
}

/* Left cluster of the toolbar: search + Tags chevron + count, all close. */
.ph-toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--s-space-2);
  min-width: 0;
}

.ph-toolbar-spacer {
  flex: 1;
  min-width: var(--s-space-2);
}

/* Toggle button — chevron + "Tags" label. Reads as a real button, not a
 * mono caps strip (the prior treatment was too quiet to register). */
.ph-tag-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-space-1);
  padding: var(--s-space-1) var(--s-space-2);
  font-family: var(--s-font-sans);
  font-size: var(--s-font-size-0);
  font-weight: var(--s-font-weight-semibold);
  color: var(--s-color-fg-primary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--s-radius-1);
  cursor: pointer;
  transition:
    background 0.12s ease,
    border-color 0.12s ease;
  flex-shrink: 0;
}

.ph-tag-toggle:hover {
  background: color-mix(in oklch, var(--s-color-fg-muted) 10%, transparent);
}

.ph-tag-toggle:focus-visible {
  outline: none;
  border-color: var(--s-color-status-info);
}

.ph-tag-chevron {
  display: inline-flex;
  align-items: center;
  color: var(--s-color-fg-muted);
}

.ph-tag-label {
  font-family: var(--s-font-sans);
  font-size: var(--s-font-size-0);
  font-weight: var(--s-font-weight-semibold);
  color: var(--s-color-fg-primary);
  letter-spacing: 0;
  text-transform: none;
}

.ph-tag-hint {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-muted);
  letter-spacing: 0.04em;
  margin-left: var(--s-space-1);
}

.ph-tag-filters {
  flex: 1;
  min-width: 0;
}

/* ── pin button (hover-revealed on cards/rows, persistent on table) ── */

.ph-pin-btn {
  width: 22px;
  height: 22px;
  padding: var(--s-space-twohair);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--s-color-fg-muted);
  border-radius: var(--s-radius-1);
  cursor: pointer;
  opacity: 0;
  transition:
    opacity 0.15s ease,
    color 0.12s ease,
    background 0.12s ease;
}

/* Always show when actually pinned (so users see it without hovering). */
.ph-pin-btn[data-pinned="true"] {
  opacity: 1;
  color: var(--s-color-status-info);
}

.ph-card:hover .ph-pin-btn,
.ph-list__row:hover .ph-pin-btn,
.ph-pin-btn:focus-visible {
  opacity: 1;
}

.ph-pin-btn:hover {
  color: var(--s-color-fg-primary);
  background: color-mix(in oklch, var(--s-color-fg-muted) 12%, transparent);
}

/* In the table, unpinned rows mute the pin until hover; pinned stays bold.
 * Without this, every row reads as pinned at a glance. */
.ph-table__pin-cell .ph-pin-btn {
  opacity: 0.18;
}
.ph-table tbody tr:hover .ph-table__pin-cell .ph-pin-btn,
.ph-table__pin-cell .ph-pin-btn:focus-visible {
  opacity: 0.7;
}
.ph-table__pin-cell .ph-pin-btn[data-pinned="true"] {
  opacity: 1;
}

/* Legacy stand-alone search (kept for back-compat in case other surfaces use it). */
.ph-search-wrap {
  display: flex;
  align-items: center;
}

.ph-search {
  width: 320px;
  padding: var(--s-space-1) var(--s-space-2);
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-primary);
  background: var(--s-color-bg-app);
  border: 1px solid var(--s-color-border);
  border-radius: var(--s-space-1);
  outline: none;
  transition: border-color 0.12s ease;
}

.ph-search::placeholder {
  color: var(--s-color-fg-muted);
}

.ph-search:focus-visible {
  border-color: var(--s-color-status-info);
}

/* Split control — single bordered shell containing [badge] [input] | [Tags ▾]. */
.ph-split {
  display: inline-flex;
  align-items: stretch;
  height: 32px;
  border: 1px solid var(--s-color-border);
  border-radius: var(--s-space-1);
  background: var(--s-color-bg-app);
  overflow: hidden;
  transition: border-color 0.12s ease;
}

.ph-split:focus-within {
  border-color: var(--s-color-status-info);
}

/* Leading badge — count of projects, mono pill at the left edge. */
.ph-split__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  padding: 0 var(--s-space-2);
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  font-weight: var(--s-font-weight-semibold);
  letter-spacing: 0.04em;
  color: var(--s-color-fg-primary);
  background: color-mix(in oklch, var(--s-color-fg-muted) 12%, transparent);
  border-right: 1px solid var(--s-color-border);
}

/* Search input — borderless inside the shell. */
.ph-split__input {
  flex: 1;
  min-width: 220px;
  padding: 0 var(--s-space-2);
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-primary);
  background: transparent;
  border: none;
  outline: none;
}

.ph-split__input::placeholder {
  color: var(--s-color-fg-muted);
}

/* Divider between the search half and the Tags toggle. */
.ph-split__divider {
  width: 1px;
  background: var(--s-color-border);
}

/* Tags toggle — borderless button on the right half. */
.ph-split__tags {
  display: inline-flex;
  align-items: center;
  gap: var(--s-space-1);
  padding: 0 var(--s-space-3);
  font-family: var(--s-font-sans);
  font-size: var(--s-font-size-0);
  font-weight: var(--s-font-weight-semibold);
  color: var(--s-color-fg-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.12s ease;
}

.ph-split__tags:hover {
  background: color-mix(in oklch, var(--s-color-fg-muted) 8%, transparent);
}

.ph-split__tags:focus-visible {
  outline: none;
  background: color-mix(in oklch, var(--s-color-status-info) 12%, transparent);
}

.ph-split__tags-hint {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-muted);
  letter-spacing: 0.04em;
}

.ph-split__tags-chev {
  display: inline-flex;
  align-items: center;
  color: var(--s-color-fg-muted);
}

/* View-mode toggle: segmented control. Container sits on a subtly tinted
 * surface so the active button reads as a "raised" lighter card on top.
 * Mirrors the .sg-zoom--segmented pattern in studio.css (sans box-shadow,
 * per the no-shadows rule). */
.ph-viewmode {
  display: inline-flex;
  align-items: center;
  gap: var(--s-space-twohair);
  padding: var(--s-space-twohair);
  background: var(--s-color-bg-subtle);
  border-radius: var(--s-radius-2);
}

.ph-viewmode__btn {
  width: 26px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--s-color-fg-muted);
  border-radius: var(--s-radius-1);
  transition:
    background 0.14s ease,
    color 0.14s ease;
}

.ph-viewmode__btn:hover {
  color: var(--s-color-fg-primary);
}

/* Active state — original dark brandscale prominent treatment.
 * Class chained to outweigh the transparent default. */
.ph-viewmode__btn.sg-toolbar-btn-active {
  background: var(--s-color-prominent-bg);
  color: var(--s-color-prominent-fg);
}

/* Hide zoom in non-gallery views — only gallery cards have density to control.
 * Use visibility (not display) so the zoom slot reserves layout space and the
 * view-mode toggle doesn't shift position when switching modes. */
.ph-page--table .ph-zoom,
.ph-page--list .ph-zoom {
  visibility: hidden;
  pointer-events: none;
}

/* Zoom stepper — reads as a zoom control. Mono label between − / +. */
.ph-zoom {
  display: inline-flex;
  align-items: center;
  gap: var(--s-space-1);
}

.ph-zoom-stepper-btn {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--s-color-border);
  border-radius: var(--s-radius-1);
  background: var(--s-color-bg-app);
  color: var(--s-color-fg-muted);
  cursor: pointer;
  transition:
    color 0.12s ease,
    background 0.12s ease,
    border-color 0.12s ease;
}

.ph-zoom-stepper-btn:hover:not([disabled]) {
  color: var(--s-color-fg-primary);
  border-color: var(--s-color-fg-muted);
}

.ph-zoom-stepper-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

.ph-zoom-stepper-label {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  letter-spacing: 0.04em;
  color: var(--s-color-fg-muted);
  min-width: 64px;
  text-align: center;
}

/* Spacer in row 1 between search and right cluster, replaces the kind filter slot. */
.ph-toolbar-spacer {
  flex: 1;
  min-width: 0;
}

.ph-count {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-muted);
  letter-spacing: 0.04em;
  margin-left: var(--s-space-1);
}

/* ── body container ────────────────────────────────────────── */

.ph-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.ph-empty {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-muted);
  padding: var(--s-space-5);
  text-align: center;
}

/* ── gallery cards (extending sg-card) ─────────────────────── */

.ph-grid {
  /* sg-grid handles row layout; sg-card aspect comes from --sg-card-aspect on each card */
}

.ph-card {
  text-decoration: none;
  color: inherit;
  display: block;
  transition:
    background 0.12s ease,
    transform 0.12s ease;
}

.ph-card:hover {
  background: color-mix(in oklch, var(--s-color-status-info) 4%, transparent);
}

.ph-card:focus-visible {
  outline: none;
  background: color-mix(in oklch, var(--s-color-status-info) 8%, transparent);
}

/* Thumbnail placeholder — mono initials on a tinted tile */
.ph-card__thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--s-color-bg-subtle);
  cursor: pointer;
  position: relative;
}

.ph-card__thumb[data-tint="decision"] {
  background: color-mix(
    in oklch,
    var(--s-color-status-info) 14%,
    var(--s-color-bg-app)
  );
}
.ph-card__thumb[data-tint="pivot"] {
  background: color-mix(
    in oklch,
    var(--s-color-status-warning) 14%,
    var(--s-color-bg-app)
  );
}
.ph-card__thumb[data-tint="retrospective"] {
  background: color-mix(
    in oklch,
    var(--s-color-status-success) 14%,
    var(--s-color-bg-app)
  );
}

.ph-card__initials {
  font-family: var(--s-font-mono);
  font-weight: var(--s-font-weight-semibold);
  font-size: clamp(28px, 8vw, 48px);
  letter-spacing: 0.04em;
  color: color-mix(in oklch, var(--s-color-fg-muted) 60%, transparent);
  user-select: none;
}

/* Top-left chips on the preview tile */
.ph-card__tags {
  pointer-events: none;
}

/* Pin slot — top-right of the gallery card preview tile. */
.ph-card__pin {
  position: absolute;
  top: var(--s-space-1);
  right: var(--s-space-1);
  z-index: 4;
}

.ph-card--pinned {
  background: color-mix(in oklch, var(--s-color-status-info) 6%, transparent);
}

.ph-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--s-space-twohair) var(--s-space-2);
  font-family: var(--s-font-mono);
  font-size: 10px;
  font-weight: var(--s-font-weight-semibold);
  letter-spacing: 0.08em;
  font-variant-caps: all-small-caps;
  border-radius: var(--s-space-1);
  background: var(--s-color-bg-app);
  color: var(--s-color-fg-muted);
  border: 1px solid var(--s-color-border);
}

.ph-badge--draft {
  color: var(--s-color-status-warning);
  border-color: var(--s-color-status-warning);
}
.ph-badge--retired {
  color: var(--s-color-fg-muted);
  text-decoration: line-through;
}
.ph-badge--decision {
  color: var(--s-color-status-info);
  border-color: var(--s-color-status-info);
}
.ph-badge--pivot {
  color: var(--s-color-status-warning);
  border-color: var(--s-color-status-warning);
}
.ph-badge--retrospective {
  color: var(--s-color-status-success);
  border-color: var(--s-color-status-success);
}

/* Card footer info — overrides sg-card-info to be relative-positioned */
.ph-card__info {
  position: static;
  background: var(--s-color-bg-app);
  padding: var(--s-space-2) var(--s-space-3);
}

.ph-card__title-row {
  align-items: center;
}

.ph-card__title {
  font-size: var(--s-font-size-1);
  font-weight: var(--s-font-weight-semibold);
  color: var(--s-color-fg-primary);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.ph-card__meta {
  display: flex;
  align-items: baseline;
  gap: var(--s-space-1);
  margin-top: var(--s-space-twohair);
  min-width: 0;
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-muted);
  letter-spacing: 0.04em;
}

.ph-card__slug {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.ph-card__sep {
  flex-shrink: 0;
  opacity: 0.6;
}

.ph-card__touched,
.ph-card__events {
  flex-shrink: 0;
}

/* Override sg-card-info absolute positioning — projects don't use the
 * iframe-overlay pattern, so footer stays in normal flow under the thumb. */
.ph-card.sg-card .sg-card-info.ph-card__info {
  position: static;
  background: var(--s-color-bg-app);
}

/* ── list view (horizontal row cards, stacked metadata groups) */

.ph-list {
  --ph-list-thumb: 56px;
  /* Default column rhythm — without the "recent" column. Adds an extra
   * track when [data-cols="5"] (kinds column present). */
  --ph-list-cols: var(--ph-list-thumb) minmax(0, 2.5fr) /* title block */
    minmax(120px, 0.9fr) /* lifecycle */ minmax(140px, 1fr) /* touched */
    minmax(110px, 0.7fr); /* events */
  display: flex;
  flex-direction: column;
  border-radius: var(--s-space-1);
  background: var(--s-color-bg-app);
  overflow: hidden;
}

.ph-list[data-cols="5"] {
  --ph-list-cols: var(--ph-list-thumb) minmax(0, 2.5fr) minmax(110px, 0.8fr)
    minmax(140px, 0.9fr) minmax(90px, 0.6fr) minmax(140px, 1.1fr);
}

.ph-list__head {
  display: grid;
  grid-template-columns: var(--ph-list-cols);
  align-items: center;
  gap: var(--s-space-3);
  padding: var(--s-space-2) var(--s-space-3);
  background: color-mix(
    in oklch,
    var(--s-color-fg-muted) 6%,
    var(--s-color-bg-app)
  );
  position: sticky;
  top: 0;
  z-index: 1;
}

.ph-list__head-cell {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  font-weight: var(--s-font-weight-semibold);
  letter-spacing: 0.08em;
  font-variant-caps: all-small-caps;
  color: var(--s-color-fg-muted);
  background: transparent;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: var(--s-space-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.ph-list__head-cell--end {
  justify-content: flex-end;
  text-align: right;
}

button.ph-list__head-cell:hover {
  color: var(--s-color-fg-primary);
}

.ph-list__head-cell--active {
  color: var(--s-color-status-info);
}

.ph-list__head-arrow {
  font-size: var(--s-font-size-micro);
  line-height: 1;
}

/* Row card — same column rhythm as head, stacked metadata groups inside cells */
.ph-list__row {
  display: grid;
  grid-template-columns: var(--ph-list-cols);
  align-items: center;
  gap: var(--s-space-3);
  padding: var(--s-space-2) var(--s-space-3);
  text-decoration: none;
  color: inherit;
  transition: background 0.12s ease;
}

.ph-list__row:last-child {
  border-bottom: none;
}

.ph-list__row:hover {
  background: color-mix(in oklch, var(--s-color-status-info) 5%, transparent);
}

.ph-list__row:focus-visible {
  outline: none;
  background: color-mix(in oklch, var(--s-color-status-info) 8%, transparent);
}

/* Thumbnail — row-height square, mono initials placeholder */
.ph-list__thumb {
  position: relative;
  width: var(--ph-list-thumb);
  height: var(--ph-list-thumb);
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(
    in oklch,
    var(--s-color-fg-muted) 8%,
    var(--s-color-bg-app)
  );
  border-radius: var(--s-space-1);
  flex-shrink: 0;
}

/* Pin slot inside the list-row thumbnail — top-right corner. */
.ph-list__pin {
  position: absolute;
  top: 2px;
  right: 2px;
}

.ph-list__row--pinned .ph-list__thumb {
  outline: 1px solid var(--s-color-status-info);
}

.ph-list__thumb[data-tint="decision"] {
  background: color-mix(
    in oklch,
    var(--s-color-status-info) 14%,
    var(--s-color-bg-app)
  );
}
.ph-list__thumb[data-tint="pivot"] {
  background: color-mix(
    in oklch,
    var(--s-color-status-warning) 14%,
    var(--s-color-bg-app)
  );
}
.ph-list__thumb[data-tint="retrospective"] {
  background: color-mix(
    in oklch,
    var(--s-color-status-success) 14%,
    var(--s-color-bg-app)
  );
}

.ph-list__thumb-initials {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-1);
  font-weight: var(--s-font-weight-semibold);
  letter-spacing: 0.04em;
  color: color-mix(in oklch, var(--s-color-fg-muted) 70%, transparent);
}

/* Group — a stacked label-above-value cluster (or value-above-label depending) */
.ph-list__group {
  display: flex;
  flex-direction: column;
  gap: var(--s-space-twohair);
  min-width: 0;
}

.ph-list__group--end {
  align-items: flex-end;
  text-align: right;
}

.ph-list__group-value {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-1);
  color: var(--s-color-fg-primary);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.ph-list__group-label {
  font-family: var(--s-font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  font-variant-caps: all-small-caps;
  color: var(--s-color-fg-muted);
}

/* Title block uses sans + larger, not the mono group treatment */
.ph-list__group--title {
  gap: var(--s-space-twohair);
}

.ph-list__title {
  font-size: var(--s-font-size-1);
  font-weight: var(--s-font-weight-semibold);
  color: var(--s-color-fg-primary);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ph-list__row:hover .ph-list__title {
  color: var(--s-color-status-info);
}

.ph-list__slug {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-muted);
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Recent-kinds chips wrap softly within their column */
.ph-list__group--kinds {
  flex-direction: row;
  flex-wrap: wrap;
  gap: var(--s-space-1);
  align-items: center;
}

.ph-list__dash {
  font-family: var(--s-font-mono);
  color: var(--s-color-fg-muted);
}

.ph-badge--xs {
  padding: var(--s-space-hair) var(--s-space-2);
  font-size: var(--s-font-size-micro);
}

/* ── table view ────────────────────────────────────────────── */

.ph-table-wrap {
  border-radius: var(--s-space-1);
  overflow: hidden;
  background: var(--s-color-bg-app);
}

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

.ph-table thead th {
  text-align: left;
  padding: var(--s-space-2) var(--s-space-3);
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  font-weight: var(--s-font-weight-semibold);
  letter-spacing: 0.06em;
  font-variant-caps: all-small-caps;
  color: var(--s-color-fg-muted);
  background: var(--s-color-bg-app);
  border-bottom: 1px solid var(--s-color-border);
}

.ph-table tbody td {
  padding: var(--s-space-2) var(--s-space-3);
  border-bottom: 1px solid var(--s-color-border);
  font-size: var(--s-font-size-1);
  color: var(--s-color-fg-primary);
}

.ph-table tbody tr:last-child td {
  border-bottom: none;
}

.ph-table tbody tr:hover {
  background: color-mix(in oklch, var(--s-color-status-info) 6%, transparent);
}

/* Pin column — narrow, mono visual rhythm. */
.ph-table__pin-col,
.ph-table__pin-cell {
  width: 32px;
  padding-left: var(--s-space-2);
  padding-right: 0;
}

.ph-table__row--pinned td:first-of-type + td a {
  font-weight: var(--s-font-weight-semibold);
}

.ph-table tbody td a {
  color: var(--s-color-fg-primary);
  text-decoration: none;
}

.ph-table tbody td a:hover {
  color: var(--s-color-status-info);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ph-mono {
  font-family: var(--s-font-mono);
  font-size: var(--s-font-size-condensed);
  color: var(--s-color-fg-muted);
  letter-spacing: 0.04em;
}

.ph-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
