/* =========================================================
   Photo Indexer — Editorial Darkroom
   ========================================================= */

:root {
  --ink-0: #0a0908;
  --ink-1: #141210;
  --ink-2: #1e1b18;
  --ink-3: #2a2622;
  --ink-4: #3a342e;
  --paper: #f5efe6;
  --paper-dim: #a8a095;
  --paper-mut: #6e675e;
  --accent: #e8542c;
  --accent-dim: #7a2c16;
  --accent-glow: rgba(232, 84, 44, 0.25);
  --ok: #7fb069;
  --warn: #e0a458;
  --err: #c94c4c;

  --serif: "Fraunces", "Canela", Georgia, "Times New Roman", serif;
  --sans: "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;

  --radius-sm: 2px;
  --radius-md: 6px;
  --radius-lg: 12px;

  --topbar-h: 64px;
  --context-h: 44px;

  --z-drawer: 40;
  --z-sheet: 50;
  --z-lightbox: 60;
  --z-palette: 70;
  --z-toast: 80;
  --z-library-menu: 90;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  background: var(--ink-0);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(232, 84, 44, 0.05), transparent 60%),
    var(--ink-0);
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
::selection { background: var(--accent); color: var(--ink-0); }

.hidden { display: none !important; }
.muted { color: var(--paper-mut); }
.eyebrow {
  font-family: var(--sans);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-mut);
  margin: 0;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0;
  margin: 0;
}
h1 { font-size: 2.25rem; line-height: 1.1; }
h2 { font-size: 1.5rem; line-height: 1.2; }
h3 { font-size: 1.125rem; line-height: 1.25; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Too small ---------- */
.too-small {
  display: none;
  position: fixed; inset: 0;
  align-items: center; justify-content: center;
  padding: 2rem; text-align: center;
  background: var(--ink-0);
  z-index: 1000;
}
.too-small h1 { font-size: 1.75rem; margin-top: 0.5rem; }
.too-small p { color: var(--paper-dim); margin: 0.5rem 0 0; }
@media (max-width: 768px) {
  .too-small { display: none; }
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-rows: var(--topbar-h) var(--context-h) 1fr;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr auto;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  background: var(--ink-1);
  border-bottom: 1px solid var(--ink-3);
  position: sticky; top: 0; z-index: 10;
}

.topbar-left, .topbar-right {
  display: flex; align-items: center; gap: 0.5rem;
}
.topbar-right { justify-content: flex-end; }

.library-button {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--paper);
  transition: background 120ms ease;
  width: 100%;
}
.library-button:hover { background: var(--ink-2); }
.library-button-mark {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  flex-shrink: 0;
}
.library-button-body {
  display: flex; flex-direction: column; align-items: flex-start;
  line-height: 1.1; min-width: 0;
}
.library-button-body > span:last-child {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1rem;
  max-width: 180px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.library-button-caret { color: var(--paper-mut); font-size: 0.75rem; }

.library-menu {
  position: fixed;
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  padding: 0.5rem;
  min-width: 320px;
  max-height: 60vh;
  overflow: auto;
  z-index: var(--z-library-menu);
}
.library-menu button {
  display: block;
  width: 100%;
  padding: 0.75rem;
  text-align: left;
  border-radius: var(--radius-sm);
}
.library-menu button:hover,
.library-menu button[aria-selected="true"] {
  background: var(--ink-3);
}
.library-menu .lm-name { font-family: var(--serif); font-size: 1rem; }
.library-menu .lm-path { color: var(--paper-mut); font-size: 0.75rem; font-family: var(--mono); margin-top: 2px; word-break: break-all; }

/* Search form */
.search-form {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-sm);
  padding: 0 0.75rem;
  height: 40px;
  transition: border-color 120ms, background 120ms, box-shadow 120ms;
  max-width: 720px;
  width: 100%;
  justify-self: center;
}
.search-form:focus-within {
  border-color: var(--accent);
  background: var(--ink-1);
  box-shadow: 0 0 0 4px var(--accent-glow);
}
.search-icon { color: var(--paper-mut); font-size: 1.1rem; }
.search-input {
  flex: 1;
  background: transparent; border: 0;
  font-size: 0.9375rem;
  outline: none;
}
.search-input::placeholder { color: var(--paper-mut); font-style: italic; }
.search-hint {
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--paper-mut);
  padding: 2px 6px;
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-sm);
}

