*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --g: #d6dde7;
  --gdim: #4e5765;
  --gfade: #8c96a5;
  --c: #b7c1cf;
  --r: #c9837d;
  --y: #cbb183;
  --bg: #0d1015;
  --bg2: #151920;
  --bg3: #11161d;
  --bord: #2d3440;
  --g-rgb: 214, 221, 231;
  --c-rgb: 183, 193, 207;
  --r-rgb: 201, 131, 125;
  --y-rgb: 203, 177, 131;
}

body {
  background:
    radial-gradient(circle at 82% 10%, rgba(98, 112, 131, .22) 0%, transparent 28%),
    radial-gradient(circle at 12% 8%, rgba(145, 154, 170, .1) 0%, transparent 24%),
    linear-gradient(180deg, #111317 0%, #090b0e 100%);
  color: var(--g);
  font-family: 'IBM Plex Sans', 'Avenir Next', 'Segoe UI Variable Text', sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

.hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 16px;
  background: rgba(20, 24, 31, .94);
  border-bottom: 1px solid var(--bord);
  font-size: 11px;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.hdr-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-toggle {
  border: 1px solid rgba(var(--c-rgb), .35);
  color: rgba(var(--c-rgb), .92);
  background: rgba(var(--c-rgb), .08);
  font-size: 10px;
  letter-spacing: 1px;
  padding: 4px 9px;
  border-radius: 8px;
  cursor: pointer;
  display: none;
}

.hdr-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  letter-spacing: 5px;
  color: #d9e0e9;
  font-weight: 700;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d08f89;
  box-shadow: 0 0 5px rgba(var(--r-rgb), .5);
  animation: pdot 1.5s ease-in-out infinite;
}

@keyframes pdot {
  0%, 100% { opacity: 1; box-shadow: 0 0 5px rgba(var(--r-rgb), .75); }
  50% { opacity: .4; box-shadow: none; }
}

.hdr-sub {
  color: rgba(var(--c-rgb), .5);
  font-size: 10px;
  letter-spacing: 3px;
}

.hdr-right {
  display: flex;
  align-items: center;
  gap: 18px;
}

.clock { font-size: 16px; letter-spacing: 3px; }

.ws-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: rgba(var(--c-rgb), .7);
}

.ws-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--r); flex-shrink: 0; }
.ws-dot.ok { background: var(--g); box-shadow: 0 0 4px rgba(var(--g-rgb), .65); animation: pdot 2.5s ease-in-out infinite; }

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

.side-nav {
  border-right: 1px solid var(--bord);
  background: linear-gradient(180deg, rgba(21, 25, 32, .97) 0%, rgba(12, 15, 20, .97) 100%);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-nav-hdr {
  color: rgba(var(--c-rgb), .72);
  font-size: 10px;
  letter-spacing: 1.2px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
  padding: 4px 8px 8px;
}

.nav-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(var(--c-rgb), .78);
  text-align: left;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 11px;
  letter-spacing: 1px;
  cursor: pointer;
}

.nav-item:hover {
  border-color: rgba(var(--c-rgb), .26);
  background: rgba(var(--c-rgb), .06);
  color: #f0f3f7;
}

.nav-item.active {
  border-color: rgba(var(--c-rgb), .42);
  background: rgba(var(--c-rgb), .12);
  color: #f0f3f7;
}

.view-stack {
  min-height: 0;
  position: relative;
}

.view {
  height: 100%;
  display: none;
  min-height: 0;
}

.view.active { display: block; }

.main {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 10px;
  padding: 10px;
  overflow: hidden;
}

.monitor-main {
  flex: 1;
  height: auto;
  padding: 0;
}

.video-col {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  min-height: 0;
}

