* {
  box-sizing: border-box;
}

:root {
  --bg: #070b12;
  --panel: #101722;
  --panel-2: #151f2e;
  --line: rgba(255, 255, 255, 0.08);
  --text: #edf3ff;
  --muted: #93a4bb;
  --soft: #607086;
  --blue: #4d8dff;
  --green: #24d18f;
  --red: #ff4d68;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(77, 141, 255, 0.16), transparent 34%),
    radial-gradient(circle at bottom right, rgba(36, 209, 143, 0.10), transparent 30%),
    var(--bg);
}

button,
input {
  font: inherit;
}

.cctv-app {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(16, 23, 34, 0.78);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--blue), #7c5cff);
  font-weight: 900;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}

.brand-text {
  min-width: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 850;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(21, 31, 46, 0.86);
  color: var(--muted);
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(36, 209, 143, 0.13);
}

.main-panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(16, 23, 34, 0.78);
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.26);
}

.panel-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-head h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.panel-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.view-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.view-actions-stack {
  min-width: 360px;
  display: grid;
  gap: 8px;
}

.button-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.search-box {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 11px;
  background: rgba(7, 11, 18, 0.38);
}

.search-box span {
  color: var(--soft);
  font-size: 18px;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  padding: 10px 0;
}

.search-box input::placeholder {
  color: var(--soft);
}

.btn {
  border: 1px solid var(--line);
  background: rgba(21, 31, 46, 0.9);
  color: var(--text);
  border-radius: 12px;
  padding: 9px 11px;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover {
  border-color: rgba(77, 141, 255, 0.55);
  background: rgba(77, 141, 255, 0.16);
}

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

.pager-bar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(7, 11, 18, 0.20);
}

.pager-info {
  color: var(--muted);
  font-size: 13px;
}

.pager-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-indicator {
  min-width: 58px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

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

.camera-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel-2);
  overflow: hidden;
  position: relative;
}

.camera-card.active {
  border-color: rgba(77, 141, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(77, 141, 255, 0.13);
}

.camera-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
}

.camera-name {
  min-width: 0;
}

.camera-name strong,
.camera-name span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.camera-name strong {
  font-size: 14px;
}

.camera-name span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255, 77, 104, 0.12);
  color: #ffb5c0;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.04em;
}

.live-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 77, 104, 0.14);
}

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

.player-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #000;
}

.stream-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  right: 10px;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  color: rgba(255, 255, 255, 0.70);
  font-size: 11px;
}

.stream-label span {
  padding: 5px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
}

.camera-footer {
  padding: 10px 13px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.path-code {
  color: #b7c6dc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 18px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
  background: rgba(21, 31, 46, 0.35);
}

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

@media (max-width: 760px) {
  .cctv-app {
    padding: 12px;
  }

  .topbar,
  .panel-head,
  .pager-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-meta,
  .view-actions,
  .button-row,
  .pager-actions {
    justify-content: flex-start;
  }

  .view-actions-stack {
    min-width: 0;
  }

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

  .brand-title {
    font-size: 16px;
  }

  .pager-btn {
    flex: 1;
  }

  .page-indicator {
    min-width: 50px;
  }
}

/* =====================================================
   HLS Mobile Player
===================================================== */

.hls-player {
  width: 100%;
  height: 100%;
  display: block;
  background: #05070b;
  object-fit: cover;
  border: 0;
  outline: 0;
}

.hls-player::-webkit-media-controls-panel {
  background-color: rgba(0, 0, 0, 0.55);
}

.hls-message {
  width: 100%;
  height: 100%;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  text-align: center;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.82);
  background: #05070b;
  font-size: 13px;
}

.hls-message a {
  color: #ffffff;
  font-weight: 700;
  text-decoration: underline;
}

@media (max-width: 760px) {
  .player-wrap {
    min-height: 220px;
  }

  .hls-player {
    min-height: 220px;
  }
}

/* =====================================================
   HLS Mobile Player Stabilizer
===================================================== */

.hls-player {
  width: 100%;
  height: 100%;
  display: block;
  background: #05070b;
  object-fit: cover;
  border: 0;
  outline: 0;
}