.icon-button {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--paper-dim);
  transition: background 120ms, color 120ms;
  position: relative;
  font-size: 1.1rem;
}
.icon-button:hover { background: var(--ink-2); color: var(--paper); }
.icon-button .badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--accent); color: var(--ink-0);
  font-size: 0.625rem; font-weight: 600;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}

.health-pill {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--ink-3);
  border-radius: 999px;
  color: var(--paper-dim);
  font-size: 0.75rem;
  font-family: var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.health-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--paper-mut);
}
.health-dot[data-state="ok"] { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.health-dot[data-state="warn"] { background: var(--warn); }
.health-dot[data-state="err"] { background: var(--err); }

/* ---------- Context bar ---------- */
.context-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--ink-0);
  border-bottom: 1px solid var(--ink-2);
  gap: 1rem;
}
.chips {
  display: flex; align-items: center; gap: 0.5rem;
  flex-wrap: wrap;
}
.chip {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.25rem 0.625rem 0.25rem 0.75rem;
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: 999px;
  font-family: var(--serif);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--paper);
}
.chip[data-kind="scope"] {
  background: linear-gradient(135deg, rgba(232, 84, 44, 0.15), rgba(232, 84, 44, 0.02));
  border-color: var(--accent-dim);
}
.chip button {
  color: var(--paper-mut);
  font-size: 0.75rem;
  padding: 0 2px;
  line-height: 1;
}
.chip button:hover { color: var(--paper); }
.context-bar-right {
  display: flex; align-items: center; gap: 1rem;
}
.result-count {
  font-size: 0.75rem;
  color: var(--paper-mut);
  letter-spacing: 0.04em;
  font-family: var(--mono);
}
.density-toggle {
  display: flex;
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.density-toggle button {
  padding: 0.3rem 0.55rem;
  color: var(--paper-mut);
  font-size: 0.9rem;
  transition: background 120ms, color 120ms;
}
.density-toggle button:hover { color: var(--paper); }
.density-toggle button[aria-pressed="true"] {
  background: var(--ink-2);
  color: var(--accent);
}

/* ---------- Gallery ---------- */
.gallery-surface {
  position: relative;
  min-height: 0;
  padding: 1.25rem 1.5rem 6rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.gallery {
  column-gap: 8px;
}
.gallery[data-density="comfortable"] { column-count: 4; }
.gallery[data-density="dense"] { column-count: 6; column-gap: 4px; }
.gallery[data-density="uniform"] {
  column-count: unset;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 2px;
}
@media (max-width: 1600px) {
  .gallery[data-density="comfortable"] { column-count: 3; }
  .gallery[data-density="dense"] { column-count: 5; }
}
@media (max-width: 1280px) {
  .gallery[data-density="comfortable"] { column-count: 3; }
  .gallery[data-density="dense"] { column-count: 4; }
}
@media (max-width: 1024px) {
  .gallery[data-density="comfortable"] { column-count: 2; }
  .gallery[data-density="dense"] { column-count: 3; }
}

.photo-card {
  display: block;
  width: 100%;
  padding: 0;
  margin: 0 0 8px;
  break-inside: avoid;
  position: relative;
  overflow: hidden;
  background: var(--ink-2);
  border-radius: 0;
  cursor: zoom-in;
  transition: transform 180ms ease;
}
.gallery[data-density="dense"] .photo-card { margin-bottom: 4px; }
.gallery[data-density="uniform"] .photo-card {
  margin: 0;
  aspect-ratio: 1 / 1;
}
.photo-card img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 400ms ease, filter 200ms ease;
}
.gallery[data-density="uniform"] .photo-card img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.photo-card::after {
  content: "";
  position: absolute; inset: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  pointer-events: none;
}
.photo-card:hover img { transform: scale(1.02); }
.photo-card .caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 2rem 0.75rem 0.625rem;
  color: var(--paper);
  font-size: 0.75rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 180ms, transform 180ms;
  pointer-events: none;
  font-family: var(--mono);
}
.photo-card:hover .caption { opacity: 1; transform: translateY(0); }
.photo-card.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.gallery-empty {
  text-align: center;
  padding: 6rem 2rem;
  color: var(--paper-dim);
}
.gallery-empty h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: var(--paper);
}
.gallery-empty p {
  max-width: 440px;
  margin: 0 auto 1.5rem;
  line-height: 1.6;
}
.gallery-empty .suggestion {
  display: inline-flex; gap: 0.5rem; flex-wrap: wrap;
  justify-content: center;
  margin-top: 1rem;
}

