/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * Copyright © 2026 Marcel Rymenhout and IniqDash contributors */
/* ==========================================================================
   Camera Widget V1. The picture fills the widget's own box (cover or contain); a quiet overlay bar
   carries name + status. Sizes come from MaisonFit (--fit, components/fit): never the screen.
     full   name + status text in a bottom bar
     mini   (< 180 px wide or < 110 px tall) only a status dot in the corner
   ========================================================================== */
.cam {
  position: relative;
  container: cam / size;
  --fit-ref-w: 320; --fit-ref-h: 200; --fit-min: .7px; --fit-max: 1.35px;
  min-width: 0;
  min-height: 72px;
  overflow: hidden;
  border-radius: var(--radius-device);
  color: var(--text-primary);
  font-family: var(--font);
  background: #0b0c0f;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05), 0 12px 26px -16px rgba(0, 0, 0, .75);
}
.cam__in { position: absolute; inset: 0; }
.cam__view { position: absolute; inset: 0; display: grid; place-items: center; }
.cam__img { width: 100%; height: 100%; object-fit: cover; display: block; user-select: none; -webkit-user-drag: none; }
.cam[data-fit-mode="contain"] .cam__img { object-fit: contain; }
.cam[data-img="none"] .cam__img { display: none; }
.cam__ph { display: none; flex-direction: column; align-items: center; gap: calc(6 * var(--fit)); color: var(--text-muted); font-size: max(11px, calc(12.5 * var(--fit))); }
.cam__ph svg { width: calc(30 * var(--fit)); height: calc(30 * var(--fit)); }
.cam[data-img="none"] .cam__ph { display: flex; }
.cam[data-state="unavailable"] .cam__img { filter: grayscale(1) brightness(.45); }
.cam[data-img="stale"] .cam__img { filter: brightness(.75); }

.cam__bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: calc(10 * var(--fit));
  padding: calc(22 * var(--fit)) calc(14 * var(--fit)) calc(11 * var(--fit));
  background: linear-gradient(180deg, transparent, rgba(5, 6, 8, .78));
  pointer-events: none;
}
.cam[data-show-name="false"] .cam__name { display: none; }
.cam__info { flex: 0 1 auto; min-width: 0; margin-left: auto; font-size: max(11px, calc(11.5 * var(--fit))); font-weight: var(--iq-fw-subtitle); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.cam__info[hidden], .cam[data-fit-arr="mini"] .cam__info { display: none; }
.cam__name { min-width: 0; font-size: max(11.5px, calc(14 * var(--fit))); font-weight: var(--iq-fw-title); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.cam__status { flex: none; display: inline-flex; align-items: center; gap: calc(6 * var(--fit)); font-size: max(11px, calc(11.5 * var(--fit))); font-weight: var(--iq-fw-status); color: var(--text-secondary);
  padding: calc(3 * var(--fit)) calc(9 * var(--fit)); border-radius: var(--radius-pill); background: rgba(10, 11, 14, .6); }
.cam__dot { width: max(7px, calc(8 * var(--fit))); height: max(7px, calc(8 * var(--fit))); border-radius: 50%; background: var(--text-muted); }
.cam[data-state="streaming"] .cam__dot, .cam[data-state="idle"][data-img="ok"] .cam__dot { background: var(--success); box-shadow: 0 0 8px color-mix(in srgb, var(--success) 70%, transparent); }
.cam[data-state="recording"] .cam__dot { background: var(--danger); box-shadow: 0 0 8px color-mix(in srgb, var(--danger) 70%, transparent); animation: cam-rec 1.6s ease-in-out infinite; }
.cam[data-state="unavailable"] .cam__dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-muted); }
@keyframes cam-rec { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .cam[data-state="recording"] .cam__dot { animation: none; } }

/* mini: the picture and a status dot only */
.cam[data-fit-arr="mini"] .cam__bar { left: auto; padding: calc(8 * var(--fit)); background: none; }
.cam[data-fit-arr="mini"] .cam__name, .cam[data-fit-arr="mini"] .cam__status b { display: none; }
.cam[data-fit-arr="mini"] .cam__status { padding: 5px; }
.cam[data-fit-arr="mini"] .cam__ph span { display: none; }

/* own size: the picture is laid out on the widget's own box, so "cover" crops around the centre at every shape (a very
   wide or very tall camera tile shows the middle of the scene, never only its top) and "contain" letterboxes it */