.video-wrap {
  position: relative;
  background: #000;
  border: 1px solid var(--bord);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* go2rtc WebRTC/MSE live-view player fills the wrap like the old <img> */
.video-wrap video-stream {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

.video-wrap video-stream video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

/* Clean live view: hide go2rtc's status text overlay and native player controls */
.video-wrap video-stream .info {
  display: none !important;
}

.video-wrap video-stream video::-webkit-media-controls,
.video-wrap video-stream video::-webkit-media-controls-enclosure {
  display: none !important;
}

.video-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.person-overlay {
  position: absolute;
  border: 3px solid #ffd84d;
  border-radius: 18px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .55), 0 0 20px rgba(255, 216, 77, .25);
  background: linear-gradient(180deg, rgba(255, 216, 77, .08) 0%, rgba(255, 216, 77, .02) 100%);
  /* Position smoothing handled by JS lerp loop — only animate opacity */
  transition: opacity 120ms ease;
  will-change: left, top, width, height;
}

.person-overlay.is-guest {
  border-color: #f2cb57;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .55), 0 0 16px rgba(242, 203, 87, .18);
}

.person-overlay__label {
  position: absolute;
  left: -3px;
  bottom: calc(100% + 10px);
  min-width: 120px;
  max-width: min(280px, 42vw);
  padding: 8px 12px 9px;
  border: 1px solid rgba(255, 216, 77, .72);
  border-radius: 12px;
  background: rgba(9, 12, 16, .9);
  color: #fff4b5;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .25);
}

.person-overlay__label::after {
  content: '';
  position: absolute;
  left: 18px;
  top: 100%;
  width: 12px;
  height: 12px;
  background: rgba(9, 12, 16, .9);
  border-right: 1px solid rgba(255, 216, 77, .72);
  border-bottom: 1px solid rgba(255, 216, 77, .72);
  transform: translateY(-6px) rotate(45deg);
}

.person-overlay__label[data-placement="below"]::after {
  top: auto;
  bottom: 100%;
  transform: translateY(6px) rotate(45deg);
  border-right: 0;
  border-bottom: 0;
  border-left: 1px solid rgba(255, 216, 77, .72);
  border-top: 1px solid rgba(255, 216, 77, .72);
}

.person-overlay__label[data-placement="inside"]::after {
  display: none;
}

.person-overlay__label[data-placement="left"]::after,
.person-overlay__label[data-placement="right"]::after {
  top: 18px;
  width: 10px;
  height: 10px;
  transform: rotate(45deg);
}

.person-overlay__label[data-placement="right"]::after {
  left: auto;
  right: 100%;
  border-right: 0;
  border-bottom: 1px solid rgba(255, 216, 77, .72);
  border-left: 1px solid rgba(255, 216, 77, .72);
  border-top: 0;
  transform: translateX(5px) rotate(45deg);
}

.person-overlay__label[data-placement="left"]::after {
  left: 100%;
  border-right: 1px solid rgba(255, 216, 77, .72);
  border-bottom: 0;
  border-left: 0;
  border-top: 1px solid rgba(255, 216, 77, .72);
  transform: translateX(-5px) rotate(45deg);
}

.person-overlay__name {
  display: block;
  color: #fff3a6;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: .2px;
  text-transform: uppercase;
}

.person-overlay__meta {
  display: block;
  margin-top: 4px;
  color: rgba(255, 244, 181, .82);
  font-size: 11px;
  line-height: 1.15;
  letter-spacing: .3px;
}

.video-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0px, transparent 2px, rgba(0,0,0,.1) 2px, rgba(0,0,0,.1) 4px);
  pointer-events: none;
  z-index: 3;
}

.cam-label {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  letter-spacing: 1px;
  color: #e4e9f0;
  background: rgba(11, 14, 19, .74);
  padding: 2px 8px;
  border-radius: 8px;
  border: 1px solid rgba(var(--c-rgb), .3);
}

.fps-label {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 10px;
  color: rgba(var(--g-rgb), .45);
}

.zoom-panel {
  border: 1px solid var(--bord);
  background: rgba(18, 22, 28, .96);
  border-radius: 12px;
  padding: 8px 10px;
  display: grid;
  gap: 8px;
}

.zoom-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 1px;
}

.zoom-title { color: var(--c); opacity: .9; }
.zoom-status { color: rgba(var(--g-rgb), .68); font-size: 9px; }
.zoom-status.err { color: rgba(var(--r-rgb), .9); }

.zoom-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
}

.zoom-val {
  min-width: 44px;
  text-align: right;
  color: var(--g);
  font-size: 12px;
}

.zoom-range {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 14px;
  cursor: pointer;
  background: transparent;
}

.zoom-range::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(var(--g-rgb), .25);
  background: linear-gradient(90deg, rgba(var(--g-rgb), .2) 0%, rgba(var(--c-rgb), .18) 100%);
}

.zoom-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(var(--c-rgb), .75);
  background: rgba(var(--c-rgb), .95);
  box-shadow: 0 0 10px rgba(var(--c-rgb), .4);
  margin-top: -4px;
}

.zoom-range::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(var(--g-rgb), .25);
  background: rgba(var(--g-rgb), .18);
}

.zoom-range::-moz-range-progress {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(var(--g-rgb), .8) 0%, rgba(var(--c-rgb), .8) 100%);
}

