:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e3e6ea; --text: #1d232b; --muted: #6b7480;
  --accent: #2459c9; --accent-bg: #e9effc; --pk: #b26a00; --pk-bg: #fff3df; --fk: #1f7a4d; --fk-bg: #e4f5ec;
  --guess: #7a5aa8; --guess-bg: #f1ebfa; --warn: #b3261e; --code-bg: #f0f3f7; --row-hover: #f7f9fc;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1b1f26; --line: #2c323b; --text: #e6e9ee; --muted: #9aa3ae;
    --accent: #7aa2ff; --accent-bg: #22304d; --pk: #f2b35b; --pk-bg: #3a2e1a; --fk: #6fd3a0; --fk-bg: #193126;
    --guess: #c3a6f0; --guess-bg: #2e2540; --warn: #ff8a80; --code-bg: #232933; --row-hover: #20252d;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; width: 100%; }
textarea { min-height: 60px; resize: vertical; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; }
.tabs button.on { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--accent); color: #fff; }

main { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 50px); }
.side { border-right: 1px solid var(--line); background: var(--panel); padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button { padding: 1px 8px; font-size: 12px; border-radius: 999px; }
.chips button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tlist { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; }
.tlist li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.tlist li:hover { background: var(--row-hover); }
.tlist li.on { background: var(--accent-bg); }
.tlist .l1 { font-weight: 600; }
.tlist .l2 { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.tlist .hit { font-size: 11.5px; color: var(--accent); }

.view { display: none; overflow: auto; padding: 16px 20px 40px; }
.view.on { display: block; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

.thead { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.thead h1 { margin: 0; font-size: 20px; }
.thead .phys { font-family: var(--mono); color: var(--muted); }
.tmeta { margin: 6px 0 12px; display: grid; gap: 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 12px 0; }
.card h2 { font-size: 14px; margin: 0 0 8px; }
.note { white-space: pre-wrap; }
.since { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.src { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 4px; }

table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.grid th, .grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.grid th { background: var(--code-bg); font-weight: 600; font-size: 12.5px; position: sticky; top: 0; }
.grid tbody tr:hover { background: var(--row-hover); }
.grid td.num { color: var(--muted); width: 32px; }
.grid td.type { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.grid td.nowrap { white-space: nowrap; }
.grid td.act { width: 40px; text-align: right; }
.grid tr.audit td { color: var(--muted); }
.grid td.note { white-space: pre-wrap; max-width: 360px; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 0 5px; border-radius: 4px; margin: 1px 2px 1px 0; white-space: nowrap; }
.tag.pk { color: var(--pk); background: var(--pk-bg); }
.tag.fk { color: var(--fk); background: var(--fk-bg); cursor: pointer; }
.tag.guess { color: var(--guess); background: var(--guess-bg); cursor: pointer; }
.tag.uk, .tag.enc, .tag.nn { color: var(--muted); background: var(--code-bg); }
.tag.grp { color: var(--accent); background: var(--accent-bg); cursor: pointer; }
.codes { font-size: 12px; color: var(--muted); }
.codes b { font-family: var(--mono); font-weight: 600; color: var(--text); }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.erdbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.erdbar select { width: auto; }
.erdwrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: auto; padding: 12px; max-height: calc(100vh - 170px); }
.erdwrap svg { max-width: none !important; }

.cg { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }
.cg ul { list-style: none; margin: 0; padding: 0; }
.cg li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.cg li.on { background: var(--accent-bg); }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); width: min(640px, 94vw); padding: 0; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { padding: 16px 18px; display: grid; gap: 10px; }
dialog h3 { margin: 0; }
dialog label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.on { opacity: .92; }

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; height: auto; }
  .side { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .cg { grid-template-columns: 1fr; }
}
