
/* ── 테마 토큰 ─────────────────────────────────────────────
   라이트를 기본으로 정의하고, 다크는 두 곳에서 덮어쓴다.
   1) 시스템이 다크이고 사용자가 라이트를 강제하지 않은 경우
   2) 사용자가 다크를 명시적으로 고른 경우
   이렇게 해야 자동/수동 모드가 양방향 모두 올바르게 동작한다. */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --nav-w: 232px;
  --nav-w-collapsed: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --surface: #131a2b;
    --surface-2: #182136;
    --border: #263148;
    --text: #e5e7eb;
    --text-muted: #9aa4b8;
    --accent: #4f8cff;
    --accent-text: #0b1020;
    --danger: #fca5a5;
    --danger-bg: #3b1618;
    --ok: #86efac;
    --ok-bg: #12321f;
    --warn: #fcd34d;
    --warn-bg: #3a2c0c;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #131a2b;
  --surface-2: #182136;
  --border: #263148;
  --text: #e5e7eb;
  --text-muted: #9aa4b8;
  --accent: #4f8cff;
  --accent-text: #0b1020;
  --danger: #fca5a5;
  --danger-bg: #3b1618;
  --ok: #86efac;
  --ok-bg: #12321f;
  --warn: #fcd34d;
  --warn-bg: #3a2c0c;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--accent); }

/* ── 레이아웃 ───────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width .15s ease, flex-basis .15s ease;
}
body.nav-collapsed .nav { width: var(--nav-w-collapsed); flex-basis: var(--nav-w-collapsed); }
body.nav-collapsed .nav .label,
body.nav-collapsed .nav .brand-text,
body.nav-collapsed .nav .nav-key { display: none; }
body.nav-collapsed .nav-item { justify-content: center; }

.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px 14px; font-weight: 800; letter-spacing: -.2px;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; flex: 0 0 26px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 600;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item[aria-current="page"] { background: var(--surface-2); border-color: var(--border); color: var(--accent); }
.nav-icon { width: 18px; text-align: center; flex: 0 0 18px; }
.nav-key {
  margin-left: auto; font-size: 11px; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 6px; padding: 0 5px;
}
.nav-spacer { flex: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar .spacer { flex: 1; }
.content { padding: 20px; max-width: 1100px; width: 100%; }

/* ── 컴포넌트 ───────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card .desc { margin: 0 0 14px; color: var(--text-muted); font-size: 13px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
input[type="text"], input:not([type]) {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
}
input:focus-visible, button:focus-visible, a:focus-visible, th[data-sort]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button, .button {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px;
  background: var(--accent); color: var(--accent-text);
  padding: 9px 14px; font-weight: 700; font-size: 14px;
  text-decoration: none; cursor: pointer; font-family: inherit;
}
button.secondary, .button.secondary {
  background: var(--surface-2); color: var(--text); border-color: var(--border);
}
button.ghost {
  background: transparent; color: var(--text); border-color: var(--border);
  padding: 7px 10px; font-size: 13px;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.picker-list { display: flex; flex-direction: column; }
.picker-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.picker-row:last-child { border-bottom: none; }
.install-row { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.install-row:last-child { border-bottom: none; }
code {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all;
}
.muted { color: var(--text-muted); }
.badge {
  display: inline-block; border-radius: 999px; padding: 2px 10px;
  font-size: 12px; font-weight: 700;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.notice {
  border: 1px solid var(--border); border-left-width: 4px;
  border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px;
}
.notice.warn { border-left-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.notice.danger { border-left-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
.notice.info { border-left-color: var(--accent); background: var(--surface-2); }
.notice.ok { border-left-color: var(--ok); background: var(--ok-bg); color: var(--ok); }

/* ── 표 ─────────────────────────────────────────────────── */
.table-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--border); padding: 10px; text-align: left; white-space: nowrap; }
th { color: var(--text-muted); font-size: 12px; text-transform: none; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
th .sort-mark { opacity: .35; margin-left: 4px; }
th[aria-sort="ascending"] .sort-mark,
th[aria-sort="descending"] .sort-mark { opacity: 1; color: var(--accent); }
tbody tr:hover { background: var(--surface-2); }
.empty { color: var(--text-muted); text-align: center; padding: 24px 10px; }

/* ── 모달 ───────────────────────────────────────────────── */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  max-width: 520px; width: calc(100% - 32px); box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(2, 6, 23, .55); }
.dialog-head {
  display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.dialog-head h3 { margin: 0; font-size: 15px; }
.dialog-body { padding: 16px; }
[data-help-body] { white-space: pre-line; line-height: 1.6; }
.dialog-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.kbd-list { display: grid; gap: 8px; margin: 0; }
.kbd-row { display: flex; align-items: center; gap: 10px; }
kbd {
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px;
  padding: 1px 7px; font-size: 12px; font-family: inherit; background: var(--surface-2);
  min-width: 26px; text-align: center;
}
.col-toggles { display: grid; gap: 8px; }
.col-toggles label { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; }

/* ── 도움말 "?" 버튼 ────────────────────────────────────── */
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; vertical-align: middle;
  margin-left: 4px; padding: 0; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-muted);
  font-size: 11px; font-weight: 700; font-family: inherit; line-height: 1; cursor: pointer;
}
.help:hover { color: var(--text); border-color: var(--text-muted); }

/* ── 스위치 (토글) ──────────────────────────────────────── */
.switch-row { display: flex; align-items: center; gap: 10px; }
.switch {
  position: relative; flex: none; width: 46px; height: 26px; padding: 0;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; transition: background .15s ease, border-color .15s ease;
}
.switch .switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.35);
  transition: transform .15s ease;
}
.switch.on { background: var(--ok); border-color: var(--ok); }
.switch.on .switch-thumb { transform: translateX(20px); }
.switch-label { font-weight: 700; font-size: 14px; }

/* ── 하단 메뉴 (모바일) ──────────────────────────────────── */
.tabbar { display: none; }

@media (max-width: 820px) {
  .nav { display: none; }
  .content { padding: 16px 14px 84px; }
  /* 좁은 화면에서 제목과 버튼 글자가 줄바꿈되지 않게 눌러 담는다. */
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar h1 { font-size: 16px; white-space: nowrap; }
  .topbar button, .topbar .button { white-space: nowrap; padding: 6px 9px; font-size: 12px; }
  .topbar .badge { white-space: nowrap; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 2px; text-decoration: none; color: var(--text-muted);
    font-size: 11px; font-weight: 700; border-radius: 10px;
  }
  .tabbar a[aria-current="page"] { color: var(--accent); background: var(--surface-2); }
  .tabbar .nav-icon { font-size: 17px; }
  .desktop-only { display: none !important; }
}
@media (min-width: 821px) {
  .mobile-only { display: none !important; }
}
