:root {
  --bg: #fafbfc;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --comp: #1d4ed8;       /* 컴응기 파랑 */
  --comp-bg: #eff6ff;
  --info: #be185d;        /* 정관기 핑크 */
  --info-bg: #fdf2f8;
  --accent: #059669;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  background: linear-gradient(135deg, #1e3a8a 0%, #6b21a8 100%);
  color: white;
  padding: 28px 24px 24px;
  text-align: center;
}
header h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }
header .sub { margin: 6px 0 18px; opacity: 0.85; font-size: 0.9rem; }

#searchForm {
  display: flex;
  gap: 8px;
  max-width: 1100px;
  margin: 0 auto;
}
#searchForm input {
  flex: 1;
  padding: 12px 16px;
  font-size: 1rem;
  border: 0;
  border-radius: 8px;
  outline: none;
  box-shadow: var(--shadow);
}
#searchForm button {
  padding: 12px 22px;
  font-size: 1rem;
  background: #059669;
  color: white;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
#searchForm button:hover { background: #047857; }

.usage-bar {
  max-width: 1100px;
  margin: 14px auto 14px;
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 14px;
  background: rgba(255,255,255,0.08);
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
}
.usage-item .usage-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.85);
  margin-bottom: 5px;
}
.usage-item .usage-val {
  font-weight: 600;
  color: white;
}
.usage-progress {
  background: rgba(255,255,255,0.15);
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
}
.usage-progress-fill {
  background: linear-gradient(90deg, #10b981 0%, #f59e0b 70%, #ef4444 95%);
  height: 100%;
  width: 0%;
  transition: width 0.4s ease;
}
.usage-item.session-total .usage-sub {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.7);
  margin-top: 4px;
}
@media (max-width: 640px) {
  .usage-bar { grid-template-columns: 1fr; }
}

.examples {
  margin-top: 14px;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.85);
}
.examples .ex {
  display: inline-block;
  padding: 4px 10px;
  margin: 0 3px;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.examples .ex:hover { background: rgba(255,255,255,0.3); }

main { max-width: 100%; margin: 24px auto; padding: 0 20px; }

.hidden { display: none !important; }

#trendSection {
  background: var(--card);
  padding: 20px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
#trendSection h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  color: var(--text);
}
#trendSection .hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
}

.result-summary {
  background: var(--card);
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
  box-shadow: var(--shadow);
}
.result-summary strong { color: var(--text); }

