/* #/wall — owned by views/wall.js. Tokens only; the literal blacks/whites below are the caption scrims and
   text ON camera imagery (DESIGN.md exception), never on a surface. */

/* ---- header ---------------------------------------------------------------------------------------------- */
.wall-page .page-actions { flex-wrap: wrap; }
.wall-site select { min-width: 12rem; max-width: 18rem; }
.wall-lay > button { min-width: 2.75rem; font-variant-numeric: tabular-nums; }
.wall-skel { display: grid; gap: var(--sp-2); grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }

/* ---- site groups ------------------------------------------------------------------------------------------- */
.wgroup + .wgroup { margin-top: var(--sp-5); }
.wg-title {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3);
  margin: 0 0 var(--sp-2); padding: var(--sp-2) 0; background: var(--bg);
  font-size: var(--fs-md); font-weight: var(--fw-semibold);
}
.wg-head {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 32px; padding: 2px var(--sp-2) 2px var(--sp-1);
  margin-left: calc(-1 * var(--sp-1)); border: 0; border-radius: var(--r-sm); background: none; color: var(--ink);
  font: inherit; font-size: var(--fs-lg); cursor: pointer; text-align: left;
  transition: background-color var(--dur-2) var(--ease-out);
}
.wg-head:hover { background: var(--surface-2); }
.wg-chev { display: inline-grid; color: var(--ink-3); transition: transform var(--dur-3) var(--ease-out); }
.wgroup.folded .wg-chev { transform: rotate(-90deg); }
.wg-name { min-width: 0; }
.wg-meta { display: inline-flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); font-size: var(--fs-sm); font-weight: var(--fw-regular); color: var(--ink-2); }
.wg-n { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-sm); font-weight: var(--fw-regular); color: var(--ink-2); }
.wgroup.folded .wg-title { margin-bottom: 0; }

/* ---- the grid: auto, or a fixed number per row --------------------------------------------------------------- */
.wall-grid { display: grid; gap: var(--sp-2); grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.wall-grid[hidden] { display: none; }
[data-layout="1"] .wall-grid { grid-template-columns: minmax(0, min(100%, calc((100dvh - 190px) * 16 / 9))); justify-content: center; }
[data-layout="4"] .wall-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
[data-layout="9"] .wall-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
[data-layout="16"] .wall-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-1); }

/* ---- a tile: the shared .camtile (components.css, lib/camtile.js) in its 'over' variant; the wall adds the hover chrome,
   the whole-tile hit button, the "nothing to show" panel and the alarm outline ------------------------------------------ */
.wall-tile { aspect-ratio: 16 / 9; border-radius: var(--r-md); content-visibility: auto; contain-intrinsic-size: auto 180px; }
.wall-tile .v { position: absolute; inset: 0; }
.wall-tile video, .wall-tile img { width: 100%; height: 100%; object-fit: contain; display: block; }
.wall-tile .v > .off { position: absolute; inset: 0; display: grid; place-items: center; color: var(--media-ink-2); font-size: var(--fs-sm); }
.wall-tile .v .fage { z-index: 1; transition: opacity var(--dur-2) var(--ease-out); }
/* A fresh frame needs no label: the age shows on hover/focus, and always once it is stale (red) or live. */
.wall-tile .v .fage:not(.stale):not(.live) { opacity: 0; }
.wall-tile:hover .v .fage, .wall-tile:focus-within .v .fage { opacity: 1; }
.wall-tile.has-alarm .v .fage, .wall-tile.is-muted .v .fage { top: 42px; }   /* the alarm label / mute chip own the top-left */

