:root {
  --bg: #0e1117;
  --panel: #171c26;
  --panel-2: #1f2632;
  --line: #2a3240;
  --text: #e8ecf3;
  --muted: #93a0b4;
  --primary: #2f6bff;
  --primary-d: #2456d8;
  --danger: #e23744;
  --danger-d: #c31e2a;
  --ok: #2ec26b;
  --radius: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Pretendard', system-ui, -apple-system, 'Malgun Gothic', sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
}
button, input, select { font-family: inherit; }

/* ---------- 상단바 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-size: 22px; font-weight: 800; }
.top-right { display: flex; align-items: center; gap: 18px; }
.clock { font-size: 20px; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); }
.conn { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.conn .dot { width: 10px; height: 10px; border-radius: 50%; background: #666; }
.conn.ok .dot { background: var(--ok); }

/* ---------- 버튼 ---------- */
.btn {
  padding: 12px 18px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 12px; font-size: 16px; font-weight: 700; cursor: pointer; transition: .15s;
}
.btn:hover { border-color: #3a475a; background: #263041; }
.btn.big { padding: 14px 22px; font-size: 17px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-d); }
.btn-outline { background: transparent; }

/* ---------- 레이아웃 ---------- */
.layout { display: grid; grid-template-columns: 1fr 400px; gap: 20px; padding: 20px; align-items: start; }
.workarea { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 70vh; }
.sidebar { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- 탭 ---------- */
.tabs { display: flex; gap: 6px; padding: 12px 12px 0; border-bottom: 1px solid var(--line); }
.tab {
  padding: 14px 22px; background: transparent; border: none; color: var(--muted);
  font-size: 17px; font-weight: 800; cursor: pointer; border-radius: 10px 10px 0 0;
}
.tab.active { color: var(--text); background: var(--panel-2); }
.tab-panel { display: none; padding: 22px; }
.tab-panel.active { display: block; }

.section-title { font-size: 18px; margin: 18px 0 12px; display: flex; align-items: center; gap: 8px; }
.count { background: var(--panel-2); border-radius: 20px; padding: 2px 12px; font-size: 14px; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; line-height: 1.5; }

/* ---------- 미디어 추가 ---------- */
.add-media { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.add-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; }
.add-title { font-weight: 800; font-size: 16px; margin-bottom: 4px; }
.add-card input[type=text] { padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); margin-bottom: 10px; }
.add-card .btn { margin-top: auto; }
.upload-progress { font-size: 13px; color: var(--ok); margin-top: 8px; }

/* ---------- 미디어 그리드 ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.media-item { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.media-thumb { aspect-ratio: 16/9; background: #000; display: flex; align-items: center; justify-content: center; position: relative; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.type-pill { position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 6px; background: rgba(0,0,0,.65); }
.type-upload { color: #7ecbff; } .type-folder { color: #ffd479; } .type-youtube { color: #ff7a7a; } .type-image { color: #9be89b; }
.media-body { padding: 10px 12px; }
.media-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-actions { display: flex; gap: 6px; margin-top: 8px; }
.media-actions .mini { flex: 1; padding: 8px; font-size: 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; }
.media-actions .mini:hover { background: #263041; }
.media-actions .mini.danger { color: #ff8a8a; }

/* ---------- 스케줄 ---------- */
.schedule-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.sched-item { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; align-items: center; gap: 16px; }
.sched-item.off { opacity: .5; }
.sched-main { flex: 1; }
.sched-name { font-size: 18px; font-weight: 800; }
.sched-meta { color: var(--muted); font-size: 14px; margin-top: 4px; }
.sched-badge { background: var(--bg); border-radius: 8px; padding: 4px 10px; font-size: 13px; margin-right: 6px; }

