/* ============================================================
 * Lens · Alert portal — v2 (professional dashboard theme)
 * ============================================================ */

:root {
  color-scheme: dark;

  /* surfaces */
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #171b24;
  --surface-3: #1e232e;
  --surface-hi: #232936;

  /* borders */
  --border: #242a36;
  --border-strong: #2f3647;
  --border-brand: rgba(91, 141, 239, 0.35);

  /* text */
  --text: #eef0f4;
  --text-soft: #c5cbd6;
  --text-muted: #8892a6;
  --text-dim: #5a6477;

  /* brand + semantic */
  --brand: #5b8def;
  --brand-strong: #4771d8;
  --brand-soft: rgba(91, 141, 239, 0.12);
  --accent: #2dd4bf;
  --success: #3ed598;
  --warn: #f0b429;
  --danger: #f65464;

  /* type */
  --font:
    "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", monospace;

  /* shape + motion */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow:
    0 1px 0 rgba(255, 255, 255, 0.02) inset,
    0 6px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg:
    0 1px 0 rgba(255, 255, 255, 0.02) inset,
    0 16px 48px rgba(0, 0, 0, 0.5);

  /* layout */
  --topbar-h: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(91, 141, 239, 0.08), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(45, 212, 191, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}

a {
  color: inherit;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: #b3c0d8;
  background: rgba(255, 255, 255, 0.04);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ============================================================
 * App shell
 * ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 28px 16px;
  overflow: hidden;
}

/* ============================================================
 * Topbar
 * ============================================================ */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: var(--topbar-h);
  padding: 0 2px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: flex;
  align-items: center;
  line-height: 0;
  text-decoration: none;
  flex-shrink: 0;
  opacity: 0.95;
  transition: opacity 0.15s ease;
}
.brand-mark:hover {
  opacity: 1;
}

.brand-logo {
  display: block;
  height: 26px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
  object-position: left center;
}

.brand-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-left: 14px;
  border-left: 1px solid var(--border-strong);
  min-width: 0;
}

.brand-product {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.brand-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.topbar__status {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.status-chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(62, 213, 152, 0.35);
  animation: pulse 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.status-chip--live {
  color: var(--success);
  border-color: rgba(62, 213, 152, 0.35);
  background: rgba(62, 213, 152, 0.08);
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(62, 213, 152, 0.4);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(62, 213, 152, 0);
  }
}

.kv {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.kv__k {
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.kv__v {
  font-family: var(--font-mono);
  color: var(--text-soft);
  font-weight: 500;
}

@media (max-width: 720px) {
  .kv--hide-sm {
    display: none;
  }
}

/* ============================================================
 * Workspace (video + feed)
 * ============================================================ */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  html,
  body,
  .app {
    height: auto;
    overflow: auto;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel--video {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.panel--feed {
  padding: 16px 16px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

@media (max-width: 1080px) {
  .panel--video,
  .panel--feed {
    height: auto;
  }
  .panel--feed {
    max-height: 60vh;
  }
}

.panel__head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.panel__head--sm {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.panel__head-left {
  min-width: 0;
}

.panel__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.3;
}

.panel__title--sm {
  font-size: 14px;
  font-weight: 600;
}

.panel__sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.count-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
  padding: 3px 9px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  min-width: 26px;
  text-align: center;
  line-height: 1.4;
}

/* ============================================================
 * Status pill (WhatsApp on/off)
 * ============================================================ */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px 5px 9px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: none;
  white-space: nowrap;
}

.status-pill__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-pill--off {
  color: var(--text-muted);
}

/* Back-compat with JS: it still toggles `.badge` + `.badge--on` classnames;
 * style them identically to the new status pill so nothing looks off. */
.badge,
.status-pill--on,
.badge--on {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px 5px 9px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  color: var(--success);
  border: 1px solid rgba(62, 213, 152, 0.4);
  background: rgba(62, 213, 152, 0.1);
  white-space: nowrap;
}

.badge--on::before,
.status-pill--on::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(62, 213, 152, 0.6);
}

.badge--off {
  color: var(--text-muted);
  border-color: var(--border);
  background: var(--surface-2);
}
.badge--off::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

/* ============================================================
 * Video stage
 * ============================================================ */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}

/* The wrap uses the real video's aspect ratio (set by JS on `loadedmetadata`). The
 * `inset: 0; margin: auto` + `max-width/height: 100%` + `aspect-ratio` combination is
 * the canonical CSS "fit-and-center with aspect-ratio" trick: the browser sizes the
 * element as large as possible while respecting the aspect ratio AND both container
 * dimensions, then centers. The `<video>` fills the wrap edge-to-edge, so the canvas
 * overlay lands exactly on video pixels — detection boxes never fall on background.
 * `--video-aspect` defaults to 16/9 until metadata loads. */
.stage__wrap {
  position: absolute;
  inset: 0;
  margin: auto;
  background: #000;
  aspect-ratio: var(--video-aspect, 16 / 9);
  max-width: 100%;
  max-height: 100%;
}

.stage__video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  vertical-align: middle;
}

.stage__overlay {
  position: absolute;
  /* Left / top / width / height are set inline by JS to match the video's actual
   * rendered rect (see `resizeCanvas` in portal.js). Defaults fill the wrap so the
   * overlay looks correct before metadata loads. */
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.stage__hud {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px 5px 9px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-soft);
  background: rgba(10, 12, 16, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  z-index: 1;
  pointer-events: none;
}

.stage__hud-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}

.stage__wrap.is-playing .stage__hud {
  color: #ffdada;
}
.stage__wrap.is-playing .stage__hud-dot {
  background: var(--danger);
  animation: rec-blink 1.3s ease-in-out infinite;
}
.stage__wrap.is-playing .stage__hud-label::after {
  content: " · REC";
}

@keyframes rec-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.stage__play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px 11px 16px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: #fff;
  background: linear-gradient(180deg, var(--brand), var(--brand-strong));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  cursor: pointer;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.22) inset,
    0 12px 32px rgba(71, 113, 216, 0.45);
  transition:
    transform 0.15s ease,
    box-shadow 0.2s ease,
    opacity 0.2s ease;
  z-index: 2;
}

