:root {
  --bg: #0c1118;
  --panel: #131b26;
  --panel2: #172232;
  --text: #ecf3ff;
  --muted: #8fa1b8;
  --border: rgba(255,255,255,.09);
  --accent: #59c7ff;
  --good: #39d98a;
  --bad: #ff5d70;
  --warn: #ffd166;
  --shadow: rgba(0,0,0,.35);
  --grid-columns: 3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top left, #192638 0, var(--bg) 42%);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

button, input, select { font: inherit; }

button {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #223147, #172234);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

button:hover { border-color: rgba(89,199,255,.6); }
button.active, .quality-btn.active {
  border-color: rgba(89,199,255,.95);
  box-shadow: 0 0 0 2px rgba(89,199,255,.15);
}

input, select {
  width: 100%;
  border: 1px solid var(--border);
  background: #0e1622;
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
  outline: none;
}

label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin: 10px 0;
}

label input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 0%, #203146, #080c12 55%);
  z-index: 30;
}

.login-card {
  width: min(390px, calc(100vw - 30px));
  background: rgba(19,27,38,.92);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 20px 70px var(--shadow);
  padding: 28px;
}

.logo-dot {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle, #d8f5ff 0, var(--accent) 40%, #146f9c 70%);
  box-shadow: 0 0 40px rgba(89,199,255,.4);
}

.login-card h1 { margin: 16px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 20px; }
.login-card input { margin-bottom: 10px; }
.login-card button { width: 100%; margin-top: 8px; }

.error {
  color: var(--bad);
  min-height: 20px;
  margin-top: 10px;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,16,24,.72);
  backdrop-filter: blur(12px);
}

.topbar h1 { margin: 0; font-size: 22px; }

#activeCamLabel {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions, .full-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 210px;
  gap: 12px;
  padding: 12px;
}

.camera-list-panel,
.ptz-panel {
  background: rgba(19,27,38,.84);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  min-height: 0;
  overflow: auto;
}

.camera-list-panel h2,
.ptz-panel h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.camera-list-item {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  padding: 9px;
}

.camera-list-item.active,
.camera-card.active {
  border-color: rgba(89,199,255,.9);
  box-shadow: 0 0 0 2px rgba(89,199,255,.15), 0 15px 35px rgba(0,0,0,.25);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  flex: 0 0 auto;
}

.viewer {
  min-width: 0;
  min-height: 0;
  position: relative;
}

.camera-grid {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
  grid-auto-rows: auto;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.camera-card {
  position: relative;
  background: #05080d;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 16 / 9;
  min-height: 0;
}

.camera-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #020304;
  user-select: none;
  -webkit-user-drag: none;
}

.camera-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,.52);
  border: 1px solid rgba(255,255,255,.09);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
}

.empty-slot {
  background:
    linear-gradient(135deg, rgba(255,255,255,.04), rgba(255,255,255,.015)),
    #111923;
  border-style: dashed;
  cursor: pointer;
}

.empty-slot-inner {
  height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  gap: 6px;
}

.empty-slot-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto;
  color: rgba(255,255,255,.72);
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  font-size: 22px;
}

.empty-slot-title { color: var(--text); font-weight: 700; }
.empty-slot-sub { font-size: 12px; }

.full-view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #05080d;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
}

.full-top {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.full-image-wrap {
  position: relative;
  flex: 1;
  touch-action: none;
  overflow: hidden;
  background: #000;
}

.full-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: black;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
  transition: transform .08s linear;
}

#swipeHint, #zoomBadge {
  position: absolute;
  color: rgba(255,255,255,.75);
  background: rgba(0,0,0,.48);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  pointer-events: none;
}

#swipeHint {
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
}

#zoomBadge {
  top: 14px;
  right: 14px;
}

.ptz-selected {
  color: var(--muted);
  min-height: 20px;
  margin-bottom: 12px;
}

