:root {
  color-scheme: dark;
  --night: #071118;
  --night-deep: #040b10;
  --steel: #11222b;
  --steel-raised: #162b35;
  --mist: #dce9e8;
  --muted: #8fa5a8;
  --line: #29404a;
  --line-strong: #3b5964;
  --signal: #58d6c7;
  --amber: #f4b860;
  --alarm: #ff665c;
  --font: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, sans-serif;
  --topbar-height: 66px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--night);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: var(--night);
  color: var(--mist);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--signal);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  transform: translateY(-150%);
  border: 1px solid var(--signal);
  background: var(--night-deep);
  color: var(--mist);
}

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

.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;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(220px, 2fr) minmax(170px, 1fr);
  align-items: center;
  height: var(--topbar-height);
  padding: 0 20px;
  border-bottom: 1px solid var(--line-strong);
  background: var(--night-deep);
}

.brand,
.camera-identity,
.topbar-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 11px;
}

.brand-mark {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 25px;
  height: 25px;
  flex: 0 0 auto;
  border: 1px solid var(--signal);
}

.brand-mark::before,
.brand-mark::after {
  position: absolute;
  width: 5px;
  height: 5px;
  content: "";
  border-color: var(--night-deep);
}

.brand-mark::before {
  top: -1px;
  right: -1px;
  border-top: 3px solid var(--night-deep);
  border-right: 3px solid var(--night-deep);
}

.brand-mark::after {
  bottom: -1px;
  left: -1px;
  border-bottom: 3px solid var(--night-deep);
  border-left: 3px solid var(--night-deep);
}

.brand-mark span {
  width: 7px;
  height: 7px;
  border: 1px solid var(--signal);
  border-radius: 50%;
}

.brand-name {
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.015em;
}

.camera-identity {
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.camera-name {
  overflow: hidden;
  color: var(--mist);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.78rem;
}

.state-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.connection-state[data-state="live"] {
  color: var(--signal);
}

.connection-state[data-state="warning"] {
  color: var(--amber);
}

.connection-state[data-state="offline"],
.connection-state[data-state="error"] {
  color: var(--alarm);
}

.connection-state[data-state="live"] .state-dot {
  box-shadow: 0 0 0 0 rgba(88, 214, 199, 0.45);
  animation: live-pulse 2.2s ease-out infinite;
}

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(88, 214, 199, 0.46); }
  55%, 100% { box-shadow: 0 0 0 7px rgba(88, 214, 199, 0); }
}

.topbar-actions {
  justify-content: flex-end;
  gap: 12px;
}

.local-clock {
  color: var(--muted);
  font-size: 0.83rem;
  font-variant-numeric: tabular-nums;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--line-strong);
  color: var(--mist);
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: square;
  stroke-linejoin: miter;
  stroke-width: 1.6;
}

.console-layout {
  display: grid;
  grid-template-columns: 188px minmax(0, 1fr) 310px;
  min-height: calc(100vh - var(--topbar-height));
  min-height: calc(100dvh - var(--topbar-height));
}

.health-rail,
.event-rail {
  min-width: 0;
  background: var(--steel);
}

.health-rail {
  display: flex;
  flex-direction: column;
  padding: 22px 18px 18px;
  border-right: 1px solid var(--line-strong);
}

.rail-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rail-heading h2,
.events-heading h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.rail-rule {
  height: 1px;
  flex: 1;
  background: var(--line-strong);
}

.health-metrics {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 22px 0 0;
}

.metric {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.metric:first-child {
  border-top: 0;
}

.metric dt {
  color: var(--muted);
  font-size: 0.76rem;
}

.metric dd {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.metric small {
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 500;
}

.battery-track {
  position: absolute;
  right: 0;
  bottom: 8px;
  left: 0;
  height: 2px;
  overflow: hidden;
  background: var(--line);
}

.battery-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--signal);
  transition: width 300ms ease;
}

#thermal-value[data-level="fair"],
#thermal-value[data-level="serious"] {
  color: var(--amber);
}

