/* Membership Admin — dark ops-console theme.
   Dense, monochrome, decoration-free. Color is reserved for state and data. */

:root {
  --bg: #0e1014;
  --panel: #14171d;
  --panel-2: #191d24;
  --line: #262b35;
  --line-soft: #1d222b;
  --ink: #dde1e8;
  --ink-2: #aab1bd;
  --muted: #767e8d;
  --muted-2: #4d5563;
  --accent: #5a8cf5; /* 다크 서피스 검증 통과값(OKLCH L 0.48–0.67 밴드) */
  --accent-strong: #3563e9;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --radius: 3px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
/* display 를 지정한 요소(.badge 등)에도 hidden 속성이 항상 이기게 한다. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
::selection { background: rgba(108, 155, 255, 0.25); }

/* ---- App shell ---- */
.layout { display: flex; min-height: 100%; }

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: #101318;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__brand {
  padding: 18px 18px 16px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--line-soft);
  text-transform: uppercase;
}
.sidebar__brand span { color: var(--muted); font-weight: 500; }
.sidebar__header { flex: 0 0 auto; }
.sidebar__panel { display: flex; flex: 1; min-height: 0; flex-direction: column; overflow-y: auto; }
.sidebar__toggle { display: none; }
.sidebar__username { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--ink-2); }
.sidebar__nav { padding: 10px 10px; display: flex; flex-direction: column; gap: 1px; flex: 1; }
.sidebar__link {
  display: block;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--ink-2);
  font-weight: 500;
  border-left: 2px solid transparent;
}
.sidebar__link:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.sidebar__link.is-active {
  background: rgba(108, 155, 255, 0.08);
  color: var(--accent);
  border-left-color: var(--accent);
}
.sidebar__user {
  border-top: 1px solid var(--line-soft);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
}
.sidebar__who { display: flex; align-items: center; gap: 9px; min-width: 0; color: var(--ink-2); font-weight: 500; }
.sidebar__signout {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 12px; font-family: inherit; padding: 2px;
  white-space: nowrap; flex-shrink: 0;
}
.sidebar__signout:hover { color: var(--ink); }
.sidebar__id { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.role-pill {
  align-self: flex-start; font-family: var(--mono); font-size: 9px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  border: 1px solid var(--line); padding: 0 5px; border-radius: 2px;
}
.role-pill--super { color: var(--accent); border-color: rgba(108, 155, 255, 0.35); }

.content { flex: 1; min-width: 0; padding: 26px 32px 60px; max-width: 1220px; }
.content > *, .card, .field { min-width: 0; }
.page-head, .alert, .card > p { overflow-wrap: anywhere; }
.content--auth {
  display: flex; align-items: center; justify-content: center;
  max-width: none; padding: 24px;
}

/* ---- Page header ---- */
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 18px; font-weight: 650; color: var(--ink); }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.muted { color: var(--muted); }

