:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #8a90a0;
  --primary: #3b5bdb;
  --primary-dark: #2f49b0;
  --review: #0ca678;
  --error: #e03131;
  --warning: #f08c00;
  --info: #1c7ed6;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

/* ---------- 헤더 ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { font-weight: 800; font-size: 20px; letter-spacing: 0.5px; color: var(--primary); }
.brand-sub { color: var(--muted); font-size: 13px; }
.pilot-badge {
  background: #fff3bf; color: #a37200; font-weight: 700; font-size: 11px;
  padding: 3px 8px; border-radius: 4px; letter-spacing: 0.5px;
}

/* ---------- 레이아웃 ---------- */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 57px);
}
.sidebar, .editor-area, .review-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
}
.editor-area { padding: 0; }
.sidebar { padding: 14px; }

/* ---------- 사이드바 ---------- */
.sidebar-section { margin-bottom: 18px; }
.sidebar-title { font-weight: 700; font-size: 12px; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; }
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; margin-bottom: 4px;
}
.doc-item:hover { background: #f1f3f5; }
.doc-item.active { background: #e7ecff; }
.doc-type { font-size: 10px; font-weight: 700; color: #fff; background: var(--muted); padding: 2px 6px; border-radius: 4px; }
.doc-item.active .doc-type, .doc-item:hover .doc-type { background: var(--primary); }
.doc-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.doc-del:hover { color: var(--error); }
.hint { color: var(--muted); font-size: 11px; margin: 6px 0 0; }

/* ---------- 버튼 ---------- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn:hover { background: #f1f3f5; }
.btn.block { display: block; width: 100%; margin-bottom: 8px; text-align: center; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { border-style: dashed; color: var(--muted); }
.btn-review { background: var(--review); color: #fff; border-color: var(--review); }
.btn-review:hover { filter: brightness(0.95); }

/* ---------- 편집 영역 ---------- */
.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel); z-index: 5;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; }
.toolbar-right { display: flex; gap: 8px; }
.type-badge { font-weight: 700; background: #e7ecff; color: var(--primary); padding: 4px 10px; border-radius: 6px; }
.preset-select, select, input[type="text"], textarea {
  font-family: inherit; font-size: 13px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
}
.preset-select { padding: 6px 10px; }
textarea { resize: vertical; width: 100%; }

.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 18px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field-wide { grid-column: 1 / -1; }
.field-label { font-weight: 600; font-size: 12px; color: #495057; }
.req { color: var(--error); margin-left: 3px; }
.field-hint { color: var(--muted); font-size: 11px; }
.field input, .field select { width: 100%; }

.empty-state { padding: 60px 30px; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--text); font-size: 18px; }

/* ---------- 검토 패널 ---------- */
.review-panel { display: flex; flex-direction: column; }
.review-header {
  font-weight: 700; padding: 14px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel);
}
.review-output { padding: 14px 16px; }
.review-meta { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.review-summary { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.count-badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 4px; color: #fff; }
.review-pass { color: var(--review); font-weight: 700; font-size: 15px; padding: 8px 0; }

.sev-error { background: var(--error); }
.sev-warning { background: var(--warning); }
.sev-info { background: var(--info); }

.finding-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.finding {
  border: 1px solid var(--border); border-left-width: 4px; border-radius: 6px; padding: 10px 12px; background: #fff;
}
.finding.sev-error { border-left-color: var(--error); }
.finding.sev-warning { border-left-color: var(--warning); }
.finding.sev-info { border-left-color: var(--info); }
.finding-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sev-tag { font-size: 10px; font-weight: 700; color: #fff; padding: 2px 6px; border-radius: 3px; }
.finding.sev-error .sev-tag { background: var(--error); }
.finding.sev-warning .sev-tag { background: var(--warning); }
.finding.sev-info .sev-tag { background: var(--info); }
.finding-field { font-weight: 700; font-size: 12px; }
.src-tag { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 3px; }
.src-rule { background: #e7ecff; color: var(--primary); }
.src-llm { background: #e6fcf5; color: var(--review); }
.llm-status { margin-left: 8px; }
.llm-status.loading { color: var(--info); }
.llm-status.ok { color: var(--review); }
.llm-status.err { color: var(--warning); }
.finding-msg { font-size: 13px; margin-bottom: 4px; }
.finding-guide { font-size: 12px; color: #495057; background: #f8f9fa; padding: 6px 8px; border-radius: 4px; }

/* ---------- 기타 ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1f2430; color: #fff; padding: 10px 18px; border-radius: 8px;
  opacity: 0; transition: all 0.25s; pointer-events: none; z-index: 100; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 버튼 변형 ---------- */
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---------- 모달 ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(31, 36, 48, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal {
  background: var(--panel); border-radius: var(--radius); width: min(560px, 92vw);
  max-height: 80vh; overflow: auto; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700;
  position: sticky; top: 0; background: var(--panel);
}
.modal-x { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px; }

/* ---------- 버전 이력 ---------- */
.ver-list { list-style: none; margin: 0; padding: 0; }
.ver-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.ver-cur {
  font-size: 10px; font-weight: 700; color: #fff; background: var(--review);
  padding: 2px 6px; border-radius: 3px; margin-left: 4px;
}

/* ---------- 공유 읽기전용 보기 ---------- */
.share-banner {
  background: #fff3bf; color: #a37200; font-weight: 700;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.ro-doc { padding: 18px; }
.ro-doc h2 { margin-top: 0; }
.ro-field { margin-bottom: 14px; }
.ro-label { font-weight: 700; font-size: 12px; color: #495057; margin-bottom: 4px; }
.ro-value { white-space: pre-wrap; background: #f8f9fa; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }

/* ---------- 기준 편집 ---------- */
.rules-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.rules-vers { max-height: 140px; overflow: auto; margin-bottom: 12px; }
.ver-item.sel { background: #f1f3f5; border-radius: 6px; padding-left: 6px; }
.btn-link { border: none; background: none; color: var(--primary); cursor: pointer; padding: 0; font-size: 13px; }
.btn-link:hover { text-decoration: underline; }
.rules-msg { margin: 8px 0; min-height: 16px; }
.rules-msg.ok { color: var(--review); }
.rules-msg.err { color: var(--error); }
.rules-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.rules-help { margin-top: 8px; }
.rules-help summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.rules-help code { background: #f1f3f5; padding: 1px 5px; border-radius: 3px; font-size: 11px; }