.ptz-pad {
  width: 160px;
  height: 160px;
  margin: 0 auto;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: radial-gradient(circle, #1f3046, #111a28 66%);
  position: relative;
  box-shadow: inset 0 0 28px rgba(255,255,255,.04), 0 12px 30px rgba(0,0,0,.28);
}

.ptz-btn {
  position: absolute;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.ptz-up { left: 56px; top: 8px; }
.ptz-down { left: 56px; bottom: 8px; }
.ptz-left { left: 8px; top: 56px; }
.ptz-right { right: 8px; top: 56px; }
.ptz-stop { left: 56px; top: 56px; background: #263951; }

.tiny {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.ptz-status {
  margin-top: 10px;
  min-height: 22px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: rgba(255,255,255,.03);
}

.ptz-status.ok { color: var(--good); }
.ptz-status.busy { color: var(--warn); }
.ptz-status.error { color: var(--bad); }

.bottom-bar {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  padding: 0 14px;
  border-top: 1px solid var(--border);
  background: rgba(10,16,24,.78);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100vw);
  height: 100vh;
  background: rgba(16,24,36,.98);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 60px rgba(0,0,0,.42);
  z-index: 20;
  overflow-y: auto;
  padding: 18px;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-head h2 { margin: 0; }

.settings-section {
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255,255,255,.025);
}

.settings-section h3,
.settings-section h4 {
  margin: 0 0 10px;
}

.slot-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.status-line {
  min-height: 22px;
  color: var(--good);
  margin-top: 10px;
}

@media (max-width: 950px) {
  body { overflow: auto; }
  .app { min-height: 100vh; height: auto; }
  .layout { grid-template-columns: 1fr; }
  .camera-grid {
    min-height: 60vh;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: auto;
  }
}

@media (max-width: 720px) {
  .camera-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .full-actions { gap: 5px; }
  .full-actions button { padding: 8px 9px; }
}

@media (max-width: 460px) {
  .camera-grid { grid-template-columns: 1fr; }
}

.bandwidth-panel {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255,255,255,.03);
}

.bandwidth-panel h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.bandwidth-meter {
  min-width: 150px;
}

.bandwidth-meter.small {
  width: 170px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.035);
}

.bandwidth-meter-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 7px;
}

.bandwidth-bar {
  width: 100%;
  height: 8px;
  background: rgba(255,255,255,.08);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.06);
}

.bandwidth-bar > div {
  height: 100%;
  width: 0%;
  background: var(--good);
  border-radius: 999px;
  transition: width .25s linear, background .25s linear;
}

.bandwidth-details {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.bandwidth-panel.warn .bandwidth-bar > div,
.bandwidth-meter.warn .bandwidth-bar > div {
  background: var(--warn);
}

.bandwidth-panel.danger .bandwidth-bar > div,
.bandwidth-meter.danger .bandwidth-bar > div {
  background: var(--bad);
}

.bandwidth-meter.small #bandwidthLabelTop {
  display: block;
  color: var(--text);
  font-size: 12px;
  margin-bottom: 4px;
  text-align: right;
}

@media (max-width: 950px) {
  .bandwidth-meter.small {
    display: none;
  }
}


.mobile-only {
  display: none;
}

.mobile-ptz-overlay {
  display: none;
}

