:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #1b1f27;
  --ink-2: #4b5363;
  --ink-3: #8a91a0;
  --line: #e3e6eb;
  --line-2: #eef0f3;
  --org: #3a5a8c;        /* 원천 */
  --org-bg: #e9eff8;
  --lab: #1f7a5c;        /* 가공 */
  --lab-bg: #e5f3ed;
  --accent: #2b4c7e;
  --warn: #b4532a;
  --warn-bg: #fbece4;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1480px; margin: 0 auto; padding: 24px 24px 48px; }

/* ---------- top bar / menu */
.topbar {
  display: flex; align-items: center; gap: 32px; padding: 0 24px; height: 60px;
  background: #151b26; color: #fff; position: sticky; top: 0; z-index: 10;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.menu { display: flex; gap: 28px; overflow-x: auto; }
.menu-group { display: flex; align-items: center; gap: 4px; }
.menu-label {
  font-size: 11px; font-weight: 700; letter-spacing: .02em; padding: 2px 8px; border-radius: 4px;
  background: #2c3d5c; color: #c9d8f2; margin-right: 4px; white-space: nowrap;
}
.menu-label.lab { background: #1d4a3b; color: #bfe8d6; }
.menu a { color: #c8cdd6; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.menu a:hover { color: #fff; background: rgba(255,255,255,.07); text-decoration: none; }
.menu a.on { color: #fff; background: rgba(255,255,255,.14); }

/* ---------- headings / badges */
.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 6px 0 4px; }
.desc { color: var(--ink-2); margin: 0; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px;
}
.badge.org { background: var(--org-bg); color: var(--org); }
.badge.lab { background: var(--lab-bg); color: var(--lab); }

/* ---------- filters */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.filters input, .filters select {
  font: inherit; font-weight: 400; color: var(--ink); height: 34px; padding: 0 10px;
  border: 1px solid #cfd4dc; border-radius: 6px; background: #fff; min-width: 180px;
}
.filters input.short { min-width: 130px; width: 130px; }
.filters select:disabled { background: #f2f3f5; color: var(--ink-3); }
.filters input:focus, .filters select:focus { outline: 2px solid #b8cbe8; border-color: var(--accent); }
.legend { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.notice {
  background: var(--lab-bg); color: var(--lab); border-radius: 6px; padding: 8px 12px; margin-bottom: 12px;
}

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 34px; padding: 0 14px;
  border-radius: 6px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: #fff; color: var(--ink-2); border-color: #cfd4dc; }
.btn.lab { background: var(--lab); color: #fff; }
.btn.sm { height: 26px; padding: 0 10px; font-size: 12px; }

/* ---------- tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; }
.grid th {
  text-align: left; font-size: 12px; font-weight: 700; color: var(--ink-2); background: #f8f9fb;
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0;
}
.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.grid tbody tr:hover td { background: #fafbfd; }
.grid tbody tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; min-width: 140px; }
.clip { color: var(--ink-2); min-width: 260px; max-width: 460px; }
.sentence { min-width: 320px; max-width: 520px; }
.claim { min-width: 420px; max-width: 760px; line-height: 1.75; }
.empty { text-align: center; color: var(--ink-3); padding: 40px 12px !important; }

.chip {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: #eef1f5; color: var(--ink-2); white-space: nowrap;
}
.chip.rel { background: #f1ecfa; color: #5b3d99; }
.chip.ok { background: var(--lab-bg); color: var(--lab); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }

mark { padding: 0 2px; border-radius: 3px; }
mark.m-subj { background: #dbe8ff; color: #1d4280; }
mark.m-obj { background: #ffe8c7; color: #7a4a06; }

/* patent claim xml */
.xtag { font-family: var(--mono); font-size: 11px; padding: 0 3px; border-radius: 3px; white-space: nowrap; }
.xtag-component { background: #dbe8ff; color: #1d4280; }
.xtag-relation  { background: #f1ecfa; color: #5b3d99; }
.xtag-sep       { background: #eceff3; color: #555d6b; }
.xtag-item      { background: #dff3e9; color: #1b6b50; }
.xtag-other     { background: #fbece4; color: var(--warn); }
.xseg-component { background: #f1f6ff; }
.xseg-relation  { background: #f8f5fd; }
.xseg-item      { background: #eff9f4; }
.xseg-sep, .xseg-other { background: transparent; }

/* ---------- pager */
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.pager-info { color: var(--ink-3); font-size: 13px; }
.pager-btns { display: flex; gap: 6px; align-items: center; }
.pager-cur { padding: 0 10px; font-weight: 700; }

/* ---------- home */
.flow { display: flex; flex-direction: column; gap: 14px; max-width: 900px; }
.flow-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; }
.flow-box {
  display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; color: var(--ink);
}
.flow-box:hover { text-decoration: none; border-color: #b9c3d3; box-shadow: 0 2px 8px rgba(20,30,50,.06); }
.flow-box strong { font-size: 16px; }
.flow-box small { color: var(--ink-3); }
.flow-box.org { border-left: 4px solid var(--org); }
.flow-box.lab { border-left: 4px solid var(--lab); }
.flow-arrow { color: var(--ink-3); font-size: 12px; font-weight: 600; }

/* ---------- popup */
body.popup .wrap { max-width: 1060px; padding-top: 18px; }
.popbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 24px;
  position: sticky; top: 0; z-index: 5;
}
.popbar h1 { font-size: 18px; margin: 4px 0 0; }
.popbar h1 small { font-weight: 400; color: var(--ink-3); margin-left: 6px; }
.popbar-actions { display: flex; gap: 8px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px;
}
.card.empty { text-align: center; color: var(--ink-2); padding: 48px 20px; }
.sec-title { font-size: 16px; margin: 24px 0 10px; }
.count { font-size: 13px; color: var(--ink-3); font-weight: 400; }

.meta { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 0 0 14px; }
.meta dt { font-size: 12px; color: var(--ink-3); }
.meta dd { margin: 2px 0 0; font-weight: 600; }

.field { margin-top: 14px; }
.field:first-child { margin-top: 0; }
.label { font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.value { background: #f8f9fb; border: 1px solid var(--line-2); border-radius: 6px; padding: 10px 12px; }
.pre { white-space: pre-wrap; word-break: break-word; }
.context { max-height: 340px; overflow-y: auto; line-height: 1.75; }
.muted { color: var(--ink-3); }
.field.q .value { background: #eef3fb; border-color: #dbe5f4; font-weight: 600; }
.field.answer .value { background: var(--lab-bg); border-color: #cfe8dc; }

.cot { border-top: 3px solid var(--lab); }
.cot-no { font-size: 12px; font-weight: 700; color: var(--lab); margin-bottom: 10px; }

/* reasoning steps */
.steps { list-style: none; margin: 0; padding: 0; position: relative; }
.steps::before { content: ""; position: absolute; left: 13px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.step { position: relative; padding: 0 0 14px 40px; }
.step:last-child { padding-bottom: 0; }
.step-head { display: flex; align-items: center; gap: 8px; }
.step-no {
  position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  background: #fff; border: 2px solid var(--lab); color: var(--lab);
}
.step-stage { font-weight: 700; line-height: 28px; }
.step-head code { font-size: 11px; color: var(--ink-3); }
.step-exp { margin: 2px 0 6px; color: var(--ink); }
.evidence { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.evidence li {
  border-left: 3px solid #c9d6ea; background: #f6f8fc; padding: 6px 10px; border-radius: 0 4px 4px 0;
  color: var(--ink-2); font-size: 13px;
}
.evidence li::before { content: "근거 "; font-size: 11px; font-weight: 700; color: var(--org); margin-right: 4px; }

.error-card pre { background: #f8f9fb; padding: 12px; border-radius: 6px; white-space: pre-wrap; }

@media (max-width: 760px) {
  .topbar { height: auto; flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px 16px; }
  .menu { flex-direction: column; gap: 6px; width: 100%; }
  .wrap { padding: 16px; }
  .flow-row { grid-template-columns: 1fr; }
  .flow-arrow { text-align: center; }
  .legend { margin-left: 0; }
}
