/* ============================================
   NATIONAL CCTV — 국제정세 모니터링 스타일
   CCTV 감시 시스템 다크 테마
   ============================================ */

/* ── 기본 리셋 ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-main:       #060608;
  --bg-panel:      #0b0d0f;
  --bg-header:     #080a0c;
  --green:         #00e676;
  --green-dim:     #00b050;
  --green-dark:    #003d1a;
  --red:           #ff1744;
  --amber:         #ffab00;
  --white:         #e8eaed;
  --gray:          #5f6368;
  --gray-light:    #9aa0a6;
  --border:        #1a2a1a;
  --border-bright: #2a4a2a;
  --font-mono:     'Courier New', Courier, monospace;
  --header-h:      48px;
  --footer-h:      32px;
  --panel-header:  42px;
  --panel-footer:  32px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-main);
  color: var(--white);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ── 전체 레이아웃 ── */
.cctv-wrap {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  background: var(--bg-main);
}

/* ────────────────────────────────────────────
   상단 헤더
   ──────────────────────────────────────────── */
.cctv-header {
  flex-shrink: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-bright);
  position: relative;
  z-index: 10;
}

/* ────────────────────────────────────────────
   CAM 설명 바
   ──────────────────────────────────────────── */
.cam-desc-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0 16px;
  height: 36px;
  background: #0d1117;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.cam-desc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  padding: 0 14px;
}

.cam-desc-id {
  color: var(--green);
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.1em;
}

.cam-desc-text {
  color: #c8cdd3;
  font-size: 13px;
  letter-spacing: 0.03em;
}

.cam-desc-sep {
  color: var(--border-bright);
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

/* 녹화 표시 */
.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 80px;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1.2s ease-in-out infinite;
  box-shadow: 0 0 6px var(--red);
}

@keyframes blink {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--red); }
  50%       { opacity: 0.2; box-shadow: none; }
}

.rec-label {
  color: var(--red);
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.1em;
}

/* 시스템 타이틀 */
.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.sys-title {
  font-size: 16px;
  font-weight: bold;
  color: var(--green);
  letter-spacing: 0.25em;
  text-shadow: 0 0 12px var(--green-dim);
}

.sys-sub {
  font-size: 10px;
  color: var(--gray-light);
  letter-spacing: 0.1em;
}

/* 시계 */
.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 120px;
}

.clock {
  font-size: 18px;
  color: var(--green);
  letter-spacing: 0.12em;
  text-shadow: 0 0 10px var(--green-dim);
  font-weight: bold;
}

.datestamp {
  font-size: 10px;
  color: var(--gray-light);
  letter-spacing: 0.08em;
}

/* ────────────────────────────────────────────
   패널 그리드 (2×2)
   ──────────────────────────────────────────── */
.panels-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  background: #000;
  overflow: hidden;
  min-height: 0;
}

/* ────────────────────────────────────────────
   개별 패널
   ──────────────────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}

.panel:hover {
  border-color: var(--border-bright);
}

/* 스캔라인 오버레이 */
.panel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
  pointer-events: none;
  z-index: 5;
}

/* 패널 헤더 */
.panel-header {
  flex-shrink: 0;
  height: var(--panel-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: rgba(0, 10, 0, 0.8);
  border-bottom: 1px solid var(--border);
  z-index: 6;
  position: relative;
}

.panel-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.cam-id {
  font-size: 13px;
  font-weight: bold;
  color: var(--green);
  letter-spacing: 0.1em;
  white-space: nowrap;
  text-shadow: 0 0 6px var(--green-dim);
}

.cam-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-light);
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 패널 컨트롤 버튼 */
.panel-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.ctrl-btn {
  width: 24px;
  height: 24px;
  background: rgba(0, 230, 118, 0.08);
  border: 1px solid var(--border-bright);
  color: var(--green-dim);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: all 0.15s;
  line-height: 1;
}

.ctrl-btn:hover {
  background: rgba(0, 230, 118, 0.2);
  color: var(--green);
  border-color: var(--green-dim);
  box-shadow: 0 0 6px rgba(0, 230, 118, 0.3);
}

/* 패널 본문 */
.panel-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

/* 로딩 오버레이 */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-panel);
  z-index: 20;
  color: var(--green-dim);
  font-size: 11px;
  letter-spacing: 0.15em;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-bright);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* iframe */
.site-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  opacity: 0;
  transition: opacity 0.3s;
}

.site-frame.loaded {
  opacity: 1;
}

/* fallback 카드 */
.fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-panel);
  z-index: 15;
  text-align: center;
  padding: 20px;
}