/* Nothing to show (offline stream, no signal yet, paused): say what and since when — not a bare black box. */
.wt-off {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-1);
  padding: var(--sp-3); text-align: center; font-size: var(--fs-sm); color: var(--media-ink-2);
  background: repeating-linear-gradient(135deg, var(--media-tint) 0 10px, transparent 10px 20px), var(--media-bg);
}
.wt-off b { color: var(--media-ink); font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.wt-off .icon { color: var(--media-ink-2); margin-bottom: var(--sp-1); }
.wall-tile.is-offline .wt-off .icon { color: var(--cam-offline); }
/* A protect camera that has gone dark keeps its last frame, dimmed, with the red age from playStill. */
.wall-tile.is-offline[data-mode="still"] .v img { filter: grayscale(1) brightness(0.55); }
.wall-tile.is-offline[data-mode="still"] .v::after {
  content: "Offline — last frame"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 3px 10px; border-radius: var(--r-pill); background: var(--media-scrim); color: var(--media-ink);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); white-space: nowrap; pointer-events: none;
}

/* The whole tile is one button (open alarm / enlarge); the chrome floats above it. */
.wt-hit { position: absolute; inset: 0; z-index: 3; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; border-radius: inherit; }
.wt-hit:focus-visible { outline: none; }
.wall-tile:has(.wt-hit:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

.wt-live, .wt-role {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 7px; border-radius: var(--r-xs);
  background: var(--media-scrim); color: var(--media-ink); font: var(--fw-bold) var(--fs-2xs)/1 var(--font-ui); letter-spacing: var(--tracking-caps);
}
.wt-live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--cam-online); }
.wt-role { padding: 0 5px; }
.wt-role-text { padding: 0 7px 0 5px; letter-spacing: 0; font-weight: var(--fw-semibold); }

.wall-tile .camtile-bar { padding-right: var(--sp-1); }
.wt-exp {
  margin-left: auto; display: inline-grid; place-items: center; width: 30px; height: 30px; flex: none; padding: 0; border: 0;
  border-radius: var(--r-sm); background: transparent; color: var(--media-ink); cursor: pointer; pointer-events: auto;
  transition: background-color var(--dur-2) var(--ease-out);
}
.wt-exp:hover { background: var(--media-hover); }
/* Caption + tags stay out of the picture until hover/focus — except on a tile that needs attention. Interior and mutes always show. */
.wall-tile .camtile-tags > :not(.wt-role-text), .wall-tile .camtile-bar { opacity: 0; transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out); }
.wall-tile .camtile-bar { transform: translateY(3px); }
.wall-tile:hover .camtile-tags > *, .wall-tile:focus-within .camtile-tags > *, .wall-tile:hover .camtile-bar, .wall-tile:focus-within .camtile-bar,
.wall-tile.has-alarm .camtile-bar, .wall-tile.is-offline .camtile-bar, .wall-tile.is-unknown .camtile-bar { opacity: 1; transform: none; }
@media (hover: none) { .wall-tile .camtile-tags > *, .wall-tile .camtile-bar { opacity: 1; transform: none; } }

