:root {
  --bg: #07111f;
  --bg-soft: rgba(15, 31, 49, 0.86);
  --card: rgba(12, 26, 43, 0.95);
  --card-2: rgba(7, 18, 31, 0.9);
  --text: #f5f7fb;
  --muted: #9fb4c9;
  --line: rgba(157, 187, 214, 0.18);
  --accent: #5ce1e6;
  --accent-2: #7aa2ff;
  --danger: #ff8b8b;
  --success: #77e7b8;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(92, 225, 230, 0.2), transparent 32%),
    radial-gradient(circle at right 20%, rgba(122, 162, 255, 0.18), transparent 26%),
    linear-gradient(180deg, #081120 0%, #0b1728 45%, #07111f 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

.hidden {
  display: none !important;
}

.identify-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(260px, 1fr) minmax(220px, 280px);
  gap: 18px;
  align-items: start;
}

.identify-preview-shell,
.identify-history-panel {
  display: grid;
  gap: 12px;
}

.identify-preview-shell {
  position: relative;
}

.identify-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 18px;
  color: #fff;
  background: rgba(3, 8, 17, 0.66);
  backdrop-filter: blur(1px);
  z-index: 2;
}

.identify-loading-text {
  font-size: 0.9rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

#identify-modal.identify-loading .identify-preview-image {
  filter: brightness(0.7);
}

.identify-preview-image {
  width: min(100%, 140px);
  justify-self: center;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--card-2);
}

.identify-status {
  margin: 0;
}

.identify-form {
  display: grid;
  gap: 12px;
}

.identify-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.identify-history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}

.identify-history-button {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.identify-history-button img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 220px;
  aspect-ratio: auto;
  object-fit: contain;
  border-radius: 12px;
  background: var(--card-2);
}

.identify-history-button span {
  color: var(--muted);
  font-size: 0.82rem;
}

.identify-edit-mode .identify-layout {
  grid-template-columns: minmax(320px, 520px);
  justify-content: center;
}

.identify-edit-mode .identify-form {
  width: 100%;
}

@media (max-width: 900px) {
  .identify-layout {
    grid-template-columns: 1fr;
  }
}

.muted {
  color: var(--muted);
}

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 64px;
}

/* The header is sticky so the brand, device picker, and profile menu stay
   reachable while the chat history scrolls. The translucent background +
   blur lets messages slip behind it without bleeding text through. */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  margin-bottom: 12px;
  background: linear-gradient(180deg, rgba(7, 17, 31, 0.92), rgba(7, 17, 31, 0.78));
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand strong {
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Inline device select that lives directly in the header. The full
   .device-picker (label-on-top) is for forms; this is the compact
   header variant. */
.header-device-select {
  width: auto;
  min-width: 160px;
  max-width: 260px;
  padding: 6px 30px 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.9rem;
}

/* Closed pill is intentionally near-transparent so it floats on the header.
   The opened dropdown popup, however, inherits the <select>'s background
   in Chromium and ends up rendering as near-white, which makes the white
   option text unreadable. Pin <option> backgrounds to a solid dark fill so
   the popup is legible regardless of which native renderer the browser
   uses for the dropdown list. */
.header-device-select option {
  background: var(--card-2);
  color: var(--text);
}

.header-device-select option:checked,
.header-device-select option:hover {
  background: var(--accent);
  color: var(--bg);
}

/* Pending / revoked / offline rows are <option disabled> so they show up in
   the popup as context but can't be picked. Force a visibly-muted style and
   strip the hover/checked highlight so they don't read as actionable. */
.header-device-select option:disabled {
  color: var(--muted);
  font-style: italic;
}

.header-device-select option:disabled:checked,
.header-device-select option:disabled:hover {
  background: var(--card-2);
  color: var(--muted);
}

.header-session-state {
  font-size: 0.82rem;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Compact pill button anchored next to the device picker so operators can
   reach the device add/revoke flow in one click instead of digging through
   the profile-menu. Same visual language as .header-device-select. */
.header-icon-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.header-icon-button:hover,
.header-icon-button:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

.header-icon-button svg {
  flex: 0 0 auto;
}

.header-icon-button-label {
  font-weight: 500;
}

/* Profile overflow menu — same visual language as .prompt-menu but
   anchored to the right edge of the header so the panel doesn't run
   off-screen. */
.profile-menu {
  position: relative;
}

.profile-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  gap: 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
}

.profile-menu-toggle span {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
}

.profile-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 60;
  min-width: 240px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(7, 18, 31, 0.98);
  box-shadow: var(--shadow);
}

.profile-menu-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}

.profile-menu-eyebrow {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.profile-menu-email {
  color: var(--text);
  font-size: 0.92rem;
  word-break: break-all;
}

.profile-menu-option {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  text-align: left;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  font-size: 0.95rem;
}

.profile-menu-option:hover,
.profile-menu-option:focus-visible {
  background: rgba(255, 255, 255, 0.06);
}

.page-content,
.chat-page {
  display: grid;
  gap: 20px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    var(--card);
  box-shadow: var(--shadow);
  padding: 22px;
}

.auth-panel {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 24px;
  align-items: center;
  min-height: calc(100vh - 120px);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-copy h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 0.96;
  letter-spacing: -0.04em;
}

.panel-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label,
.device-picker {
  display: grid;
  gap: 8px;
}

.auth-form span,
.device-picker span {
  font-size: 0.92rem;
  color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card-2);
  color: var(--text);
  padding: 14px 16px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(92, 225, 230, 0.45);
  box-shadow: 0 0 0 3px rgba(92, 225, 230, 0.12);
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 999px;
  padding: 0 18px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #07111f;
  font-weight: 700;
}