@media (max-width: 950px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
  }

  .topbar {
    height: auto;
    min-height: 64px;
    gap: 10px;
    padding: 12px 14px;
    position: sticky;
    top: 0;
    z-index: 15;
  }

  .topbar h1 {
    font-size: 24px;
  }

  #activeCamLabel {
    font-size: 14px;
  }

  .top-actions {
    gap: 8px;
  }

  .top-actions button {
    padding: 10px 12px;
    font-size: 15px;
  }

  .layout {
    display: block;
    padding: 12px;
  }

  .camera-list-panel {
    margin-bottom: 12px;
    max-height: none;
  }

  .camera-list-panel h2 {
    font-size: 18px;
  }

  .camera-list-item {
    font-size: 18px;
    padding: 13px;
    border-radius: 12px;
  }

  .camera-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    min-height: 0;
    overflow: visible;
  }

  .camera-card {
    border-radius: 16px;
  }

  .empty-slot {
    min-height: 170px;
  }

  .ptz-panel {
    margin-top: 12px;
  }

  .full-view {
    position: fixed;
    inset: 0;
    z-index: 50;
    border-radius: 0;
    border: 0;
    background: #05080d;
  }

  .full-top {
    height: auto;
    min-height: 56px;
    padding: 8px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .full-top strong {
    max-width: 92px;
    line-height: 1.05;
    overflow-wrap: anywhere;
  }

  .full-actions {
    gap: 6px;
    flex: 1;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .full-actions button {
    padding: 8px 10px;
    font-size: 14px;
  }

  .mobile-only {
    display: inline-grid;
  }

  .full-image-wrap {
    min-height: 0;
    height: calc(100vh - 70px);
    flex: 1;
  }

  .full-image-wrap img {
    object-fit: contain;
  }

  .mobile-ptz-overlay {
    display: block;
    position: absolute;
    width: 154px;
    height: 196px;
    right: 14px;
    bottom: 18px;
    z-index: 8;
    touch-action: none;
    user-select: none;
    border-radius: 22px;
    background: rgba(13, 23, 36, .64);
    border: 1px solid rgba(89,199,255,.35);
    box-shadow: 0 18px 45px rgba(0,0,0,.42), inset 0 0 24px rgba(89,199,255,.08);
    backdrop-filter: blur(10px);
  }

  .mobile-ptz-handle {
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    color: var(--text);
    font-size: 13px;
    cursor: grab;
    border-bottom: 1px solid rgba(255,255,255,.08);
  }

  .mobile-ptz-handle small {
    color: var(--muted);
    font-size: 11px;
  }

  .mobile-ptz-pad {
    position: relative;
    width: 138px;
    height: 138px;
    margin: 10px auto 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(45,66,96,.95), rgba(15,25,39,.75) 68%);
    border: 1px solid rgba(255,255,255,.08);
  }

  .overlay-ptz-btn {
    position: absolute;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(35,52,76,.88);
  }

  .overlay-ptz-up { left: 48px; top: 7px; }
  .overlay-ptz-down { left: 48px; bottom: 7px; }
  .overlay-ptz-left { left: 7px; top: 48px; }
  .overlay-ptz-right { right: 7px; top: 48px; }
  .overlay-ptz-stop { left: 48px; top: 48px; background: rgba(67,91,126,.92); }

  #swipeHint {
    bottom: 8px;
    max-width: calc(100vw - 20px);
    white-space: normal;
    text-align: center;
    font-size: 11px;
    padding: 6px 9px;
  }

  #zoomBadge {
    top: 64px;
    right: 10px;
    font-size: 11px;
    padding: 6px 9px;
  }

  .ptz-panel {
    display: none;
  }

  .full-view.hidden + .ptz-panel,
  .layout > .ptz-panel {
    display: block;
  }
}

@media (max-width: 950px) and (orientation: landscape) {
  .full-view {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .full-image-wrap {
    height: auto;
  }

  .mobile-ptz-overlay {
    width: 142px;
    height: 176px;
  }

  .mobile-ptz-pad {
    width: 124px;
    height: 124px;
  }

  .overlay-ptz-btn {
    width: 38px;
    height: 38px;
  }

  .overlay-ptz-up { left: 43px; top: 6px; }
  .overlay-ptz-down { left: 43px; bottom: 6px; }
  .overlay-ptz-left { left: 6px; top: 43px; }
  .overlay-ptz-right { right: 6px; top: 43px; }
  .overlay-ptz-stop { left: 43px; top: 43px; }
}

@media (min-width: 951px) {
  .mobile-ptz-overlay,
  .mobile-only {
    display: none !important;
  }
}


/* Build 0.0.7 - mobiele grid fix */
@media (max-width: 950px) {
  .layout {
    display: block;
    padding: 10px;
  }

  .viewer {
    min-height: auto;
  }

  .camera-grid:not(.hidden) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    overflow: visible;
    min-height: 0;
    height: auto;
    align-content: start;
  }

  .camera-card {
    aspect-ratio: 16 / 9;
    min-height: 0;
    border-radius: 14px;
  }

  .camera-card img {
    object-fit: cover;
  }

  .camera-label {
    left: 7px;
    right: 7px;
    bottom: 7px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .empty-slot {
    min-height: 0;
  }

  .empty-slot-inner {
    gap: 3px;
  }

  .empty-slot-icon {
    width: 34px;
    height: 34px;
    font-size: 20px;
  }

  .empty-slot-title {
    font-size: 14px;
  }

  .empty-slot-sub {
    font-size: 11px;
  }
}

/* Smalle telefoons blijven 2 kolommen, zodat het geen lange slinger wordt */
@media (max-width: 460px) {
  .camera-grid:not(.hidden) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar h1 {
    font-size: 21px;
  }

  .top-actions button {
    padding: 9px 10px;
    font-size: 14px;
  }
}

/* Telefoon horizontaal: 3 kolommen */
@media (max-width: 950px) and (orientation: landscape) {
  .camera-grid:not(.hidden) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .camera-list-panel {
    margin-bottom: 10px;
  }
}

/* In grootbeeld mag het grid nooit door de fullscreen overlay heen rommelen */
@media (max-width: 950px) {
  .full-view:not(.hidden) {
    position: fixed;
    inset: 0;
    z-index: 50;
  }
}