.gallery-loading {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.gallery-loading .skeleton {
  background: var(--ink-2);
  height: 240px;
  position: relative;
  overflow: hidden;
}
.gallery-loading .skeleton::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.03), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ---------- Pill buttons ---------- */
.pill-button {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  background: var(--accent);
  color: var(--ink-0);
  transition: background 120ms, transform 80ms;
}
.pill-button:hover { background: #ff6a3d; }
.pill-button:active { transform: translateY(1px); }
.pill-button.ghost {
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--ink-3);
}
.pill-button.ghost:hover { background: var(--ink-2); border-color: var(--ink-4); }
.pill-button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Lightbox ---------- */
.lightbox {
  margin: 0; padding: 0; border: 0;
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  background: transparent;
  color: var(--paper);
}
.lightbox::backdrop {
  background: rgba(5, 4, 3, 0.94);
  backdrop-filter: blur(8px);
}
.lightbox-inner {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 380px;
  width: 100%; height: 100%;
}
.lightbox-close {
  position: fixed; top: 1rem; right: 1rem;
  z-index: 2;
}
.lightbox-nav {
  position: fixed; top: 50%;
  width: 48px; height: 48px;
  transform: translateY(-50%);
  background: rgba(20, 18, 16, 0.6);
  border: 1px solid var(--ink-3);
  border-radius: 50%;
  color: var(--paper);
  font-size: 1.75rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 120ms;
}
.lightbox-nav:hover { background: var(--ink-2); }
.lightbox-nav.prev { left: 1.5rem; }
.lightbox-nav.next { right: calc(380px + 1.5rem); }
.lightbox-stage {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 2.5rem;
  min-height: 0;
}
.lightbox-stage img {
  max-width: 100%;
  max-height: calc(100vh - 5rem);
  object-fit: contain;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.6);
}
.face-overlay {
  position: absolute;
  pointer-events: none;
}
.face-box {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}
.face-box .face-label {
  position: absolute;
  bottom: -1.5rem; left: 0;
  background: var(--accent); color: var(--ink-0);
  font-size: 0.6875rem;
  padding: 2px 6px;
  white-space: nowrap;
  font-family: var(--mono);
}

.lightbox-rail {
  background: var(--ink-1);
  border-left: 1px solid var(--ink-3);
  padding: 2rem 1.75rem;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 1.5rem;
}
.rail-head h2 {
  font-size: 1.625rem;
  margin-top: 0.25rem;
  word-break: break-word;
}
.rail-subtitle {
  color: var(--paper-mut);
  font-size: 0.75rem;
  font-family: var(--mono);
  margin: 0.5rem 0 0;
  word-break: break-all;
}
.rail-actions {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
}
.rail-section p.eyebrow { margin-bottom: 0.75rem; }
.rail-section dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
  margin: 0;
  font-size: 0.8125rem;
}
.rail-section dt { color: var(--paper-mut); }
.rail-section dd { margin: 0; font-family: var(--mono); font-size: 0.75rem; word-break: break-word; }
.rail-section details summary {
  cursor: pointer;
  color: var(--paper-dim);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.rail-section pre {
  background: var(--ink-2);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.6875rem;
  max-height: 280px;
  overflow: auto;
  color: var(--paper-dim);
  margin: 0.75rem 0 0;
}

.rail-face-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--ink-2);
  cursor: pointer;
  transition: background 120ms;
  margin: 0 -0.5rem;
}
.rail-face-row:hover { background: var(--ink-2); }
.rail-face-row:last-child { border-bottom: 0; }
.rail-face-swatch {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink-3);
  flex-shrink: 0;
  border: 1px solid var(--ink-4);
}
.rail-face-name {
  flex: 1;
  font-size: 0.8125rem;
  color: var(--paper);
}
.rail-face-name.unassigned { color: var(--paper-mut); font-style: italic; }
.rail-face-conf {
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--paper-mut);
}
.rail-face-edit {
  color: var(--paper-mut);
  padding: 0 0.25rem;
}
.rail-face-edit:hover { color: var(--accent); }