#thermal-value[data-level="critical"],
#power-value[data-level="critical"] {
  color: var(--alarm);
}

.rail-foot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.72rem;
}

.rail-foot strong {
  color: var(--mist);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}

.live-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: 18px 20px 16px;
  background: var(--night);
}

.live-heading {
  display: flex;
  min-height: 45px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.live-heading h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 620;
}

.live-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 2px;
  color: var(--signal);
  font-size: 0.75rem;
  font-weight: 600;
}

.live-badge span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.feed-area {
  display: grid;
  min-height: 330px;
  flex: 1;
  place-items: center;
  padding: 3px 0 14px;
}

.video-stage {
  position: relative;
  width: min(100%, calc((100dvh - 180px) * 1.7778));
  height: auto;
  min-height: 0;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: var(--night-deep);
  isolation: isolate;
}

#live-video,
#live-frame,
#detection-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#live-video,
#live-frame {
  z-index: 1;
  object-fit: contain;
  background: #000;
}

#detection-overlay {
  z-index: 2;
  pointer-events: none;
}

.feed-placeholder {
  position: absolute;
  z-index: 0;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.feed-placeholder strong {
  margin-top: 18px;
  color: var(--mist);
  font-size: 0.95rem;
  font-weight: 580;
}

.feed-placeholder > span:last-child {
  max-width: 330px;
  margin-top: 5px;
  font-size: 0.77rem;
}

.placeholder-lens {
  position: relative;
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.placeholder-lens::before,
.placeholder-lens::after {
  position: absolute;
  content: "";
  background: var(--line-strong);
}

.placeholder-lens::before {
  width: 76px;
  height: 1px;
}

.placeholder-lens::after {
  width: 1px;
  height: 76px;
}

.placeholder-lens span {
  width: 12px;
  height: 12px;
  border: 1px solid var(--muted);
  border-radius: 50%;
}

.frame-corner {
  position: absolute;
  z-index: 3;
  width: 25px;
  height: 25px;
  pointer-events: none;
  border-color: var(--signal);
  opacity: 0.72;
}

.corner-top-left {
  top: 8px;
  left: 8px;
  border-top: 2px solid;
  border-left: 2px solid;
}

.corner-top-right {
  top: 8px;
  right: 8px;
  border-top: 2px solid;
  border-right: 2px solid;
}

.corner-bottom-left {
  bottom: 8px;
  left: 8px;
  border-bottom: 2px solid;
  border-left: 2px solid;
}

.corner-bottom-right {
  right: 8px;
  bottom: 8px;
  border-right: 2px solid;
  border-bottom: 2px solid;
}

.detection-summary {
  display: flex;
  min-height: 31px;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

.detection-total {
  flex: 0 0 auto;
}

.detection-tags {
  display: flex;
  min-width: 0;
  gap: 7px;
  overflow: hidden;
}

.detection-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  color: var(--signal);
}

.detection-tag::before {
  width: 5px;
  height: 5px;
  content: "";
  border: 1px solid currentColor;
}

.event-rail {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-left: 1px solid var(--line-strong);
}

.events-heading {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 17px;
  border-bottom: 1px solid var(--line-strong);
}

.events-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.event-count {
  display: inline-grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.73rem;
  font-variant-numeric: tabular-nums;
}

.event-list {
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

.event-item {
  border-bottom: 1px solid var(--line);
}

.event-item.is-new {
  animation: event-in 380ms ease-out;
}

@keyframes event-in {
  from { background: rgba(244, 184, 96, 0.16); transform: translateX(8px); }
  to { background: transparent; transform: translateX(0); }
}

.event-link {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 12px;
  padding: 13px 17px;
  color: inherit;
  text-decoration: none;
}

.event-link:hover {
  background: var(--steel-raised);
}

.event-link.is-static {
  cursor: default;
}

.event-link.is-static:hover {
  background: transparent;
}

.event-image-wrap {
  position: relative;
  width: 84px;
  height: 52px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--night-deep);
}

.event-image-wrap::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  content: "Captura";
  color: var(--muted);
  font-size: 0.62rem;
}

.event-image-wrap.no-snapshot::after {
  content: "Sem captura";
}

.event-image {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.event-image.is-missing {
  display: none;
}

.event-copy {
  min-width: 0;
}

.event-primary,
.event-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.event-label {
  overflow: hidden;
  font-size: 0.82rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-confidence {
  color: var(--amber);
  font-size: 0.67rem;
  font-variant-numeric: tabular-nums;
}

.event-meta {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.67rem;
  font-variant-numeric: tabular-nums;
}

.event-id {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.events-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  flex-direction: column;
  padding: 32px 24px;
  color: var(--muted);
  text-align: center;
}

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

.events-empty strong {
  margin-top: 14px;
  color: var(--mist);
  font-size: 0.82rem;
  font-weight: 580;
}

.events-empty p {
  max-width: 220px;
  margin: 5px 0 0;
  font-size: 0.72rem;
}

.empty-marker {
  position: relative;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
}

.empty-marker::before,
.empty-marker::after {
  position: absolute;
  content: "";
  background: var(--line-strong);
}

.empty-marker::before {
  top: 50%;
  right: 7px;
  left: 7px;
  height: 1px;
}

.empty-marker::after {
  top: 7px;
  bottom: 7px;
  left: 50%;
  width: 1px;
}

.toast {
  position: fixed;
  z-index: 80;
  right: 18px;
  bottom: 18px;
  max-width: min(390px, calc(100vw - 36px));
  padding: 12px 15px;
  border-left: 3px solid var(--amber);
  background: var(--steel-raised);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  color: var(--mist);
  font-size: 0.8rem;
}

dialog {
  max-width: calc(100vw - 30px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--steel);
  color: var(--mist);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.54);
}

dialog::backdrop {
  background: rgba(2, 8, 11, 0.84);
  backdrop-filter: blur(3px);
}

.access-dialog {
  width: 440px;
  padding: 30px 34px 34px;
}

.dialog-brand {
  margin-bottom: 22px;
}

.brand-mark-large {
  width: 38px;
  height: 38px;
}

.brand-mark-large span {
  width: 11px;
  height: 11px;
}

.dialog-intro .product-name {
  margin: 0 0 5px;
  color: var(--signal);
  font-size: 0.76rem;
  font-weight: 600;
}

.dialog-intro h2,
.dialog-header h2 {
  margin: 0;
  font-size: 1.38rem;
  font-weight: 620;
  letter-spacing: -0.018em;
}

.dialog-intro > p:last-child {
  max-width: 34ch;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.access-dialog form {
  display: flex;
  flex-direction: column;
  margin-top: 26px;
}

.access-dialog label {
  margin: 16px 0 7px;
  font-size: 0.78rem;
  font-weight: 580;
}

.access-dialog label:first-child {
  margin-top: 0;
}

.access-dialog input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  outline: none;
  background: var(--night);
  color: var(--mist);
  caret-color: var(--signal);
}

.access-dialog input:focus {
  border-color: var(--signal);
  box-shadow: 0 0 0 1px var(--signal);
}

.field-hint {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.68rem;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 72px;
}

.password-field button {
  position: absolute;
  top: 1px;
  right: 1px;
  height: 42px;
  padding: 0 11px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  cursor: pointer;
}

.password-field button:hover {
  color: var(--mist);
}

.form-error {
  margin: 14px 0 0;
  padding: 9px 11px;
  border-left: 2px solid var(--alarm);
  background: rgba(255, 102, 92, 0.07);
  color: #ffb3ad;
  font-size: 0.74rem;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  padding: 0 15px;
  border-radius: 0;
  font-weight: 600;
  cursor: pointer;
}

.primary-button {
  margin-top: 22px;
  border: 1px solid var(--signal);
  background: var(--signal);
  color: #06211f;
}

.primary-button:hover {
  background: #77e1d5;
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--mist);
}

.secondary-button:hover {
  border-color: var(--mist);
}

.danger-button {
  border: 1px solid rgba(255, 102, 92, 0.56);
  background: transparent;
  color: #ffaaa4;
}

.danger-button:hover {
  border-color: var(--alarm);
}

.settings-dialog {
  width: 430px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 25px 26px 20px;
  border-bottom: 1px solid var(--line-strong);
}

.dialog-header p {
  max-width: 300px;
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.close-button {
  margin-top: -5px;
  margin-right: -7px;
}

.settings-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 20px 26px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

.settings-status strong {
  color: var(--mist);
  font-weight: 600;
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 22px 26px 26px;
}

.noscript-message {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 30px;
  background: var(--night);
  color: var(--mist);
  text-align: center;
}

/* ---- Ferramentas ao vivo e editor de zona ---- */

.live-tools {
  display: flex;
  align-items: center;
  gap: 14px;
}

.tool-button {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.tool-button:hover,
.tool-button[aria-pressed="true"] {
  border-color: var(--amber);
  color: var(--mist);
}

.tool-button.has-zone::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  content: "";
  background: var(--signal);
  vertical-align: 1px;
}

.video-stage.is-editing #detection-overlay {
  pointer-events: auto;
  cursor: crosshair;
}

.zone-editor {
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 10px 12px;
  border-top: 1px solid var(--amber);
  background: rgba(7, 17, 24, 0.92);
}

.zone-editor p {
  flex: 1 1 260px;
  margin: 0;
  color: var(--mist);
  font-size: 0.74rem;
}

.zone-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.zone-actions button {
  min-height: 34px;
  margin: 0;
  font-size: 0.74rem;
}

#detector-value,
#power-value,
#transport-value {
  font-size: 0.86rem;
  text-align: right;
}