.stage__play:hover {
  transform: translate(-50%, -50%) translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.24) inset,
    0 14px 36px rgba(71, 113, 216, 0.55);
}

.stage__play:active {
  transform: translate(-50%, -50%) translateY(0);
}

.stage__play:disabled,
.stage__play[hidden] {
  opacity: 0;
  pointer-events: none;
}

.stage__play-icon {
  width: 16px;
  height: 16px;
  display: block;
  color: #fff;
}

/* ============================================================
 * Meta strip (Playback / Events / Sent / Recipients)
 * ============================================================ */
.meta-strip {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin-top: 12px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

@media (max-width: 720px) {
  .meta-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.meta-strip__cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 12px 10px;
  background: var(--surface-2);
  min-width: 0;
}

.meta-strip__k {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.meta-strip__v {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.meta-strip__v--mono,
.meta-strip__sub--mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.meta-strip__v--mono {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0;
}

.meta-strip__sub {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.35;
}

.meta-strip__sub--mono {
  font-size: 10.5px;
}

/* ============================================================
 * Notes + errors under video
 * ============================================================ */
.note-row {
  flex: 0 0 auto;
  margin: 12px 0 0;
  padding: 9px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

.error {
  flex: 0 0 auto;
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  color: #fecaca;
  background: rgba(246, 84, 100, 0.08);
  border: 1px solid rgba(246, 84, 100, 0.35);
  border-radius: var(--radius-sm);
}

.error code {
  display: block;
  margin-top: 6px;
  color: #fecaca;
  background: rgba(0, 0, 0, 0.25);
  border-color: rgba(246, 84, 100, 0.3);
  word-break: break-all;
}

/* ============================================================
 * Extra recipients card
 * ============================================================ */
.extra-card {
  flex: 0 0 auto;
  margin-top: 12px;
  padding: 12px 14px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  position: relative;
  transition:
    border-color 0.2s ease,
    background 0.3s ease;
}

.extra-card--locked {
  border-color: rgba(62, 213, 152, 0.35);
  background: linear-gradient(
    180deg,
    rgba(62, 213, 152, 0.06) 0%,
    var(--surface) 100%
  );
}

.extra-card__head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.extra-card__bubble {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--brand-soft);
  border: 1px solid var(--border-brand);
  color: #b8cbff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition:
    color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease;
}

.extra-card__icon {
  width: 16px;
  height: 16px;
  display: block;
}

.extra-card--locked .extra-card__bubble {
  color: #9dfacf;
  background: rgba(62, 213, 152, 0.12);
  border-color: rgba(62, 213, 152, 0.4);
}

.extra-card__intro {
  min-width: 0;
}

.extra-card__title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.3;
}

.extra-card__sub {
  margin: 2px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

.extra-card__label {
  display: none;
}

.extra-card__input-wrap {
  position: relative;
}

.extra-card__input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: rgba(10, 12, 16, 0.55);
  color: var(--text);
  font: inherit;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
}

.extra-card__input::placeholder {
  color: var(--text-dim);
  font-family: var(--font);
}

.extra-card__input:hover {
  border-color: var(--border-brand);
}

.extra-card__input:focus {
  outline: none;
  border-color: var(--brand);
  background: rgba(10, 12, 16, 0.8);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.18);
}

.extra-card__input:read-only {
  opacity: 0.95;
  cursor: default;
  border-color: rgba(62, 213, 152, 0.35);
}

.extra-card__hint {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

.extra-card__hint--warn {
  color: var(--warn);
}

.extra-card--locked .extra-card__hint {
  color: var(--success);
}
.extra-card--locked .extra-card__hint--warn {
  color: var(--warn);
}

/* ============================================================
 * Alert activity feed
 * ============================================================ */
.alert-feed {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  margin: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.alert-feed::-webkit-scrollbar {
  width: 6px;
}

.alert-feed::-webkit-scrollbar-track {
  background: transparent;
}

.alert-feed::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.alert-feed__empty {
  margin: auto;
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
}

.alert-feed__empty-icon {
  width: 32px;
  height: 32px;
  color: var(--text-dim);
  margin-bottom: 10px;
  opacity: 0.7;
}

.alert-feed__empty-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
}

.alert-feed__empty-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.feed-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
  flex-shrink: 0;
  transition:
    border-color 0.2s ease,
    background 0.2s ease,
    transform 0.2s ease;
  animation: feed-card-in 0.25s ease-out;
}

@keyframes feed-card-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.feed-card[data-state="ok"] {
  border-color: rgba(62, 213, 152, 0.25);
}

.feed-card--err {
  border-color: rgba(246, 84, 100, 0.4);
  background: rgba(246, 84, 100, 0.05);
}

.feed-card--pending {
  border-color: rgba(240, 180, 41, 0.35);
  background: linear-gradient(
    180deg,
    rgba(240, 180, 41, 0.05) 0%,
    var(--surface-2) 100%
  );
  position: relative;
}

.feed-card--pending::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    rgba(240, 180, 41, 0) 0%,
    rgba(240, 180, 41, 0.9) 50%,
    rgba(240, 180, 41, 0) 100%
  );
  animation: feed-card-scan 1.4s linear infinite;
}