.fallback-icon {
  font-size: 36px;
  line-height: 1;
  filter: grayscale(30%);
}

.fallback-name {
  font-size: 13px;
  font-weight: bold;
  color: var(--green);
  letter-spacing: 0.1em;
  text-shadow: 0 0 8px var(--green-dim);
}

.fallback-desc {
  font-size: 10px;
  color: var(--gray-light);
  line-height: 1.6;
  letter-spacing: 0.06em;
}

.fallback-btn {
  display: inline-block;
  margin-top: 4px;
  padding: 8px 18px;
  background: transparent;
  border: 1px solid var(--green-dim);
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-decoration: none;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}

.fallback-btn:hover {
  background: rgba(0, 230, 118, 0.15);
  border-color: var(--green);
  box-shadow: 0 0 10px rgba(0, 230, 118, 0.3);
}

/* ── 패널 푸터 ── */
.panel-footer {
  flex-shrink: 0;
  height: var(--panel-footer);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: rgba(0, 10, 0, 0.85);
  border-top: 1px solid var(--border);
  z-index: 6;
  position: relative;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.live {
  background: var(--green);
  box-shadow: 0 0 5px var(--green);
  animation: pulse-green 2s ease-in-out infinite;
}

.status-dot.alert {
  background: var(--amber);
  box-shadow: 0 0 5px var(--amber);
  animation: pulse-amber 1s ease-in-out infinite;
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

@keyframes pulse-amber {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--amber); }
  50%       { opacity: 0.5; box-shadow: none; }
}

.status-text {
  font-size: 12px;
  font-weight: bold;
  color: var(--green);
  letter-spacing: 0.1em;
}

.status-text.alert-text {
  color: var(--amber);
}

.location {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-light);
  letter-spacing: 0.06em;
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.panel-time {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-light);
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

/* ────────────────────────────────────────────
   패널 확대 오버레이
   ──────────────────────────────────────────── */
.expand-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.expand-overlay.active {
  display: flex;
}

.expand-box {
  width: 100%;
  max-width: 1200px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border-bright);
  border-radius: 2px;
  box-shadow: 0 0 40px rgba(0, 230, 118, 0.15);
}

.expand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-bright);
}

.expand-title {
  font-size: 12px;
  color: var(--green);
  letter-spacing: 0.1em;
}

.expand-close {
  background: transparent;
  border: 1px solid var(--border-bright);
  color: var(--gray-light);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 12px;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: all 0.15s;
}

.expand-close:hover {
  border-color: var(--red);
  color: var(--red);
}

.expand-frame {
  flex: 1;
  width: 100%;
  border: none;
  min-height: 0;
}

/* ────────────────────────────────────────────
   하단 푸터
   ──────────────────────────────────────────── */
.cctv-footer {
  flex-shrink: 0;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  font-size: 9px;
  color: var(--gray);
  letter-spacing: 0.08em;
}

.footer-mid {
  color: var(--gray);
}

#footer-status {
  color: var(--green-dim);
}

/* ────────────────────────────────────────────
   모바일 반응형
   ──────────────────────────────────────────── */

/* 태블릿 세로 (768px 이하): 1열 스크롤 */
@media (max-width: 768px) {
  html, body {
    overflow: auto;
  }

  .cctv-wrap {
    height: auto;
    min-height: 100vh;
  }

  .panels-grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 60vw);
    gap: 3px;
    height: auto;
  }

  .cctv-header {
    height: auto;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .sys-title {
    font-size: 13px;
  }

  .sys-sub {
    display: none;
  }

  .clock {
    font-size: 14px;
  }

  .cam-title {
    display: none;
  }

  .cctv-footer {
    flex-direction: column;
    height: auto;
    padding: 6px 12px;
    gap: 2px;
    text-align: center;
  }

  .footer-mid {
    display: none;
  }
}

/* 가로 모드 모바일 (높이가 낮을 때) */
@media (max-height: 500px) and (orientation: landscape) {
  .cctv-header {
    height: 36px;
  }

  .sys-sub {
    display: none;
  }

  .sys-title {
    font-size: 13px;
  }

  .clock {
    font-size: 13px;
  }

  .datestamp {
    display: none;
  }

  .cctv-footer {
    height: 24px;
    font-size: 8px;
  }

  .footer-mid {
    display: none;
  }
}

/* 아주 좁은 화면 */
@media (max-width: 400px) {
  .panels-grid {
    grid-template-rows: repeat(4, 70vw);
  }
}
