:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #667085;
  --line: #d8dee8;
  --primary: #0f6e56;
  --primary-ink: #ffffff;
  --secondary: #1f3a5f;
  --danger: #b42318;
  --ok: #067647;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
  --radius: 14px;
  --font: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(circle at top left, rgba(15, 110, 86, 0.08), transparent 40%),
    radial-gradient(circle at top right, rgba(31, 58, 95, 0.08), transparent 35%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  min-height: 100%;
}

button, input, select {
  font: inherit;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.header h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.view-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.view-tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.view-tab.active {
  background: var(--secondary);
  border-color: var(--secondary);
  color: #fff;
}

.hint-text {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.modal-xl {
  max-width: min(96vw, 1400px);
  width: 96vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.modal-wide {
  max-width: 860px;
}

.competition-modal-body {
  overflow: auto;
}

.competition-input-row {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 16px;
  margin-bottom: 16px;
}

#competition-keywords {
  width: 100%;
  min-height: 220px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  resize: vertical;
}

.competition-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.competition-progress {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.competition-progress .k {
  color: var(--muted);
  margin-right: 6px;
}

.competition-current {
  grid-column: 1 / -1;
}

.competition-table-wrap {
  max-height: 420px;
}

#competition-table {
  min-width: 2600px;
}

.row-failed {
  background: #fff5f5;
}

.comp-level {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.comp-level-VERY_LOW {
  background: #ecfdf5;
  color: #047857;
}

.comp-level-LOW {
  background: #eff6ff;
  color: #1d4ed8;
}

.comp-level-MEDIUM {
  background: #fffbeb;
  color: #b45309;
}

.comp-level-HIGH {
  background: #fff7ed;
  color: #c2410c;
}

.comp-level-VERY_HIGH {
  background: #fef2f2;
  color: #b91c1c;
}

.attack-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.attack-priority {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #6ee7b7;
}

.attack-candidate {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
}

.attack-review {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fcd34d;
}

.attack-stale {
  background: #f8fafc;
  color: #64748b;
  border: 1px solid #cbd5e1;
}

.rec-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.rec-PRIORITY {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #6ee7b7;
}

.rec-CANDIDATE {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
}

.rec-REVIEW {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fcd34d;
}

.rec-HOLD {
  background: #f8fafc;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.rec-REJECT {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

.rec-reason {
  max-width: 320px;
  white-space: normal;
  font-size: 0.85rem;
  color: var(--muted);
}

.promising-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #86efac;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .competition-input-row {
    grid-template-columns: 1fr;
  }
}


.modal-footer-actions {
  flex-wrap: wrap;
  gap: 8px;
}

.inline-label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0;
}

#candidate-note-input {
  flex: 1;
  min-width: 180px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.trend-chart {
  width: 100%;
  max-width: 560px;
  height: auto;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chart-label {
  fill: #64748b;
  font-size: 10px;
}

.muted {
  color: var(--muted);
}

.analyze-limit-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7fafc;
}

.analyze-limit-label {
  margin: 0;
  flex-direction: row;
  align-items: center;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.85rem;
}

.analyze-limit-group select {
  min-width: 88px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.seed-form,
.filters-grid {
  display: grid;
  gap: 10px;
}

.seed-form {
  grid-template-columns: 1.6fr 0.8fr auto auto;
  align-items: center;
}

.collect-progress-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.collect-progress-grid .k {
  color: var(--muted);
  margin-right: 6px;
}

.collect-current {
  margin: 0;
  color: var(--ink);
}

.filters-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.filters-header,
.table-header,
.table-meta,
.pagination,
.filter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filters-header,
.table-header {
  justify-content: space-between;
  margin-bottom: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}

.btn-ghost {
  background: #eef2f7;
  color: var(--ink);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card {
  background: linear-gradient(180deg, #ffffff, #f7fafc);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.summary-card .label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.summary-card strong {
  font-size: 1.6rem;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
  background: #fff;
}

th, td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.9rem;
  white-space: nowrap;
}

th {
  background: #f7f9fc;
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f3faf7;
}

.grade {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.8rem;
}

.grade-S { background: #dcfae6; color: #067647; }
.grade-A { background: #e0f2fe; color: #026aa2; }
.grade-B { background: #eef4ff; color: #3538cd; }
.grade-C { background: #fff6ed; color: #c4320a; }
.grade-D { background: #f2f4f7; color: #475467; }

.comp-LOW { color: #067647; font-weight: 600; }
.comp-MEDIUM { color: #b54708; font-weight: 600; }
.comp-HIGH { color: #b42318; font-weight: 600; }

.status-text {
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state,
.error-state {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.error-state {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #102a43;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 40;
  max-width: 360px;
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--ok);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.modal-header,
.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-footer {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.modal-body {
  padding: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fafbfc;
}

.detail-item .k {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.detail-item .v {
  font-weight: 600;
  word-break: break-word;
}

.detail-full {
  grid-column: 1 / -1;
}

@media (max-width: 1400px) {
  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.confirm-body p {
  margin: 0 0 12px;
}

.confirm-stats {
  margin: 0 0 12px;
  padding-left: 1.2rem;
}

.confirm-stats li {
  margin-bottom: 6px;
}

.confirm-warning {
  color: #b42318;
  font-weight: 600;
}

.confirm-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.btn-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
}

.action-cell {
  white-space: nowrap;
}

.planner-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.planner-completed {
  background: #ecfdf5;
  color: #047857;
}

.planner-approved {
  background: #eff6ff;
  color: #1d4ed8;
}

.planner-hold {
  background: #f8fafc;
  color: #475569;
}

.planner-failed {
  background: #fef2f2;
  color: #b91c1c;
}

.planner-analyzing {
  background: #fffbeb;
  color: #b45309;
}

.planner-pending {
  background: #f1f5f9;
  color: #64748b;
}

.planner-result-body {
  max-height: 75vh;
  overflow: auto;
}

.planner-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.planner-meta-grid .k {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.planner-section {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.planner-section h3,
.planner-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.planner-list,
.planner-search-list,
.planner-outline {
  margin: 0;
  padding-left: 1.2rem;
}

.planner-highlight {
  font-size: 1.05rem;
  font-weight: 600;
}

.planner-search-block + .planner-search-block {
  margin-top: 1rem;
}

.planner-search-title {
  font-weight: 600;
}

.planner-search-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.planner-title {
  max-width: 280px;
  white-space: normal;
}

.planner-footer-meta {
  margin-top: 1rem;
}

.topic-tag {
  display: inline-block;
  margin: 0.15rem 0.25rem 0.15rem 0;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 0.78rem;
}

.verify-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.verify-yes {
  background: #fffbeb;
  color: #b45309;
}

.verify-no {
  background: #f1f5f9;
  color: #64748b;
}

.planner-cluster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

.planner-cluster-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: #fafafa;
}

.planner-cluster-card h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.planner-cluster-card .k {
  color: var(--muted);
  font-size: 0.8rem;
}

.planner-tags-cell {
  grid-column: 1 / -1;
}

.writer-section {
  margin-top: 1.5rem;
  border-top: 2px solid var(--border);
  padding-top: 1rem;
}

.writer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.writer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1rem 0;
}

.writer-col {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: var(--surface);
}

.writer-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}

.writer-tab {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
}

.writer-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.writer-content-preview {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
}

.writer-dup-result.dup-pass {
  border-left: 3px solid var(--success, #2e7d32);
  padding-left: 0.5rem;
}

.writer-dup-result.dup-fail {
  border-left: 3px solid var(--warning, #ed6c02);
  padding-left: 0.5rem;
}

.writer-status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--border);
}

.writer-status-badge.status-approved {
  background: #e8f5e9;
  color: #2e7d32;
}

.writer-status-badge.status-review {
  background: #fff3e0;
  color: #e65100;
}

.writer-cost-hint {
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

.fact-status-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  margin-right: 0.35rem;
  vertical-align: middle;
}

.fact-status-badge.fact-plan-derived {
  background: #e3f2fd;
  color: #1565c0;
}

.fact-status-badge.fact-verified {
  background: #e8f5e9;
  color: #2e7d32;
}

.fact-status-badge.fact-unverified {
  background: #fff3e0;
  color: #e65100;
}

.fc-section {
  margin-top: 1rem;
  border-top: 1px dashed var(--border, #ddd);
  padding-top: 1rem;
}

.fc-stats {
  margin: 0.5rem 0 1rem;
}

.fc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.fc-claim-list {
  margin-top: 0.5rem;
}

.fc-claim-row {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border, #eee);
}

.fc-claim-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.fc-claim-text {
  margin: 0.25rem 0 0.5rem;
}

.fc-result-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
}

.fc-result-supported {
  background: #e8f5e9;
  color: #2e7d32;
}

.fc-result-partial {
  background: #fff8e1;
  color: #f57f17;
}

.fc-result-notfound {
  background: #ffebee;
  color: #c62828;
}

.fc-result-other {
  background: #eceff1;
  color: #455a64;
}

.fc-evidence {
  font-size: 0.85rem;
  line-height: 1.4;
}

.fc-meta {
  font-size: 0.8rem;
}

.fc-chain {
  margin: 0.15rem 0;
  font-size: 0.9rem;
}

.fc-debug {
  margin: 0.35rem 0;
  font-size: 0.8rem;
}

@media (max-width: 1100px) {
  .filters-grid,
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .seed-form {
    grid-template-columns: 1fr;
  }

  .header {
    flex-direction: column;
  }
}

@media (max-width: 700px) {
  .filters-grid,
  .summary-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .table-header,
  .filters-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
