/* Evolution 관리 콘솔 디자인 시스템. 다크 기본 + 라이트 지원. 관리형·절제된 톤. */
:root {
  --bg: #0b0e14;
  --bg-2: #0f131c;
  --surface: #141925;
  --surface-2: #1a2130;
  --surface-3: #212a3b;
  --line: #27314599;
  --line-solid: #273145;
  --fg: #e8ecf4;
  --fg-dim: #aab4c5;
  --fg-mut: #6b7686;
  --accent: #5b8cff;
  --accent-ink: #0a1020;
  --accent-soft: #5b8cff22;
  --ok: #34d399;
  --ok-soft: #34d39920;
  --warn: #fbbf24;
  --warn-soft: #fbbf2420;
  --err: #f87171;
  --err-soft: #f8717120;
  --info: #60a5fa;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px #0006, 0 8px 24px -12px #0009;
  --font: -apple-system, "Segoe UI", "Pretendard", Roboto, "Noto Sans KR", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, "SFMono-Regular", monospace;
}
:root[data-theme="light"] {
  --bg: #eef1f6; --bg-2: #e6eaf2; --surface: #ffffff; --surface-2: #f6f8fc; --surface-3: #eef2f8;
  --line: #d7dde8; --line-solid: #d7dde8; --fg: #121722; --fg-dim: #3c4658; --fg-mut: #78839a;
  --accent: #3b6fe0; --accent-ink: #ffffff; --accent-soft: #3b6fe016;
  --shadow: 0 1px 2px #0000000f, 0 10px 30px -18px #0003;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-soft); }

/* ── Layout ───────────────────────────────────────────────── */
#layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
#sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg)); border-right: 1px solid var(--line-solid);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 16px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff; font-weight: 800; font-size: 17px;
  box-shadow: 0 6px 16px -6px var(--accent);
}
.brand b { font-size: 14.5px; letter-spacing: .2px; }
.brand small { display: block; color: var(--fg-mut); font-size: 11px; font-weight: 500; }
.nav-label { color: var(--fg-mut); font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; padding: 14px 10px 5px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--fg-dim); font-weight: 500; transition: background .12s, color .12s; position: relative;
}
.nav a:hover { background: var(--surface); color: var(--fg); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--fg); }
.nav a.active::before { content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav a svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.nav a .pill-count { margin-left: auto; font-size: 11px; color: var(--fg-mut); }
.side-foot { margin-top: auto; padding: 10px; color: var(--fg-mut); font-size: 11.5px; border-top: 1px solid var(--line); }
.side-foot .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

#main { min-width: 0; display: flex; flex-direction: column; }
#topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line-solid);
  padding: 13px 26px; display: flex; align-items: center; gap: 14px;
}
#topbar h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
#topbar .sub { color: var(--fg-mut); font-size: 12.5px; }
#topbar .spacer { margin-left: auto; }
#content { padding: 24px 26px 60px; max-width: 1360px; width: 100%; }
.page-intro { color: var(--fg-dim); margin: -4px 0 20px; max-width: 720px; }

