/* UniFi Protect "Cameras" widget: a live grid of the user's cameras as near-live
   JPEG snapshots. Styled to match the Liquid Glass tiles (accent ambience,
   translucent cards). Rendered into .unifi-widget-mount by js/unifi-widget.js.
   Reuses the shared sh-set-* rules (from SmartHomePanel.css) for its Settings
   card + camera picker, so only the tile-specific rules live here. */
.unifi-panel { display: flex; }
.unifi-widget-mount { width: 100%; height: 100%; display: flex; min-height: 0; border-radius: inherit; }

/* ── Camera grid ─────────────────────────────────────────────────── */
.up-grid {
  box-sizing: border-box;
  width: 100%; height: 100%; min-height: 0;
  padding: 10px; border-radius: inherit; overflow: auto;
  display: grid; gap: 8px;
  /* Auto-fit so 1 camera fills the tile and many cameras wrap into a neat grid. */
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  grid-auto-rows: 1fr;
  background:
    radial-gradient(125% 95% at 100% -12%, rgba(var(--accent-rgb), 0.14), transparent 55%),
    radial-gradient(100% 70% at 0% 112%, rgba(var(--accent-rgb), 0.05), transparent 60%);
}
/* Fixed-column mode (user picked 1–4 in Settings). Rows size to the card's
   aspect-ratio and the tile scrolls, so 4 cameras become a real 2×2 grid instead
   of squashing into a single row. */
.up-grid--fixed {
  grid-template-columns: repeat(var(--up-cols, 2), minmax(0, 1fr));
  grid-auto-rows: auto;
}
.up-grid::-webkit-scrollbar { width: 6px; }
.up-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

/* A single camera card: the snapshot fills it, with an overlaid name + status. */
.up-cam {
  position: relative; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(0,0,0,0.55);
  min-height: 96px; aspect-ratio: var(--up-aspect, 16 / 9);
  padding: 0; cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease;
}
.up-cam:hover { border-color: rgba(var(--accent-rgb), 0.5); }
.up-cam:active { transform: scale(0.985); }
.up-cam:focus-visible { outline: 2px solid rgb(var(--accent-rgb)); outline-offset: 2px; }

.up-cam-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: var(--up-fit, cover);
  opacity: 0; transition: opacity 220ms ease, transform 220ms ease;
  background: #0b0d0f;   /* letterbox backdrop when fit = contain */
}
.up-cam-img.is-live { opacity: 1; }
/* A quarter-turn (90/270) swaps the image's aspect, so contain it to avoid a
   mis-crop; the transform itself is set inline by js/unifi-widget.js. */
.up-cam-img--rot { object-fit: contain; }
/* A camera whose snapshot failed dims and desaturates so it reads as stale. */
.up-cam--stale .up-cam-img { filter: grayscale(0.7) brightness(0.7); }

.up-cam-label {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 14px 9px 7px;
  background: linear-gradient(transparent, rgba(0,0,0,0.72));
  pointer-events: none;
}
.up-cam-name {
  font-size: 0.72rem; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.up-cam-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: #1ed760; box-shadow: 0 0 0 3px rgba(30,215,96,0.18);
}
.up-cam-dot.is-off { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.18); }
/* Source badge — shown on Home Assistant cameras only when both UniFi and HA
   cameras share the tile, so a single-source tile stays clutter-free. Sits at the
   right edge of the label; the name shrinks (min-width:0) to keep it visible. */
.up-cam-label .up-cam-name { min-width: 0; }
.up-cam-src {
  margin-left: auto; flex: 0 0 auto;
  font-size: 0.56rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 1px 5px; border-radius: 5px;
  color: #d7e4ff; background: rgba(90,140,240,0.34);
  text-shadow: none;
}

/* ── Live detection badge (SSE `unifi_event`) ────────────────────── */
.up-cam--alert { border-color: rgba(var(--accent-rgb), 0.9); }
.up-cam--alert .up-cam-img { animation: up-alert-pulse 1.6s ease; }
@keyframes up-alert-pulse { 0%, 100% { filter: none; } 22% { filter: brightness(1.1); } }
.up-cam-alert {
  position: absolute; top: 7px; left: 7px; z-index: 2;
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 0.66rem; font-weight: 800; letter-spacing: 0.02em;
  color: #fff; background: rgba(var(--accent-rgb), 0.94);
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  animation: up-alert-in 180ms ease; pointer-events: none;
}
@keyframes up-alert-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ── Settings: Notifications sub-section ──────────────────────────── */
.up-notify-master { font-weight: 700; }
.up-notify-body { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; transition: opacity 140ms ease; }
.up-notify-body.is-disabled { opacity: 0.4; pointer-events: none; }