.secondary-button,
.ghost-button {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-color: var(--line);
}

.prompt-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
}

.prompt-menu {
  position: relative;
}

.prompt-menu-toggle {
  min-width: 46px;
  width: 46px;
  padding: 0;
  gap: 4px;
}

.prompt-menu-toggle span {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
}

.prompt-menu-panel {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  z-index: 40;
  min-width: 240px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(7, 18, 31, 0.98);
  box-shadow: var(--shadow);
}

.prompt-menu-option {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

.prompt-menu-option:hover,
.prompt-menu-option:focus-visible {
  background: rgba(255, 255, 255, 0.06);
}

.form-error,
.form-status {
  margin: 0;
  font-size: 0.92rem;
}

.form-error {
  color: var(--danger);
}

.form-status {
  color: var(--success);
}

/* Chat shell now has only the messages region + input area; the
   header above (sticky) carries the device picker and profile menu
   that used to live in the chat toolbar.

   Heights use ``dvh`` (the dynamic viewport unit) where supported so
   iOS Safari's collapsing URL bar doesn't keep growing the container
   past the visible viewport — the prior ``vh`` math sized to the
   *largest* viewport, which on mobile pushed the input bar off-screen
   until the user scrolled the whole page. The ``vh`` line stays as a
   fallback for older browsers. */
.chat-shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: calc(100vh - 120px);
  min-height: calc(100dvh - 120px);
  gap: 18px;
}

.device-picker {
  min-width: 220px;
}

.messages-container {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.02);
  padding: 16px;
  overflow-y: auto;
  min-height: 320px;
  max-height: calc(100vh - 220px);
  max-height: calc(100dvh - 220px);
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* "Show older messages" sentinel that lives at the top of the chat
   feed when older items aren't yet rendered. The IntersectionObserver
   in setupLoadOlderTrigger() pre-loads when this scrolls within
   150px of the viewport top, so the button rarely flashes for users
   who scroll up; keeping it visually present (not hidden) preserves
   the affordance for keyboard / click users. */
.chat-load-older {
  display: flex;
  justify-content: center;
  padding: 4px 0 6px;
}

.chat-load-older-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.82rem;
  cursor: pointer;
}

.chat-load-older-button:hover,
.chat-load-older-button:focus-visible {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.message {
  display: flex;
}

.message-content {
  max-width: min(720px, 88%);
  padding: 14px 16px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.user-message {
  justify-content: flex-end;
}

.user-message .message-content {
  background: linear-gradient(135deg, rgba(92, 225, 230, 0.9), rgba(122, 162, 255, 0.9));
  color: #07111f;
  border-bottom-right-radius: 8px;
}

.assistant-message .message-content,
.alarm-message .message-content {
  background: rgba(10, 23, 38, 0.96);
  border: 1px solid var(--line);
  color: var(--text);
  border-bottom-left-radius: 8px;
  max-width: min(860px, 96%);
}

.message-meta {
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.user-message .message-meta {
  color: rgba(7, 17, 31, 0.72);
}

.message-text {
  line-height: 1.65;
  white-space: normal;
  word-break: break-word;
}

.message-text a {
  color: var(--accent);
  text-decoration: underline;
}

.message-time {
  margin-top: 10px;
  font-size: 0.76rem;
  color: var(--muted);
}

.user-message .message-time {
  color: rgba(7, 17, 31, 0.78);
}

.alarm-content p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.55;
}

.alarm-content strong {
  color: var(--text);
}

.scene-summary-widget-list {
  display: grid;
  gap: 14px;
}

.scene-summary-widget-card {
  display: block;
}

.scene-summary-widget-card .message-content {
  max-width: 100%;
}

.alarm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(92, 225, 230, 0.12);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid rgba(92, 225, 230, 0.2);
}

.alarm-preview-row {
  margin-top: 12px;
}

.alarm-thumb {
  width: 136px;
  max-width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  display: block;
}

.alarm-preview-card {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #081119;
  text-decoration: none;
}

.alarm-preview-image {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #081119;
}

.alarm-preview-card .alarm-preview-image {
  border: 0;
  border-radius: 0;
}

.alarm-preview-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(to top, rgba(3, 8, 17, 0.52), rgba(3, 8, 17, 0.08));
  pointer-events: none;
}

.alarm-preview-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  color: #fff;
  background: rgba(3, 8, 17, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.32);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
  font-size: 1.08rem;
}

.summary-clip-row {
  margin: 12px 0;
}

.summary-clip-inline-group {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 12px 0;
  flex-wrap: wrap;
}

.summary-clip-cue {
  flex: 1 1 220px;
  min-width: 0;
  line-height: 1.65;
  word-break: break-word;
}

