:root {
  --blue: #2563eb; --blue-dark: #1d4ed8;
  --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --green: #16a34a; --red: #dc2626; --amber: #d97706;
  --bg: #ffffff; --card: #ffffff;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  font-size: 15px; color: var(--text); background: var(--bg);
}
button { font-family: inherit; cursor: pointer; }
input, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; background: #fff;
}
input:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--blue); }
textarea { width: 100%; resize: vertical; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: 9px 16px; font-size: 14px;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: bold; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef2f7; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 상단바 ---------- */
#topbar {
  position: sticky; top: 0; z-index: 50; height: 54px; background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
}
#topbar .brand { font-size: 16px; font-weight: bold; }

/* ---------- 랜딩 ---------- */
.hero { max-width: 720px; margin: 0 auto; padding: 9vh 20px 40px; text-align: center; }
.hero h1 { font-size: 34px; margin: 0 0 10px; letter-spacing: -1px; }
.hero h1 b { color: var(--blue); }
.hero .sub { color: var(--muted); margin: 0 0 30px; line-height: 1.7; }
.search-card {
  border: 1px solid var(--line); border-radius: 16px; padding: 18px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, .06); text-align: left;
}
.search-row { display: flex; gap: 10px; }
.search-row input { flex: 1; min-width: 0; }
.search-row .btn { white-space: nowrap; padding: 10px 22px; }
.advanced { margin-top: 12px; }
.advanced summary { color: var(--muted); font-size: 13px; cursor: pointer; }
.adv-body { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.adv-body label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.guide-box { border: 1px dashed var(--line); border-radius: 8px; padding: 8px 12px; }
.guide-box summary { font-size: 13px; color: var(--muted); cursor: pointer; }
.guide-box textarea { margin-top: 8px; font-size: 12.5px; font-family: Consolas, monospace; }
.provider-hint { color: var(--muted); font-size: 12.5px; margin-top: 16px; }
.provider-hint.warn { color: var(--amber); font-weight: bold; }

/* ---------- 진행 피드 ---------- */
#workflow { max-width: 860px; margin: 0 auto; padding: 22px 20px 80px; }
.feed-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px;
  margin-bottom: 14px; background: var(--card);
}
.feed-card.running { border-color: #fcd34d; box-shadow: 0 0 0 3px #fef3c7; }
.feed-card.done { border-color: #bbf7d0; }
.feed-card.error { border-color: #fecaca; }
.feed-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.feed-title { font-weight: bold; font-size: 15.5px; }
.feed-badge { font-size: 11px; padding: 2px 9px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.feed-badge.pplx { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.feed-badge.ds { background: #ecfeff; color: #0e7490; border-color: #a5f3fc; }
.feed-status { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.feed-status.busy { color: var(--amber); }
.feed-status.ok { color: var(--green); }
.feed-status.err { color: var(--red); }

.feed-body { line-height: 1.75; overflow-wrap: break-word; max-height: 420px; overflow-y: auto; padding-right: 6px; }
.feed-body h1, .feed-body h2, .feed-body h3 { border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.feed-body table { border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.feed-body th, .feed-body td { border: 1px solid var(--line); padding: 5px 9px; }
.feed-body blockquote { border-left: 3px solid var(--line); margin: 8px 0; padding: 2px 12px; color: var(--muted); }
.feed-body code { background: #f3f4f6; border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }
.feed-body pre { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; }
.feed-body pre code { background: none; }

/* 접힘 토글 */
.feed-toggle { border: none; background: none; color: var(--blue); font-size: 13px; padding: 0; margin-top: 6px; }
.feed-body.collapsed { max-height: 180px; overflow: hidden; }

/* 확인 카드 */
.confirm-card {
  border: 1px solid #fcd34d; background: #fffbeb; border-radius: 12px;
  padding: 16px 18px; margin-bottom: 14px;
}
.confirm-title { font-weight: bold; margin-bottom: 4px; }
.confirm-desc { color: var(--muted); font-size: 13px; margin-bottom: 12px; line-height: 1.6; }
.confirm-row { display: flex; gap: 8px; flex-wrap: wrap; }
.confirm-row input { flex: 1; min-width: 240px; }
.btn.big { padding: 11px 24px; font-size: 15px; }

/* 게이트 카드 */
.gate-card { border: 1px solid #fecaca; background: #fef2f2; border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.gate-title { font-weight: bold; margin-bottom: 10px; color: var(--red); }
.gate-text { background: #fff; border: 1px solid #fecaca; border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; font-size: 13px; line-height: 1.6; margin-bottom: 12px; }
.gate-vars { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.gate-vars label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); flex: 1; min-width: 200px; }
.gate-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* 인포그래픽 카드 */
.ig-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.ig-title { font-weight: bold; margin-bottom: 10px; }
.ig-frame { width: 100%; height: 520px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* 완료 카드 */
.final-card { border: 2px solid #bbf7d0; background: #f0fdf4; border-radius: 12px; padding: 16px 18px; }
.final-title { font-weight: bold; margin-bottom: 12px; }
.final-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* 승인 배너 (문제 감지 시 처음 화면 상단) */
#gate-banner { margin-bottom: 20px; }
.gate-banner-card {
  border: 2px solid #dc2626; background: #fef2f2; border-radius: 12px;
  padding: 18px 20px; text-align: left;
}
.gb-title { font-weight: bold; font-size: 16.5px; color: #b91c1c; margin-bottom: 8px; }
.gb-desc { color: var(--muted); font-size: 13.5px; line-height: 1.7; margin-bottom: 12px; }
.gb-text {
  background: #fff; border: 1px solid #fecaca; border-radius: 8px; padding: 12px 14px;
  white-space: pre-wrap; font-size: 13px; line-height: 1.7; margin-bottom: 12px;
}
.gb-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.gb-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* 결과 화면 상단 승인 바 */
.gate-topbar {
  border: 2px solid #dc2626; background: #fef2f2; border-radius: 12px;
  padding: 14px 18px; margin-bottom: 14px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.gate-topbar .gt-text { flex: 1; min-width: 240px; font-size: 13.5px; color: #b91c1c; font-weight: bold; }
.gate-topbar .gt-sub { font-size: 12.5px; color: var(--muted); font-weight: normal; white-space: pre-wrap; max-height: 120px; overflow-y: auto; }

.muted { color: var(--muted); }
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: #111827; color: #fff; padding: 10px 20px; border-radius: 8px; font-size: 13.5px; max-width: 84vw;
}
#toast.err { background: var(--red); }