.location-coords {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--paper-dim);
}
.location-placeholder {
  margin-top: 0.5rem;
  height: 120px;
  border-radius: var(--radius-sm);
  background:
    repeating-linear-gradient(45deg, var(--ink-2), var(--ink-2) 6px, var(--ink-3) 6px, var(--ink-3) 12px);
  border: 1px solid var(--ink-3);
  display: flex; align-items: center; justify-content: center;
  color: var(--paper-mut);
  font-family: var(--mono);
  font-size: 0.6875rem;
}

/* ---------- Filter drawer ---------- */
.filter-drawer {
  margin: 0; padding: 0; border: 0;
  position: fixed; top: 0; right: 0; bottom: 0; left: auto;
  z-index: var(--z-drawer);
  width: 400px; max-width: 100vw; height: 100vh; max-height: none;
  background: var(--ink-1);
  border-left: 1px solid var(--ink-3);
  color: var(--paper);
}
.filter-drawer::backdrop { background: rgba(5, 4, 3, 0.4); }
.filter-form {
  display: flex; flex-direction: column;
  height: 100%;
}
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 1.5rem 1.75rem 1rem;
  border-bottom: 1px solid var(--ink-2);
}
.filter-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.75rem;
  display: flex; flex-direction: column; gap: 1.75rem;
}
.filter-section { display: flex; flex-direction: column; gap: 0.625rem; }
.filter-label {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-mut);
}
.filter-label.inline {
  display: flex; align-items: center; gap: 0.5rem;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8125rem;
  color: var(--paper);
  font-weight: 400;
}
.year-range { display: flex; align-items: center; gap: 0.5rem; }
.year-range input {
  flex: 1;
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.625rem;
  outline: none;
  font-family: var(--mono);
  font-size: 0.8125rem;
}
.year-range input:focus { border-color: var(--accent); }
.bounds-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}
.bounds-grid input {
  width: 100%;
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.625rem;
  outline: none;
  font-family: var(--mono);
  font-size: 0.8125rem;
}
.bounds-grid input:focus { border-color: var(--accent); }
.month-chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.month-chips button {
  padding: 0.45rem 0;
  font-size: 0.6875rem;
  font-family: var(--mono);
  color: var(--paper-dim);
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.month-chips button[aria-pressed="true"] {
  background: var(--accent-dim);
  color: var(--paper);
  border-color: var(--accent);
}

.tri-toggle { display: flex; border: 1px solid var(--ink-3); border-radius: var(--radius-sm); overflow: hidden; }
.tri-toggle button {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--paper-dim);
  background: var(--ink-2);
  border: 0;
  border-right: 1px solid var(--ink-3);
}
.tri-toggle button:last-child { border-right: 0; }
.tri-toggle button[aria-pressed="true"] { background: var(--accent-dim); color: var(--paper); }

.filter-select {
  background: var(--ink-2);
  color: var(--paper);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.625rem;
  font-size: 0.8125rem;
}

.drawer-foot {
  display: flex; justify-content: space-between; gap: 0.5rem;
  padding: 1rem 1.75rem;
  border-top: 1px solid var(--ink-2);
}

/* ---------- People sheet ---------- */
.people-sheet {
  position: fixed;
  left: 1.5rem; right: 1.5rem; bottom: 1.5rem;
  background: var(--ink-1);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-lg);
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6);
  transform: translateY(calc(100% + 2rem));
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: var(--z-sheet);
  max-height: 50vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.people-sheet.open { transform: translateY(0); }