.hls-player::-webkit-media-controls-panel {
  background-color: rgba(0, 0, 0, 0.55);
}

.hls-message {
  width: 100%;
  height: 100%;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  text-align: center;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.82);
  background: #05070b;
  font-size: 13px;
}

.hls-message a {
  color: #ffffff;
  font-weight: 700;
  text-decoration: underline;
}

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

  .player-wrap {
    min-height: 230px;
  }

  .hls-player {
    min-height: 230px;
  }
}

/* =====================================================
   Mobile HLS - Video Tidak Kepotong
===================================================== */

@media (max-width: 760px) {
  .player-wrap {
    width: 100%;
    min-height: 230px;
    aspect-ratio: 16 / 9;
    background: #05070b;
    overflow: hidden;
  }

  .hls-player {
    width: 100%;
    height: 100%;
    min-height: 230px;
    display: block;
    object-fit: contain !important;
    background: #05070b;
  }

  .camera-card {
    overflow: hidden;
  }
}

/* =====================================================
   Mobile HLS - Video Tidak Kepotong
===================================================== */

@media (max-width: 760px) {
  .player-wrap {
    width: 100%;
    min-height: 230px;
    aspect-ratio: 16 / 9;
    background: #05070b;
    overflow: hidden;
  }

  .hls-player {
    width: 100%;
    height: 100%;
    min-height: 230px;
    display: block;
    object-fit: contain !important;
    background: #05070b;
  }

  .camera-card {
    overflow: hidden;
  }
}

/* =====================================================
   FORCE MOBILE HLS FIT - FINAL OVERRIDE
   Video utuh, tidak crop/kepotong
===================================================== */

@media (max-width: 760px) {
  .camera-card .player-wrap {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    aspect-ratio: 16 / 9 !important;
    background: #05070b !important;
    overflow: hidden !important;
  }

  .camera-card .player-wrap iframe,
  .camera-card .player-wrap video,
  .camera-card .player-wrap .hls-player {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    display: block !important;
    object-fit: contain !important;
    background: #05070b !important;
  }

  .camera-card .stream-label {
    position: absolute !important;
    left: 10px !important;
    right: 10px !important;
    bottom: 10px !important;
    z-index: 5 !important;
  }
}

/* =====================================================
   Hide in-frame stream label
   Info kamera sudah tampil di card/header/footer
===================================================== */

.stream-label {
  display: none !important;
}

/* =====================================================
   Per-card reload button
===================================================== */

.camera-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.card-reload-btn {
  appearance: none;
  border: 1px solid rgba(110, 168, 255, 0.28);
  background: rgba(12, 22, 38, 0.72);
  color: #dbeafe;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 7px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.card-reload-btn:hover {
  border-color: rgba(110, 168, 255, 0.55);
  background: rgba(31, 51, 82, 0.86);
}

.card-reload-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

@media (max-width: 760px) {
  .card-reload-btn {
    padding: 7px 8px;
    font-size: 10px;
  }

  .camera-actions {
    gap: 6px;
  }
}

/* =====================================================
   Full HD button
===================================================== */

.camera-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.card-hd-btn,
.card-reload-btn {
  appearance: none;
  border: 1px solid rgba(110, 168, 255, 0.28);
  background: rgba(12, 22, 38, 0.72);
  color: #dbeafe;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 7px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.card-hd-btn {
  border-color: rgba(250, 204, 21, 0.42);
  color: #fef3c7;
  background: rgba(68, 48, 12, 0.72);
}

.card-hd-btn:hover {
  border-color: rgba(250, 204, 21, 0.75);
  background: rgba(92, 63, 12, 0.9);
}

.card-reload-btn:hover {
  border-color: rgba(110, 168, 255, 0.55);
  background: rgba(31, 51, 82, 0.86);
}

.card-reload-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

@media (max-width: 760px) {
  .card-hd-btn,
  .card-reload-btn {
    padding: 7px 8px;
    font-size: 10px;
  }

  .camera-actions {
    gap: 6px;
  }
}