/* ---- Cards ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.card > h2 {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 12px; display: flex; align-items: center; gap: 10px;
}
.card > h2 .muted { font-weight: 400; text-transform: none; letter-spacing: 0; }

/* ---- Stat strip (stat tiles: label · value · optional sparkline) ---- */
.stats {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}
.stat { flex: 1; min-width: 0; padding: 13px 16px 11px; border-left: 1px solid var(--line-soft); }
.stat:first-child { border-left: 0; }
.stat__label {
  font-size: 10.5px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.stat__row { display: flex; align-items: flex-end; gap: 14px; margin-top: 6px; min-height: 30px; }
/* 큰 단독 숫자는 본문 sans + 비례 숫자(모노/tabular 는 표 컬럼 전용). */
.stat__num { font-size: 24px; font-weight: 650; line-height: 1.15; letter-spacing: -0.02em; color: var(--ink); }
.stat__num.is-warn { color: var(--amber); }
.stat__spark { flex: 1; min-width: 0; height: 30px; display: block; overflow: visible; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.table-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.table-scroll > table { min-width: 640px; }
.table-scroll td { min-width: 120px; max-width: 360px; overflow-wrap: anywhere; }
.table-scroll td.mono-cell, .table-scroll td.num, .table-scroll td.mono { min-width: 0; }
.table-scroll td.muted { min-width: 240px; }
.table-scroll td:has(> .status) { min-width: 100px; }
.table-scroll thead th, .table-scroll td.mono-cell, .table-scroll td.num, .table-scroll td.mono, .table-scroll td code { white-space: nowrap; }
.table-scroll td.actions { min-width: 240px; max-width: 320px; white-space: normal; }
.table-scroll .actions .row-form { flex-wrap: wrap; max-width: 100%; }
.table-scroll .actions select { max-width: 240px; }
.detail-table { table-layout: fixed; }
.detail-table th { width: 110px; vertical-align: top; color: var(--muted); font-weight: 500; }
.detail-table td { overflow-wrap: anywhere; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); }
thead th {
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.07em;
  border-bottom: 1px solid var(--line);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #171b22; }
td.num, td.mono, .mono-cell { font-family: var(--mono); font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
td code, code.chip {
  font-family: var(--mono); font-size: 12px;
  background: var(--line-soft); padding: 2px 6px; border-radius: 2px; color: var(--ink);
}

/* ---- Status (dot + label) ---- */
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; background: currentColor; }
.status--active { color: var(--green); }
.status--expired { color: var(--amber); }
.status--disabled { color: var(--red); }
.status--used { color: var(--muted); }
.status--unused { color: var(--green); }

/* ---- Forms ---- */
.form-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
input, select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px; font-family: inherit; background: #0f1218; color: var(--ink);
  transition: border-color .12s;
}
input::placeholder { color: var(--muted-2); }
input:focus, select:focus {
  outline: none; border-color: var(--accent);
}
input[type="number"] { width: 120px; }
.row-form { display: inline-flex; gap: 5px; align-items: center; margin: 0 6px 5px 0; }
.row-form input[type="number"] { width: 66px; padding: 4px 8px; }
.row-form > span { font-size: 12px; color: var(--muted); font-weight: 500; min-width: 78px; }
.actions { white-space: nowrap; }

/* 상세 페이지 관리 액션: 한 줄에 하나씩, 라벨 정렬. */
.action-grid { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.action-grid .row-form { margin: 0; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid var(--line); background: transparent; color: var(--ink-2);
  padding: 6px 12px; border-radius: var(--radius); cursor: pointer;
  font-size: 12.5px; font-family: inherit; font-weight: 500;
  transition: background .1s, border-color .1s, color .1s;
}
.btn:hover { background: var(--panel-2); border-color: #323947; color: var(--ink); }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.primary:hover { background: #2b53c7; border-color: #2b53c7; color: #fff; }
.btn.danger { color: var(--red); border-color: rgba(248, 81, 73, 0.35); }
.btn.danger:hover { background: rgba(248, 81, 73, 0.08); border-color: rgba(248, 81, 73, 0.55); color: var(--red); }
.btn.small { padding: 3px 9px; font-size: 11.5px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.45; cursor: default; }

/* ---- Alerts ---- */
.alert { padding: 9px 12px; border-radius: var(--radius); margin-bottom: 14px; font-size: 12.5px; border: 1px solid transparent; }
.alert.error { background: rgba(248, 81, 73, 0.08); color: #ff7b72; border-color: rgba(248, 81, 73, 0.3); }
.alert.success { background: rgba(63, 185, 80, 0.08); color: #56d364; border-color: rgba(63, 185, 80, 0.3); }

/* ---- Connections monitor ---- */
.conn-toolbar { margin-left: auto; display: inline-flex; align-items: center; }
.conn-search { padding: 5px 9px; font-size: 12px; min-width: 240px; }
.actions-col { width: 1%; white-space: nowrap; }

/* 배지: 박스 없는 모노 마이크로 텍스트 — 색만 상태를 나른다. */
.badge {
  display: inline-block; font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.badge--warn { color: var(--amber); }
.badge--multi { color: var(--accent); }

/* SSE stream status (Live / Reconnecting / Disconnected) — 텍스트 + 사각 점 */
.conn-status {
  display: inline-flex; align-items: center; gap: 6px; vertical-align: 3px;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin-left: 6px;
}
.conn-status::before { content: ""; width: 6px; height: 6px; background: currentColor; }
.conn-status--live { color: var(--green); }
.conn-status--reconnecting { color: var(--amber); }
.conn-status--offline { color: var(--red); }

/* 카드 헤더 카운터: 모노 텍스트 */
.count-chip {
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  color: var(--muted); text-transform: none; letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

/* Sortable table headers */
th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.th-sort:hover { color: var(--ink-2); }
th.th-sort::after { content: "↕"; margin-left: 5px; opacity: 0; font-size: 10px; }
th.th-sort:hover::after { opacity: 0.5; }
th.th-sort[aria-sort="ascending"]::after { content: "↑"; opacity: 1; }
th.th-sort[aria-sort="descending"]::after { content: "↓"; opacity: 1; }

/* Row enter/exit (new connection highlight, disconnect fade) */
tr.row-enter > td { animation: row-flash 1s ease-out; }
@keyframes row-flash { from { background: rgba(63, 185, 80, 0.07); } to { background: transparent; } }
tr.row-exit { opacity: 0; transition: opacity 0.3s ease; }
tr.row-exit .btn { pointer-events: none; }

/* Two-tier empty state */
td.empty .empty-title { color: var(--ink-2); font-weight: 550; }
td.empty .empty-hint { margin-top: 3px; color: var(--muted-2); font-size: 12px; }

/* Detail modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); animation: modal-fade 0.1s ease-out; }
.modal__card {
  position: relative; width: 460px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5); overflow: hidden;
  animation: modal-fade 0.1s ease-out;
  display: flex; flex-direction: column; max-height: calc(100dvh - 32px);
}
@keyframes modal-fade { from { opacity: 0; } }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 13px 18px; border-bottom: 1px solid var(--line-soft); }
.modal__head h3 { font-size: 13px; font-weight: 650; color: var(--ink); }
.modal__x { background: none; border: 0; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.modal__x:hover { color: var(--ink); }
.modal__body { padding: 6px 18px 12px; min-height: 0; overflow-y: auto; }
.modal__head, .modal__foot { flex: 0 0 auto; }
.modal__foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line-soft); background: var(--panel-2); }
table.kv th { width: 130px; color: var(--muted); font-weight: 500; vertical-align: top; }
table.kv td { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
table.kv td .muted { font-family: var(--font); }
table.kv { table-layout: fixed; }
table.kv td { overflow-wrap: anywhere; }

/* ---- Generated codes ---- */
.generated { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.generated h3 { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.07em; }
.code-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- Pager ---- */
.pager { display: flex; gap: 14px; align-items: center; justify-content: flex-end; margin-top: 14px; font-size: 13px; }
.pager .disabled { color: var(--muted-2); }
.pager .page-info { color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* ---- Auth (login) ---- */
.auth-card {
  width: 340px; max-width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 4px; padding: 28px 26px;
}
.auth-card .auth-brand { font-size: 14px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.02em; }
.auth-card .auth-sub { color: var(--muted); margin: 4px 0 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .field > span { color: var(--ink-2); }
.auth-card input { width: 100%; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* 잔존 호환: 예전 라이브 점(사용처 없어도 안전하게 정적 점으로) */
.live-dot { width: 7px; height: 7px; background: var(--green); display: inline-block; }

/* ---- TCP activity console ---- */
.tcp-log-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px;
}
.tcp-log-toolbar select { width: 126px; flex: 0 0 auto; }
.tcp-log-toolbar .tcp-log-ip { width: min(360px, 30vw); }
.tcp-log-toolbar input { flex: 1; min-width: 180px; }
.tcp-log-toolbar .count-chip { margin-left: 4px; }
.tcp-log-toolbar .btn:first-of-type { margin-left: auto; }
.tcp-log-meta {
  display: flex; justify-content: space-between; gap: 12px; margin: 0 0 8px;
  color: var(--muted); font-size: 11px;
}

.tcp-console {
  height: calc(100vh - 218px); min-height: 520px;
  border: 1px solid var(--line); background: #05070a; overflow: hidden;
}
.tcp-console__output {
  height: 100%; overflow: auto; padding: 10px 12px;
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  white-space: pre; color: #c9d1d9; contain: content;
}
.tcp-console__line { min-height: 18px; }
.tcp-console__time { color: #6e7681; }
.tcp-console__level { color: #8b949e; margin-left: 7px; }
.tcp-console__ip { color: #7ee787; margin-left: 7px; }
.tcp-console__source { color: #79c0ff; margin-left: 7px; }
.tcp-console__category { color: #a5d6ff; margin-left: 7px; }
.tcp-console__message { color: #c9d1d9; }
.tcp-console__fields { color: #8b949e; }
.tcp-console__line--debug .tcp-console__level { color: #8b949e; }
.tcp-console__line--info .tcp-console__level { color: #58a6ff; }
.tcp-console__line--warn .tcp-console__level { color: #d29922; }
.tcp-console__line--error .tcp-console__level,
.tcp-console__line--error .tcp-console__message { color: #f85149; }

@media (max-width: 720px) {
  .tcp-log-toolbar { flex-wrap: wrap; }
  .tcp-log-toolbar .tcp-log-ip { width: 100%; }
  .tcp-log-toolbar input { flex-basis: calc(100% - 134px); }
  .tcp-log-toolbar .count-chip { order: 4; }
  .tcp-log-toolbar .btn:first-of-type { margin-left: auto; }
  .tcp-log-meta { flex-direction: column; gap: 2px; }
  .tcp-console { height: calc(100vh - 320px); min-height: 420px; }
}

/* Keep the entire app usable on phones; wide data scrolls inside its own region. */
@media (max-width: 1100px) {
  .content { padding: 24px 20px 48px; }
  .card > h2 { flex-wrap: wrap; }
  .conn-toolbar { flex: 1 1 240px; }
  .conn-search { width: 100%; min-width: 0; }
}

@media (max-width: 800px) {
  html { scroll-padding-top: 76px; }
  .layout { flex-direction: column; min-height: 100svh; }
  .sidebar { width: 100%; flex: 0 0 auto; height: auto; position: sticky; top: 0; z-index: 20; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; min-height: 60px; }
  .sidebar__brand { padding: 0; border: 0; font-size: 12px; }
  .sidebar[data-enhanced="true"] .sidebar__toggle { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); color: var(--ink); font: 500 13px var(--font); cursor: pointer; }
  .sidebar__toggle-icon { width: 14px; height: 10px; border-top: 1px solid currentColor; border-bottom: 1px solid currentColor; position: relative; }
  .sidebar__toggle-icon::after { content: ""; position: absolute; left: 0; right: 0; top: 4px; border-top: 1px solid currentColor; }
  .sidebar__panel { max-height: calc(100svh - 76px); overscroll-behavior-y: contain; border-top: 1px solid var(--line-soft); }
  .sidebar[data-enhanced="true"]:not([data-open="true"]) .sidebar__panel { display: none; }
  .sidebar__nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 10px 12px; }
  .sidebar__link { display: flex; align-items: center; min-height: 44px; padding: 10px; font-size: 13px; }
  .sidebar__user { padding: 8px 16px; }
  .sidebar__signout { min-height: 44px; flex-shrink: 0; padding: 8px; }
  .content { width: 100%; max-width: none; padding: 20px 16px 40px; }
  .content--auth { min-height: 100svh; padding: 20px 16px; }
  .card { padding: 14px 12px; }
  .btn, .btn.small { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 8px 12px; }
  input, select, textarea { max-width: 100%; min-width: 0; font-size: 16px; }
  .conn-search { font-size: 16px; }
  input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]), select { min-height: 44px; }
  .field input, .field select { width: 100%; }
  .form-row { gap: 12px; }
  .form-row > .field { flex: 1 1 180px; }
  .action-grid { align-items: stretch; }
  .action-grid .row-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; width: 100%; }
  .action-grid .row-form > span { grid-column: 1 / -1; }
  .action-grid .row-form input, .action-grid .row-form select { width: 100%; min-width: 0; }
  .action-grid .row-form:not(:has(input:not([type="hidden"]), select)) { grid-template-columns: 1fr; }
  .pager { flex-wrap: wrap; gap: 8px 16px; justify-content: center; }
  .pager a { display: inline-flex; align-items: center; min-height: 44px; }
  .modal__x { min-width: 44px; min-height: 44px; }
  .modal__head, .modal__body, .modal__foot { padding-left: 12px; padding-right: 12px; }
  .modal__foot { flex-wrap: wrap; }
  table.kv th { width: 100px; }
  .tcp-log-toolbar select, .tcp-log-toolbar .tcp-log-ip { width: auto; min-width: 0; max-width: 100%; flex: 1 1 160px; }
  .tcp-log-toolbar input { flex: 1 1 100%; min-width: 0; width: 100%; }
  .tcp-log-toolbar .btn:first-of-type { margin-left: 0; }
  .tcp-log-toolbar .count-chip { flex: 1 1 100%; order: 0; margin: 0; }
  .tcp-log-meta { overflow-wrap: anywhere; }
  .tcp-console { height: 60svh; min-height: 280px; }
  .tcp-console__output { padding: 10px 8px; }
}

@media (max-width: 480px) {
  .content { padding-left: 12px; padding-right: 12px; }
  .sidebar__header { padding-left: 12px; padding-right: 12px; }
  .stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 12px; }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line-soft); }
  .stat__label { font-size: 10px; letter-spacing: .04em; }
  .stat__num { font-size: 23px; }
  .form-row > .field, .form-row > .btn { flex-basis: 100%; width: 100%; }
  .conn-toolbar { flex-basis: 100%; margin-left: 0; }
  .auth-card { padding: 24px 20px; }
  .detail-table th { width: 86px; padding-left: 0; }
  .detail-table td { padding-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