.zoom-range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(var(--c-rgb), .75);
  background: rgba(var(--c-rgb), .95);
  box-shadow: 0 0 10px rgba(var(--c-rgb), .4);
}

.zoom-range[disabled] {
  opacity: .45;
  cursor: not-allowed;
}

.zoom-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 9px;
  color: rgba(var(--g-rgb), .5);
  letter-spacing: .8px;
}

.zoom-actions,
.btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.zoom-btn {
  border: 1px solid rgba(var(--c-rgb), .28);
  background: rgba(var(--c-rgb), .06);
  color: rgba(var(--c-rgb), .92);
  font-family: inherit;
  font-size: 10px;
  padding: 4px 9px;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 1px;
}

.zoom-btn:hover,
.ptz-btn:hover {
  border-color: rgba(var(--c-rgb), .55);
  color: #f1f4f8;
}

.zoom-btn:disabled { opacity: .45; cursor: not-allowed; }

#no-signal {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

#noise-cvs {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: .18;
}

.nosig-txt { position: relative; z-index: 2; text-align: center; }
.nosig-txt h2 { font-size: 20px; letter-spacing: 10px; color: rgba(var(--g-rgb), .52); margin-bottom: 8px; }
.nosig-txt p { font-size: 10px; color: rgba(var(--g-rgb), .3); letter-spacing: 1px; }
.nosig-hint { margin-top: 6px; color: rgba(var(--g-rgb), .24); }

.term {
  display: flex;
  flex-direction: column;
  background: #0d1116;
  border: 1px solid #303845;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 16px rgba(var(--c-rgb), .05), 0 0 42px rgba(var(--c-rgb), .018), inset 0 0 50px rgba(0,0,0,.5);
}

.term::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0px, transparent 3px, rgba(var(--c-rgb), .012) 3px, rgba(var(--c-rgb), .012) 4px);
  pointer-events: none;
  z-index: 3;
}

.term::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(var(--c-rgb), .01);
  animation: flicker 9s step-end infinite;
  pointer-events: none;
  z-index: 2;
}

@keyframes flicker {
  0%, 94%, 100% { opacity: 1; }
  95% { opacity: .6; }
  96% { opacity: 1; }
  97% { opacity: .8; }
}

