:root {
  color-scheme: light;
  --canvas: #f5f5f5;
  --surface: #ffffff;
  --surface-subtle: #fafafa;
  --surface-hover: #f0f0f0;
  --border: #d1d1d1;
  --border-strong: #b3b3b3;
  --text: #242424;
  --text-secondary: #616161;
  --text-tertiary: #707070;
  --accent: #0f6cbd;
  --accent-hover: #115ea3;
  --accent-active: #0c3b5e;
  --success: #107c10;
  --success-bg: #f1faf1;
  --success-border: #9fd89f;
  --warning: #8a5d00;
  --warning-bg: #fff7e0;
  --warning-border: #e8c36a;
  --danger: #c50f1f;
  --danger-bg: #fde7e9;
  --danger-border: #f1aeb5;
  --info-bg: #eff6fc;
  --info-border: #9ccbee;
  --shadow-small: 0 1px 2px rgb(0 0 0 / 8%);
  --shadow-panel: 0 4px 18px rgb(0 0 0 / 8%);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
}
* { box-sizing: border-box; }

html {
  min-width: 0;
  min-height: 100%;
  overflow-x: clip;
  background: var(--canvas);
}

body {
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: clip;
  color: var(--text);
  background: var(--canvas);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select { font: inherit; }

button { cursor: pointer; }

button:disabled {
  cursor: default;
  opacity: 0.62;
}

:is(button, input, select):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 50;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: var(--shadow-panel);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 max(24px, calc((100vw - 1440px) / 2));
  border-bottom: 1px solid var(--border);
  background: rgb(255 255 255 / 96%);
}

.brand,
.topbar-status,
.connection {
  display: flex;
  align-items: center;
}

.brand { gap: 10px; }