/* 📚 키워드 정의 섹션 */
.def-section {
  background: linear-gradient(135deg, #fefce8 0%, #f0fdf4 100%);
  border: 1px solid #e0e7ff;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.def-section-title {
  margin: 0 0 12px;
  font-size: 1rem;
  color: #4338ca;
}
.def-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.def-card:last-child { margin-bottom: 0; }
.def-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.def-head .def-no {
  font-family: ui-monospace, monospace;
  color: #9ca3af;
  font-size: 0.78rem;
}
.def-head .def-keyword {
  font-weight: 700;
  color: var(--text);
  font-size: 0.95rem;
}
.def-head .def-status {
  font-size: 0.72rem;
  padding: 2px 8px;
  border: 1px solid;
  border-radius: 10px;
  font-weight: 600;
}
.def-head .def-cat {
  color: var(--muted);
  font-size: 0.75rem;
}
.def-head .def-score {
  margin-left: auto;
  background: #ede9fe;
  color: #6b21a8;
}
.def-body {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
}

/* 페어 카드 (컴응기 1개 + 정관기 매칭 N개) */
.pair-card {
  background: var(--card);
  border-radius: 10px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--border);
}
.pair-comp {
  padding: 14px 18px 12px;
  background: linear-gradient(180deg, #eff6ff 0%, #ffffff 70%);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.pair-comp:hover { background: #dbeafe; }
.pair-comp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--muted);
}
.pair-comp-head .ref { font-weight: 600; color: var(--text); }
.pair-comp-body {
  font-size: 0.93rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
}
.score-pill {
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  margin-left: auto;
}
.score-pill.comp-score { background: #dbeafe; color: #1e40af; }
.score-pill.info-score { background: #fce7f3; color: #9d174d; }

.pair-info-list {
  padding: 8px 16px 14px 30px;
  background: #fafafa;
}
.pair-info {
  padding: 10px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.pair-info:hover { background: #fdf2f8; border-color: var(--info); }
.pair-info-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 5px;
}
.pair-info-head .ref { font-weight: 600; color: var(--text); }
.pair-info-head .connector { color: #9ca3af; font-family: monospace; }
.pair-info-body {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}
.pair-comment {
  margin-top: 8px;
  padding: 7px 11px;
  background: linear-gradient(90deg, #fef3c7 0%, #fff7ed 100%);
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  font-size: 0.83rem;
  color: #78350f;
}

/* SVG 다이어그램 공통 - 컨텐츠 크기로 */
svg.diagram {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 6px 0 10px;
  background: white;
}
svg.diagram.flow {}
svg.diagram.components {}
svg.diagram.layered {}

.col-count {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 9px;
  background: #f3f4f6;
  color: var(--muted);
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 800px) {
  .columns { grid-template-columns: 1fr; }
}

.col {
  background: var(--card);
  border-radius: 10px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.col h2 {
  margin: 0 0 14px;
  font-size: 1.05rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 6px;
}
.badge.comp { background: var(--comp-bg); color: var(--comp); }
.badge.info { background: var(--info-bg); color: var(--info); }

.result-list { list-style: none; margin: 0; padding: 0; }
.result-list li {
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.result-list li:hover {
  border-color: var(--accent);
  background: #f0fdf4;
  transform: translateX(2px);
}
.result-list li.weak-match {
  opacity: 0.55;
  background: #fafafa;
}
.result-list li.weak-match:hover {
  opacity: 1.0;
}
.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.result-head .ref {
  font-weight: 600;
  color: var(--text);
}
.result-head .session-tag {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f3f4f6;
  margin-left: 4px;
}
.result-head .score {
  font-size: 0.75rem;
  background: #ecfdf5;
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.result-body {
  font-size: 0.9rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.result-explain {
  margin-top: 10px;
  padding: 8px 12px;
  background: linear-gradient(90deg, #fef3c7 0%, #fff7ed 100%);
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  font-size: 0.83rem;
  color: #78350f;
  line-height: 1.5;
}
.explain-labels {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
}
.explain-text {
  color: #78350f;
}
.result-explain.loading {
  color: #9ca3af;
  background: #f9fafb;
  border-left-color: #d1d5db;
  font-style: italic;
}
.result-explain .icon {
  margin-right: 4px;
}

#emptyState {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

#loading {
  text-align: center;
  padding: 40px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 모달 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-content {
  background: var(--card);
  border-radius: 12px;
  max-width: 720px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 28px 30px;
  position: relative;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: 0;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
}
.modal-close:hover { color: var(--text); }

#modalBody h3 { margin-top: 0; }
#modalBody .modal-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
#modalBody .modal-content-body {
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 0.95rem;
}

/* 📒 지식 자산 섹션 */
#notesSection {
  margin-top: 24px;
  background: var(--card);
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.notes-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.notes-head h2 { margin: 0; font-size: 1.05rem; }
.notes-head .muted { color: var(--muted); font-size: 0.8rem; font-weight: 400; margin-left: 8px; }
.notes-tabs {
  display: flex;
  gap: 4px;
}
.notes-tabs .tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.notes-tabs .tab:hover { background: #f9fafb; }
.notes-tabs .tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

#noteSearchForm, #noteAskForm, #noteAddForm, .browse-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
#noteSearchForm input, #noteAddForm input, #noteSearchForm select,
.browse-filter select, .browse-filter button {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
#noteSearchForm input, #noteAddForm input[type="text"] { flex: 1; min-width: 180px; }
#noteAskForm textarea, #noteAddForm textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}
#noteSearchForm button, #noteAskForm button, #noteAddForm button,
.browse-filter button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 9px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}
#noteSearchForm button:hover, #noteAskForm button:hover,
#noteAddForm button:hover, .browse-filter button:hover { background: #047857; }
.browse-filter button { background: #6b7280; }

#noteAskForm { flex-direction: column; align-items: stretch; }
#noteAskForm button { align-self: flex-start; }
#noteAddForm { flex-direction: column; align-items: stretch; }
#noteAddForm button { align-self: flex-start; }

.note-answer {
  background: #f0fdf4;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 14px 18px;
  margin-top: 10px;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 0.92rem;
}
.note-answer .q { font-weight: 600; color: var(--text); margin-bottom: 8px; }
.note-answer .a { color: #1f2937; }

.note-list { list-style: none; margin: 0; padding: 0; }
.note-list li {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  position: relative;
  background: #fafafa;
}
.note-list .note-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.8rem;
}
.note-list .note-source {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
}
.note-list .note-source.llm { background: #dbeafe; color: #1e40af; }
.note-list .note-source.llm_qa { background: #ede9fe; color: #6b21a8; }
.note-list .note-source.user { background: #fef9c3; color: #854d0e; }
.note-list .note-meta { color: var(--muted); font-size: 0.75rem; }
.note-list .note-content {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}
.note-list .note-title { font-weight: 600; margin-bottom: 4px; }
.note-list .note-labels { margin-top: 6px; }
.note-list .note-delete {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: 0;
  color: #ef4444;
  cursor: pointer;
  font-size: 0.85rem;
}
.note-list .note-delete:hover { text-decoration: underline; }

.hint { color: var(--muted); font-size: 0.78rem; margin: 8px 0 0; }

/* 상단 메뉴 */
.top-nav {
  max-width: 1100px;
  margin: 16px auto 0;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.top-nav a {
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.top-nav a:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

footer {
  text-align: center;
  padding: 28px;
  color: var(--muted);
  font-size: 0.8rem;
}