.summary-clip-inline-previews {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex: 0 1 auto;
}

.summary-clip-inline-previews .summary-clip-row {
  margin: 0;
}

.alarm-media-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.alarm-crop-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  align-items: center;
  margin: 0;
  flex: 0 0 auto;
}

.alarm-crop-stack {
  display: grid;
  gap: 6px;
}

.alarm-crop-help {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.alarm-crop-identify-button {
  position: relative;
  border-radius: 12px;
  cursor: pointer;
}

.alarm-crop-identify-button::after {
  content: "Identify";
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(3, 8, 17, 0.72);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.alarm-crop-identify-button:hover::after,
.alarm-crop-identify-button:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.alarm-crop-thumb {
  width: auto;
  height: auto;
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
  background: #081119;
}

.summary-clip-card {
  position: relative;
  display: block;
  width: min(220px, 100%);
  overflow: hidden;
  border-radius: 14px;
  text-decoration: none;
  background: #081119;
  border: 1px solid var(--line);
}

.alarm-media-row .summary-clip-row,
.alarm-media-row .play-btn {
  flex: 0 1 160px;
  margin: 0;
}

.alarm-media-row .summary-clip-card {
  width: 160px;
}

.summary-clip-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
}

.summary-clip-image {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  pointer-events: none;
}

.summary-clip-generated-image:not([src]),
.summary-clip-generated-image[src=""] {
  background:
    linear-gradient(135deg, rgba(8, 17, 25, 0.98), rgba(20, 39, 56, 0.92));
}

.summary-clip-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  background: linear-gradient(to top, rgba(3, 8, 17, 0.64), rgba(3, 8, 17, 0.2));
}

.summary-clip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 999px;
  font-size: 1.15rem;
  background: rgba(3, 8, 17, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.summary-clip-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.video-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.video-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 17, 0.78);
}

.video-modal-panel,
.widget-modal-panel {
  position: relative;
  z-index: 1;
  width: min(960px, calc(100vw - 32px));
  border-radius: 18px;
  padding: 18px;
  background: rgba(7, 18, 31, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.video-modal-player {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: min(54vw, 540px);
  max-height: min(78vh, 720px);
  border-radius: 12px;
  background: #000;
  object-fit: contain;
}

.video-modal-stage {
  position: relative;
}

/* "Outside the video, inside the window" timestamp strip. Sits between
   the close-button row and the <video> stage so it never overlaps the
   native HLS controls bar at the bottom. Click-to-copy + a transient
   toast give surveillance operators a one-tap way to lift a timestamp
   into an incident report. */
.video-modal-timestamp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 0 0 10px;
  border-radius: 10px;
  background: rgba(15, 27, 42, 0.7);
  border: 1px solid var(--line);
  color: #c9d6e3;
  font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: 13px;
  letter-spacing: 0.02em;
  cursor: pointer;
  user-select: text;
  outline: none;
  transition: background 120ms ease, color 120ms ease;
}

.video-modal-timestamp:hover,
.video-modal-timestamp:focus-visible {
  background: rgba(33, 53, 78, 0.9);
  color: #ffffff;
}

/* Span pill — rendered as a CSS pseudo-element so the strip's
   textContent can stay a pure wall-clock string (the PR-1 contract).
   The pill only appears for summary-clip playback once the edge has
   published per-span anchors; otherwise the data attribute is unset
   and the pseudo-element collapses. */
.video-modal-timestamp[data-span-label]::before {
  content: attr(data-span-label);
  display: inline-block;
  margin-right: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(94, 158, 255, 0.18);
  color: #aac9ff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* LIVE pill — distinct color so an operator can tell at a glance
   they're watching real-time vs. cached playback. The latency
   suffix ("LIVE −2s") is built into the dataset value by
   refreshVideoModalLive, not as a separate child element. */
.video-modal-timestamp[data-live-label]::before {
  content: attr(data-live-label);
  display: inline-block;
  margin-right: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(231, 76, 60, 0.22);
  color: #ffb4ac;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.video-modal-timestamp.hidden {
  display: none;
}

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(7, 18, 31, 0.96);
  border: 1px solid var(--line);
  color: #ffffff;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.video-modal-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 14px;
  border-radius: 12px;
  background: rgba(3, 8, 17, 0.58);
  color: #fff;
  pointer-events: none;
  text-align: center;
  z-index: 2;
}

.video-modal-loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255, 255, 255, 0.24);
  border-top-color: #fff;
  border-radius: 999px;
  animation: videoSpinner 0.8s linear infinite;
}

.video-modal-loading-text {
  font-size: 0.95rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.widget-modal {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#identify-modal {
  z-index: 1150;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.widget-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 17, 0.78);
}

.widget-modal-panel {
  max-height: min(88vh, 920px);
  display: grid;
  gap: 18px;
  overflow: hidden;
}

#identify-modal .widget-modal-panel {
  width: min(1040px, 100%);
  overflow-y: auto;
  overflow-x: hidden;
}

.widget-modal-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
  letter-spacing: -0.03em;
}

.identify-modal-subtitle {
  margin: 8px 0 0;
}

.widget-modal-body {
  min-height: 240px;
  max-height: min(70vh, 760px);
  overflow: auto;
}

