:root {
  --accent: #ff3d1f;
  --accent-soft: #fff1ee;
  --bg: #fafafa;
  --card: #ffffff;
  --text: #0a0a0a;
  --muted: #8a8a8f;
  --border: #e8e8ea;
  --band: #eaeaec;
  --radius: 4px;
}

* { box-sizing: border-box; }

/* display를 지정한 요소는 hidden 속성만으로 안 숨는다 — 전역으로 못 박아둔다. */
[hidden] { display: none !important; }

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

/* ── 헤더: 블랙 + 볼드 워드마크, 로고 없이 타이포로만 ────────────────────── */

header {
  background: #0a0a0a;
  color: white;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 22px 28px;
  border-bottom: 1px solid #1e1e1e;
}

header h1 { margin: 0; }

.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  white-space: nowrap;
  font-weight: 800;
  font-size: 24px;
  letter-spacing: -0.01em;
  color: #fff;
}

.wordmark-dot { color: var(--accent); margin: 0 6px; font-weight: 900; }

.wordmark-sub {
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 0;
  color: rgba(255, 255, 255, 0.55);
}

.session-badges { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
}

.badge.ok { background: var(--accent); color: #fff; font-weight: 600; border-color: transparent; }

/* ── 탭: 미니멀 언더라인 ─────────────────────────────────────────────────── */

/* 가운데 정렬. 좌우 끝까지 벌려도 봤는데 사이가 너무 떠서 지저분했다 — 살짝만 띄운다. */
.tabs {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding: 0 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  border: none;
  border-radius: 0;
  background: none;
  padding: 16px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

/* 좁은 화면에서는 사이 간격까지 주면 '수 집'처럼 글자가 세로로 쪼개진다 —
   그때는 간격을 줄이고 가로로 밀어서 보게 한다. */
@media (max-width: 820px) {
  .tabs { justify-content: flex-start; gap: 0; overflow-x: auto; padding: 0 16px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

main { padding: 28px; max-width: 900px; margin: 0 auto; }


.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in 0.15s ease; }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── 카드 ────────────────────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
}

/* 카드 제목은 눈에 확실히 들어와야 한다 — 포인트 컬러 대신 굵기·검정·연회색 띠로 세운다.
   카드마다 h2가 항상 첫 요소라, 카드 안쪽 여백(22px)만큼 음수 마진을 줘서 띠를 끝까지 뺀다. */
.card h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  background: var(--band);
  margin: -22px -22px 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.card h2::before {
  content: '';
  width: 3px;
  height: 15px;
  background: var(--text);
  flex-shrink: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

input[type="text"], input[type="number"], select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s;
}

input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--text);
}

input[type="text"] { flex: 1; min-width: 200px; }
textarea { width: 100%; min-height: 88px; margin: 8px 0; }
select { width: 100%; margin-bottom: 8px; }

button {
  padding: 10px 18px;
  border: 1px solid var(--text);
  border-radius: var(--radius);
  background: var(--text);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
}

button:hover { opacity: 0.85; }
button:disabled { opacity: 0.35; cursor: default; }

/* 카드마다 주된 실행 버튼 하나에만 포인트 컬러를 준다 */
#collect-start-btn, #analyze-btn, #generate-btn, #feedback-btn,
#insights-refresh-btn, #ads-refresh-btn, #trend-scan-btn, #classify-btn {
  background: var(--accent);
  border-color: var(--accent);
}

button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
button.secondary:hover { border-color: var(--text); color: var(--text); opacity: 1; }

.muted { color: var(--muted); font-size: 13px; }

.log {
  background: #0a0a0a;
  color: #d4d4d4;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  padding: 14px;
  border-radius: var(--radius);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  margin-top: 10px;
}

.output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.7;
}

.file-list, .record-list { list-style: none; margin: 0; padding: 0; }
.file-list li, .record-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.file-list li:last-child, .record-list li:last-child { border-bottom: none; }

table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

details { margin-top: 10px; }
summary { cursor: pointer; font-size: 13px; color: var(--muted); }

/* ── 폼 그리드 ───────────────────────────────────────────────────────────── */

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 12px;
}

.field-grid.three { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 760px) {
  .field-grid, .field-grid.three { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; margin-bottom: 12px; }

/* 부제목은 옅은 회색 바탕을 깔아 카드 안에서 구획이 눈에 들어오게 한다. */
.field > label {
  align-self: flex-start;
  background: #f0f0f3;
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.field select, .field input[type="text"] { width: 100%; margin: 0; }

.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }

.radio-row { display: flex; gap: 16px; padding: 9px 0; }

label.radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
}

label.radio input { accent-color: var(--accent); margin: 0; }

/* ── 인사이트 목록 ───────────────────────────────────────────────────────── */

.insight-list { list-style: none; margin: 12px 0 0; padding: 0; }

/* 본문·근거·버튼을 한 줄에 밀어넣으면 긴 근거가 폭을 다 가져가
   본문이 한 글자씩 세로로 떨어진다. 근거는 아랫줄로 내린다. */
.insight-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.6;
}

.insight-list li:last-child { border-bottom: none; }

.insight-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

/* min-width:0 이 없으면 flex 항목이 제 내용보다 좁아지지 않아 글자가 세로로 쌓인다 */
.insight-text { flex: 1; min-width: 0; word-break: break-word; }

.insight-actions { display: flex; gap: 8px; flex-shrink: 0; }

.insight-evidence {
  margin: 6px 0 0;
  padding-left: 34px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--border);
  color: var(--muted);
  letter-spacing: 0.04em;
}