/* ── Setup / empty state ─────────────────────────────────────────── */
.up-setup {
  width: 100%; height: 100%; min-height: 0; box-sizing: border-box;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 20px; text-align: center; border-radius: inherit;
}
.up-setup-icon { color: rgb(var(--accent-rgb)); opacity: 0.85; }
.up-setup-icon svg { width: 34px; height: 34px; }
.up-setup-title { font-size: 0.95rem; font-weight: 800; color: var(--text, #e7e9ee); }
.up-setup-msg { font-size: 0.78rem; color: rgba(255,255,255,0.6); max-width: 30ch; line-height: 1.45; }

/* ── Expanded overlay (portal to <body>) ─────────────────────────── */
.up-overlay {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4,6,8,0.86); backdrop-filter: blur(6px);
  animation: up-fade 160ms ease;
}
@keyframes up-fade { from { opacity: 0; } to { opacity: 1; } }
/* A fixed 16:9 frame (the Protect snapshot aspect) that clips the image, so a
   digital zoom/pan crops exactly as it will on the live tile. Sized to the largest
   16:9 box that fits 94vw × 86vh. `touch-action: none` lets us own pan gestures. */
.up-overlay-frame {
  position: relative; overflow: hidden;
  width: min(94vw, calc(86vh * 16 / 9)); aspect-ratio: 16 / 9;
  border-radius: 12px; box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  background: #0b0d0f; touch-action: none;
}
.up-overlay-frame.is-zoomed { cursor: grab; }
.up-overlay-frame.is-panning { cursor: grabbing; }
.up-overlay-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: contain;
  background: #0b0d0f; border-radius: inherit;
}
.up-overlay-bar {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px 8px 16px; border-radius: 999px;
  background: rgba(20,22,26,0.7); border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(10px);
}
.up-overlay-name { font-size: 0.82rem; font-weight: 700; color: #fff; }
.up-overlay-btn,
.up-overlay-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.06);
  color: #fff; cursor: pointer; transition: background 140ms ease;
}
.up-overlay-btn:hover,
.up-overlay-close:hover { background: rgba(255,255,255,0.16); }
.up-overlay-btn:focus-visible,
.up-overlay-close:focus-visible { outline: 2px solid rgb(var(--accent-rgb)); outline-offset: 2px; }
.up-overlay-btn svg,
.up-overlay-close svg { width: 16px; height: 16px; }
/* A little breathing room before the close button on the right. */
.up-overlay-close { margin-left: 2px; }

/* ── Settings: Layout controls + camera reorder ──────────────────── */
.up-layout { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.up-seg-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.up-seg {
  display: inline-flex; gap: 2px; padding: 3px; flex: 0 0 auto;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
}
.up-seg-btn {
  min-width: 36px; padding: 6px 11px;
  border: 0; border-radius: 7px; cursor: pointer;
  background: transparent; color: rgba(255,255,255,0.66);
  font-size: 0.78rem; font-weight: 700; font-family: inherit;
  transition: background 140ms ease, color 140ms ease;
}
.up-seg-btn:hover { color: #fff; }
.up-seg-btn.is-active { background: rgba(var(--accent-rgb), 0.9); color: #fff; }
.up-seg-btn:focus-visible { outline: 2px solid rgb(var(--accent-rgb)); outline-offset: 2px; }

.up-reorder-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.up-reorder-name { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; cursor: pointer; }
.up-reorder-moves { display: inline-flex; gap: 4px; flex: 0 0 auto; }
.up-move-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.8); cursor: pointer;
  transition: background 140ms ease, opacity 140ms ease;
}
.up-move-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }
.up-move-btn:disabled { opacity: 0.28; cursor: default; }
.up-move-btn:focus-visible { outline: 2px solid rgb(var(--accent-rgb)); outline-offset: 2px; }
.up-move-btn svg { width: 15px; height: 15px; }

/* Retro skin: hard edges, no glass — match the Pixel Retro tokens. */
:root[data-style="retro"] .up-cam,
:root[data-style="retro"] .up-overlay-frame { border-radius: 4px; }
:root[data-style="retro"] .up-cam-alert { border-radius: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
:root[data-style="retro"] .up-cam-name { text-transform: uppercase; letter-spacing: 0.04em; }
:root[data-style="retro"] .up-seg,
:root[data-style="retro"] .up-seg-btn,
:root[data-style="retro"] .up-move-btn { border-radius: 4px; }
:root[data-style="retro"] .up-seg-btn { text-transform: uppercase; letter-spacing: 0.03em; }