.widget-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
}

.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

/* PR 3 — render-tool widgets attached to assistant chat bubbles. They use
 * the same card / grid styling as the modal versions but sit inline in the
 * timeline, so we add a small wrapper with a separating border + caption. */
.chat-widget {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
}

.chat-widget + .chat-widget {
  margin-top: 8px;
}

.chat-widget-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chat-widget .widget-grid {
  /* Slightly tighter cards inside the chat lane than in the full-screen
   * modal so a single live-feed card doesn't dominate the bubble. */
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.widget-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.widget-card h3,
.widget-card p {
  margin: 0;
}

.widget-card p {
  color: var(--muted);
  line-height: 1.5;
}

.widget-kicker {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.widget-live-shell {
  position: relative;
  width: 100%;
}

.widget-live-player {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  background: #000;
}

.widget-live-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: 0;
  border-radius: 14px;
  background: rgba(3, 8, 17, 0.52);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  backdrop-filter: blur(1px);
}

.widget-live-status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 1;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(7, 18, 31, 0.82);
  color: #eef7ff;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1;
}

.widget-live-status[data-tone="ready"] {
  background: rgba(17, 94, 89, 0.88);
}

.widget-live-status[data-tone="warning"] {
  background: rgba(146, 64, 14, 0.9);
}

.widget-live-status[data-tone="error"] {
  background: rgba(127, 29, 29, 0.92);
}

.widget-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #081119;
}

.widget-thumb-natural {
  width: auto;
  max-width: 100%;
  max-height: 320px;
  aspect-ratio: auto;
  object-fit: contain;
}

.widget-media-button {
  display: inline-flex;
  width: fit-content;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}

.widget-thumb-frame {
  position: relative;
  display: inline-flex;
  max-width: 100%;
}

.widget-thumb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  color: #fff;
  background: linear-gradient(to top, rgba(3, 8, 17, 0.72), rgba(3, 8, 17, 0.2));
  border-radius: 14px;
  text-align: center;
  pointer-events: none;
}

.widget-thumb-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: rgba(3, 8, 17, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: 1.05rem;
}

.picture-modal {
  position: fixed;
  inset: 0;
  z-index: 1075;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.picture-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 17, 0.86);
}

.picture-modal-panel {
  position: relative;
  z-index: 1;
  width: fit-content;
  max-width: min(92vw, 1200px);
  max-height: 90vh;
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(7, 18, 31, 0.96);
  box-shadow: var(--shadow);
}

.picture-modal-image {
  display: block;
  max-width: 100%;
  max-height: calc(90vh - 36px);
  width: auto;
  height: auto;
  border-radius: 12px;
  background: #081119;
}

.widget-meta {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.identity-gallery {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.identity-gallery-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  max-width: 96px;
  max-height: 96px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  overflow: hidden;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.identity-gallery-thumb:hover {
  transform: translateY(-1px);
  border-color: rgba(92, 225, 230, 0.4);
}

.identity-gallery-thumb.is-selected {
  border-color: rgba(92, 225, 230, 0.8);
  box-shadow: 0 0 0 2px rgba(92, 225, 230, 0.15);
}

.identity-gallery-thumb img {
  width: auto;
  height: auto;
  max-width: 96px;
  max-height: 96px;
  object-fit: contain;
  display: block;
}

.widget-recording-controls {
  display: grid;
  gap: 12px;
}

.widget-recording-field {
  display: grid;
  gap: 8px;
}

.widget-recording-field span {
  color: var(--muted);
  font-size: 0.88rem;
}

.widget-inline-button,
.widget-launch-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(92, 225, 230, 0.2);
  background: rgba(92, 225, 230, 0.12);
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

.widget-inline-button {
  margin-top: 12px;
}

.widget-launch-button {
  width: fit-content;
}

.widget-card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.video-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(7, 18, 31, 0.75);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}

.chat-input-area {
  display: grid;
  gap: 12px;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 16px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.45;
  animation: typingPulse 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

.input-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.input-form textarea {
  min-height: 56px;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 16px;
}

@media (max-width: 980px) {
  .auth-panel {
    grid-template-columns: 1fr;
  }

  /* On mobile we deliberately KEEP the .messages-container
     ``max-height`` (calc(100dvh - 220px)) so the container itself is
     the scroller. Setting ``max-height: none`` here pushed the actual
     scroll onto the document, which broke ``scrollTimelineToBottom``
     (its ``container.scrollTop = container.scrollHeight`` is a no-op
     when the container has no internal overflow) and the chat no
     longer landed at the latest message on load. ``min-height``
     shrinks below to give small phones a fighting chance of fitting
     the messages region above the input bar. */
  .messages-container {
    min-height: 240px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1200px);
    padding-top: 0;
  }

  /* The header keeps its single-row layout on phones (logo / device /
     "..."); the email pill is hidden because it duplicates the value
     inside the profile menu and would force a second line otherwise. */
  .header-session-state {
    display: none;
  }

  .header-device-select {
    min-width: 0;
    flex: 1 1 auto;
    max-width: none;
  }

  /* Collapse the device-management pill to icon-only on phones so the
     header still fits on a single row alongside the device dropdown. */
  .header-icon-button {
    padding: 6px 8px;
  }

  .header-icon-button-label {
    display: none;
  }

  .panel {
    padding: 18px;
  }

  .device-picker {
    min-width: 100%;
    width: 100%;
  }

  .input-form {
    grid-template-columns: 1fr;
  }

  .input-actions {
    width: 100%;
    justify-content: flex-end;
    position: relative;
  }

  .message-content {
    max-width: 100%;
  }

  .messages-container {
    padding: 12px;
  }

  .prompt-menu {
    position: static;
  }

  .prompt-menu-panel {
    left: auto;
    right: 0;
    max-width: 100%;
  }

  .widget-modal,
  .video-modal,
  .picture-modal {
    padding: 12px;
  }

  #identify-modal {
    align-items: stretch;
    padding: 0;
  }

  #identify-modal .widget-modal-panel {
    width: 100%;
    min-height: 100%;
    max-height: none;
    border-radius: 0;
    padding: 56px 16px 20px;
  }

  .identify-history-grid {
    grid-template-columns: 1fr;
  }

  .summary-clip-inline-group {
    flex-direction: column;
  }

  .summary-clip-cue {
    flex: none;
    width: 100%;
  }

  .summary-clip-inline-previews {
    width: 100%;
  }
}