/* ---- Lista de eventos (botões) ---- */

button.event-link {
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.clip-badge {
  position: absolute;
  z-index: 2;
  right: 3px;
  bottom: 3px;
  padding: 1px 5px;
  background: rgba(7, 17, 24, 0.86);
  color: var(--signal);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---- Configurações ---- */

.settings-dialog {
  width: 480px;
}

.settings-form {
  display: flex;
  flex-direction: column;
  padding: 6px 26px 22px;
  border-bottom: 1px solid var(--line);
}

.settings-form fieldset {
  margin: 0;
  padding: 16px 0 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.settings-form legend {
  float: left;
  width: 100%;
  margin-bottom: 4px;
  color: var(--signal);
  font-size: 0.78rem;
  font-weight: 650;
}

.settings-help,
.settings-line {
  clear: both;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.74rem;
}

.settings-line {
  margin: 12px 0 0;
}

.settings-line strong {
  color: var(--mist);
  font-weight: 600;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 12px;
  margin-bottom: 14px;
}

.check-field,
.switch-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

.switch-field {
  margin: 4px 0 12px;
}

.check-field input,
.switch-field input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--signal);
}

.range-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
}

.range-field span {
  display: flex;
  justify-content: space-between;
}

.range-field output {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.range-field input {
  width: 100%;
  accent-color: var(--signal);
}

.range-field small {
  color: var(--muted);
  font-size: 0.68rem;
}

.time-range {
  display: flex;
  gap: 14px;
  margin: 0 0 14px 24px;
  font-size: 0.8rem;
}

.time-range input {
  height: 34px;
  margin-left: 6px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--night);
  color: var(--mist);
  color-scheme: dark;
}