.term-hdr {
  padding: 9px 12px 8px;
  border-bottom: 1px solid rgba(var(--c-rgb), .18);
  font-size: 10.5px;
  letter-spacing: 2px;
  color: #dce2ea;
  background: rgba(var(--c-rgb), .08);
  position: relative;
  z-index: 4;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.term-hdr-title {
  color: var(--c);
  font-size: 11px;
  letter-spacing: 2px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.term-hdr-ver { color: rgba(var(--g-rgb), .5); font-size: 9px; letter-spacing: 1px; }

.term-body {
  flex: 1;
  padding: 14px 12px 10px;
  font-size: 13.5px;
  line-height: 1.8;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  font-family: 'IBM Plex Mono', 'JetBrains Mono', 'SFMono-Regular', ui-monospace, monospace;
  color: rgba(var(--g-rgb), .92);
}

.prompt { color: rgba(var(--g-rgb), .74); font-size: 11.5px; letter-spacing: .5px; }

.person-card {
  padding: 8px 10px;
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 8px;
  background: rgba(var(--c-rgb), .035);
}

.person-card + .person-card { margin-top: 8px; }

/* Gate decision (КПП): pass/no-pass tint at opacity 0.2 + bold colored verdict. */
.person-card.card-approved { background: rgba(40, 200, 90, 0.2); border-color: rgba(40, 200, 90, 0.45); }
.person-card.card-denied   { background: rgba(225, 45, 45, 0.2); border-color: rgba(225, 45, 45, 0.45); }
.person-card.card-pending { background: rgba(240, 190, 40, 0.2); border-color: rgba(240, 190, 40, 0.5); }
.term-line .decision { font-weight: 700; letter-spacing: 1px; }
.term-line .decision-ok { color: #3ae06a; }
.term-line .decision-no { color: #ff5a5a; }
.term-line .decision-wait { color: #f5c542; }
.term-line .decision-queue { color: #9aa7b4; }

/* Guard approval buttons (КПП Step 5) — shown on a pending guest card. */
.gate-actions { display: flex; gap: 8px; margin-top: 8px; }
.gate-btn { flex: 1; padding: 7px 10px; border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-weight: 700; cursor: pointer; letter-spacing: .5px; }
.gate-btn.gate-allow { background: rgba(40, 200, 90, 0.18); border-color: rgba(40, 200, 90, 0.55); color: #3ae06a; }
.gate-btn.gate-allow:hover { background: rgba(40, 200, 90, 0.3); }
.gate-btn.gate-deny { background: rgba(225, 45, 45, 0.18); border-color: rgba(225, 45, 45, 0.55); color: #ff6a6a; }
.gate-btn.gate-deny:hover { background: rgba(225, 45, 45, 0.3); }

.divider {
  border: none;
  border-top: 1px solid var(--gdim);
  margin: 9px 0;
}

.term-line { display: flex; gap: 0; }
.lbl { color: var(--c); opacity: .86; min-width: 102px; flex-shrink: 0; font-size: 12.5px; }
.val { color: rgba(var(--g-rgb), 1); min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; word-break: break-word; }

.panel {
  height: 100%;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-hdr {
  border: 1px solid var(--bord);
  background: rgba(var(--c-rgb), .08);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--c);
  font-size: 12px;
  letter-spacing: 2px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.panel-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ptz-layout {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
}

.card {
  border: 1px solid var(--bord);
  background: rgba(17, 21, 27, .95);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.card-hdr {
  color: var(--c);
  font-size: 11px;
  letter-spacing: 1.2px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.form-row {
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr);
  gap: 8px;
  align-items: center;
}

.form-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label,
.form-col label {
  color: rgba(var(--c-rgb), .75);
  font-size: 10px;
  letter-spacing: 1px;
}

input,
textarea,
select {
  border: 1px solid rgba(var(--c-rgb), .24);
  background: rgba(19, 24, 32, .86);
  color: #eef1f5;
  font-family: 'IBM Plex Mono', 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 5px 7px;
  border-radius: 8px;
  width: 100%;
}

textarea {
  resize: vertical;
  min-height: 110px;
}

select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 26px;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(var(--g-rgb), .8) 50%),
    linear-gradient(135deg, rgba(var(--g-rgb), .8) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) calc(50% - 2px),
    calc(100% - 9px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

select::-ms-expand {
  display: none;
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: .6;
  cursor: not-allowed;
}

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

.ptz-preview-wrap {
  position: relative;
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 12px;
  background: #000;
  overflow: hidden;
  min-height: 230px;
}

.ptz-preview-card .ptz-preview-wrap {
  min-height: 255px;
}

.ptz-controls-card {
  justify-self: start;
  width: 100%;
  max-width: 440px;
}

.ptz-preview-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ptz-preview-nosig {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(var(--g-rgb), .4);
  letter-spacing: 2px;
  font-size: 11px;
  background: rgba(0, 0, 0, .6);
}

.ptz-preview-wrap.live .ptz-preview-nosig {
  display: none;
}

.ptz-btn {
  border: 1px solid rgba(var(--c-rgb), .28);
  background: rgba(var(--c-rgb), .06);
  color: rgba(var(--c-rgb), .92);
  border-radius: 9px;
  padding: 9px 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 1px;
}

.ptz-btn.danger {
  border-color: rgba(var(--r-rgb), .45);
  color: rgba(var(--r-rgb), .92);
  background: rgba(var(--r-rgb), .08);
}

.lens-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.zoom-key .zoom-symbol {
  display: inline-block;
  font-size: 20px;
  line-height: 1;
  font-weight: 400;
  transform: translateY(1px);
}

.lens-zoom-scale {
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 10px;
  padding: 8px 8px 6px;
  background: rgba(19, 24, 32, .72);
  display: grid;
  gap: 6px;
}

.lens-zoom-range {
  width: 100%;
}

.lens-zoom-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: rgba(var(--g-rgb), .68);
  font-size: 10px;
  letter-spacing: .8px;
}

.lens-zoom-meta strong {
  color: var(--c);
  font-size: 11px;
}

.preset-list {
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 10px;
  background: rgba(19, 24, 32, .74);
  min-height: 120px;
  max-height: 100%;
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.settings-cat-list {
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 10px;
  background: rgba(19, 24, 32, .74);
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.settings-cat-btn {
  border: 1px solid rgba(var(--c-rgb), .2);
  border-radius: 8px;
  background: rgba(var(--c-rgb), .045);
  color: rgba(var(--c-rgb), .88);
  font-family: inherit;
  font-size: 10px;
  letter-spacing: .7px;
  padding: 6px 8px;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background-color .15s ease;
}

.settings-cat-btn:hover {
  border-color: rgba(var(--g-rgb), .58);
  color: var(--g);
}

.settings-cat-btn.active {
  border-color: rgba(var(--c-rgb), .5);
  background: rgba(var(--c-rgb), .14);
  color: var(--c);
}

.settings-form {
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 10px;
  background: rgba(19, 24, 32, .76);
  min-height: 290px;
  padding: 8px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-preview-wrap {
  position: relative;
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 12px;
  background: #000;
  overflow: hidden;
  min-height: 140px;
}

.settings-preview-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.settings-preview-nosig {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(var(--g-rgb), .42);
  letter-spacing: 2px;
  font-size: 10px;
  background: rgba(0, 0, 0, .65);
}

.settings-preview-wrap.live .settings-preview-nosig {
  display: none;
}

.settings-empty {
  color: rgba(var(--g-rgb), .6);
  font-size: 11px;
  letter-spacing: .5px;
}

.settings-section {
  border: 1px solid rgba(var(--c-rgb), .16);
  border-radius: 10px;
  background: rgba(var(--c-rgb), .03);
}

.settings-section-hdr {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(var(--g-rgb), .16);
  color: var(--c);
  font-size: 10.5px;
  letter-spacing: 1px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.settings-fields {
  display: grid;
  gap: 8px;
  padding: 8px;
}

.settings-profile-hdr {
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid rgba(var(--c-rgb), .2);
  border-radius: 8px;
  background: rgba(var(--c-rgb), .08);
  color: rgba(var(--c-rgb), .92);
  font-size: 10px;
  letter-spacing: .9px;
  font-weight: 700;
  text-transform: uppercase;
}

.settings-field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  align-items: center;
  gap: 8px;
}

.settings-field-meta {
  min-width: 0;
}

.settings-field-label {
  color: rgba(var(--g-rgb), .9);
  font-size: 11px;
  line-height: 1.3;
}

.settings-field-path {
  margin-top: 2px;
  color: rgba(var(--c-rgb), .58);
  font-size: 10px;
  line-height: 1.2;
  word-break: break-word;
}

.settings-field-check {
  width: 16px;
  height: 16px;
  justify-self: start;
}

.settings-slider-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  align-items: center;
  gap: 8px;
}

.settings-field-slider {
  width: 100%;
  height: 14px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.settings-field-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(var(--g-rgb), .24);
  background: linear-gradient(90deg, rgba(var(--g-rgb), .2) 0%, rgba(var(--c-rgb), .15) 100%);
}

.settings-field-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(var(--c-rgb), .74);
  background: rgba(var(--c-rgb), .95);
  margin-top: -4px;
}

.settings-field-slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(var(--g-rgb), .24);
  background: rgba(var(--g-rgb), .15);
}

.settings-field-slider::-moz-range-progress {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(var(--g-rgb), .8) 0%, rgba(var(--c-rgb), .8) 100%);
}

.settings-field-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(var(--c-rgb), .74);
  border-radius: 50%;
  background: rgba(var(--c-rgb), .95);
}

.settings-field-slider-value {
  width: 100%;
}

.settings-field-fixed {
  background: rgba(var(--g-rgb), .08);
  color: rgba(var(--c-rgb), .74);
}

.settings-field-err {
  margin: 8px;
  color: rgba(var(--r-rgb), .95);
  font-size: 11px;
}

#settings-form input[type='number'],
#settings-form input[type='text'],
#settings-form select {
  width: 100%;
}

#settings-form {
  min-height: 290px;
}

.preset-item {
  border: 1px solid rgba(var(--c-rgb), .16);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}

.preset-item-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.preset-item button {
  border: 1px solid rgba(var(--c-rgb), .26);
  color: rgba(var(--c-rgb), .92);
  background: rgba(var(--c-rgb), .05);
  font-size: 10px;
  letter-spacing: 1px;
  border-radius: 8px;
  padding: 3px 6px;
  cursor: pointer;
}

.preset-item .preset-del-btn {
  min-width: 28px;
  font-size: 13px;
  line-height: 1;
  padding: 3px 4px;
  border: none;
  color: rgba(var(--r-rgb), .95);
  background: rgba(var(--r-rgb), .12);
}

.preset-item .preset-del-btn:hover {
  background: rgba(var(--r-rgb), .22);
}

.json-box {
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 10px;
  background: rgba(19, 24, 32, .8);
  color: rgba(var(--g-rgb), .92);
  font-size: 12px;
  line-height: 1.45;
  padding: 10px;
  overflow: auto;
  flex: 1;
  min-height: 120px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'IBM Plex Mono', 'JetBrains Mono', monospace;
}

.diag-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 10px;
  font-size: 11px;
}

.diag-grid span {
  color: rgba(var(--c-rgb), .7);
  letter-spacing: .7px;
}

.diag-grid strong {
  color: rgba(var(--g-rgb), .94);
  font-weight: 600;
  word-break: break-word;
}

.status-line {
  min-height: 20px;
  color: rgba(var(--c-rgb), .74);
  font-size: 10px;
  letter-spacing: 1px;
}

.status-line.err {
  color: rgba(var(--r-rgb), .94);
}

.active-face-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-family: 'IBM Plex Mono', 'JetBrains Mono', monospace;
  font-size: 10px;
}

.active-face-empty,
.active-face-row {
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 8px;
  background: rgba(7, 12, 18, .42);
  padding: 8px 9px;
}

.active-face-empty {
  color: rgba(var(--c-rgb), .55);
  letter-spacing: 1px;
}

.active-face-row {
  display: grid;
  grid-template-columns: auto minmax(100px, 1fr) auto auto auto auto;
  gap: 7px;
  align-items: center;
}

.active-face-row .face-track,
.active-face-row .face-name {
  color: rgba(var(--g-rgb), .95);
}

.active-face-row .face-meta,
.active-face-row .face-age {
  color: rgba(var(--c-rgb), .72);
}

.ptz-person-panel {
  padding: 14px 12px 10px;
  font-size: 12.5px;
  line-height: 1.7;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  font-family: 'IBM Plex Mono', 'JetBrains Mono', 'SFMono-Regular', ui-monospace, monospace;
  color: rgba(var(--g-rgb), .92);
}

.ptz-person-panel .lbl,
.ptz-person-panel .val {
  font-size: 12px;
}

.scanning { animation: spulse 1.8s ease-in-out infinite; }
@keyframes spulse { 0%, 100% { color: var(--g); } 50% { color: var(--gdim); } }

.cursor {
  display: inline-block;
  width: 9px;
  height: 14px;
  background: var(--g);
  box-shadow: 0 0 4px rgba(var(--g-rgb), .7);
  animation: cur 1.1s step-end infinite;
  vertical-align: middle;
  flex-shrink: 0;
  margin-left: 2px;
}

@keyframes cur { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

.cur-line { display: flex; align-items: center; margin-top: 12px; }

.badge { padding: 0 5px; border-radius: 2px; font-size: 11px; }
.badge-emp { background: rgba(var(--g-rgb), .16); color: var(--g); }
.badge-gst { background: rgba(var(--y-rgb), .15); color: var(--y); }

.act-record { color: var(--g); }
.act-incident { color: var(--r); animation: iflash .35s ease 5; }
.act-ignore { color: rgba(var(--g-rgb), .35); }
@keyframes iflash { 0%, 100% { opacity: 1; } 50% { opacity: .15; } }

.sbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 16px;
  background: var(--bg2);
  border-top: 1px solid var(--bord);
  font-size: 10px;
  color: rgba(var(--g-rgb), .5);
  letter-spacing: 1px;
  flex-shrink: 0;
  gap: 8px;
}

.sim-btn {
  background: none;
  border: 1px solid var(--gdim);
  color: rgba(var(--g-rgb), .5);
  font-family: inherit;
  font-size: 10px;
  padding: 2px 10px;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all .15s;
  flex-shrink: 0;
}

.sim-btn:hover {
  border-color: var(--g);
  color: var(--g);
  box-shadow: 0 0 6px rgba(var(--g-rgb), .25);
}

@media (max-width: 1120px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(230px, 42%);
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

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

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

  .ptz-preview-wrap {
    min-height: 200px;
  }
}

@media (max-width: 900px) {
  .nav-toggle { display: inline-block; }
  .hdr-sub { display: none; }

  .app-shell {
    grid-template-columns: 1fr;
    position: relative;
  }

  .side-nav {
    position: absolute;
    z-index: 20;
    width: min(260px, 78vw);
    height: 100%;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.45);
  }

  body.nav-open .side-nav {
    transform: translateX(0);
  }

  .sbar {
    font-size: 9px;
    padding: 5px 10px;
  }

  .sbar span {
    max-width: 30%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ── 3D Face Profiles View ────────────────────────────────────── */
.faces3d-layout {
  display: flex;
  gap: 16px;
  height: calc(100vh - 140px);
  min-height: 400px;
}

.faces3d-sidebar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #0a0a0a;
  border: 1px solid #1e2a1e;
  padding: 10px;
}

.faces3d-sidebar-hdr {
  font-size: 10px;
  color: #4caf50;
  letter-spacing: 2px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #1e2a1e;
}

.faces3d-person-btn {
  display: block;
  width: 100%;
  background: none;
  border: 1px solid #1e2a1e;
  color: #8fbc8f;
  font-family: inherit;
  font-size: 11px;
  text-align: left;
  padding: 7px 10px;
  margin-bottom: 4px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background .15s, color .15s;
}

.faces3d-person-btn:hover,
.faces3d-person-btn.active {
  background: #1a2e1a;
  color: #4caf50;
  border-color: #4caf50;
}

.faces3d-person-meta {
  font-size: 9px;
  color: #3a4a3a;
  margin-top: 2px;
}

.faces3d-empty {
  color: #3a4a3a;
  font-size: 11px;
  padding: 8px 0;
}

.faces3d-viewer-wrap {
  flex: 1;
  position: relative;
  background: #050f05;
  border: 1px solid #1e2a1e;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#faces3d-preview {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 180px;
  max-width: 28%;
  border: 1px solid #284028;
  background: rgba(4, 12, 4, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: none;
  z-index: 2;
}

.faces3d-person-meta-inline {
  color: #6f8f6f;
  font-size: 10px;
  letter-spacing: 1px;
}

#faces3d-no-selection {
  color: #3a4a3a;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  position: absolute;
}

#faces3d-canvas {
  display: none;
  width: 100%;
  height: 100%;
}

.faces3d-controls {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 14px;
  pointer-events: none;
}

#faces3d-person-label {
  color: #4caf50;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.faces3d-hint {
  color: #2a3a2a;
  font-size: 10px;
}

.hdr-action {
  border: 1px solid #315331;
  padding: 9px 14px;
  color: #d8ffd8;
  text-decoration: none;
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  background: linear-gradient(180deg, rgba(28, 52, 28, 0.92), rgba(11, 20, 11, 0.92));
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.hdr-action:hover {
  border-color: #4caf50;
  color: #ffffff;
  background: linear-gradient(180deg, rgba(41, 82, 41, 0.96), rgba(12, 28, 12, 0.96));
}

.auth-body {
  min-height: 100vh;
  height: auto;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(162, 170, 184, 0.12), transparent 30%),
    radial-gradient(circle at bottom right, rgba(120, 129, 143, 0.16), transparent 28%),
    linear-gradient(180deg, #111317 0%, #090b0e 100%);
  color: #eef1f5;
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
  user-select: text;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth-card {
  width: min(100%, 460px);
  border: 1px solid #2c313a;
  background: rgba(17, 20, 25, 0.94);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
  border-radius: 12px;
  padding: 32px 30px 28px;
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #b8c0cb;
  font-size: 12px;
  letter-spacing: 2.4px;
  text-transform: uppercase;
  margin-bottom: 18px;
}

.auth-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: 1px;
}

.auth-subtitle {
  margin: 10px 0 24px;
  color: #96a0ad;
  font-size: 13px;
  line-height: 1.6;
}

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

.auth-label {
  color: #9ea7b3;
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

.auth-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #313845;
  background: #141821;
  color: #eef1f5;
  border-radius: 8px;
  padding: 13px 14px;
  font-size: 14px;
  outline: none;
}

.auth-input:focus {
  border-color: #8f9aae;
  box-shadow: 0 0 0 1px rgba(143, 154, 174, 0.22);
}

.auth-submit {
  margin-top: 8px;
  border: 1px solid #727d8e;
  background: linear-gradient(180deg, #d7dde6 0%, #9ba6b7 100%);
  color: #11151c;
  border-radius: 9px;
  padding: 13px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
}

.auth-submit:hover {
  filter: brightness(1.03);
}

.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.auth-links a {
  color: #aeb8c6;
  text-decoration: none;
  font-size: 12px;
}

.auth-links a:hover {
  color: #eef1f5;
}

.auth-alert {
  margin: 0 0 18px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid #343b47;
  background: rgba(20, 24, 31, 0.92);
  border-radius: 10px;
}

.auth-alert-error {
  border-color: #7f2d2d;
  background: rgba(36, 10, 10, 0.9);
  color: #ffd2d2;
}

.auth-alert-success {
  border-color: #536072;
  background: rgba(25, 30, 38, 0.94);
  color: #e4e9f0;
}

.auth-reset-link {
  margin-top: 16px;
  border: 1px dashed #45505f;
  background: rgba(20, 24, 31, 0.88);
  border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}

.auth-reset-link span {
  color: #9ea7b3;
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.auth-reset-link code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #eef1f5;
  font-size: 12px;
}

.setup-shell {
  min-height: 100vh;
  display: block;
  padding: 32px 22px;
}

.setup-card {
  width: min(1120px, 100%);
  margin: 0 auto;
  border: 1px solid #2c313a;
  background: rgba(17, 20, 25, 0.95);
  border-radius: 16px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  padding: 30px;
}

.setup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.setup-actions,
.setup-actions-bar,
.camera-form-actions,
.camera-card-actions,
.setup-empty-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.setup-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 14px;
  border: 1px solid #4d5665;
  border-radius: 9px;
  background: rgba(191, 199, 212, 0.05);
  color: #dfe5ed;
  text-decoration: none;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
}

.setup-link-btn:hover {
  border-color: #7c8799;
  color: #f4f7fa;
}

.setup-danger-btn {
  border-color: rgba(var(--r-rgb), .45);
  color: #efb2ac;
}

.setup-empty-state {
  border: 1px solid rgba(var(--c-rgb), .16);
  border-radius: 14px;
  background: rgba(27, 32, 39, .78);
  padding: 28px;
  display: grid;
  gap: 14px;
}

.setup-empty-state h2 {
  margin: 0;
  font-size: 24px;
  color: #eef1f5;
}

.setup-empty-state p,
.setup-help {
  color: #a7b0bc;
  line-height: 1.65;
}

.setup-cta {
  text-decoration: none;
}

.setup-cta-inline {
  text-decoration: none;
  min-height: 42px;
}

.setup-cta-secondary {
  min-height: 42px;
}

.camera-form,
.camera-discovery-form {
  display: grid;
  gap: 16px;
}

.camera-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}

.camera-list-grid {
  display: grid;
  gap: 14px;
}

.camera-card {
  border: 1px solid rgba(var(--c-rgb), .18);
  border-radius: 14px;
  background: rgba(22, 27, 34, .78);
  padding: 16px;
  display: grid;
  gap: 14px;
}

.camera-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.camera-card-top h3 {
  margin: 0;
  color: #eef1f5;
  font-size: 19px;
}

.camera-card-top p {
  margin: 6px 0 0;
  color: #aeb7c3;
}

.camera-card-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.camera-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid rgba(var(--c-rgb), .2);
  color: #dce2ea;
  background: rgba(var(--c-rgb), .06);
}