@keyframes typingPulse {
  0%, 80%, 100% {
    transform: scale(0.85);
    opacity: 0.35;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes videoSpinner {
  to {
    transform: rotate(360deg);
  }
}

/* Camera-setup widgets (PR 4): editable add/update form and confirm-delete
   button. Both render only inside chat bubbles, never in the modal pane,
   so styles here are scoped to keep the chat bubble compact rather than
   reusing the .widget-grid layout. */
.setup-camera-form,
.confirm-delete-camera {
  display: grid;
  gap: 10px;
}

.setup-camera-row {
  display: grid;
  gap: 4px;
}

.setup-camera-label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.setup-camera-form input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(92, 225, 230, 0.18);
  background: rgba(7, 18, 31, 0.6);
  color: inherit;
  font-family: inherit;
  font-size: 0.95rem;
}

/* Per-camera alarm object-class toggles inside the edit form. */
.setup-alarm-cats-body {
  display: grid;
  gap: 6px;
}

.setup-alarm-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(92, 225, 230, 0.18);
  background: rgba(7, 18, 31, 0.6);
}

.setup-alarm-cat {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.92rem;
}

.setup-alarm-cat input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

.setup-alarm-cat-hint {
  color: var(--muted);
  font-size: 0.78rem;
  margin-left: 4px;
}

.setup-alarm-cats-note {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.setup-alarm-cats-loading {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 6px 0;
}

.setup-camera-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* Password row: input + inline eye-toggle button living in a single
   horizontal wrapper so the icon sits flush against the right edge of
   the input instead of being laid out as a third grid row by the
   default ``.setup-camera-row`` rule. */
.setup-camera-pw-input-wrap {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.setup-camera-pw-input-wrap input[type="password"],
.setup-camera-pw-input-wrap input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(92, 225, 230, 0.18);
  background: rgba(7, 18, 31, 0.6);
  color: inherit;
  font-family: inherit;
  font-size: 0.95rem;
}

.setup-camera-pw-input-wrap input[type="password"]:focus,
.setup-camera-pw-input-wrap input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.setup-camera-pw-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(92, 225, 230, 0.18);
  background: rgba(7, 18, 31, 0.6);
  color: var(--muted);
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.setup-camera-pw-toggle:hover {
  color: var(--accent);
  border-color: rgba(92, 225, 230, 0.45);
  background: rgba(92, 225, 230, 0.08);
}

.setup-camera-pw-toggle:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(92, 225, 230, 0.25);
}

.setup-camera-pw-toggle[aria-pressed="true"] {
  color: var(--accent);
  border-color: rgba(92, 225, 230, 0.4);
  background: rgba(92, 225, 230, 0.12);
}

.setup-camera-pw-toggle svg {
  display: block;
}

.setup-camera-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 8px;
}

.setup-camera-actions .widget-inline-button {
  margin-top: 0;
}

/* Push Save to the right edge so the inline probe banner (when present)
   visually clusters with the Test button it belongs to. ``margin-left:
   auto`` works whether or not the banner is rendered. */
.setup-camera-actions .setup-camera-save {
  margin-left: auto;
}

/* Compact the probe banner when it lives in the actions row. The default
   ``.setup-camera-banner`` rule below is sized for full-width placement
   at the top of the form; here we want it to sit between the Test and
   Save buttons without dominating the row. */
.setup-camera-actions .setup-camera-banner {
  margin: 0;
  padding: 6px 10px;
  font-size: 0.82rem;
  flex: 1 1 200px;
  min-width: 0;
}

/* Save-result banner row — ``flex: 1 1 100%`` forces it to wrap onto a
   new line below the buttons (the actions row already has flex-wrap),
   ``justify-content: flex-end`` anchors the banner under the Save
   button it confirms. The nested rule overrides the inline-banner
   ``flex: 1 1 200px`` so the save banner can size to its content rather
   than stretching across the row. */