.tag-ai { background: var(--accent-soft); color: var(--accent); }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-weight: 400;
}

.link-btn:hover { color: var(--accent); opacity: 1; }

/* ── 설정 카드 ───────────────────────────────────────────────────────────── */

.sub-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg);
}

.sub-card input[type="text"] { background: var(--card); }
.sub-card .bm-memo { width: 100%; margin: 8px 0; }

.chip-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
  padding: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
}

.chip-x {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.chip-x:hover { color: var(--accent); opacity: 1; }

/* ── 계정 연결 ───────────────────────────────────────────────────────────── */

.account-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 0;
  font-size: 14px;
}

#account-overview .account-line { border-bottom: 1px solid var(--border); }
#account-overview .account-line:last-child { border-bottom: none; }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d4d4d8;
  flex-shrink: 0;
}

.dot.on { background: #16a34a; }

.account-who {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 3px;
  background: #f0f0f3;
}

.assign-row { padding: 8px 0; border-bottom: 1px solid var(--border); }
.assign-row:last-child { border-bottom: none; }
.assign-row select { width: auto; min-width: 180px; margin: 0; }

/* ── 지식베이스 내용 보기 ────────────────────────────────────────────────── */
/* 새 창(window.open)은 팝업 차단에 막혀 아무 일도 안 일어난 것처럼 보였다. 페이지 안에서 연다. */

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

.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  width: min(760px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--border);
}

.modal-head .link-btn[aria-pressed="true"] { color: var(--accent); font-weight: 700; }

#kb-modal-body {
  margin: 12px 0 0;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.75;
}

#kb-modal-edit {
  flex: 1;
  min-height: 320px;
  margin: 12px 0 0;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
}

/* 수집 결과 본문 — 줄바꿈을 살리되 너무 길면 접어둔다 */
.post-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.7;
  margin-top: 10px;
  max-height: 260px;
  overflow-y: auto;
}

.cat-terms { min-height: 56px; font-size: 13px; background: var(--card); }

/* 수집한 사진·영상 — 원문에 실린 시각물을 한눈에 본다.
   쓰레드 CDN 주소는 시간이 지나면 만료되므로 안 뜨면 칸을 지워 자리만 차지하지 않게 한다. */
.media-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.media-thumb {
  display: block;
  width: 96px;
  height: 96px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
  position: relative;
}

.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.media-thumb.video span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 22px;
  background: rgba(10, 10, 10, 0.35);
}

/* 고른 항목은 한눈에 보이게 — 무엇이 다음 단계로 넘어가는지가 이 화면의 핵심이다 */
.post-item.picked, .fragment.picked {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.frag-text {
  width: 100%;
  min-height: 62px;
  margin: 8px 0 0;
  background: var(--card);
  font-size: 14px;
  line-height: 1.6;
}

.fragment .frag-kind, .fragment input[type="text"] { background: var(--card); }

.idea-text {
  width: 100%;
  min-height: 190px;
  margin: 10px 0 0;
  background: var(--card);
  font-size: 14px;
  line-height: 1.7;
}

/* 어떤 사진·영상을 붙일지 — 글과 구분되게 왼쪽에 선을 두고, 한 컷에 한 줄씩 */
.idea-visual {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--border);
  background: var(--bg);
  font-size: 13px;
  line-height: 1.65;
}

.idea-visual ul { margin: 6px 0 0; padding-left: 18px; }
.idea-visual li { margin: 4px 0; }

.check-list { list-style: none; margin: 8px 0 16px; padding: 0; }
.check-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; line-height: 1.6; }
.check-list li:last-child { border-bottom: none; }
.fix-list li { border-left: 3px solid var(--accent); padding-left: 12px; }

/* ── 넓은 화면: 조작 칸(왼쪽) + 결과 칸(오른쪽) 2단 ──────────────────────────
   좁은 화면에서는 지금처럼 위아래로 쌓인다. 데스크톱에서 900px 한 줄만 쓰면
   양옆이 텅 비고 결과 목록만 한없이 길어져서, 조건을 보면서 결과를 볼 수 없었다. */
@media (min-width: 1100px) {
  main { max-width: 1440px; padding: 28px 40px; }
  .header-inner, .tabs { max-width: 1440px; margin: 0 auto; width: 100%; padding-left: 40px; padding-right: 40px; }

  .tab-panel.active {
    display: grid;
    grid-template-columns: minmax(400px, 470px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
  }
  /* 카드가 하나뿐인 탭(생성)은 칸을 나누지 않고 한 폭을 다 쓴다 */
  .tab-panel.active > .card { grid-column: 1 / -1; }

  /* 조건 칸은 스크롤을 따라다닌다 — 결과를 내리면서 조건을 다시 만질 수 있게.
     화면보다 길어질 수 있으므로 칸 자체에 스크롤을 준다. */
  .col-side {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    scrollbar-width: thin;
  }

  /* 왼쪽 칸은 폭이 절반도 안 되니, 그 안에서는 가로로 늘어놓지 않는다 —
     '모든 계정에 서'처럼 단어가 잘려 읽히던 문제. */
  .col-side .radio-row { flex-direction: column; gap: 9px; padding: 6px 0; }
  .col-side .field-grid.three { grid-template-columns: 1fr 1fr; }

  /* 생성 결과는 넓은 화면에서 나란히 놓고 비교한다 */
  #generate-ideas {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 14px;
    align-items: start;
  }
}

@media (min-width: 1700px) {
  main, .header-inner, .tabs { max-width: 1680px; }
}