/* ---- open alarm: an outline + a label that stays; NEW breathes (slowly), acked holds still ------------------- */
.wt-alarm {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%; min-width: 0; pointer-events: none;
  padding: 3px 8px 3px 3px; border-radius: var(--r-pill); background: var(--surface); color: var(--ink);
  border: 1px solid var(--danger-line); box-shadow: var(--shadow-2); font-size: var(--fs-xs); white-space: nowrap;
}
.wt-alarm[hidden] { display: none; }
.wt-atype { font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; }
.wt-aage { color: var(--ink-2); }
.wt-ack { padding: 1px 7px; border-radius: var(--r-pill); font-weight: var(--fw-bold); letter-spacing: .04em; background: var(--caution-soft); color: var(--caution-ink); border: 1px solid var(--caution-line); }
.wall-tile.has-alarm::after, .wall-tile.has-alarm::before { content: ""; position: absolute; inset: 0; z-index: 3; border-radius: inherit; pointer-events: none; }
.wall-tile.has-alarm::after { box-shadow: inset 0 0 0 2px var(--danger-line); }
.wall-tile.alarm-new::after { box-shadow: inset 0 0 0 3px var(--danger); }
.wall-tile.alarm-new::before { box-shadow: inset 0 0 28px 2px var(--danger-soft), inset 0 0 0 6px var(--danger-soft); animation: wt-breathe 2.4s var(--ease-in-out) infinite alternate; }
@keyframes wt-breathe { from { opacity: 0.25; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .wall-tile.alarm-new::before { animation: none; opacity: 1; } }

/* ---- solo (enlarged) ---------------------------------------------------------------------------------------- */
.wsolo {
  position: absolute; inset: 0; z-index: var(--z-overlay); display: grid; grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg); animation: wsolo-in var(--dur-3) var(--ease-out);
}
@keyframes wsolo-in { from { opacity: 0; transform: scale(0.985); } }
.wsolo-bar { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); background: var(--surface); border-bottom: 1px solid var(--line); min-width: 0; }
.wsolo-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.wsolo-title h2 { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-lg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wsolo-sub { font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wsolo-alarm:empty { display: none; }
.wsolo-alarm .btn { gap: 6px; }
.wsolo-pos { white-space: nowrap; }
.wsolo-stage { position: relative; overflow: hidden; background: var(--media-bg); margin: var(--sp-3); aspect-ratio: auto; height: auto; min-height: 0; content-visibility: visible; touch-action: pan-y; }
.wsolo-stage:fullscreen { margin: 0; border-radius: 0; }

/* ---- phones: 1–2 across, chrome always on (no hover), bigger targets --------------------------------------- */
@media (max-width: 900px) {
  .wall-page .page-actions { width: 100%; }
  .wall-site { flex: 1; }
  .wall-site select { width: 100%; max-width: none; min-width: 0; }
  [data-layout="9"] .wall-grid, [data-layout="16"] .wall-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wsolo-stage { margin: 0; border-radius: 0; }
  .wsolo-bar { padding: var(--sp-1) var(--sp-2); flex-wrap: wrap; }
  .wsolo-alarm { order: 5; width: 100%; }
  .wsolo-alarm .btn { width: 100%; }
}
@media (max-width: 600px) {
  /* Phones: two across by default (name + status only); "1" in the layout switch is the one-per-row view. */
  [data-layout="auto"] .wall-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-1); }
  [data-layout="auto"] .wall-grid .wall-tile .camtile-bar { padding-left: var(--sp-2); font-size: var(--fs-xs); }
  [data-layout="auto"] .wt-exp, [data-layout="auto"] .wt-alarm .wt-aage, [data-layout="auto"] .wt-alarm .wt-atype { display: none; }
  [data-layout="auto"] .wall-tile .camtile-tags > :not(.wt-role-text), [data-layout="auto"] .wall-tile .fage:not(.stale):not(.live) { display: none; }
  [data-layout="auto"] .wt-off { gap: 0; padding: var(--sp-2) var(--sp-2) var(--sp-6); }
  [data-layout="auto"] .wt-off > span, [data-layout="auto"] .wt-off .icon { display: none; }   /* the caption says "dark 1h 11m" */
  [data-layout="auto"] .wt-off b { font-size: var(--fs-sm); }
  .wall-tile .camtile-top { top: 6px; left: 6px; right: 6px; }
  [data-layout="4"] .wall-grid .wall-tile .camtile-bar, [data-layout="9"] .wall-grid .wall-tile .camtile-bar, [data-layout="16"] .wall-grid .wall-tile .camtile-bar { padding-left: var(--sp-2); font-size: var(--fs-xs); }
  [data-layout="4"] .wt-exp, [data-layout="9"] .wt-exp, [data-layout="16"] .wt-exp { display: none; }
  [data-layout="4"] .wt-alarm .wt-aage, [data-layout="9"] .wt-alarm .wt-aage, [data-layout="16"] .wt-alarm .wt-aage { display: none; }
}
@media (pointer: coarse), (max-width: 900px) { .wt-exp { width: 40px; height: 40px; } }
