/* photos.css - the dedicated Photos tool (#photos-tool).
   Loaded only by /pages/photos.html. Uses the shared design tokens from
   styles.css so it tracks the light/dark theme for free. */

/* #402: this was --content-w (880px) — the READING width, which is the wrong
   measure for a wall of photographs. At 880px a 1512px laptop showed three
   columns of tiles with a third of the screen empty on each side. The grid now
   takes the width it is given, capped only where a line of 178px tiles stops
   being scannable (--content-w-photos), with gutters that shrink with the
   viewport instead of holding 20px on a 390px phone. The prose note below keeps
   its reading width — that rule is about text, not tiles. */
.ph-page {
  max-width: var(--content-w-photos, 2000px);
  margin: 0 auto;
  padding: clamp(12px, 1.6vw, 24px) clamp(10px, 1.6vw, 24px) var(--sp-12, 48px);
}

/* ---- header ---- */
.ph-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.ph-title { font-size: 20px; font-weight: 800; color: var(--heading); margin: 0; }
.ph-sub { font-size: 12.5px; color: var(--muted); margin: 3px 0 0; }
.ph-count {
  font-size: var(--fs-md); color: var(--muted); font-variant-numeric: tabular-nums;
  padding: 5px 10px; border: 1px solid var(--line); border-radius: var(--radius-pill);
  background: var(--surface);
}

/* ---- filter bar ---- */
.ph-filters {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
  padding: 14px 16px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.ph-field { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.ph-field-search { flex: 1 1 200px; }
.ph-field-lbl {
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  color: var(--muted);
}
.ph-field-hint { font-weight: 600; text-transform: none; letter-spacing: 0; opacity: .8; cursor: help; }
.ph-field-muted .ph-field-lbl { opacity: .55; }
.ph-select, .ph-input {
  font-size: var(--fs-base); padding: 8px 10px; border-radius: 8px; font-family: inherit;
  border: 1px solid var(--line-dk, var(--line)); background: var(--surface-2, var(--surface));
  color: var(--ink); max-width: 100%;
}
.ph-select:disabled { opacity: .5; cursor: not-allowed; }
.ph-input { min-width: 0; }

/* Two mutually-exclusive photo sources: the Subcontractor field draws from the
   Daily Log; Album / Trade / Search draw from the Photos album. When one side is
   active, dim the other so it's visible that it doesn't apply (and that picking it
   would switch sources) — no silent grey-out. */
.ph-filters.src-dl .ph-src-img,
.ph-filters.src-img .ph-src-dl { opacity: .5; }
.ph-filters-note {
  font-size: var(--fs-md); color: var(--muted); line-height: 1.5;
  margin: -8px 2px 18px; max-width: var(--content-w);
}
.ph-filters-note b { color: var(--ink); font-weight: 700; }

/* ---- body / messages ---- */
.ph-msg {
  padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13.5px;
  border: 1px dashed var(--line); border-radius: 12px; background: var(--surface);
  max-width: 560px; margin: 24px auto; line-height: 1.5;
}

/* ---- grid ---- */
.ph-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
}
.ph-tile {
  position: relative; display: block; padding: 0; cursor: pointer;
  border-radius: 11px; overflow: hidden; background: var(--surface-3, var(--surface-2, var(--surface)));
  border: 1px solid var(--line); aspect-ratio: 1 / 1;
  font-family: inherit; text-align: left; color: inherit;
  transition: transform .12s ease, box-shadow .12s ease;
}
.ph-tile:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,0,0,.28); }
.ph-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ph-tile-img { position: absolute; inset: 0; display: block; }
.ph-tile-img img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .25s ease;
}
.ph-tile.is-loaded .ph-tile-img img { opacity: 1; }
/* A thumbnail that failed to load: hide the empty <img> so no broken glyph
   shows; the tile keeps its background and caption. */
.ph-tile.is-broken .ph-tile-img img { display: none; }
.ph-tile.is-broken::after {
  content: "Image unavailable"; position: absolute; inset: 0;
  display: grid; place-items: center; font-size: var(--fs-xs); color: var(--muted); padding: 8px;
}

.ph-badges { position: absolute; top: 8px; left: 8px; display: flex; gap: 5px; z-index: 2; }
.ph-badge {
  font-size: var(--fs-2xs); font-weight: 700; padding: 2px 7px; border-radius: var(--radius-pill);
  background: rgba(0,0,0,.62); color: #fff; backdrop-filter: blur(2px);
}
.ph-badge-star { background: rgba(214,158,20,.9); }

