:root {
  --bg: #0f1216;
  --panel: #171c23;
  --panel-2: #1f262f;
  --line: #2a323d;
  --text: #e6ebf2;
  --muted: #8d99a8;
  --accent: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --tile-w: 280px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: #2a323d; border-color: #3a4553; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #2f6fe0; }
button.danger { border-color: #5a2a2a; color: #ffb4b4; }

input, select {
  background: #10151b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid rgba(59,130,246,.45); outline-offset: -1px; }

.hidden { display: none !important; }

/* ---------------------------------------------------------- 로그인 */

.auth-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.auth-card label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 12px; }
.auth-card button { width: 100%; margin-top: 18px; }
.auth-links { margin-top: 14px; text-align: center; color: var(--muted); font-size: 13px; }
.auth-links a { color: var(--accent); cursor: pointer; text-decoration: none; }

.msg { margin-top: 14px; font-size: 13px; min-height: 18px; }
.msg.error { color: #ff9c9c; }
.msg.ok { color: #86efac; }

/* ---------------------------------------------------------- 기기 목록 */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.topbar h1 { font-size: 16px; margin: 0; flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }

.container { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.container.wide { max-width: 1600px; }
.section-head {
  display: flex; align-items: baseline; gap: 10px; margin: 0 0 14px;
}
.section-head h2 { font-size: 15px; margin: 0; }
.section-head .count { color: var(--muted); font-size: 13px; }
.section-head .spacer { flex: 1; }

/* ---------------------------------------------------------- 썸네일 월 */

.wall {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-w), 1fr));
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .12s, transform .12s;
}
.tile:hover { border-color: #3f4c5c; }
.tile.offline { opacity: .55; }

.tile-screen {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #05070a;
  cursor: pointer;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.tile.offline .tile-screen { cursor: default; }
.tile-screen canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile-idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12.5px;
  background: #05070a;
}

.tile-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 11px;
  font-size: 13px;
  min-width: 0;
}
.tile-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { margin-left: auto; color: var(--muted); font-size: 11.5px; white-space: nowrap; }

.tile-actions { display: flex; gap: 7px; padding: 0 11px 11px; }
.tile-actions button { flex: 1; padding: 5px 8px; font-size: 12.5px; }

.tile.picked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tile-pick { width: auto; margin: 0; flex: none; accent-color: var(--accent); }
.tile-group {
  position: absolute; left: 8px; top: 8px;
  background: rgba(15,18,22,.82);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  color: #cfe0f5;
  pointer-events: none;
}

button.mini { padding: 3px 9px; font-size: 12px; }

.bulkbar {
  position: sticky;
  bottom: 16px;
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(23,28,35,.97);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  z-index: 15;
}
.bulkbar .spacer { flex: 1; }
.bulk-count { font-weight: 600; margin-right: 6px; }

.wall-opt { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.wall-opt select { width: auto; padding: 4px 7px; }
.wall-opt input[type=checkbox] { width: auto; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #4b5563; flex: none; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.15); }
.dot.busy { background: var(--warn); box-shadow: 0 0 0 3px rgba(245,158,11,.15); }

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}
.empty code {
  display: block;
  margin-top: 12px;
  padding: 12px;
  background: #0b0f14;
  border-radius: 8px;
  color: #9ecbff;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
  text-align: left;
}

.logs { margin-top: 34px; }
.logs table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.logs th, .logs td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.logs th { color: var(--muted); font-weight: 500; }
.logs td.ev { color: #9ecbff; }

/* ---------------------------------------------------------- 뷰어 */

.viewer-body { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
  flex-wrap: wrap;
}
.toolbar .title { font-weight: 600; margin-right: 6px; }
.toolbar .spacer { flex: 1; }
.toolbar label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.toolbar select { width: auto; padding: 5px 8px; }
.toolbar input[type=range] { width: 96px; }
.stat { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.stage {
  flex: 1;
  position: relative;
  background: #05070a;
  display: grid;
  place-items: center;
  overflow: hidden;
}
#screen { max-width: 100%; max-height: 100%; cursor: none; image-rendering: auto; }
#cursor {
  position: absolute;
  width: 14px; height: 14px;
  margin: -2px 0 0 -2px;
  pointer-events: none;
  border-left: 2px solid #fff;
  border-top: 2px solid #fff;
  transform: rotate(-12deg);
  filter: drop-shadow(0 0 2px rgba(0,0,0,.9));
}
.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(5,7,10,.86);
  text-align: center;
  padding: 24px;
  z-index: 5;
}
.overlay .big { font-size: 16px; margin-bottom: 8px; }
.overlay .small { color: var(--muted); font-size: 13px; }

#hidden-input {
  position: absolute; left: -9999px; top: 0;
  width: 1px; height: 1px; opacity: 0;
}

/* 사이드 패널 (파일 / 채팅) */
.side {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 340px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  z-index: 10;
}
.side header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.side header b { flex: 1; font-size: 13px; }
.side .body { flex: 1; overflow: auto; padding: 10px 12px; }
.side .foot { padding: 10px 12px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.side .foot input { flex: 1; }

.path-bar { display: flex; gap: 6px; margin-bottom: 10px; }
.path-bar input { flex: 1; font-size: 12px; padding: 6px 8px; }
.fs-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.fs-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px; border-radius: 6px; cursor: pointer;
}
.fs-list li:hover { background: var(--panel-2); }
.fs-list .size { margin-left: auto; color: var(--muted); font-size: 11.5px; }

.chat-log { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.chat-log .m { padding: 7px 10px; border-radius: 8px; background: var(--panel-2); max-width: 90%; }
.chat-log .m.me { background: #23405f; align-self: flex-end; }

.toasts {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 20; pointer-events: none;
}
.toast {
  background: rgba(23,28,35,.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.error { border-color: #5a2a2a; color: #ffb4b4; }
.toast.warn { border-color: #5a4a1f; color: #ffdca8; }

/* ---------------------------------------------------------- 모달 / 팝오버 / 다중 제어 */

.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(5,7,10,.7);
  display: grid; place-items: center; padding: 24px;
}
.modal-card {
  width: 100%; max-width: 420px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px;
  max-height: 90vh; overflow: auto;
}
.modal-card h2 { margin: 0 0 6px; font-size: 17px; }
.modal-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; line-height: 1.6; }
.modal-card label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 12px; }
.modal-card button { width: 100%; margin-top: 14px; }
.modal-card .mono { font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.qr { background: #fff; border-radius: 10px; padding: 10px; display: grid; place-items: center; }
.qr svg { width: 100%; height: auto; max-width: 220px; display: block; }

.popover {
  position: absolute; right: 16px; top: 16px; z-index: 12;
  background: rgba(23,28,35,.98);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; min-width: 260px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.popover .row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.popover .row:first-child { margin-top: 0; }
.popover .row b { flex: 1; font-size: 13px; }
.popover input[type=range] { flex: 1; width: auto; }

.pip {
  position: absolute; right: 16px; bottom: 16px; z-index: 12;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; width: 300px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.pip-bar { display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-size: 12.5px; }
.pip-bar b { flex: 1; }
.pip canvas { width: 100%; display: block; background: #05070a; }

.logs td.ok { color: #86efac; }
.logs td.fail { color: #ff9c9c; }
.logs td.muted { color: var(--muted); }

.multi-grid {
  flex: 1; display: grid; gap: 10px; padding: 10px;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  align-content: start; overflow: auto; background: #05070a;
}
.mpane {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; display: flex; flex-direction: column;
}
.mpane.focused { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.mpane-bar { display: flex; align-items: center; gap: 7px; padding: 7px 10px; font-size: 12.5px; }
.mpane-name { font-weight: 600; }
.mpane-meta { margin-left: auto; color: var(--muted); font-size: 11.5px; }
.mpane-screen { position: relative; aspect-ratio: 16/9; background: #05070a; }
.mpane-screen canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.mpane-idle {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 12.5px; background: #05070a; padding: 12px; text-align: center;
}

/* ---------------------------------------------- 창 분리 */
.win-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow-y: auto; }
.win-list li { padding: 0; }
.win-list button {
  display: flex; align-items: baseline; gap: 8px; width: 100%; text-align: left;
  padding: 7px 9px; background: transparent; border: 0; border-radius: 6px;
  color: var(--text); cursor: pointer; font-size: 13px;
}
.win-list button:hover { background: var(--panel-2); }
.win-list button.on { background: var(--accent); color: #fff; }
.win-list .wt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win-list .ws { font-size: 11.5px; color: var(--muted); flex: none; }
.win-list button.on .ws { color: rgba(255,255,255,.75); }
.win-list li.stat { padding: 10px 9px; color: var(--muted); font-size: 12.5px; }

.win-pip { left: 16px; right: auto; bottom: 16px; width: 420px; resize: horizontal; }
.win-pip .pip-bar b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pip-note { padding: 8px 10px; font-size: 12.5px; color: var(--warn, #f0b429); border-top: 1px solid var(--line); }