.brand strong {
  display: block;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand small {
  display: block;
  margin-top: 1px;
  color: var(--text-secondary);
  font-size: 11px;
}

.brand-mark {
  display: flex;
  align-items: end;
  gap: 2px;
  width: 28px;
  height: 28px;
  padding: 7px;
  border-radius: 6px;
  background: var(--accent);
}

.brand-mark i {
  display: block;
  width: 3px;
  border-radius: 1px;
  background: #ffffff;
}

.brand-mark i:nth-child(1) { height: 42%; }
.brand-mark i:nth-child(2) { height: 100%; }
.brand-mark i:nth-child(3) { height: 68%; }

.topbar-status { gap: 14px; }

.logout-form { margin: 0; }

.logout-button {
  min-height: 30px;
  padding: 4px 9px;
  border: 1px solid #b7c6d4;
  border-radius: 6px;
  color: #294766;
  background: #fbfdff;
  font-size: 11px;
  font-weight: 650;
}

.logout-button:hover { border-color: #8ba2b8; background: #f2f7fb; }

.mode-badge {
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  background: var(--surface-subtle);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.connection {
  gap: 7px;
  color: var(--text-secondary);
  font-size: 12px;
}

.connection i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
}

.connection[data-state="online"] i { background: var(--success); }
.connection[data-state="offline"] i { background: var(--danger); }

main {
  width: min(1440px, calc(100% - 48px));
  margin: 0 auto;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 32px;
  padding: 34px 0 24px;
}

.hero .eyebrow { display: none; }

h1,
h2,
h3,
p { margin-top: 0; }

h1 {
  max-width: 780px;
  margin-bottom: 6px;
  font-size: clamp(26px, 3vw, 34px);
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.intro {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.hero-actions {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  min-width: 280px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: var(--shadow-small);
  font-weight: 600;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.primary-button span { display: none; }
.primary-button:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.primary-button:active { border-color: var(--accent-active); background: var(--accent-active); transform: translateY(1px); }
.primary-button:disabled { transform: none; }

.test-status {
  max-width: 340px;
  margin: 6px 0 0;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.4;
  text-align: right;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
}

.metric-card {
  min-width: 0;
  min-height: 112px;
  padding: 18px 20px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.metric-card:last-child { border-right: 0; }

.metric-label {
  display: block;
  min-height: 20px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.metric-card strong {
  display: block;
  margin: 4px 0 3px;
  font-family: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.035em;
}

.metric-card small {
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 1.35;
}

.readiness {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin: 12px 0 24px;
  padding: 12px 16px 12px 13px;
  border: 1px solid var(--warning-border);
  border-left: 3px solid var(--warning);
  border-radius: 8px;
  background: var(--warning-bg);
}

.readiness[data-ready="true"] {
  border-color: var(--success-border);
  border-left-color: var(--success);
  background: var(--success-bg);
}

.readiness-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  color: var(--warning);
  font-size: 12px;
  font-weight: 700;
}

.readiness[data-ready="true"] .readiness-icon { color: var(--success); }

.readiness strong {
  display: block;
  margin-bottom: 1px;
  font-size: 13px;
  font-weight: 650;
}

.readiness p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
}

.last-seen {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.last-seen b {
  color: var(--text);
  font-weight: 600;
}

.feed-panel {
  margin-bottom: 20px;
  scroll-margin-top: 72px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-heading .eyebrow,
.dialog-heading .eyebrow { display: none; }

.panel-heading h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.quiet-button,
.filter-button,
.reset-button,
.dialog-close,
.detail-button {
  border-radius: 6px;
  font-weight: 600;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.quiet-button,
.reset-button,
.dialog-close,
.detail-button {
  border: 1px solid var(--border-strong);
  color: var(--text);
  background: var(--surface);
}

.quiet-button {
  min-height: 32px;
  padding: 5px 11px;
  font-size: 12px;
}

.quiet-button:hover,
.reset-button:hover,
.dialog-close:hover,
.detail-button:hover { background: var(--surface-hover); }

.quiet-button:active,
.filter-button:active,
.reset-button:active,
.dialog-close:active,
.detail-button:active { transform: translateY(1px); }

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.7fr) repeat(5, minmax(120px, 1fr)) auto auto;
  align-items: end;
  gap: 10px;
  padding: 12px 16px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

.filters label {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.filters label > span {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
}

.filters input,
.filters select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  outline: none;
  color: var(--text);
  background: var(--surface);
  font-size: 12px;
}

.filters input::placeholder { color: var(--text-tertiary); }

.filters input:hover,
.filters select:hover { border-color: #8a8a8a; }

.filters input:focus,
.filters select:focus {
  border-color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.filter-button,
.reset-button {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
  white-space: nowrap;
}

.filter-button {
  border: 1px solid var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.filter-button:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.filter-button:active { border-color: var(--accent-active); background: var(--accent-active); }

.table-wrap {
  position: relative;
  min-height: 340px;
  overflow-x: auto;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--canvas);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

td {
  max-width: 280px;
  padding: 11px 14px;
  border-bottom: 1px solid #e8e8e8;
  color: var(--text-secondary);
  vertical-align: middle;
}

tbody tr { transition: background 120ms ease; }
tbody tr:hover { background: var(--surface-subtle); }
tbody tr:last-child td { border-bottom: 0; }

.cell-main {
  display: block;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-sub {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-tertiary);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mono {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 7px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.status-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}

.status-captured {
  border-color: var(--success-border);
  color: var(--success);
  background: var(--success-bg);
}

.status-duplicate {
  border-color: var(--info-border);
  color: var(--accent);
  background: var(--info-bg);
}

.status-unknown_camera,
.status-configuration_incomplete {
  border-color: var(--warning-border);
  color: var(--warning);
  background: var(--warning-bg);
}

.status-rejected,
.status-unknown_org,
.status-missing_org,
.status-missing_camera,
.status-rate_limited {
  border-color: var(--danger-border);
  color: var(--danger);
  background: var(--danger-bg);
}

.detail-button {
  min-height: 28px;
  padding: 3px 9px;
  font-size: 11px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: start;
  padding: 48px;
  text-align: left;
}

.empty-state[hidden] { display: none; }
.radar { display: none; }

.empty-state h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 650;
}

.empty-state p {
  max-width: 520px;
  margin-bottom: 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0 28px;
  color: var(--text-tertiary);
  font-size: 11px;
}

dialog {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(620px, 100vw);
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: -12px 0 36px rgb(0 0 0 / 18%);
}

dialog::backdrop { background: rgb(0 0 0 / 28%); }

.dialog-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgb(255 255 255 / 98%);
}

.dialog-heading h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}

.dialog-close {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

#event-detail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 20px;
  margin: 0;
  padding: 14px 20px 8px;
}

#event-detail div {
  min-width: 0;
  padding: 11px 0;
  border-bottom: 1px solid #e8e8e8;
}

#event-detail dt {
  margin-bottom: 3px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
}

#event-detail dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.payload-section { padding: 12px 20px 24px; }

.payload-section > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.payload-section h3 {
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 650;
}

.payload-section span {
  color: var(--text-secondary);
  font-size: 11px;
}

pre {
  max-height: 380px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid #3d3d3d;
  border-radius: 8px;
  color: #e8e8e8;
  background: #242424;
  font: 12px/1.55 "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1120px) {
  .summary-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }

  .metric-card {
    grid-column: span 2;
    border-right: 1px solid var(--border);
  }

  .metric-card:nth-child(3) { border-right: 0; }
  .metric-card:nth-child(-n + 3) { border-bottom: 1px solid var(--border); }
  .metric-card:nth-child(4),
  .metric-card:nth-child(5) { grid-column: span 3; }
  .metric-card:nth-child(5) { border-right: 0; }

  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .search-field { grid-column: span 2; }
}

@media (max-width: 840px) {
  main { width: min(100% - 32px, 1440px); }

  .hero {
    grid-template-columns: 1fr;
    gap: 16px;
    padding-top: 28px;
  }

  .hero-actions {
    align-items: flex-start;
    min-width: 0;
  }

  .test-status { text-align: left; }

  .readiness {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .last-seen { grid-column: 2; }

  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-field { grid-column: span 2; }
}

@media (max-width: 767px),
  (orientation: landscape) and (max-width: 950px) and (max-height: 500px) {
  .skip-link {
    top: max(0.75rem, env(safe-area-inset-top));
    left: max(0.75rem, env(safe-area-inset-left));
  }

  .topbar {
    min-height: calc(56px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-right: max(12px, env(safe-area-inset-right));
    padding-left: max(12px, env(safe-area-inset-left));
  }

  .brand,
  .brand > span:last-child,
  .topbar-status,
  .connection { min-width: 0; }

  .brand { flex: 0 1 auto; }

  .brand strong,
  .brand small,
  .connection span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-status {
    flex: 0 1 auto;
    gap: 8px;
  }

  .mode-badge { display: none; }

  .connection {
    max-width: min(46vw, 190px);
    font-size: 11px;
  }

  main {
    width: auto;
    margin-right: max(12px, env(safe-area-inset-right));
    margin-left: max(12px, env(safe-area-inset-left));
  }

  .feed-panel { scroll-margin-top: calc(72px + env(safe-area-inset-top)); }

  .hero {
    gap: 12px;
    padding: 20px 0 16px;
  }

  h1 { font-size: clamp(23px, 7vw, 27px); }

  .hero-actions { align-items: stretch; }

  .primary-button,
  .quiet-button,
  .filter-button,
  .reset-button,
  .dialog-close,
  .detail-button {
    min-height: 44px;
    touch-action: manipulation;
  }

  .primary-button { width: 100%; }

  .test-status {
    max-width: none;
    margin-top: 7px;
  }

  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .metric-card {
    grid-column: auto;
    min-height: 100px;
    padding: 14px 13px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .metric-card:nth-child(odd):not(:last-child) { border-right: 1px solid var(--border); }
  .metric-card:nth-child(3) { border-right: 1px solid var(--border); }
  .metric-card:nth-child(4) { border-right: 0; }
  .metric-card:nth-child(4),
  .metric-card:nth-child(5) { grid-column: auto; }
  .metric-card:last-child {
    grid-column: span 2;
    border-bottom: 0;
  }

  .metric-card strong { font-size: 26px; }

  .readiness {
    gap: 9px;
    margin-bottom: 18px;
    padding: 11px 12px 11px 10px;
  }

  .readiness > div:nth-child(2) { min-width: 0; }

  .readiness p,
  .last-seen { overflow-wrap: anywhere; }

  .last-seen { white-space: normal; }

  .panel-heading {
    min-height: 64px;
    padding: 9px 12px;
  }

  .panel-heading h2 { font-size: 17px; }

  .quiet-button {
    min-width: 72px;
    padding-inline: 12px;
    font-size: 13px;
  }

  .filters {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .filters label > span { font-size: 12px; }

  .filters input,
  .filters select {
    height: 44px;
    padding-inline: 11px;
    font-size: 16px;
  }

  .search-field { grid-column: auto; }

  .filter-button,
  .reset-button {
    width: 100%;
    height: 44px;
    padding-inline: 14px;
    font-size: 14px;
  }

  .table-wrap {
    min-height: 320px;
    overflow-x: hidden;
  }

  table {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    position: absolute;
    inset: 0 auto auto 0;
    contain: strict;
    width: 1px;
    max-width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  thead tr {
    display: block;
    width: 1px;
    max-width: 1px;
    height: 1px;
    overflow: hidden;
  }

  thead th {
    position: absolute;
    inset: 0 auto auto 0;
    width: 1px;
    max-width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    border: 0;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
  }

  tbody {
    display: grid;
    width: 100%;
    min-width: 0;
    gap: 10px;
    padding: 12px;
  }

  tbody:empty { padding: 0; }

  tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
    min-width: 0;
    gap: 8px 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
  }

  tbody tr:hover { background: var(--surface); }

  td {
    display: block;
    min-width: 0;
    max-width: none;
    padding: 0;
    border: 0;
  }

  td:nth-child(1) { grid-column: 1; grid-row: 1; }
  td:nth-child(2) { grid-column: 2; grid-row: 1; justify-self: end; }
  td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; }
  td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; }
  td:nth-child(5) { grid-column: 1 / -1; grid-row: 4; }
  td:nth-child(6) { grid-column: 1; grid-row: 5; align-self: end; }
  td:nth-child(7) { grid-column: 2; grid-row: 5; align-self: end; }

  td:nth-child(n + 3):nth-child(-n + 6) {
    padding-top: 7px;
    border-top: 1px solid #e8e8e8;
  }

  td:nth-child(n + 3):nth-child(-n + 6)::before {
    display: block;
    margin-bottom: 2px;
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.3;
  }

  td:nth-child(n + 3):nth-child(-n + 5) {
    display: grid;
    grid-template-columns: minmax(88px, 38%) minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: baseline;
    column-gap: 10px;
    row-gap: 1px;
  }

  td:nth-child(n + 3):nth-child(-n + 5)::before {
    grid-column: 1;
    grid-row: 1 / span 2;
    margin-bottom: 0;
  }

  td:nth-child(3)::before { content: "Kamera / organisation"; }
  td:nth-child(4)::before { content: "Hændelsestype"; }
  td:nth-child(5)::before { content: "Event-reference"; }
  td:nth-child(6)::before { content: "Kilde-IP"; }

  td:nth-child(1) .cell-main,
  td:nth-child(1) .cell-sub,
  td:nth-child(3) .cell-main,
  td:nth-child(3) .cell-sub,
  td:nth-child(4) .cell-main,
  td:nth-child(4) .cell-sub,
  td:nth-child(6) .cell-main,
  td:nth-child(6) .cell-sub {
    overflow: visible;
    overflow-wrap: anywhere;
    text-overflow: clip;
    white-space: normal;
  }

  td:nth-child(n + 3):nth-child(-n + 5) .cell-main,
  td:nth-child(n + 3):nth-child(-n + 5) .cell-sub {
    grid-column: 2;
    min-width: 0;
  }

  td:nth-child(n + 3):nth-child(-n + 5) .cell-main { grid-row: 1; }
  td:nth-child(n + 3):nth-child(-n + 5) .cell-sub { grid-row: 2; }

  td:nth-child(5) .cell-main {
    display: -webkit-box;
    max-height: 2.9em;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  td:nth-child(5) .cell-sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .detail-button {
    min-width: 44px;
    padding-inline: 10px;
    font-size: 12px;
  }

  .empty-state { padding: 32px 20px; }

  footer {
    flex-direction: column;
    gap: 3px;
    padding-bottom: max(28px, calc(16px + env(safe-area-inset-bottom)));
  }

  dialog {
    width: 100%;
    max-width: 100%;
    overscroll-behavior: contain;
    border-left: 0;
  }

  .dialog-heading {
    min-height: calc(64px + env(safe-area-inset-top));
    padding-top: max(9px, env(safe-area-inset-top));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }

  .dialog-close {
    width: 44px;
    min-width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }

  #event-detail {
    grid-template-columns: 1fr;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }

  .payload-section {
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(24px, calc(16px + env(safe-area-inset-bottom)));
    padding-left: max(16px, env(safe-area-inset-left));
  }

  .payload-section > div {
    align-items: flex-start;
    flex-direction: column;
    gap: 0;
  }

  pre {
    max-width: 100%;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}

@media (min-width: 600px) and (max-width: 950px) and (max-height: 500px) and (orientation: landscape) {
  .hero {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 280px);
    align-items: center;
    gap: 16px;
    padding: 16px 0 14px;
  }

  .summary-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }

  .metric-card {
    grid-column: span 2;
    min-height: 96px;
    padding: 13px 14px;
    border-right: 1px solid var(--border);
  }

  .metric-card:nth-child(3) { border-right: 0; }
  .metric-card:nth-child(-n + 3) { border-bottom: 1px solid var(--border); }
  .metric-card:nth-child(4),
  .metric-card:nth-child(5) { grid-column: span 3; }
  .metric-card:nth-child(4) {
    border-right: 1px solid var(--border);
    border-bottom: 0;
  }
  .metric-card:nth-child(5) {
    border-right: 0;
    border-bottom: 0;
  }

  .filters { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .search-field { grid-column: span 6; }
  .filters > label:not(.search-field) { grid-column: span 2; }
  .filter-button,
  .reset-button { grid-column: span 3; }

  tbody tr { grid-template-columns: repeat(2, minmax(0, 1fr)) auto; }

  td:nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
  td:nth-child(2) { grid-column: 3; grid-row: 1; }
  td:nth-child(3) { grid-column: 1; grid-row: 2; }
  td:nth-child(4) { grid-column: 2; grid-row: 2; }
  td:nth-child(5) { grid-column: 1; grid-row: 3; }
  td:nth-child(6) { grid-column: 2; grid-row: 3; }
  td:nth-child(7) { grid-column: 3; grid-row: 3; }

  td:nth-child(6) {
    display: grid;
    grid-template-columns: minmax(88px, 38%) minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: baseline;
    column-gap: 10px;
    row-gap: 1px;
  }

  td:nth-child(6)::before {
    grid-column: 1;
    grid-row: 1 / span 2;
    margin-bottom: 0;
  }

  td:nth-child(6) .cell-main,
  td:nth-child(6) .cell-sub {
    grid-column: 2;
    min-width: 0;
  }

  td:nth-child(6) .cell-main { grid-row: 1; }
  td:nth-child(6) .cell-sub { grid-row: 2; }

  #event-detail { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .payload-section > div {
    align-items: baseline;
    flex-direction: row;
    gap: 16px;
  }

  footer {
    flex-direction: row;
    gap: 16px;
  }
}

@media (min-width: 390px) and (max-width: 599px) {
  .summary-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }

  .metric-card {
    grid-column: span 2;
    border-right: 1px solid var(--border);
  }

  .metric-card:nth-child(3) { border-right: 0; }
  .metric-card:nth-child(-n + 3) { border-bottom: 1px solid var(--border); }
  .metric-card:nth-child(4),
  .metric-card:nth-child(5) { grid-column: span 3; }
  .metric-card:nth-child(4) {
    border-right: 1px solid var(--border);
    border-bottom: 0;
  }
  .metric-card:nth-child(5) {
    border-right: 0;
    border-bottom: 0;
  }
}

.workspace-nav {
  display: flex;
  gap: 4px;
  margin: 20px 0 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
}

.workspace-tab {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-secondary);
  background: transparent;
  font-size: 12px;
  font-weight: 650;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}

.workspace-tab:hover { color: var(--text); background: var(--surface-hover); }
.workspace-tab:active { transform: translateY(1px); }
.workspace-tab.is-active {
  border-color: #b9cce0;
  color: #1d4d7a;
  background: #eef5fb;
}

.view-feedback {
  min-height: 0;
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.view-feedback:not(:empty) { margin: 10px 0 -6px; }
.workspace-view[hidden] { display: none; }

.admin-view { padding: 28px 0 32px; }

.admin-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.section-kicker {
  margin-bottom: 6px;
  color: #476c91;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.06em;
}

.admin-heading h1 {
  max-width: 800px;
  margin-bottom: 7px;
  font-size: clamp(25px, 2.7vw, 33px);
}

.admin-heading p:not(.section-kicker) {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--text-secondary);
}

.admin-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.card-heading h2 {
  margin: 0;
  color: #1f3b56;
  font-size: 17px;
  font-weight: 700;
}

.card-heading > span:not(.status-chip) {
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
}

.automation-layout,
.device-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.85fr) minmax(0, 1.4fr);
  gap: 16px;
}

.automation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  text-align: left;
}

.automation-row:hover { background: var(--surface-hover); }
.automation-row.is-selected { box-shadow: inset 3px 0 0 var(--accent); background: #f7fbff; }
.automation-row:last-child { border-bottom: 0; }
.automation-name { font-weight: 700; }
.automation-row small { grid-column: 1 / -1; color: var(--text-secondary); font-size: 12px; }

.automation-detail { padding-bottom: 16px; }
.rule-chain {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.rule-chain > div {
  min-width: 0;
  padding: 15px;
  border-right: 1px solid var(--border);
}

.rule-chain > div:last-child { border-right: 0; }
.rule-chain span,
.rule-chain small {
  display: block;
  color: var(--text-secondary);
  font-size: 11px;
}

.rule-chain span { margin-bottom: 5px; font-weight: 650; }
.rule-chain strong { display: block; margin-bottom: 4px; color: var(--text); font-size: 14px; }

.safety-callout {
  margin: 0 16px 16px;
  padding: 13px 14px;
  border: 1px solid var(--warning-border);
  border-left: 3px solid var(--warning);
  border-radius: 7px;
  background: var(--warning-bg);
}

.safety-callout strong { color: #6d4a0a; font-size: 12px; }
.safety-callout p { margin: 3px 0 0; color: var(--text-secondary); font-size: 12px; line-height: 1.45; }
.button-row { display: flex; gap: 8px; padding: 0 16px; }

.device-table { padding: 4px 0; }
.device-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(120px, 0.9fr) minmax(120px, 0.9fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  font-size: 12px;
  text-align: left;
}

.device-row:not(.device-header):hover { background: var(--surface-hover); }
.device-row.is-selected { box-shadow: inset 3px 0 0 var(--accent); background: #f7fbff; }
.device-row:last-child { border-bottom: 0; }
.device-header { color: var(--text-secondary); background: var(--surface-subtle); font-size: 11px; font-weight: 700; }
.device-row > span:nth-child(3) { font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace; font-size: 11px; }

.rename-card {
  display: grid;
  align-content: start;
  gap: 12px;
  padding-bottom: 16px;
}

.rename-card .card-heading { margin-bottom: 2px; }
.rename-card label { display: grid; gap: 5px; padding: 0 16px; color: var(--text-secondary); font-size: 11px; font-weight: 650; }
.rename-card input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  font-size: 13px;
}

.rename-card input[readonly] { color: var(--text-secondary); background: var(--surface-subtle); }
.rename-card .primary-button { margin: 0 16px; }
.field-help { margin: 0 16px; color: var(--text-secondary); font-size: 11px; line-height: 1.45; }

.operations-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.operations-grid .admin-card { padding-bottom: 16px; }
.configuration-list { display: grid; gap: 0; margin-bottom: 12px; }
.configuration-list > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.configuration-list strong { font-size: 13px; }
.configuration-list span,
.configuration-list small { color: var(--text-secondary); font-size: 11px; }
.configuration-list small { grid-column: 1; font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace; }
.configuration-list button { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.operations-grid > .admin-card > .quiet-button { margin-left: 16px; }

.retention-options { display: grid; gap: 0; }
.retention-options > div { padding: 13px 16px; border-bottom: 1px solid var(--border); }
.retention-options strong { display: block; margin-bottom: 2px; color: #1f3b56; font-size: 16px; }
.retention-options span { color: var(--text-secondary); font-size: 12px; }

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

@media (max-width: 767px) {
  .workspace-nav { margin-top: 14px; overflow-x: auto; }
  .workspace-tab { flex: 0 0 auto; min-height: 40px; padding-inline: 11px; }
  .admin-view { padding-top: 22px; }
  .admin-heading { align-items: flex-start; flex-direction: column; gap: 14px; }
  .admin-heading .primary-button { width: 100%; }
  .rule-chain { grid-template-columns: 1fr; }
  .rule-chain > div { border-right: 0; border-bottom: 1px solid var(--border); }
  .rule-chain > div:last-child { border-bottom: 0; }
  .button-row { flex-direction: column; }
  .button-row .quiet-button { min-height: 42px; }
  .device-table { overflow-x: auto; }
  .device-row { min-width: 620px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* Verkada-Relay Portal visual system: independent integration identity. */
:root {
  --canvas: #f3f6fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: #d8e1ea;
  --border-strong: #aebdcb;
  --text: #1d2c3d;
  --text-secondary: #586a7b;
  --text-tertiary: #738292;
  --accent: #2f5f91;
  --accent-hover: #244c75;
  --accent-active: #183957;
  --success: #16765f;
  --success-bg: #edf8f3;
  --success-border: #adddc8;
  --warning: #9a6512;
  --warning-bg: #fff8e9;
  --warning-border: #edd394;
  --danger: #b53a4d;
  --danger-bg: #fff1f3;
  --danger-border: #efb9c2;
  --info-bg: #eef5fb;
  --info-border: #b4cde5;
  --shadow-small: 0 1px 2px rgb(25 47 72 / 5%);
  --shadow-panel: 0 12px 32px rgb(25 47 72 / 7%);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.topbar {
  min-height: 66px;
  padding-inline: max(28px, calc((100vw - 1540px) / 2));
  background: rgb(255 255 255 / 98%);
  box-shadow: 0 1px 0 rgb(25 47 72 / 3%);
}

.brand { gap: 11px; }

.brand-mark {
  width: 33px;
  height: 33px;
  padding: 8px;
  border: 1px solid #244f7e;
  border-radius: 9px;
  background: linear-gradient(145deg, #3d78b1, #265782);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 22%);
}

.brand strong {
  color: #183957;
  font-size: 14px;
  font-weight: 720;
  letter-spacing: -0.02em;
}

.brand small {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.mode-badge {
  padding: 4px 8px;
  border-color: #c6d5e3;
  border-radius: 5px;
  color: #315d88;
  background: #f4f8fc;
  font-size: 9.5px;
  letter-spacing: 0.08em;
}

.connection {
  gap: 8px;
  color: #52697e;
  font-weight: 600;
}

main { width: min(1540px, calc(100% - 56px)); }

.hero {
  gap: 36px;
  margin-top: 24px;
  padding: 29px 30px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
}

h1 {
  max-width: 760px;
  margin-bottom: 8px;
  color: #1a354f;
  font-size: clamp(25px, 2.7vw, 33px);
  font-weight: 690;
  letter-spacing: -0.035em;
}

.intro {
  color: #5b6f81;
  font-size: 13.5px;
}

.hero-actions {
  min-width: 258px;
  padding-left: 28px;
  border-left: 1px solid var(--border);
}

.primary-button,
.filter-button {
  border-color: var(--accent);
  border-radius: 6px;
  background: var(--accent);
  box-shadow: 0 1px 1px rgb(25 47 72 / 9%);
}

.primary-button { min-height: 38px; padding-inline: 15px; }

.test-status {
  color: #68798a;
  font-size: 11.5px;
}

.summary-grid {
  gap: 12px;
  margin-top: 16px;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.metric-card {
  position: relative;
  min-height: 116px;
  padding: 17px 18px 15px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-small);
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: #9ab4cd;
}

.metric-card:nth-child(2)::before { background: var(--success); }
.metric-card:nth-child(3)::before { background: var(--danger); }
.metric-card:nth-child(4)::before { background: var(--warning); }
.metric-card:nth-child(5)::before { background: #647da4; }

.metric-label {
  color: #607183;
  font-weight: 650;
}

.metric-card strong {
  color: #203c58;
  font-size: 31px;
  font-weight: 690;
}

.metric-card small { color: #758596; }

.readiness {
  margin: 16px 0 22px;
  padding: 14px 17px 14px 14px;
  border-width: 1px 1px 1px 4px;
  border-radius: 9px;
  box-shadow: var(--shadow-small);
}

.readiness[data-ready="true"] {
  border-color: #9bcdbb;
  border-left-color: var(--success);
  background: #f1faf6;
}

.readiness strong { color: #1d473a; }

.feed-panel {
  border-radius: 10px;
  box-shadow: var(--shadow-small);
}

.panel-heading {
  min-height: 66px;
  padding: 14px 18px;
}

.panel-heading h2 {
  color: #1f3b56;
  font-size: 17px;
  font-weight: 700;
}

.quiet-button,
.reset-button,
.detail-button,
.dialog-close {
  border-color: #b7c6d4;
  border-radius: 6px;
  color: #294766;
}

.quiet-button,
.detail-button { background: #fbfdff; }

.filters {
  gap: 12px;
  padding: 14px 18px 16px;
  background: #f8fafc;
}

.filters label > span {
  color: #4d6276;
  font-weight: 650;
}

.filters input,
.filters select {
  border-color: #c4d1dd;
  border-radius: 6px;
  color: #21394f;
  background: #ffffff;
}

.filters input:hover,
.filters select:hover { border-color: #8aa4bd; }

th {
  padding: 10px 14px;
  color: #516579;
  background: #f4f7fa;
  font-weight: 700;
}

td {
  padding-block: 12px;
  border-bottom-color: #e7edf3;
}

tbody tr:hover { background: #f7fbff; }

.status-chip {
  border-radius: 5px;
  font-weight: 650;
}

.status-chip::before { width: 5px; height: 5px; }

footer {
  padding-top: 5px;
  color: #748496;
}

dialog {
  border-left-color: #cdd9e5;
  box-shadow: -18px 0 46px rgb(21 47 73 / 16%);
}

.dialog-heading { background: rgb(255 255 255 / 98%); }

@media (max-width: 1120px) {
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric-card,
  .metric-card:nth-child(4),
  .metric-card:nth-child(5) { grid-column: auto; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
  .metric-card:nth-child(4),
  .metric-card:nth-child(5) { grid-column: span 1; }
}

@media (max-width: 840px) {
  main { width: min(100% - 32px, 1540px); }
  .hero { padding: 23px; }
  .hero-actions { padding-left: 0; border-left: 0; }
}

@media (max-width: 767px),
  (orientation: landscape) and (max-width: 950px) and (max-height: 500px) {
  .topbar { min-height: calc(62px + env(safe-area-inset-top)); }
  .brand-mark { width: 31px; height: 31px; }
  .brand strong { font-size: 13px; }
  .brand small { max-width: 150px; }
  .hero { margin-top: 14px; padding: 20px 16px; border-radius: 9px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric-card,
  .metric-card:nth-child(4),
  .metric-card:nth-child(5) { grid-column: auto; min-height: 104px; border: 1px solid var(--border); border-radius: 9px; }
  .metric-card:last-child { grid-column: span 2; }
  .filters { padding: 14px; }
  .panel-heading { padding: 12px 14px; }
  tbody { gap: 9px; padding: 12px; }
  tbody tr { border-color: #d7e2ec; border-radius: 8px; box-shadow: 0 1px 2px rgb(25 47 72 / 4%); }
}