.ph-tile-cap {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1;
  padding: 20px 9px 7px; display: flex; flex-direction: column; gap: 1px;
  color: #fff; font-size: var(--fs-sm);
  background: linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,0));
}
.ph-tile-cap b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ph-tile-cap span { opacity: .82; font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ph-more { padding: 24px; text-align: center; }
.ph-more-lbl { display: block; font-size: 12.5px; color: var(--muted); }
.ph-more-btn { margin-bottom: 8px; }

/* ---- lightbox ---- */
body.ph-lb-open { overflow: hidden; }
.ph-lb {
  position: fixed; inset: 0; z-index: 1000; display: flex;
  background: rgba(8,10,14,.92); backdrop-filter: blur(3px);
}
.ph-lb[hidden] { display: none; }
.ph-lb-stage {
  flex: 1 1 auto; position: relative; display: grid; place-items: center;
  padding: 40px 20px; min-width: 0;
}
.ph-lb-img {
  max-width: 100%; max-height: calc(100vh - 80px); object-fit: contain;
  border-radius: var(--radius); box-shadow: 0 12px 48px rgba(0,0,0,.5);
}
.ph-lb-img.is-broken { display: none; }
/* Blur-up placeholder: the grid thumbnail upscaled while the full-view image
   loads. Blurred on purpose — an upscaled 300px thumbnail shown sharp reads as
   a broken image, whereas a soft one reads as "still loading". It sits in the
   same grid cell as the real image so the swap does not shift the layout. */
.ph-lb-preview {
  position: absolute; filter: blur(12px); transform: scale(1.02);
  opacity: 1; transition: opacity .18s ease-out;
}
.ph-lb-preview.is-fading { opacity: 0; }
.ph-lb-img#phLbImg { opacity: 0; transition: opacity .18s ease-in; }
.ph-lb-img#phLbImg.is-shown { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .ph-lb-preview, .ph-lb-img#phLbImg { transition: none; }
}
.ph-lb-spin {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: ph-spin .8s linear infinite; position: absolute;
}
@keyframes ph-spin { to { transform: rotate(360deg); } }

.ph-lb-close {
  position: absolute; top: 14px; right: 18px; z-index: 3;
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.12); color: #fff; font-size: 26px; line-height: 1;
}
.ph-lb-close:hover { background: rgba(255,255,255,.22); }
.ph-lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 3;
  width: 48px; height: 64px; border: 0; cursor: pointer; border-radius: var(--radius-lg);
  background: rgba(255,255,255,.1); color: #fff; font-size: 34px; line-height: 1;
}
.ph-lb-nav:hover { background: rgba(255,255,255,.2); }
.ph-lb-nav:disabled { opacity: .25; cursor: default; }
.ph-lb-prev { left: 16px; }
.ph-lb-next { right: 396px; }

.ph-lb-meta {
  flex: 0 0 360px; width: 360px; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--line);
  padding: 22px 22px 32px; color: var(--ink);
}
.ph-meta-head { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px; }
.ph-meta-title { font-size: 16px; font-weight: 800; color: var(--heading); line-height: 1.3; }
.ph-meta-desc { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.5; white-space: pre-wrap; }
.ph-meta-flags { margin-top: 10px; display: flex; gap: 6px; }
.ph-meta-flags .ph-badge { background: var(--surface-3, var(--surface-2)); color: var(--ink); border: 1px solid var(--line); }
.ph-meta-flags .ph-badge-star { background: rgba(214,158,20,.16); color: var(--ink); border-color: rgba(214,158,20,.4); }
.ph-meta-row { display: flex; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.ph-meta-row:first-child { border-top: 0; }
.ph-meta-k { flex: 0 0 92px; color: var(--muted); font-weight: 600; }
.ph-meta-v { flex: 1; color: var(--ink); word-break: break-word; }
.ph-meta-actions { margin-top: 16px; }
.ph-meta-orig {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface-3, var(--surface-2)); color: var(--ink);
  font-size: 12.5px; font-weight: 600; text-decoration: none;
}
.ph-meta-orig:hover { border-color: var(--accent, var(--ink)); }
.ph-meta-pos { margin-top: 18px; font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- responsive: stack the viewer meta below the image on narrow screens ---- */
@media (max-width: 820px) {
  .ph-lb { flex-direction: column; }
  .ph-lb-stage { padding: 16px 12px; max-height: 62vh; }
  .ph-lb-img { max-height: calc(62vh - 24px); }
  .ph-lb-meta { flex: 1 1 auto; width: 100%; border-left: 0; border-top: 1px solid var(--line); }
  .ph-lb-next { right: 16px; }
  .ph-lb-nav { top: auto; bottom: calc(38vh + 8px); transform: none; height: 48px; width: 44px; }
}
@media (max-width: 640px) {
  /* #402: a 390px phone divides into two 140px tiles with the 8px gap and the
     page's own clamped 10px gutters — two big, tappable photos per row rather
     than one-and-a-bit. The filter bar loses its card inset for the same reason:
     28px of horizontal chrome around a 370px column is a column of photos. */
  .ph-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .ph-filters { padding: 10px; gap: 8px; }
  .ph-field { min-width: 0; flex: 1 1 140px; }
  /* 16px inputs stop iOS focus-zoom (same rule the Insurance page uses). */
  .ph-select, .ph-input { font-size: 16px; }
}