/* ---------- 설정 ---------- */
.settings-block { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.res-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.res-presets .chip { padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-weight: 700; }
.res-presets .chip.active { background: var(--primary); border-color: var(--primary); }
.res-custom { display: flex; align-items: center; gap: 10px; }
.res-custom input { width: 100px; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.bright-mode { display: flex; gap: 20px; margin-bottom: 14px; }
.radio { display: flex; align-items: center; gap: 8px; font-size: 16px; cursor: pointer; }
.big-check { font-size: 17px; font-weight: 700; }
.bright-box { display: none; }
.bright-box.active { display: block; }
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type=range] { flex: 1; height: 6px; }
.slider-row .val { min-width: 54px; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.daynight { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dn-card { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.dn-card.day { border-color: #4a3f1e; } .dn-card.night { border-color: #23324a; }
.dn-title { font-weight: 800; margin-bottom: 10px; }
.dn-card label { display: block; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
.dn-card input[type=time] { margin-left: 8px; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }

/* ---------- 미리보기 ---------- */
.preview-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.preview-head { padding: 12px 14px; font-weight: 800; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }
.preview-frame { aspect-ratio: 16/9; background: #000; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#preview-stage { position: relative; transform-origin: center center; background: #000; overflow: hidden; }
.preview-info { padding: 12px 14px; }
.pi-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; border-bottom: 1px dashed var(--line); }
.pi-row:last-child { border-bottom: none; }
.pi-row span { color: var(--muted); }

/* ---------- 긴급송출 ---------- */
.emergency-card { background: linear-gradient(180deg, #2a1418, var(--panel)); border: 2px solid var(--danger); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.em-title { font-size: 19px; font-weight: 900; color: #ff9aa2; }
.emergency-card select { padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 15px; }
.emergency-card.active { box-shadow: 0 0 0 4px rgba(226,55,68,.3); }

/* ---------- 모달 ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: min(600px, 92vw); max-height: 90vh; overflow: auto; }
.modal h2 { margin-bottom: 16px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 8px; font-weight: 700; }
.field input[type=text] { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.time-row { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.time-row input[type=time] { padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); margin-left: 6px; }
.days { display: flex; gap: 6px; }
.day-btn { width: 46px; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-weight: 800; cursor: pointer; }
.day-btn.on { background: var(--primary); border-color: var(--primary); }
.media-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 8px; max-height: 260px; overflow: auto; }
.pick-item { border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; display: flex; align-items: center; gap: 8px; background: var(--bg); }
.pick-item.on { border-color: var(--primary); background: #1a2740; }
.pick-item .order { width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 12px; display: none; align-items: center; justify-content: center; font-weight: 800; }
.pick-item.on .order { display: flex; }
.pick-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.empty { color: var(--muted); text-align: center; padding: 40px; font-size: 15px; }

/* ---------- 재생 이력 ---------- */
.hist-wrap { max-height: 62vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.hist-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hist-table th, .hist-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.hist-table thead th { position: sticky; top: 0; background: var(--panel-2); font-weight: 800; z-index: 1; }
.hist-table td:nth-child(2) { white-space: normal; }
.hist-table tbody tr:hover { background: var(--panel-2); }

/* ---------- 모니터 감지 ---------- */
.monitor-detect { display: flex; align-items: center; gap: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.md-info { flex: 1; }
.md-label { font-size: 13px; color: var(--muted); }
.md-value { font-size: 18px; font-weight: 800; margin-top: 2px; }
.md-value.live { color: var(--ok); }
.monitor-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.monitor-list .mon { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-weight: 700; }
.monitor-list .mon:hover { border-color: var(--primary); }
.monitor-list .mon small { display: block; color: var(--muted); font-weight: 500; }

/* ---------- 스케일 방식 ---------- */
.scale-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.scale-opt { display: flex; flex-direction: column; gap: 4px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; }
.scale-opt:has(input:checked) { border-color: var(--primary); background: #16213a; }
.scale-opt input { margin-bottom: 4px; }
.scale-opt b { font-size: 15px; }
.scale-opt span { font-size: 12px; color: var(--muted); line-height: 1.4; }

/* ---------- 스케줄 툴바 ---------- */
.sched-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.sched-toolbar .spacer { flex: 1; }

/* ---------- 스케줄 모달: 폴더 스캔 / 재생순서 ---------- */
.scan-row { display: flex; gap: 8px; }
.scan-row input { flex: 1; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.playlist-order { display: flex; flex-direction: column; gap: 6px; min-height: 54px; border: 1px dashed var(--line); border-radius: 10px; padding: 8px; }
.playlist-order .empty-drop { color: var(--muted); text-align: center; padding: 14px; font-size: 14px; }
.pl-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; cursor: grab; }
.pl-item.dragging { opacity: .4; }
.pl-item.drag-over { border-color: var(--primary); box-shadow: inset 0 2px 0 var(--primary); }
.pl-handle { color: var(--muted); font-size: 18px; cursor: grab; }
.pl-num { width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.pl-name { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-type { font-size: 11px; color: var(--muted); }
.pl-remove { background: transparent; border: none; color: #ff8a8a; font-size: 18px; cursor: pointer; }

/* ---------- 타임테이블 ---------- */
.modal-wide { width: min(1100px, 96vw); }
.tt-head { display: flex; align-items: center; justify-content: space-between; }
.timetable-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 10px; }
.timetable { display: flex; min-width: 720px; }
.tt-col { flex: 1; border-left: 1px solid var(--line); position: relative; }
.tt-axis { flex: 0 0 52px; }
.tt-axis .tt-body { }
.tt-headcell { height: 34px; position: sticky; top: 0; z-index: 3; background: var(--panel-2); display: flex; align-items: center; justify-content: center; font-weight: 800; border-bottom: 1px solid var(--line); }
.tt-headcell.sun { color: #ff8a8a; } .tt-headcell.sat { color: #8ab4ff; }
.tt-body { position: relative; }
.tt-hourlabel { position: absolute; right: 6px; font-size: 11px; color: var(--muted); transform: translateY(-6px); }
.tt-hourline { position: absolute; left: 0; right: 0; border-top: 1px solid #212936; }
.tt-block { position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 3px 6px; font-size: 11px; font-weight: 800; color: #fff; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.4); box-sizing: border-box; }
.tt-block small { display: block; font-weight: 500; opacity: .9; font-size: 10px; }
.tt-nowline { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 4; }
.tt-nowdot { position: absolute; left: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); transform: translateY(-2px); z-index: 5; }

/* 드래그로 파일 업로드 */
.add-card.dragover { border-color: var(--primary); background: #16213a; }

/* ---------- 포스터/현수막 ---------- */
.box-priority { background: #2a2410; border: 1px solid #5c4f1e; color: #ffe08a; border-radius: 10px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.field-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.field-head > span { margin-bottom: 0; }
.btn-mini { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.poster-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.poster-item { display: flex; align-items: center; gap: 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.poster-item.off { opacity: .5; }
.poster-thumb { width: 120px; height: 68px; border-radius: 8px; background: #000; object-fit: cover; flex-shrink: 0; }
.poster-main { flex: 1; min-width: 0; }
.poster-name { font-size: 17px; font-weight: 800; }
.poster-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.poster-meta .badge { background: var(--bg); border-radius: 7px; padding: 3px 9px; margin-right: 5px; display: inline-block; }
.poster-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; max-height: 220px; overflow: auto; }
.poster-pick .pi { border: 2px solid var(--line); border-radius: 9px; overflow: hidden; cursor: pointer; background: #000; }
.poster-pick .pi.on { border-color: var(--primary); }
.poster-pick .pi img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.poster-pick .pi .cap { font-size: 11px; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--panel-2); }
.poster-pick .empty { grid-column: 1/-1; }
.slot-list { display: flex; flex-direction: column; gap: 8px; }
.slot-row { display: flex; align-items: center; gap: 10px; }
.slot-row input[type=time] { padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.slot-row .slot-del { background: transparent; border: none; color: #ff8a8a; font-size: 18px; cursor: pointer; }
.slot-row .tilde { color: var(--muted); }

/* ---------- 원격 지원 ---------- */
.remote-status { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-weight: 700; }
.remote-status .dot { width: 11px; height: 11px; border-radius: 50%; background: #666; }
.remote-status.connected .dot { background: var(--ok); }
.remote-status.connecting .dot { background: var(--warn); }
.remote-status.denied .dot { background: var(--danger); }
.field2 { display: block; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
.field2 input { display: block; width: 100%; margin-top: 5px; padding: 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.remote-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- 클라우드 백업 · 로컬 저장 ---------- */
.cloud-info { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 14px; line-height: 1.7; color: var(--muted); margin-bottom: 4px; }
.cloud-info b { color: var(--text); }
.snap-list { display: flex; flex-direction: column; gap: 6px; }
.snap-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 14px; }
.snap-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snap-row small { color: var(--muted); }
.snap-size { color: var(--muted); font-size: 13px; white-space: nowrap; }
.snap-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-xs { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.badge-count { background: var(--danger); color: #fff; border-radius: 20px; padding: 1px 8px; font-size: 12px; font-weight: 800; margin-left: 4px; }

/* ---------- 인증 게이트 ---------- */
.gate-input { width: 100%; padding: 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); margin: 8px 0; font-size: 15px; }
.gate-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 6px; }

/* ---------- 화면 레이아웃(멀티존) ---------- */
.layout-presets { display: flex; flex-wrap: wrap; gap: 12px; }
.lp { border: 2px solid var(--line); border-radius: 11px; padding: 10px; background: var(--bg); cursor: pointer; text-align: center; width: 140px; }
.lp:hover { border-color: #3a475a; }
.lp.on { border-color: var(--primary); background: #16213a; }
.lp span { display: block; font-size: 12px; margin-top: 8px; color: var(--muted); font-weight: 700; }
.lp-vis { width: 100%; aspect-ratio: 16/9; border-radius: 6px; position: relative; overflow: hidden; background: #2a3240; }
.lp-vis::before, .lp-vis::after { content: ''; position: absolute; background: var(--primary); }
/* 메인=파랑, 보조=회색 표현 */
.lp-single .lp-vis::before { inset: 8%; background: var(--primary); }
.lp-split-lr .lp-vis::before { left: 6%; top: 8%; bottom: 8%; width: 58%; }
.lp-split-lr .lp-vis::after { right: 6%; top: 8%; bottom: 8%; width: 24%; background: #7e8a9c; }
.lp-split-tb .lp-vis::before { left: 8%; right: 8%; top: 6%; height: 60%; }
.lp-split-tb .lp-vis::after { left: 8%; right: 8%; bottom: 6%; height: 22%; background: #7e8a9c; }
.lp-main-bottom .lp-vis::before { left: 8%; right: 8%; top: 6%; height: 70%; }
.lp-main-bottom .lp-vis::after { left: 8%; right: 8%; bottom: 6%; height: 12%; background: #7e8a9c; }

/* ---------- 오버레이(자막·시계) ---------- */
.ov-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-top: 6px; }
.ov-row label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.ov-row select { padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.ov-row input[type=color] { width: 42px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: pointer; }
.ov-row input[type=range] { width: 120px; }
#ov-ticker-box { transition: opacity .15s; }