.setup-camera-save-banner-row {
  flex: 1 1 100%;
  display: flex;
  justify-content: flex-end;
  margin: 0;
}

.setup-camera-actions .setup-camera-save-banner-row .setup-camera-banner {
  flex: 0 1 auto;
  max-width: 100%;
}

/* Inline loading affordance for the Test button. The handler swaps the
   button's innerHTML to spinner + "Testing…" before awaiting the probe;
   renderWidgetModal() re-renders the form afterwards which restores the
   original label, so this only needs to look right while spinning. */
.setup-camera-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border: 2px solid rgba(92, 225, 230, 0.25);
  border-top-color: currentColor;
  border-radius: 50%;
  vertical-align: -2px;
  animation: setup-camera-spin 0.8s linear infinite;
}

@keyframes setup-camera-spin {
  to { transform: rotate(360deg); }
}

.setup-camera-banner {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  border: 1px solid transparent;
}

.setup-camera-banner-ok {
  background: rgba(64, 196, 160, 0.12);
  border-color: rgba(64, 196, 160, 0.35);
  color: rgba(160, 240, 210, 0.95);
}

.setup-camera-banner-err {
  background: rgba(232, 92, 116, 0.12);
  border-color: rgba(232, 92, 116, 0.35);
  color: rgba(248, 188, 196, 0.95);
}

.setup-camera-save {
  font-weight: 700;
}

.confirm-delete-meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.confirm-delete-button {
  border-color: rgba(232, 92, 116, 0.35);
  background: rgba(232, 92, 116, 0.18);
  color: rgba(248, 188, 196, 0.95);
}

.confirm-delete-button:hover {
  background: rgba(232, 92, 116, 0.28);
}

.confirm-delete-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Unified Cameras modal: live views, Details panels, and Add/Scan actions. */
.camera-chooser-grid {
  align-items: stretch;
}

.camera-chooser-toolbar {
  justify-content: flex-end;
  margin-bottom: 12px;
}

.camera-chooser-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.camera-chooser-url {
  font-family: ui-monospace, "SFMono-Regular", "Menlo", monospace;
  font-size: 0.82rem;
  word-break: break-all;
  color: var(--muted);
}

.camera-chooser-actions {
  margin-top: auto;
}

.camera-card-primary-actions {
  margin-top: 0;
}

.camera-live-state {
  min-height: 120px;
  align-content: center;
}

.camera-details-panel {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.camera-details-panel.hidden {
  display: none;
}

.camera-simulate-upload {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px dashed rgba(157, 187, 214, 0.28);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.camera-simulate-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.camera-simulate-progress {
  display: grid;
  gap: 6px;
  margin-top: 2px;
}

.camera-simulate-progress.hidden {
  display: none;
}

.camera-simulate-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.camera-simulate-progress-header span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-simulate-progress-header strong {
  color: var(--text);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.camera-simulate-progress-bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.camera-simulate-progress-bar span {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  transition: width 160ms ease;
}

.camera-chooser-stop {
  border-color: rgba(232, 92, 116, 0.35);
  background: rgba(232, 92, 116, 0.12);
  color: rgba(248, 188, 196, 0.95);
}

.camera-chooser-stop:hover {
  background: rgba(232, 92, 116, 0.22);
}

.camera-chooser-banner {
  /* Empty by default; classes are added by setCameraChooserBanner so the
     banner shares the setup-camera-banner-ok / -err / -info palette. */
  margin-top: 4px;
}

.setup-camera-banner-info {
  background: rgba(99, 154, 232, 0.12);
  border-color: rgba(99, 154, 232, 0.35);
  color: rgba(196, 218, 248, 0.95);
}

/* Devices modal */
.devices-modal-panel {
  max-width: 720px;
}

body.devices-embed {
  min-height: 100vh;
  overflow: hidden;
  background: transparent;
}

body.devices-embed .app-shell {
  display: none;
}

body.widget-embed {
  min-height: 100vh;
  overflow: hidden;
  background: transparent;
}

body.widget-embed .app-shell {
  display: none;
}

body.devices-embed #devices-modal.widget-modal {
  padding: 0;
  background: transparent;
}

body.widget-embed #widget-modal.widget-modal {
  padding: 0;
  background: transparent;
}

body.devices-embed #devices-modal .widget-modal-backdrop {
  display: none;
}

body.widget-embed #widget-modal .widget-modal-backdrop {
  display: none;
}

body.devices-embed #devices-modal-close {
  display: none;
}

body.widget-embed #widget-modal-close {
  display: none;
}

body.devices-embed #devices-modal .devices-modal-panel {
  width: 100%;
  height: 100vh;
  max-width: none;
  max-height: none;
  border-radius: 0;
}

body.widget-embed #widget-modal .widget-modal-panel {
  width: 100%;
  height: 100vh;
  max-width: none;
  max-height: none;
  border-radius: 0;
}

body.devices-embed #devices-modal .devices-modal-body {
  max-height: none;
}

body.widget-embed #widget-modal .widget-modal-body {
  max-height: none;
}

.devices-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.devices-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.devices-table th,
.devices-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  vertical-align: top;
}