.people-sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--ink-2);
}
.people-sheet-actions { display: flex; align-items: center; gap: 0.75rem; }
.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1rem;
  padding: 1.25rem 1.5rem 1.5rem;
  overflow-y: auto;
}
.person-card {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  transition: background 120ms;
  cursor: pointer;
  text-align: center;
}
.person-card:hover { background: var(--ink-2); }
.person-swatch {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--ink-3);
  overflow: hidden;
  border: 1px solid var(--ink-4);
  position: relative;
}
.person-swatch img { width: 100%; height: 100%; object-fit: cover; }
.person-name {
  font-family: var(--serif);
  font-size: 0.875rem;
  max-width: 110px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.person-count { font-size: 0.6875rem; color: var(--paper-mut); font-family: var(--mono); }
.person-card.auto .person-name { color: var(--paper-dim); font-style: italic; }

/* ---------- Command palette ---------- */
.palette {
  margin: 10vh auto 0;
  padding: 0; border: 0;
  background: transparent;
  width: 640px; max-width: 95vw;
}
.palette::backdrop {
  background: rgba(5, 4, 3, 0.7);
  backdrop-filter: blur(4px);
}
.palette-inner {
  background: var(--ink-1);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-lg);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}
.palette-head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--ink-2);
}
.palette-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  font-size: 1rem;
}
.palette-head kbd {
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--paper-mut);
  border: 1px solid var(--ink-3);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.palette-list {
  list-style: none; margin: 0; padding: 0.5rem;
  max-height: 50vh; overflow-y: auto;
}
.palette-item {
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem;
}
.palette-item:hover,
.palette-item[aria-selected="true"] {
  background: var(--ink-2);
}
.palette-item[aria-selected="true"] {
  box-shadow: inset 2px 0 0 var(--accent);
}
.palette-item-title { font-family: var(--serif); font-size: 0.9375rem; }
.palette-item-hint { font-size: 0.6875rem; color: var(--paper-mut); font-family: var(--mono); }
.palette-group {
  padding: 0.625rem 0.875rem 0.25rem;
  font-size: 0.625rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-mut);
}