.cam__img { position: absolute; inset: 0; }
/* a short, wide tile: the bar stays one quiet line */
@container cam (max-height: 120px) and (min-width: 300px) { .cam__bar { padding-top: calc(12 * var(--fit)); } }

/* ================================================================ Doorbell presentation + the enlarge button (iq-cam-* for new dialog parts) */
.cam__chips { position: absolute; left: calc(10 * var(--fit)); top: calc(10 * var(--fit)); right: calc(48 * var(--fit)); display: flex; flex-wrap: wrap; gap: 5px; pointer-events: none; }
.cam__chips[hidden], .cam__expand[hidden] { display: none; }
.cam__chip { padding: calc(3 * var(--fit)) calc(9 * var(--fit)); border-radius: var(--radius-pill); font-size: max(11px, calc(11.5 * var(--fit))); font-weight: var(--iq-fw-control); color: var(--text-primary); background: rgba(10, 11, 14, .68); white-space: nowrap; }
.cam__chip[data-tone="alert"] { background: var(--accent); color: var(--page-bg, #111); }
.cam__upd { flex: 0 1 auto; min-width: 0; font-size: max(11px, calc(11 * var(--fit))); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.cam__upd:empty { display: none; }
.cam__expand { position: absolute; right: calc(8 * var(--fit)); top: calc(8 * var(--fit)); width: max(30px, calc(34 * var(--fit))); height: max(30px, calc(34 * var(--fit))); padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--text-primary); background: rgba(10, 11, 14, .6); opacity: .85; }
.cam__expand svg { width: 55%; height: 55%; }
.cam__expand:hover, .cam__expand:focus-visible { opacity: 1; }
.cam__expand:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.cam[data-fit-arr="mini"] .cam__expand, .cam[data-fit-arr="mini"] .cam__chips, .cam[data-fit-arr="mini"] .cam__upd { display: none; }
.cam[data-ringing="true"]::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 3px var(--accent); pointer-events: none; animation: cam-ring 1.1s ease-in-out infinite; }
@keyframes cam-ring { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .cam[data-ringing="true"]::after { animation: none; } }
@container cam (max-height: 150px) { .cam[data-variant="doorbell"] .cam__upd { display: none; } }
.iq-cam-lightbox { width: min(96vw, 1100px); max-height: 94vh; padding: 0; border: 0; border-radius: 14px; overflow: hidden; background: #0b0c0f; color: #fff; }
.iq-cam-lightbox::backdrop { background: rgba(0, 0, 0, .75); }
.iq-cam-lightbox img { display: block; width: 100%; max-height: calc(94vh - 48px); object-fit: contain; }
.iq-cam-lightbox__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 14px; font: 600 13px var(--font, system-ui); background: #15171c; }
.iq-cam-lightbox__bar button { padding: 6px 14px; border: 0; border-radius: 16px; cursor: pointer; font: 600 12.5px var(--font, system-ui); color: #fff; background: #2a2d35; }
.iq-cam-lightbox__bar button:focus-visible { outline: 2px solid #f0a64b; outline-offset: 2px; }

/* pass 2: a narrow doorbell keeps the name whole on its own line; snapshot time and live status share the line under it */
@container cam (max-width: 259px) {
  .cam[data-variant="doorbell"] .cam__bar { flex-wrap: wrap; row-gap: 2px; }
  .cam[data-variant="doorbell"] .cam__name { flex: 1 1 100%; }
  .cam[data-variant="doorbell"] .cam__upd { flex: 1 1 0; }
}

/* ---------------------------------------------------------------- PTZ presentation: controls over the picture (the shared control button) */
.cam__ptz { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.cam__ptz > * { pointer-events: auto; }
.cam__pad { position: absolute; left: 12px; bottom: 56px; display: grid; grid-template-columns: repeat(3, 36px); grid-template-rows: repeat(3, 36px); gap: 2px;
  padding: 6px; border-radius: 999px; background: color-mix(in srgb, #000 42%, transparent); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.cam__pad .cam__ptzb[data-role="tiltUp"] { grid-area: 1 / 2; }
.cam__pad .cam__ptzb[data-role="panLeft"] { grid-area: 2 / 1; }
.cam__pad .cam__ptzb[data-role="panRight"] { grid-area: 2 / 3; }
.cam__pad .cam__ptzb[data-role="tiltDown"] { grid-area: 3 / 2; }
.cam__zoom { position: absolute; right: 12px; bottom: 56px; display: grid; gap: 6px; padding: 6px; border-radius: 999px; background: color-mix(in srgb, #000 42%, transparent); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.cam__pad[hidden], .cam__zoom[hidden], .cam__preset[hidden] { display: none; }
.cam__ptzbar { position: absolute; left: 10px; right: 54px; top: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cam__preset { min-height: 32px; max-width: 46%; padding: 0 8px; border: 0; border-radius: 10px; font: 600 12px var(--font); color: #fff; background: color-mix(in srgb, #000 55%, transparent); }
.cam__preset:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.cam__toggles { display: inline-flex; gap: 6px; }
.cam__toggles .cam__ptzb.is-armed { box-shadow: 0 0 0 2px var(--warning); }
.cam__ind { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.cam__ind .cam__chip[data-tone="rec"] { color: #fff; background: var(--danger); }
.cam__ptz-msg { flex-basis: 100%; min-height: 1em; font-size: 12px; font-weight: 600; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .7); }
.cam[data-variant="ptz"][data-fit-arr="mini"] .cam__ptz { display: none; }
/* PTZ on a SHORT card: a compact pad at the bottom edge, so the preset / privacy bar at the top and the pad never cover each other
   (every pan / tilt button stays reachable); on a wide, short card the top bar starts to the right of the pad */
@container cam (max-height: 259px) {
  .cam[data-variant="ptz"] .cam__pad { bottom: 10px; grid-template-columns: repeat(3, 26px); grid-template-rows: repeat(3, 26px); padding: 5px; }
  .cam[data-variant="ptz"] .cam__pad .cam__ptzb { width: 26px; height: 26px; min-width: 0; min-height: 0; }
  .cam[data-variant="ptz"] .cam__zoom { bottom: 10px; }
  .cam[data-variant="ptz"] .cam__ptzbar { flex-wrap: nowrap; }
  .cam[data-variant="ptz"] .cam__ptz-msg { position: absolute; top: 100%; left: 0; margin-top: 4px; }
}
@container cam (max-height: 150px) and (min-width: 300px) {
  .cam[data-variant="ptz"] .cam__ptzbar { left: 112px; }
}
/* …and on a small, narrow one there is no room for the status chips beside the controls (as in the other variants' smallest size) */
@container cam (max-height: 259px) and (max-width: 339px) { .cam[data-variant="ptz"] .cam__ind { display: none; } }

/* ================================================================ GRID (variant 'grid') — several cameras in one card */
.cam-grid { box-sizing: border-box; height: 100%; min-width: 0; padding: 16px 18px; border-radius: 20px; background: linear-gradient(180deg, #1f2129 0%, #1a1c22 100%); border: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .25); color: #fff; font-family: var(--mai-font, var(--font)); }
.cam-grid__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.cam-grid__head h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; font-weight: 600; line-height: 16px; }
.cam-grid__head > span { font-size: 9px; color: #8b909c; }
.cam-grid__list { display: grid; grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr)); gap: 10px; }
.cam-grid__cam { position: relative; display: block; padding: 0; border: 0; border-radius: 16px; overflow: hidden; background: #0f1118; cursor: pointer; aspect-ratio: 16 / 10; color: #fff; text-align: left; font: inherit; }
.cam-grid__view { position: absolute; inset: 0 0 auto 0; aspect-ratio: 16 / 9; background: #0d0f14; }
.cam-grid__view img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: saturate(.55) brightness(.85) contrast(1.05); z-index: 1; }
.cam-grid__off { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: #8b909c; font-size: 10px; }
.cam-grid__off svg { width: 26px; height: 26px; }
.cam-grid__cam::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(10, 11, 15, .85) 0%, rgba(10, 11, 15, 0) 45%); pointer-events: none; z-index: 1; }
.cam-grid__meta { position: absolute; left: 12px; bottom: 10px; z-index: 2; display: flex; flex-direction: column; }
.cam-grid__meta b { font-size: 11px; font-weight: 600; line-height: 15px; }
.cam-grid__meta small { display: inline-flex; align-items: center; gap: 5px; font-size: 8.5px; line-height: 11px; color: #c9ccd4; }
.cam-grid__meta small i { width: 7px; height: 7px; border-radius: 50%; background: #ff4b4b; box-shadow: 0 0 6px rgba(255, 75, 75, .7); }
.cam-grid__meta small.is-off i { background: #6d7280; box-shadow: none; }
.cam-grid__open { position: absolute; right: 10px; bottom: 10px; z-index: 2; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 12px; background: rgba(20, 22, 30, .6); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
@container (max-width: 520px) { .cam-grid__list { grid-template-columns: minmax(0, 1fr); } }
.cam-grid { container-type: inline-size; }