.camera-status-ok {
  border-color: rgba(139, 178, 146, .35);
  color: #d5ead9;
  background: rgba(93, 132, 104, .14);
}

.camera-status-warn {
  border-color: rgba(var(--y-rgb), .34);
  color: #eadaba;
  background: rgba(var(--y-rgb), .12);
}

.camera-status-err {
  border-color: rgba(var(--r-rgb), .34);
  color: #efbeb9;
  background: rgba(var(--r-rgb), .12);
}

.camera-status-primary {
  border-color: rgba(var(--c-rgb), .36);
  color: #f4f7fa;
  background: rgba(var(--c-rgb), .13);
}

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

.camera-card-grid dt {
  color: #94a0ae;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.camera-card-grid dd {
  margin: 6px 0 0;
  color: #edf1f5;
  line-height: 1.45;
  word-break: break-word;
}

.camera-card-error {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(var(--r-rgb), .26);
  background: rgba(var(--r-rgb), .08);
  color: #e9c0bb;
  line-height: 1.5;
}

.camera-discovery-results {
  margin-top: 6px;
  border: 1px solid rgba(var(--c-rgb), .16);
  border-radius: 12px;
  overflow: hidden;
}

.camera-discovery-table {
  width: 100%;
  border-collapse: collapse;
}

.camera-discovery-table th,
.camera-discovery-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid rgba(var(--c-rgb), .12);
}

.camera-discovery-table th {
  color: #96a0ad;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: rgba(var(--c-rgb), .05);
}

.camera-discovery-table td {
  color: #eef1f5;
  font-size: 13px;
}

.camera-discovery-table tbody tr:last-child td {
  border-bottom: none;
}

@media (max-width: 880px) {
  .camera-form-grid,
  .camera-card-grid {
    grid-template-columns: 1fr;
  }
}
