:root {
  --bg: #0c0e13;
  --side: #10131a;
  --panel: #151922;
  --panel2: #1b2029;
  --hover: #1f2531;
  --line: #242a36;
  --line2: #2e3544;
  --text: #e8ebf1;
  --muted: #8d95a8;
  --dim: #5f6779;
  --acc: #f5a524;
  --acc-ink: #1d1400;
  --ok: #35c77c;
  --bad: #ef5350;
  --info: #5b9dff;
  --radius: 10px;
  --font: "Pretendard Variable", Pretendard, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, "D2Coding", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 var(--font); letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ── 레이아웃 ─────────────────────────────── */
#app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-top { padding: 18px 16px 12px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px; background: var(--acc); color: var(--acc-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 22px;
}
.brand-mark.sm { width: 28px; height: 28px; border-radius: 8px; font-size: 15px; }
.env-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 14px; background: var(--bg); padding: 3px; border-radius: 8px; border: 1px solid var(--line); }
.env-switch button { border: 0; background: transparent; color: var(--muted); padding: 6px 4px; font-size: 12px; border-radius: 6px; }
.env-switch button.on { background: var(--panel2); color: var(--text); font-weight: 600; }
.env-switch button.on[data-env="live"] { background: #3a1818; color: #ffb4b2; }
.side-nav { flex: 1; overflow-y: auto; padding: 8px 10px 16px; }
.side-nav .grp { color: var(--dim); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; padding: 16px 10px 6px; }
.side-nav a { display: block; color: var(--muted); padding: 7px 10px; border-radius: 7px; font-size: 13.5px; }
.side-nav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.side-nav a.active { background: var(--panel2); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--acc); }
.side-foot { border-top: 1px solid var(--line); padding: 12px 14px 14px; }
.who { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.who b { color: var(--text); font-weight: 600; }
.side-actions { display: flex; gap: 6px; }

.main-wrap { min-width: 0; }
.env-bar { display: none; }
body.env-live .env-bar {
  display: block; background: #3a1818; color: #ffc9c7; font-size: 12.5px; padding: 7px 28px;
  border-bottom: 1px solid #5a2323; position: sticky; top: 0; z-index: 4;
}
main { padding: 26px 28px 60px; max-width: 1480px; }

/* ── 페이지 머리 ─────────────────────────── */
.ph { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.ph h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.ph .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.ph .act { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: var(--text); }
h3 .muted { font-weight: 400; font-size: 12.5px; margin-left: 6px; }
h4 { margin: 22px 0 10px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ── 카드 / 패널 ─────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card .k { color: var(--muted); font-size: 12.5px; }
.card .v { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; overflow-wrap: anywhere; }
.card .v.sm { font-size: 17px; }
.card .s { color: var(--muted); font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }
.card.alert { border-color: #5a2323; background: #1c1214; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 16px; margin-bottom: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid2 > .panel { margin-bottom: 0; }
.grid2 + .grid2, .grid2 + .panel, .panel + .grid2 { margin-top: 16px; }

/* ── 표 ─────────────────────────────────── */
.tbl { overflow-x: auto; margin: 0 -4px; }
.tbl.tall { max-height: 560px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
th.num, td.num { text-align: right; }
tbody tr:hover td { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 260px; }
td.empty { text-align: center; color: var(--dim); padding: 22px 10px; }
.sub-id { color: var(--dim); font-size: 11.5px; font-family: var(--mono); margin-top: 1px; }

/* 이벤트 데이터 칩 */
.dvs { display: flex; flex-wrap: wrap; gap: 4px 6px; max-width: 760px; }
.dv { display: inline-flex; gap: 5px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; font-size: 12px; line-height: 1.6; }
.dv b { color: var(--muted); font-weight: 500; }
.dv i { font-style: normal; color: var(--text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ── 폼 ─────────────────────────────────── */
input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--line2); border-radius: 8px; padding: 0 11px; height: 36px; min-width: 0;
}
textarea { height: auto; min-height: 84px; padding: 9px 11px; width: 100%; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--acc); box-shadow: 0 0 0 3px #f5a52422; }
input::placeholder, textarea::placeholder { color: var(--dim); }
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld > span { font-size: 12px; color: var(--muted); }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); align-items: end; }
.form .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row + .row, .form + .row, .row + .form { margin-top: 12px; }
.spacer { flex: 1; }
.hint { color: var(--dim); font-size: 12px; margin-top: 10px; }
button {
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel2);
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
button:hover { background: var(--hover); }
button.primary { background: var(--acc); color: var(--acc-ink); border-color: transparent; font-weight: 700; }
button.primary:hover { filter: brightness(1.07); }
button.danger { background: #3a1818; color: #ffb4b2; border-color: #5a2323; }
button.danger:hover { background: #4a1d1d; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: var(--hover); color: var(--text); }
button.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
button.big { height: 42px; font-size: 15px; }
button:disabled { opacity: 0.4; cursor: default; filter: none; }
.pager { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

/* ── 태그 / 탭 ──────────────────────────── */
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 500; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); line-height: 1.7; vertical-align: middle; }
.tag.ok { background: #10291d; color: #6fe0a4; border-color: #1d4731; }
.tag.bad { background: #2c1414; color: #ff9d9a; border-color: #532222; }
.tag.warn { background: #2d2310; color: #ffc766; border-color: #4f3b12; }
.tag.info { background: #13233d; color: #9cc3ff; border-color: #22406e; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg a { color: var(--muted); padding: 4px 11px; border-radius: 6px; font-size: 12.5px; }
.seg a:hover { color: var(--text); text-decoration: none; background: var(--hover); }
.seg a.on { background: var(--panel2); color: var(--text); font-weight: 600; }

/* ── 차트 ───────────────────────────────── */
.chart { width: 100%; height: 230px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart text { fill: var(--dim); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); }
.chart .col:hover { fill: #ffffff08; }
.chart .nodata { fill: var(--dim); font-size: 13px; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .r { color: var(--dim); }
.hbar { height: 8px; background: var(--acc); border-radius: 4px; display: inline-block; vertical-align: middle; min-width: 2px; }

/* ── 기타 ───────────────────────────────── */
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px 14px; font-size: 13px; }
.kv > .k { color: var(--muted); padding-top: 2px; }
.json { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; color: #c7cddb; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 10px; max-height: 420px; overflow: auto; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 14px; }
.err { color: var(--bad); min-height: 18px; font-size: 12.5px; }
.loading { color: var(--dim); padding: 40px 0; }
.section-sep { border: 0; border-top: 1px solid var(--line); margin: 20px 0 18px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); padding: 34px 30px 26px; border-radius: 14px; border: 1px solid var(--line); width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 6px 0 0; font-size: 21px; letter-spacing: -0.02em; }
.login p { margin: -8px 0 4px; font-size: 13px; }

#toast { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 20; }
#toast div { background: var(--panel2); border: 1px solid var(--line2); border-left: 3px solid var(--ok); padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px #0009; font-size: 13px; max-width: 360px; }
#toast div.bad { border-left-color: var(--bad); }

/* ── 반응형 ─────────────────────────────── */
@media (max-width: 1100px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .env-switch { margin-top: 0; margin-left: auto; }
  .side-nav { display: flex; overflow-x: auto; padding: 8px; gap: 2px; }
  .side-nav .grp { display: none; }
  .side-nav a { white-space: nowrap; }
  .side-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; }
  .who { margin: 0; }
  main { padding: 18px 16px 50px; }
  body.env-live .env-bar { padding: 7px 16px; }
}

optgroup { color: var(--muted); font-style: normal; }
option { color: var(--text); background: var(--panel); }
