:root {
  color-scheme: light;
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --surface-3: #edf3f5;
  --ink: #11181d;
  --text: #1f2a32;
  --muted: #66737d;
  --soft: #8a969f;
  --line: #d8e0e5;
  --line-strong: #c5d0d7;
  --nav: #11181d;
  --nav-2: #18242c;
  --nav-line: #26343d;
  --accent: #0f766e;
  --accent-2: #115e59;
  --accent-soft: #dff3ef;
  --blue: #2563eb;
  --blue-soft: #e6efff;
  --warn: #a16207;
  --warn-soft: #fff5d8;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --ok: #137333;
  --ok-soft: #e6f5eb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .07);
  --shadow-strong: 0 12px 28px rgba(17, 24, 39, .08);
  font-family: "KoPub Dotum", "KoPub돋움체", Dotum, "돋움", ui-sans-serif, system-ui, sans-serif;
}

@font-face {
  font-family: "KoPub Dotum";
  src: url("/static/fonts/KoPubDotumLight.woff2") format("woff2");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "KoPub Dotum";
  src: url("/static/fonts/KoPubDotumMedium.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "KoPub Dotum";
  src: url("/static/fonts/KoPubDotumBold.woff2") format("woff2");
  font-weight: 700 900;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { border: 0; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--nav);
  color: #d8e1e8;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--nav-line);
}

.brand { display: block; padding: 6px; margin-bottom: 18px; }
.brand.is-login { padding: 0; margin: 0 0 22px; color: var(--ink); }
.brand-logo {
  min-height: 54px;
  display: grid;
  place-items: center;
  padding: 10px 12px;
  border: 1px solid #2c404a;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(217,249,157,.12), rgba(141,215,208,.08)),
    #101b21;
}
.brand-wordmark {
  color: #fff;
  font-family: "Segoe UI", Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 24px;
  font-weight: 950;
  letter-spacing: .3px;
  line-height: 1;
}

.nav-list { display: grid; gap: 5px; margin-top: 0; }
.nav-section {
  color: #798d9c;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 900;
  padding: 16px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 8px;
  color: #b4c1ca;
  border: 1px solid transparent;
}
.nav-item:hover { background: #1d2b34; color: #fff; }
.nav-item.is-active { background: #21343d; color: #fff; border-color: #31505a; }
.nav-icon { width: 22px; text-align: center; color: #9bd4cc; font-weight: 900; }
.sidebar-meta {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #93a4b3;
  font-size: 12px;
  padding: 10px 8px;
}
.status-dot { width: 8px; height: 8px; border-radius: 999px; background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.12); }

.main-panel { min-width: 0; padding: 24px; }
.topbar {
  min-height: 78px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 0; }
h1 { margin: 0; font-size: 28px; line-height: 1.12; color: var(--ink); letter-spacing: 0; }
h2 { margin: 0; font-size: 16px; color: var(--ink); letter-spacing: 0; }
h3 { margin: 0; font-size: 15px; color: var(--ink); letter-spacing: 0; }
p { margin: 0; }
.page-subtitle { color: var(--muted); margin-top: 6px; max-width: 760px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.panel, .metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 16px; }
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.panel-header p { color: var(--muted); margin-top: 4px; font-size: 13px; }
.stack { display: grid; gap: 16px; align-content: start; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.metric { padding: 15px; display: grid; gap: 5px; min-height: 104px; }
.metric span, .metric small, .muted { color: var(--muted); }
.metric span { font-weight: 800; }
.metric strong { font-size: 30px; line-height: 1; color: var(--ink); }

.ops-strip, .workflow-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.ops-strip a, .workflow-band div {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.ops-strip strong, .workflow-band strong {
  flex: 0 0 auto;
  min-width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-2);
}
.ops-strip span, .workflow-band span { color: var(--muted); font-size: 13px; }
.workflow-band div { display: grid; gap: 3px; }
.workflow-band strong { width: auto; min-width: 0; height: auto; background: none; place-items: start; color: var(--ink); }

.dashboard-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(340px, .65fr); gap: 16px; }
.split-layout, .chat-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.chat-layout { grid-template-columns: minmax(0, 1fr) 410px; }

.button {
  border: 1px solid var(--accent-2);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  min-height: 36px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}
.button:hover { background: var(--accent-2); }
.button.is-secondary { background: #fff; color: var(--text); border-color: var(--line-strong); }
.button.is-secondary:hover { background: var(--surface-2); }
.button.is-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.button.is-ghost:hover { background: var(--surface-3); color: var(--text); }
.button.is-danger { background: #fff; color: var(--danger); border-color: #efb7b2; }
.button.is-danger:hover { background: var(--danger-soft); }
.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: #fff;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  color: var(--text);
}
.icon-button:hover { background: var(--surface-2); }
.icon-button.danger { color: var(--danger); }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  min-height: 36px;
}
select { cursor: pointer; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(15,118,110,.16); border-color: var(--accent); }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 800; font-size: 12px; }
.form-stack { display: grid; gap: 13px; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) 82px auto; gap: 8px; align-items: center; }
.inline-form.compact { grid-template-columns: minmax(180px, 300px) auto; }
.inline-form.compact.has-checkbox { grid-template-columns: minmax(180px, 300px) auto auto; }
.compact-form { display: flex; gap: 8px; }
.control-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; margin-bottom: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.checkbox-row input { width: auto; min-height: auto; }

.dropzone {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 16px;
  color: var(--text);
  cursor: pointer;
}
.dropzone span { font-size: 15px; font-weight: 900; color: var(--ink); }
.dropzone small { color: var(--muted); font-weight: 600; }
.dropzone input { margin-top: 10px; background: #fff; }
.upload-card { min-height: 286px; }
.direct-editor { margin-top: 16px; }

.table-tools, .review-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.tabbar {
  display: flex;
  gap: 6px;
  margin: 2px 0 12px;
  border-bottom: 1px solid var(--line);
}
.tabbar a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  font-weight: 900;
}
.tabbar a:hover { color: var(--text); background: var(--surface-2); }
.tabbar a.is-active {
  color: var(--accent-2);
  background: #fff;
  border-color: var(--line);
  position: relative;
  bottom: -1px;
}
.tabbar span {
  min-width: 22px;
  min-height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 12px;
}
.table-tools input { max-width: 420px; }
.node-filter { min-width: 260px; }
.review-toolbar {
  justify-content: flex-start;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.review-toolbar div { display: flex; align-items: baseline; gap: 6px; padding-right: 18px; border-right: 1px solid var(--line); }
.review-toolbar div:last-child { border-right: 0; }
.review-toolbar strong { font-size: 20px; color: var(--ink); }
.review-toolbar span { color: var(--muted); }

.table-wrap {
  overflow: auto;
  max-height: min(620px, calc(100vh - 240px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f2f6f8; color: #51606b; font-size: 12px; text-transform: uppercase; letter-spacing: 0; position: sticky; top: 0; z-index: 1; }
td small { display: block; margin-top: 3px; color: var(--muted); max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.actions-col { width: 76px; }
.empty-row { text-align: center; color: var(--muted); padding: 28px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf2f5;
  color: #41505f;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.status-approved, .status-indexed, .status-active, .status-merged { background: var(--ok-soft); color: var(--ok); }
.badge.is-suggestion { background: var(--blue-soft); color: var(--blue); }
.status-pending, .status-queued, .status-staged { background: var(--warn-soft); color: var(--warn); }
.status-failed, .status-deleted, .status-rejected, .status-replaced { background: var(--danger-soft); color: var(--danger); }
.status-ignored { background: #eef2f4; color: #64707a; }
.flash, .notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.flash.is-success { background: var(--ok-soft); color: var(--ok); border: 1px solid #bee5ca; }
.flash.is-error, .notice { background: var(--warn-soft); color: var(--warn); border: 1px solid #edd18c; }

.tree-list, .candidate-list, .chat-log, .citation-list { display: grid; gap: 8px; }
.tree-list.is-compact { max-height: 380px; overflow: auto; padding-right: 4px; }
.review-panel {
  height: calc(100vh - 132px);
  min-height: 560px;
  display: flex;
  flex-direction: column;
}
.bulk-review-form {
  flex: 0 0 auto;
}
.bulk-toolbar {
  display: grid;
  grid-template-columns: auto 200px auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.candidate-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
  align-content: start;
}
.tree-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px 9px calc(10px + var(--depth) * 18px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.tree-label { font-weight: 900; }
.mini-table {
  display: grid;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.mini-table > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px; border-bottom: 1px solid var(--line); }
.mini-table > div:last-child { border-bottom: 0; }
.empty-state { color: var(--muted); padding: 18px; border: 1px dashed #c5d0d7; border-radius: 8px; background: #fbfcfd; }
.result-box { min-height: 96px; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 11px; background: #fbfcfd; display: grid; gap: 8px; align-content: start; white-space: pre-wrap; }
.result-line { display: flex; justify-content: space-between; gap: 12px; }

.candidate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  background: #fff;
}
.review-row { align-items: stretch; }
.candidate-title, .meta-line, .candidate-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.candidate-title { flex-wrap: nowrap; }
.candidate-title h3 { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-check input { width: 16px; min-height: 16px; }
.candidate-main { display: grid; gap: 9px; }
.candidate-main p, .candidate-preview { color: #3d4955; line-height: 1.55; }
.candidate-preview {
  max-height: 112px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.meta-line { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.candidate-actions {
  align-content: start;
  justify-content: stretch;
  display: grid;
  gap: 8px;
  border-left: 1px solid var(--line);
  padding-left: 16px;
}
.candidate-actions form { display: grid; gap: 7px; }
.inline-action { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.search-entry { max-width: 760px; }
.decision-label { color: var(--muted); text-transform: uppercase; font-size: 11px; font-weight: 900; }
.title-flags { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.risk-dot {
  width: 26px;
  height: 18px;
  border-radius: 999px;
  font-size: 0;
  border: 1px solid transparent;
}
.risk-dot.is-clear { background: var(--ok-soft); border-color: #bde6c8; }
.risk-dot.is-warning { background: var(--warn-soft); border-color: #edcf83; }
.risk-dot.is-danger { background: var(--danger-soft); border-color: #efb7b2; }
.evidence-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.evidence-grid div { border: 1px solid var(--line); border-radius: 8px; padding: 9px; background: #fff; display: grid; gap: 3px; }
.evidence-grid strong { color: var(--ink); font-size: 12px; }
.evidence-grid span { color: var(--muted); font-size: 12px; }

.chat-panel { min-height: calc(100vh - 136px); display: grid; grid-template-rows: auto minmax(340px, 1fr) auto; }
.chat-log { align-content: start; overflow: auto; padding-right: 4px; }
.chat-message { max-width: 84%; border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; background: #fff; }
.chat-message span { display: block; color: var(--muted); font-size: 12px; font-weight: 900; margin-bottom: 4px; text-transform: uppercase; }
.chat-message p { line-height: 1.55; white-space: pre-wrap; }
.chat-message.is-user { justify-self: end; background: var(--accent-soft); border-color: #b9ddd6; }
.chat-form { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; margin-top: 12px; }
.chat-controls { display: grid; grid-template-columns: minmax(0, 1fr) 100px auto; gap: 10px; align-items: end; }
.side-panel { position: sticky; top: 24px; }
.citation { border: 1px solid var(--line); border-radius: 8px; padding: 11px; background: #fff; display: grid; gap: 7px; }
.citation div { display: flex; justify-content: space-between; gap: 10px; }
.citation p { color: #3d4955; line-height: 1.45; }
.citation small { color: var(--muted); overflow-wrap: anywhere; }
.answer-box { white-space: pre-wrap; line-height: 1.6; color: #2f3c45; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 13px; }

.graph-panel {
  min-height: calc(100vh - 132px);
  overflow: hidden;
}
.graph-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 12px;
}
.knowledge-graph {
  height: calc(100vh - 230px);
  min-height: 520px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.graph-detail {
  height: calc(100vh - 230px);
  min-height: 520px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.graph-detail strong { font-size: 18px; color: var(--ink); }
.graph-detail small,
.graph-detail p { color: var(--muted); overflow-wrap: anywhere; }
.graph-detail dl { display: grid; gap: 8px; margin: 0; }
.graph-detail dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.graph-detail dt {
  color: var(--muted);
  font-weight: 800;
}
.graph-detail dd { margin: 0; color: var(--ink); font-weight: 900; }

.busy-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 24, 29, .42);
  z-index: 80;
}
.busy-overlay[hidden] { display: none; }
.busy-box {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-strong);
  text-align: center;
}
.busy-box p { color: var(--muted); line-height: 1.55; }
.busy-spinner {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(255,255,255,.7), rgba(238,242,244,.94)),
    radial-gradient(circle at 30% 20%, #dff3ef 0, transparent 32%),
    var(--bg);
  padding: 24px;
}
.login-card {
  width: min(430px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-strong);
  padding: 26px;
}
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card p { color: var(--muted); margin-bottom: 18px; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 236px minmax(0, 1fr); }
  .metric-grid, .ops-strip, .workflow-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-layout, .chat-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar-meta, .nav-section { display: none; }
  .nav-list { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .nav-item { justify-content: center; padding: 9px; }
  .nav-item span:last-child { display: none; }
  .main-panel { padding: 16px; }
  .topbar, .panel-header, .table-tools, .candidate-row, .control-grid, .inline-form, .inline-form.compact, .inline-form.compact.has-checkbox, .split-layout, .bulk-toolbar { display: grid; grid-template-columns: 1fr; }
  .topbar-actions { justify-content: start; }
  h1 { font-size: 23px; }
  .metric-grid, .ops-strip, .workflow-band, .evidence-grid, .chat-controls { grid-template-columns: 1fr; }
  .candidate-actions { border-left: 0; border-top: 1px solid var(--line); padding-left: 0; padding-top: 12px; }
  .review-panel { height: calc(100vh - 150px); min-height: 520px; }
  .graph-workbench { grid-template-columns: 1fr; }
  .knowledge-graph, .graph-detail { height: auto; min-height: 420px; }
  .chat-message { max-width: 100%; }
}
