:root {
  --bg: #0f1218;
  --bg2: #151a23;
  --bg3: #1c2330;
  --line: #2a3446;
  --text: #e7ecf5;
  --muted: #8b98ad;
  --accent: #6ea8ff;
  --accent2: #3d7bfd;
  --green: #3ecf8e;
  --red: #ff6b6b;
  --yellow: #ffd166;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
b { font-weight: 700; }

/* ── 로그인 ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 16px;
  padding: 40px 36px; width: 340px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo { font-size: 44px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box p { margin: 0 0 8px; }
.login-box input {
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-size: 15px; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-err { color: var(--red); min-height: 18px; font-size: 13px; }

/* ── 상단바 / 탭 ── */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 16px; white-space: nowrap; }
.topbar-game { display: flex; gap: 8px; align-items: center; flex: 1; }
.topbar-game select {
  background: var(--bg3); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; font-size: 14px; min-width: 180px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.tabs {
  display: flex; gap: 4px; padding: 8px 20px 0; background: var(--bg2);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  background: none; border: none; color: var(--muted); font-size: 14px;
  padding: 9px 14px; cursor: pointer; border-radius: 8px 8px 0 0; white-space: nowrap;
  border-bottom: 2px solid transparent; font-family: inherit;
}
.tab:hover { color: var(--text); background: var(--bg3); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* ── 공통 컴포넌트 ── */
.btn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { background: none; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.wide { width: 100%; padding: 11px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar input[type=search] {
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; width: 240px; outline: none;
}
.toolbar input[type=search]:focus { border-color: var(--accent); }

.card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 16px;
}
.card .card-head {
  padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; gap: 10px; flex-wrap: wrap;
}
.card .card-body { padding: 16px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--bg2); white-space: nowrap; }
tbody tr:hover { background: rgba(110,168,255,.05); }
td.num { font-variant-numeric: tabular-nums; }
td .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.chip.live { color: var(--green); border-color: var(--green); background: rgba(62,207,142,.08); }
.chip.wait { color: var(--yellow); border-color: var(--yellow); background: rgba(255,209,102,.08); }
.chip.end { color: var(--muted); border-color: var(--line); background: var(--bg3); }
.chip.always { color: var(--accent); border-color: var(--accent); background: rgba(110,168,255,.08); }
.chip.off { color: var(--red); border-color: var(--red); background: rgba(255,107,107,.08); }

/* 토글 스위치 */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--bg3); border: 1px solid var(--line);
  border-radius: 999px; cursor: pointer; transition: .15s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px;
  background: var(--muted); border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider { background: rgba(62,207,142,.25); border-color: var(--green); }
.switch input:checked + .slider::before { transform: translateX(16px); background: var(--green); }

.empty {
  text-align: center; color: var(--muted); padding: 44px 16px; font-size: 14px;
}
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* ── 모달 ── */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow-y: auto;
}
.modal {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 640px; padding: 0; animation: pop .12s ease-out;
}
.modal.narrow { max-width: 440px; }
.modal.wide { max-width: 820px; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.modal-head {
  display: flex; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 16px; flex: 1; }
.modal-head .close { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px;
  border-top: 1px solid var(--line);
}

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input[type=text], .field input[type=number], .field input[type=datetime-local],
.field textarea, .field select {
  width: 100%; background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none; font-family: inherit;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 70px; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }

.lang-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.lang-table th, .lang-table td { padding: 5px 6px; border: none; }
.lang-table th { font-size: 11.5px; }
.lang-table input {
  width: 100%; background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 6px 8px; font-size: 12.5px; outline: none;
}
.lang-table input:focus { border-color: var(--accent); }
.lang-table .lang-name { color: var(--muted); font-size: 12px; white-space: nowrap; font-weight: 600; }

/* 선물 선택 피커 */
.picker-search { margin-bottom: 10px; }
.picker-search input {
  width: 100%; background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; outline: none;
}
.picker-list { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.picker-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px;
}
.picker-item:last-child { border-bottom: none; }
.picker-item:hover { background: rgba(110,168,255,.07); }
.picker-item.checked { background: rgba(62,207,142,.08); }
.picker-item .pk-key { font-weight: 700; min-width: 64px; font-variant-numeric: tabular-nums; }
.picker-item .pk-name { flex: 1; }
.picker-item .pk-sub { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* 유저 카드 */
.user-card { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; background: var(--bg2); overflow: hidden; }
.user-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer;
}
.user-head:hover { background: var(--bg3); }
.user-head .uh-label { font-weight: 700; }
.user-head .uh-id { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.user-head .uh-count { margin-left: auto; }
.user-body { border-top: 1px solid var(--line); padding: 8px 16px 14px; }

/* API·설정 */
.api-url {
  display: flex; gap: 8px; align-items: center; background: var(--bg3);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 6px 0;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px;
  overflow-x: auto;
}
.api-url .u { flex: 1; white-space: nowrap; }
.api-url .desc { color: var(--muted); font-family: inherit; white-space: nowrap; }
code.inline {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 6px; font-size: 12px; font-family: ui-monospace, Consolas, monospace;
}
.key-box { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.key-box input {
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; width: 340px;
  font-family: ui-monospace, Consolas, monospace;
}
textarea.yaml-input {
  width: 100%; min-height: 220px; background: var(--bg3); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 12px; font-size: 12.5px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; outline: none; resize: vertical;
}
.import-result {
  margin-top: 10px; background: var(--bg3); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px; font-size: 13px; white-space: pre-wrap;
}

/* 토스트 */
#toast-root { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4); animation: pop .15s ease-out;
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  main { padding: 12px; }
}