.devices-table th {
  font-weight: 600;
  color: rgba(196, 218, 248, 0.8);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@media (max-width: 640px) {
  .devices-modal-panel {
    width: min(100%, calc(100vw - 16px));
  }

  .devices-modal-body {
    min-width: 0;
  }

  .devices-table,
  .devices-table thead,
  .devices-table tbody,
  .devices-table tr,
  .devices-table td {
    display: block;
    width: 100%;
  }

  .devices-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .devices-table tr {
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.025);
  }

  .devices-table tr + tr {
    margin-top: 10px;
  }

  .devices-table td {
    min-width: 0;
    padding: 7px 0;
    border-bottom: 0;
    overflow-wrap: anywhere;
  }

  .devices-table td::before {
    display: block;
    margin-bottom: 3px;
    color: rgba(196, 218, 248, 0.68);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .devices-table td:nth-child(1)::before {
    content: "Device";
  }

  .devices-table td:nth-child(2)::before {
    content: "Status";
  }

  .devices-table td:nth-child(3)::before {
    content: "Last seen";
  }

  .devices-table td:nth-child(4)::before {
    content: "Enrolled";
  }

  .devices-table td:nth-child(5)::before {
    content: "Actions";
  }

  .device-row-actions {
    justify-content: flex-start;
  }

  .device-deploy-status,
  .device-deploy-status-line {
    min-width: 0;
  }
}

.devices-table tr.device-revoked {
  opacity: 0.55;
}

.device-open-cameras {
  display: grid;
  gap: 3px;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.device-open-cameras:hover .device-open-name,
.device-open-cameras:focus-visible .device-open-name {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.device-open-cameras:focus-visible {
  outline: 2px solid rgba(92, 225, 230, 0.75);
  outline-offset: 4px;
  border-radius: 6px;
}

.device-open-name {
  overflow-wrap: anywhere;
}

.device-status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.device-status-pill.online {
  background: rgba(106, 209, 138, 0.18);
  border-color: rgba(106, 209, 138, 0.45);
  color: rgba(193, 240, 207, 0.96);
}

.device-status-pill.offline {
  background: rgba(255, 196, 105, 0.16);
  border-color: rgba(255, 196, 105, 0.42);
  color: rgba(255, 230, 184, 0.95);
}

.device-status-pill.pending {
  background: rgba(124, 159, 232, 0.18);
  border-color: rgba(124, 159, 232, 0.45);
  color: rgba(204, 220, 250, 0.96);
}

.device-status-pill.revoked {
  background: rgba(232, 92, 116, 0.18);
  border-color: rgba(232, 92, 116, 0.45);
  color: rgba(252, 200, 211, 0.96);
}

.device-id-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  color: rgba(220, 230, 245, 0.85);
}

.device-version {
  margin-top: 3px;
  max-width: 100%;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: rgba(196, 218, 248, 0.72);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.device-row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.device-deploy-status {
  flex-basis: 100%;
  display: grid;
  gap: 5px;
  min-width: 190px;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.device-deploy-status-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.device-deploy-status.completed .device-deploy-status-line {
  color: var(--success);
}

.device-deploy-status.failed .device-deploy-status-line {
  color: var(--danger);
}

.device-deploy-progress {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.device-deploy-progress span {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 180ms ease;
}

.device-deploy-status.failed .device-deploy-progress span {
  background: var(--danger);
}

.device-deploy-detail {
  overflow-wrap: anywhere;
}

.device-deploy-details-toggle {
  justify-self: start;
  min-height: 28px;
  padding: 3px 9px;
  font-size: 0.74rem;
}

.device-deploy-logs {
  max-height: 180px;
  overflow: auto;
  margin: 2px 0 0;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: rgba(220, 230, 245, 0.9);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.device-action-button {
  background: rgba(232, 92, 116, 0.16);
  border: 1px solid rgba(232, 92, 116, 0.45);
  color: rgba(252, 210, 220, 0.96);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

.device-action-button:hover {
  background: rgba(232, 92, 116, 0.28);
}

.device-action-button.ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
  color: rgba(220, 230, 245, 0.85);
}

.device-action-button.ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

.devices-empty {
  padding: 24px;
  text-align: center;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: rgba(196, 218, 248, 0.75);
}

.edge-release-panel {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.edge-deploy-modal-panel {
  width: min(640px, calc(100vw - 24px));
}

#edge-deploy-modal {
  z-index: 1200;
}

#device-timezone-modal {
  z-index: 1200;
}

#device-timezone-modal .widget-modal-panel {
  width: min(520px, calc(100vw - 24px));
}

#zone-editor-modal {
  z-index: 1200;
}

.zone-editor-panel {
  width: min(860px, calc(100vw - 24px));
}

.zone-editor-body {
  display: grid;
  gap: 14px;
}

.zone-editor-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
  margin: 0 auto;
  cursor: crosshair;
  touch-action: none;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  overflow: hidden;
}

.zone-editor-image {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.zone-editor-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.zone-editor-poly {
  fill: rgba(56, 189, 248, 0.22);
  stroke: #38bdf8;
}

.zone-editor-line {
  stroke: #38bdf8;
}

.zone-editor-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.zone-editor-hints span {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
  font-size: 12px;
  line-height: 1.4;
}

.zone-editor-dot {
  fill: #38bdf8;
  stroke: #04263a;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}

.zone-editor-dot:active {
  cursor: grabbing;
  fill: #7dd3fc;
}

.zone-editor-actions {
  padding: 2px;
}

.zone-editor-actions .primary-button,
.zone-editor-actions .secondary-button {
  flex: 0 0 auto;
  min-width: 96px;
}

.edge-deploy-form {
  display: grid;
  gap: 14px;
}

.edge-deploy-form label {
  display: grid;
  gap: 8px;
}

.edge-deploy-form label span {
  color: var(--muted);
  font-size: 0.92rem;
}

.edge-deploy-form p {
  margin: 0;
}

.edge-deploy-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 2px;
}

.edge-deploy-actions .primary-button,
.edge-deploy-actions .secondary-button {
  flex: 0 0 auto;
  min-width: 108px;
}

.edge-deploy-progress-shell {
  width: 100%;
}

.edge-deploy-progress-card {
  display: grid;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
}

.edge-deploy-status-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: rgba(220, 230, 245, 0.95);
  font-weight: 600;
}

.edge-deploy-progress-card.completed .edge-deploy-status-line {
  color: var(--success);
}

.edge-deploy-progress-card.failed .edge-deploy-status-line {
  color: var(--danger);
}

.edge-deploy-progress-bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.edge-deploy-progress-bar span {
  display: block;
  height: 100%;
  min-width: 4px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 180ms ease;
}

.edge-deploy-progress-card.failed .edge-deploy-progress-bar span {
  background: var(--danger);
}

.edge-deploy-detail {
  overflow-wrap: anywhere;
}

.edge-deploy-details {
  display: grid;
  gap: 8px;
  width: 100%;
  max-height: min(46vh, 420px);
  overflow: auto;
  padding-right: 4px;
}

.edge-deploy-details strong {
  color: rgba(220, 230, 245, 0.9);
  font-size: 0.85rem;
}

.edge-deploy-details ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.edge-deploy-details li {
  overflow-wrap: anywhere;
}

.edge-deploy-details time {
  display: block;
  margin-top: 2px;
  color: rgba(196, 218, 248, 0.58);
  font-size: 0.74rem;
}

.edge-deploy-logs {
  width: 100%;
  max-height: 220px;
  overflow: auto;
  margin: 2px 0 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: rgba(220, 230, 245, 0.9);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.edge-release-panel .eyebrow {
  margin: 0 0 4px;
}

.edge-release-panel h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.edge-release-panel p {
  margin: 0;
  overflow-wrap: anywhere;
}

.edge-release-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.edge-release-action-row,
.edge-release-row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.edge-release-actions a {
  display: inline-flex;
  align-items: center;
}

.edge-release-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: min(360px, 100%);
  margin: 0;
  padding: 0;
  list-style: none;
}

.edge-release-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.edge-release-row strong,
.edge-release-row span {
  display: block;
}

.edge-release-row span {
  margin-top: 2px;
  color: rgba(196, 218, 248, 0.72);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .edge-release-panel {
    flex-direction: column;
  }

  .edge-release-actions {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .edge-release-action-row,
  .edge-release-row,
  .edge-release-row-actions {
    justify-content: flex-start;
  }

  .edge-release-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

.enroll-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 12px 0;
}

.enroll-field span {
  font-size: 0.82rem;
  color: rgba(196, 218, 248, 0.85);
}

.enroll-field input {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.18);
  color: inherit;
  font-size: 0.9rem;
}

.enroll-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 8px 0;
}

.enroll-status {
  margin-top: 8px;
  padding: 10px 12px;
  background: rgba(99, 154, 232, 0.10);
  border: 1px solid rgba(99, 154, 232, 0.35);
  border-radius: 8px;
  font-size: 0.88rem;
  color: rgba(214, 230, 252, 0.92);
}

.enroll-waiting-list {
  margin: 12px 0 4px;
}

.enroll-waiting-empty {
  font-size: 0.86rem;
  margin: 0;
}

.enroll-waiting-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}

.enroll-waiting-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 120ms ease, background 120ms ease;
}

.enroll-waiting-row:hover,
.enroll-waiting-row:focus-visible {
  border-color: rgba(99, 154, 232, 0.65);
  background: rgba(99, 154, 232, 0.08);
}

.enroll-waiting-row.selected {
  border-color: rgba(99, 154, 232, 0.95);
  background: rgba(99, 154, 232, 0.18);
  box-shadow: inset 0 0 0 1px rgba(99, 154, 232, 0.55);
}

.enroll-waiting-row-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.enroll-waiting-id {
  font-weight: 600;
  font-size: 0.96rem;
}

.enroll-waiting-ip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.84rem;
}

.enroll-waiting-meta {
  font-size: 0.78rem;
}

.enroll-summary {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.enroll-summary li {
  font-size: 0.9rem;
}

.enroll-summary code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 1px 6px;
  border-radius: 4px;
}

.enroll-summary a {
  color: rgba(155, 192, 252, 0.96);
  text-decoration: underline;
  word-break: break-all;
}

.enroll-troubleshoot {
  margin-top: 8px;
  font-size: 0.82rem;
}