/* ── Cards / grid ─────────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) { #layout { grid-template-columns: 1fr; } #sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .2s; width: 248px; } #sidebar.open { transform: none; } .cols-4, .cols-3, .cols-2 { grid-template-columns: 1fr; } }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card .card-head { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.card .card-head h2 { font-size: 14px; margin: 0; font-weight: 650; }
.card .card-head .sub { color: var(--fg-mut); font-size: 12px; }
.card .card-body { padding: 16px 18px; }
.card .card-body.flush { padding: 0; }

/* Stat tiles */
.stat { padding: 17px 18px; }
.stat .k { color: var(--fg-mut); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.stat .k svg { width: 15px; height: 15px; }
.stat .v { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 9px 0 2px; font-variant-numeric: tabular-nums; }
.stat .d { color: var(--fg-dim); font-size: 12.5px; }
.stat .v small { font-size: 15px; color: var(--fg-mut); font-weight: 600; }

/* ── Buttons ──────────────────────────────────────────────── */
button, .btn {
  font: inherit; font-weight: 550; color: var(--fg); background: var(--surface-2); cursor: pointer;
  border: 1px solid var(--line-solid); border-radius: var(--radius-sm); padding: 8px 13px;
  display: inline-flex; align-items: center; gap: 7px; transition: background .12s, border-color .12s, opacity .12s;
}
button:hover, .btn:hover { background: var(--surface-3); }
button:disabled { opacity: .45; cursor: not-allowed; }
button svg, .btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line-solid)); }
.btn-danger:hover { background: var(--err-soft); }
.btn-sm { padding: 5px 9px; font-size: 12.5px; }
.btn-icon { padding: 7px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Form controls ───────────────────────────────────────── */
input:not([type]), input[type="text"], input[type="number"], input[type="password"], input[type="search"], input[type="email"], input[type="url"], select, textarea {
  font: inherit; color: var(--fg); background: var(--bg-2); border: 1px solid var(--line-solid);
  border-radius: var(--radius-sm); padding: 8px 11px; width: 100%; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
label.field { display: flex; flex-direction: column; gap: 6px; }
label.field > span { color: var(--fg-dim); font-size: 12.5px; font-weight: 550; display: flex; align-items: center; gap: 7px; }
label.field .help { color: var(--fg-mut); font-size: 11.5px; font-weight: 400; margin-top: 2px; line-height: 1.45; }
.input-affix { position: relative; display: flex; }
.input-affix button { position: absolute; right: 4px; top: 4px; bottom: 4px; padding: 0 9px; background: transparent; border: none; color: var(--fg-mut); }
.search-box { position: relative; min-width: 220px; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--fg-mut); }
.search-box input { padding-left: 32px; }

/* Toggle switch */
.switch { position: relative; width: 40px; height: 22px; display: inline-block; flex: none; }
.switch input { display: none; }
.switch i { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: .15s; border: 1px solid var(--line-solid); }
.switch i::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px #0005; }
.switch input:checked + i { background: var(--ok); border-color: var(--ok); }
.switch input:checked + i::before { transform: translateX(18px); }

/* ── Badges ───────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-ok { color: var(--ok); background: var(--ok-soft); }
.b-warn { color: var(--warn); background: var(--warn-soft); }
.b-err { color: var(--err); background: var(--err-soft); }
.b-info { color: var(--info); background: #60a5fa20; }
.b-mut { color: var(--fg-mut); background: var(--surface-3); }
.b-accent { color: var(--accent); background: var(--accent-soft); }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
/* 헤더는 스크롤 컨테이너(.table-wrap, overflow-x:auto) 기준으로 sticky 되므로 top:0 이어야 첫 행을 덮지 않는다. */
table.data thead th { color: var(--fg-mut); font-weight: 600; font-size: 11.5px; letter-spacing: .03em; text-transform: uppercase; position: sticky; top: 0; background: var(--surface); z-index: 1; cursor: pointer; user-select: none; }
table.data thead th.no-sort { cursor: default; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.mono { font-family: var(--mono); font-size: 12px; }
/* 에러 칸: 한 줄 말줄임(행 높이 균일 유지). 전체 내용은 title 툴팁/이벤트 로그에서 확인. */
table.data td.err { color: var(--err); max-width: 320px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.data .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 40px 20px; text-align: center; color: var(--fg-mut); }
.empty svg { width: 34px; height: 34px; opacity: .4; margin-bottom: 10px; }

/* ── Modal / toast ────────────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: #0009; backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--line-solid); border-radius: var(--radius); width: min(460px, 100%); box-shadow: 0 30px 80px -20px #000c; }
.modal h3 { margin: 0; padding: 16px 20px; font-size: 15px; border-bottom: 1px solid var(--line); }
.modal .body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal .foot { padding: 14px 20px; display: flex; gap: 9px; justify-content: flex-end; border-top: 1px solid var(--line); }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 9px; z-index: 200; }
.toast { background: var(--surface-2); border: 1px solid var(--line-solid); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: 11px 15px; box-shadow: var(--shadow); font-size: 13px; max-width: 360px; animation: slidein .18s ease; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } }

/* misc */
.muted { color: var(--fg-mut); }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.hr { height: 1px; background: var(--line); margin: 18px 0; }
.spin { width: 15px; height: 15px; border: 2px solid var(--line-solid); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; display: inline-block; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }
.offline-banner { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); color: var(--warn); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 16px; display: flex; gap: 9px; align-items: center; }

/* ── Viewer (테이블 실시간: 비디오 + 게임/채팅 소켓) ───────────── */
body[data-page="viewer"] #content { max-width: none; padding: 16px 18px 18px; width: 100%; }
.viewer-wrap { display: grid; grid-template-columns: 300px 1fr; gap: 14px; height: calc(100vh - 120px); min-height: 460px; }
@media (max-width: 860px) { .viewer-wrap { grid-template-columns: 1fr; height: auto; } .viewer-list { height: 320px; } .viewer-stage { height: 72vh; } }
.viewer-list { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.viewer-list .card-head { padding: 11px 14px; }
.vlist { display: flex; flex-direction: column; }
.vlist-item { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .12s; }
.vlist-item:hover { background: var(--surface-2); }
.vlist-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.vlist-item .vl-main { min-width: 0; flex: 1; }
.vlist-item .vl-id { font-family: var(--mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vlist-item .vl-sub { color: var(--fg-mut); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.viewer-stage { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.viewer-bar { padding: 9px 14px; border-bottom: 1px solid var(--line-solid); display: flex; align-items: center; gap: 10px; background: var(--surface); flex: none; }
.vstage-body { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* 상단: 비디오 */
.vvideo { flex: none; display: flex; flex-direction: column; background: var(--surface); }
.vvideo-ctrl { flex: none; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; padding: 7px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
/* 비디오 표시 영역: 항상 16:9. 세로가 커져 소켓을 밀지 않도록 높이 상한(56vh)만 둔다. */
.vcanvas-wrap { position: relative; width: 100%; max-width: calc(56vh * 16 / 9); aspect-ratio: 16 / 9; margin: 0 auto; display: grid; place-items: center; background: #000; overflow: hidden; }
.vcanvas-wrap canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.vlog { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; max-height: 42%; overflow: auto; padding: 6px 10px; background: #000000cc; color: #9fe6c0; font: 11px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; }

/* 하단: 게임 | 채팅 (반반) */
.vsockets { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line-solid); }
.vsock { min-width: 0; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.vsock:last-child { border-right: 0; }
.vsock-head { flex: none; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--surface); font-size: 12.5px; }
.vsock-feed { flex: 1; min-height: 0; overflow: auto; padding: 4px 9px; }
.vmsg { border-bottom: 1px solid var(--line); padding: 4px 0; }
.vmsg .h { display: flex; gap: 7px; align-items: center; cursor: pointer; }
.vmsg .tm { color: var(--fg-mut); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.vmsg .ty { color: var(--ok); font-weight: 700; font-size: 11.5px; }
.vmsg .txt { margin: 2px 0 0; color: var(--fg); word-break: break-word; font-size: 12.5px; }
.vmsg pre { margin: 3px 0 0; white-space: pre-wrap; word-break: break-word; font: 11px/1.4 var(--mono); color: var(--fg-dim); max-height: 34vh; overflow: auto; }

/* ── API 문서 ──────────────────────────────────────────────── */
.doc-sec { margin-bottom: 18px; }
.doc-sec .card-body > p { margin: 0 0 12px; color: var(--fg-dim); }
.doc-sec .card-body > p:last-child { margin-bottom: 0; }
.code { position: relative; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; margin: 0 0 12px; font: 12.5px/1.65 var(--mono); color: var(--fg-dim); overflow-x: auto; white-space: pre; }
.code:last-child { margin-bottom: 0; }
.code .cmt { color: var(--fg-mut); }
.code .tok { color: var(--accent); }
.code .str { color: var(--ok); }
.code .copy { position: absolute; top: 7px; right: 7px; padding: 3px 8px; font-size: 11px; opacity: .7; }
.code:hover .copy { opacity: 1; }
.ep-method { font-family: var(--mono); font-weight: 700; font-size: 11px; padding: 2px 7px; border-radius: 5px; letter-spacing: .02em; }
.m-get { color: var(--ok); background: var(--ok-soft); }
.m-ws { color: var(--info); background: #60a5fa20; }
.m-post { color: var(--warn); background: var(--warn-soft); }
.doc-flow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--fg-dim); font-size: 13px; }
.doc-flow .step { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.doc-flow .step b { color: var(--accent); }
.doc-flow .arrow { color: var(--fg-mut); }

/* 노드 부하 바 */
.loadbar { display: inline-block; vertical-align: middle; width: 100%; max-width: 110px; height: 7px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.loadbar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

.viewer-ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--fg-mut); text-align: center; padding: 24px; background: var(--bg); line-height: 1.7; z-index: 3; }
.viewer-ph svg { width: 40px; height: 40px; opacity: .4; margin-bottom: 10px; }
@media (max-width: 860px) { .vsockets { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; } .vsock:last-child { border-top: 1px solid var(--line); } }