@keyframes feed-card-scan {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.feed-card__media {
  background: #000;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.feed-card__img {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
}

.feed-card__missing {
  margin: 0;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--warn);
  line-height: 1.45;
  border-bottom: 1px solid var(--border);
  background: rgba(240, 180, 41, 0.06);
}

.feed-card__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 12px 2px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  letter-spacing: -0.005em;
}

.feed-card__title::before {
  content: "";
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.feed-card[data-state="ok"] .feed-card__title::before {
  background: var(--success);
  box-shadow: 0 0 8px rgba(62, 213, 152, 0.45);
}

.feed-card--pending .feed-card__title {
  color: #fde4a8;
}
.feed-card--pending .feed-card__title::before {
  background: var(--warn);
  box-shadow: 0 0 8px rgba(240, 180, 41, 0.6);
  animation: rec-blink 1.1s ease-in-out infinite;
}

.feed-card--err .feed-card__title {
  color: #fecaca;
}
.feed-card--err .feed-card__title::before {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(246, 84, 100, 0.55);
}

.feed-card__sub {
  margin: 0;
  padding: 0 12px 10px 27px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

.feed-card__meta {
  margin: 0;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  line-height: 1.4;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
}

/* ============================================================
 * Footer
 * ============================================================ */
.foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

.foot__sep {
  opacity: 0.5;
}
