/* ─────────────────────────────────────────────
   NewsWall — 다중 라이브 뉴스 그리드 뷰어
   ───────────────────────────────────────────── */

.newswall-root {
  --nw-bg: #0b0d10;
  --nw-panel: #14171c;
  --nw-border: #2a2f38;
  --nw-text: #e6e8eb;
  --nw-text-mute: #8b939e;
  --nw-accent: #2563eb;
  --nw-accent-hover: #1d4ed8;
  --nw-active: #22c55e;
  --nw-danger: #ef4444;

  background: var(--nw-bg);
  color: var(--nw-text);
  min-height: calc(100vh - 60px);
  margin: -1rem -15px 0; /* base.html container 패딩 무시 */
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Noto Sans KR", sans-serif;
}

/* ───────── Toolbar ───────── */
.nw-toolbar {
  background: var(--nw-panel);
  border-bottom: 1px solid var(--nw-border);
  padding: 12px 16px 10px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.nw-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.nw-tabs {
  display: inline-flex;
  background: #0f1216;
  border: 1px solid var(--nw-border);
  border-radius: 8px;
  padding: 3px;
}
.nw-tab {
  background: transparent;
  border: 0;
  color: var(--nw-text-mute);
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.15s;
}
.nw-tab:hover { color: var(--nw-text); }
.nw-tab.is-active {
  background: var(--nw-accent);
  color: #fff;
}

.nw-grid-modes {
  display: inline-flex;
  background: #0f1216;
  border: 1px solid var(--nw-border);
  border-radius: 8px;
  padding: 3px;
}
.nw-grid-btn {
  background: transparent;
  border: 0;
  color: var(--nw-text-mute);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.15s;
  min-width: 44px;
}
.nw-grid-btn:hover { color: var(--nw-text); }
.nw-grid-btn.is-active {
  background: var(--nw-active);
  color: #07120b;
}

.nw-actions {
  display: inline-flex;
  gap: 6px;
}
.nw-icon-btn {
  background: #0f1216;
  border: 1px solid var(--nw-border);
  color: var(--nw-text);
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: 0.15s;
}
.nw-icon-btn:hover {
  border-color: var(--nw-accent);
  color: var(--nw-accent);
}
.nw-icon-label { font-weight: 600; }

.nw-hint {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--nw-text-mute);
  line-height: 1.4;
}

/* ───────── Grid ───────── */
.nw-grid {
  display: grid;
  gap: 6px;
  padding: 6px;
  /* viewport 높이에서 toolbar 빼고 다 채우기 */
  height: calc(100vh - 130px);
}
.nw-grid[data-grid="2"] {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
.nw-grid[data-grid="3"] {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.nw-grid[data-grid="4"] {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

/* 모바일: 4×4는 2×N으로 강제 */
@media (max-width: 768px) {
  .nw-grid[data-grid="3"],
  .nw-grid[data-grid="4"] {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: none;
    grid-auto-rows: minmax(180px, 1fr);
    height: auto;
  }
  .nw-grid[data-grid="2"] {
    grid-template-rows: none;
    grid-auto-rows: minmax(220px, 1fr);
    height: auto;
  }
  .nw-icon-label { display: none; }
}

/* ───────── Cell ───────── */
.nw-cell {
  position: relative;
  background: #000;
  border: 1px solid var(--nw-border);
  border-radius: 8px;
  overflow: hidden;
  min-height: 0; /* grid에서 iframe overflow 방지 */
}
.nw-cell.is-active {
  border-color: var(--nw-active);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
}

.nw-cell iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.nw-cell-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--nw-text-mute);
  cursor: pointer;
  background: linear-gradient(135deg, #14171c, #0f1216);
  transition: 0.2s;
}
.nw-cell-empty:hover {
  background: #181c22;
  color: var(--nw-text);
}
.nw-cell-empty .plus { font-size: 36px; line-height: 1; }
.nw-cell-empty .label { margin-top: 8px; font-size: 13px; }

.nw-cell-overlay {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.18s;
}
.nw-cell:hover .nw-cell-overlay,
.nw-cell.is-active .nw-cell-overlay {
  opacity: 1;
}

.nw-cell-name {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12.5px;
  font-weight: 600;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nw-cell-name .live-dot {
  width: 6px;
  height: 6px;
  background: var(--nw-danger);
  border-radius: 50%;
  animation: nw-pulse 1.5s infinite;
}
@keyframes nw-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.nw-cell-controls {
  display: inline-flex;
  gap: 4px;
  pointer-events: auto;
}
.nw-cell-btn {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  border: 0;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
}
.nw-cell-btn:hover {
  background: var(--nw-accent);
}
.nw-cell-btn.danger:hover {
  background: var(--nw-danger);
}

/* 영상 클릭 영역 — overlay 위에 투명 레이어 */
.nw-cell-clickzone {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: pointer;
}

/* ───────── Modal ───────── */
.nw-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nw-modal[hidden] { display: none !important; }

.nw-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
}

.nw-modal-panel {
  position: relative;
  background: var(--nw-panel);
  border: 1px solid var(--nw-border);
  border-radius: 12px;
  width: min(680px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1;
}
.nw-modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--nw-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nw-modal-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.nw-modal-close {
  background: transparent;
  border: 0;
  color: var(--nw-text-mute);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
}
.nw-modal-close:hover { color: var(--nw-text); }

.nw-modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  flex: 1;
}
.nw-modal-desc {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--nw-text-mute);
}

.nw-channel-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}
.nw-channel-item {
  background: #0f1216;
  border: 1px solid var(--nw-border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: 0.15s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.nw-channel-item:hover {
  border-color: var(--nw-accent);
}
.nw-channel-item.is-selected {
  background: rgba(37, 99, 235, 0.12);
  border-color: var(--nw-accent);
}
.nw-channel-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--nw-text);
}
.nw-channel-tag {
  font-size: 11px;
  color: var(--nw-text-mute);
  background: #1c212a;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}
.nw-channel-item.is-selected .nw-channel-tag {
  background: var(--nw-accent);
  color: #fff;
}

.nw-modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--nw-border);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}
.nw-selected-count {
  margin-right: auto;
  font-size: 12.5px;
  color: var(--nw-text-mute);
}

.nw-btn {
  background: transparent;
  border: 1px solid var(--nw-border);
  color: var(--nw-text);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s;
}
.nw-btn-ghost:hover { border-color: var(--nw-text-mute); }
.nw-btn-primary {
  background: var(--nw-accent);
  border-color: var(--nw-accent);
  color: #fff;
}
.nw-btn-primary:hover { background: var(--nw-accent-hover); border-color: var(--nw-accent-hover); }
.nw-btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