.text-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
  font-size: 0.78rem;
}

.text-field input {
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  outline: none;
  background: var(--night);
  color: var(--mist);
}

.text-field input:focus {
  border-color: var(--signal);
}

.settings-help.is-warning {
  color: var(--amber);
}

.settings-form .primary-button {
  margin-top: 18px;
}

.settings-form .secondary-button {
  align-self: flex-start;
}

.settings-form .secondary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.settings-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* ---- Diálogos de mídia (evento e gravações) ---- */

.media-dialog {
  width: min(1100px, calc(100vw - 30px));
}

.media-tabs {
  display: flex;
  gap: 0;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
}

.media-tabs button {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.media-tabs button[aria-selected="true"] {
  border-bottom-color: var(--signal);
  color: var(--mist);
}

.media-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
}

.media-stage video,
.media-stage img,
.media-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.media-stage canvas {
  pointer-events: none;
}

.media-empty {
  position: absolute;
  inset: 0;
  display: grid;
  margin: 0;
  padding: 24px;
  place-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.media-footer {
  display: flex;
  justify-content: flex-end;
  padding: 14px 26px 18px;
}

.link-button {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.recordings-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
}

.recording-list {
  max-height: min(540px, 60vh);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  list-style: none;
}

.recording-day {
  padding: 12px 16px 6px;
  color: var(--signal);
  font-size: 0.7rem;
  font-weight: 650;
  text-transform: capitalize;
}

.recording-item {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 16px;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
}

.recording-item small {
  color: var(--muted);
  font-size: 0.66rem;
}

.recording-item:hover {
  background: var(--steel-raised);
}

.recording-item.is-selected {
  border-left-color: var(--signal);
  background: var(--steel-raised);
}

@media (max-width: 1120px) {
  .console-layout {
    grid-template-columns: 162px minmax(0, 1fr) 270px;
  }

  .event-link {
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 10px;
    padding-right: 13px;
    padding-left: 13px;
  }

  .event-image-wrap {
    width: 70px;
    height: 46px;
  }
}

@media (max-width: 880px) {
  :root {
    --topbar-height: 62px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 0 14px;
  }

  .brand-name,
  .local-clock {
    display: none;
  }

  .camera-identity {
    justify-content: flex-start;
    margin-left: 14px;
  }

  .console-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "health"
      "live"
      "events";
  }

  .health-rail {
    grid-area: health;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
  }

  .rail-heading,
  .rail-foot {
    display: none;
  }

  .health-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 0;
  }

  .metric,
  .metric:first-child {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    padding: 5px 12px;
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .metric:first-child {
    padding-left: 0;
    border-left: 0;
  }

  .metric dd {
    font-size: 1rem;
  }

  .battery-track {
    right: 12px;
    bottom: 1px;
    left: 12px;
  }

  .metric:first-child .battery-track {
    left: 0;
  }

  .live-panel {
    grid-area: live;
    min-height: min(690px, calc(100dvh - 62px));
  }

  .video-stage {
    width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 16 / 9;
  }

  .event-rail {
    grid-area: events;
    min-height: 390px;
    border-top: 1px solid var(--line-strong);
    border-left: 0;
  }

  .event-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow-y: visible;
  }

  .event-item:nth-child(odd) {
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 580px) {
  .camera-identity {
    gap: 8px;
  }

  .camera-name {
    max-width: 38vw;
  }

  .connection-state {
    font-size: 0.7rem;
  }

  .health-rail {
    padding-right: 12px;
    padding-left: 12px;
  }

  .health-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 10px;
  }

  .metric,
  .metric:first-child {
    padding: 3px 10px;
  }

  .metric:nth-child(odd) {
    padding-left: 0;
    border-left: 0;
  }

  .metric:nth-child(3),
  .metric:nth-child(4) {
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }

  .battery-track {
    display: none;
  }

  .live-panel {
    min-height: auto;
    padding: 14px 12px 12px;
  }

  .feed-area {
    min-height: 0;
    padding-top: 8px;
  }

  .live-heading {
    min-height: 46px;
  }

  .live-heading p {
    max-width: 65vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .frame-corner {
    width: 17px;
    height: 17px;
  }

  .detection-summary {
    padding-top: 7px;
  }

  .detection-tags {
    overflow-x: auto;
  }

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

  .event-item:nth-child(odd) {
    border-right: 0;
  }

  .event-link {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .event-image-wrap {
    width: 96px;
    height: 58px;
  }

  .access-dialog {
    width: calc(100vw - 24px);
    padding: 25px 22px 27px;
  }

  .settings-actions {
    grid-template-columns: 1fr;
  }
}

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

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

  .recording-list {
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .settings-actions {
    grid-template-columns: 1fr;
  }

  .live-tools .tool-button {
    font-size: 0.7rem;
  }
}