/* ---------- Task chips ---------- */
.task-chips {
  position: fixed;
  left: 1.5rem; top: calc(var(--topbar-h) + var(--context-h) + 1rem);
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: 30;
}
.task-chip {
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  display: flex; align-items: center; gap: 0.75rem;
  font-family: var(--mono);
  color: var(--paper-dim);
}
.task-chip .task-progress {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}
.task-chip button {
  color: var(--paper-mut);
  font-family: inherit;
}
.task-chip button:hover { color: var(--paper); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  left: 1.5rem; bottom: 1.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: var(--z-toast);
  max-width: 400px;
}
.toast {
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: var(--paper);
  animation: slide-in 220ms ease;
}
.toast[data-kind="error"] { border-left-color: var(--err); }
.toast[data-kind="success"] { border-left-color: var(--ok); }
@keyframes slide-in {
  from { transform: translateX(-12px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---------- Rename dialog ---------- */
.rename-dialog {
  margin: auto;
  border: 0; padding: 0;
  background: var(--ink-1);
  color: var(--paper);
  border-radius: var(--radius-lg);
  width: 420px; max-width: 95vw;
}
.rename-dialog::backdrop { background: rgba(5, 4, 3, 0.7); backdrop-filter: blur(4px); }
.rename-form {
  padding: 1.75rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}
.rename-form h2 { margin-top: 0.25rem; }
.rename-form input {
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  outline: none;
  margin-top: 0.5rem;
}
.rename-form input:focus { border-color: var(--accent); }
.dialog-actions {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  margin-top: 0.75rem;
}
.form-error { color: var(--err); font-size: 0.8125rem; margin: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  :root {
    --topbar-h: 112px;
    --context-h: 72px;
  }

  html {
    font-size: 14px;
  }

  body {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    min-height: 100dvh;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "library actions"
      "search search";
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    align-items: center;
  }

  .topbar-left {
    grid-area: library;
    min-width: 0;
  }

  .topbar-right {
    grid-area: actions;
    gap: 0.25rem;
  }

  .search-form {
    grid-area: search;
    height: 40px;
    max-width: none;
    justify-self: stretch;
  }

  .search-input {
    min-width: 0;
  }

  .search-hint {
    display: none;
  }

  .library-button {
    padding: 0.25rem 0;
  }

  .library-button-mark {
    width: 24px;
    height: 24px;
  }

  .library-button-body > span:last-child {
    max-width: 170px;
    font-size: 0.9375rem;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .health-pill {
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: var(--radius-sm);
  }

  .health-pill span:last-child {
    display: none;
  }

  .library-menu {
    left: 0.75rem !important;
    right: 0.75rem;
    min-width: 0;
    max-height: 50dvh;
  }

  .context-bar {
    align-items: stretch;
    flex-direction: column;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.125rem;
    scrollbar-width: none;
  }

  .chips::-webkit-scrollbar {
    display: none;
  }

  .chip {
    flex: 0 0 auto;
    max-width: 76vw;
  }

  .chip > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .context-bar-right {
    justify-content: space-between;
  }

  .result-count {
    min-width: 0;
  }

  .gallery-surface {
    padding: 0.5rem 0.5rem 5rem;
    -webkit-overflow-scrolling: touch;
  }

  .gallery[data-density="comfortable"] {
    column-count: 2;
    column-gap: 6px;
  }

  .gallery[data-density="dense"] {
    column-count: 3;
    column-gap: 4px;
  }

  .gallery[data-density="uniform"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .photo-card {
    margin-bottom: 6px;
  }

  .photo-card .caption {
    opacity: 1;
    transform: none;
    padding: 1.5rem 0.5rem 0.45rem;
    font-size: 0.6875rem;
  }

  .gallery-empty {
    padding: 4rem 1rem;
  }

  .gallery-empty h2 {
    font-size: 1.625rem;
  }

  .gallery-loading {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gallery-loading .skeleton {
    height: 180px;
  }

  .lightbox {
    height: 100dvh;
  }

  .lightbox-inner {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 56dvh) minmax(220px, 44dvh);
    height: 100dvh;
  }

  .lightbox-stage {
    padding: 3.25rem 0.75rem 0.75rem;
  }

  .lightbox-stage img {
    max-height: calc(56dvh - 4rem);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  }

  .lightbox-rail {
    border-left: 0;
    border-top: 1px solid var(--ink-3);
    padding: 1rem;
    gap: 1rem;
  }

  .rail-head h2 {
    font-size: 1.25rem;
  }

  .rail-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .rail-actions .pill-button {
    padding-inline: 0.5rem;
  }

  .rail-section dl {
    grid-template-columns: 5.5rem minmax(0, 1fr);
  }

  .lightbox-close {
    top: 0.75rem;
    right: 0.75rem;
    background: rgba(20, 18, 16, 0.8);
  }

  .lightbox-nav {
    top: 30dvh;
    width: 40px;
    height: 40px;
    font-size: 1.35rem;
  }

  .lightbox-nav.prev {
    left: 0.75rem;
  }

  .lightbox-nav.next {
    right: 0.75rem;
  }

  .face-box .face-label {
    display: none;
  }

  .filter-drawer {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    border-left: 0;
  }

  .drawer-head,
  .filter-body,
  .drawer-foot {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .filter-body {
    gap: 1.25rem;
  }

  .month-chips {
    grid-template-columns: repeat(4, 1fr);
  }

  .people-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 72dvh;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .people-sheet-head {
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
  }

  .people-sheet-actions {
    gap: 0.5rem;
  }

  .people-sheet-actions .muted {
    display: none;
  }

  .people-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    padding: 1rem;
  }

  .person-swatch {
    width: 72px;
    height: 72px;
  }

  .palette {
    margin: 1rem auto 0;
    width: calc(100vw - 1rem);
    max-width: none;
  }

  .palette-head {
    padding: 0.875rem;
  }

  .palette-head kbd {
    display: none;
  }

  .palette-list {
    max-height: 70dvh;
  }

  .palette-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.25rem;
  }

  .task-chips {
    left: 0.75rem;
    right: 0.75rem;
    top: calc(var(--topbar-h) + var(--context-h) + 0.75rem);
  }

  .task-chip {
    justify-content: space-between;
  }

  .toasts {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
    max-width: none;
  }

  .rename-dialog {
    width: calc(100vw - 2rem);
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
