/* ==========================================================
   독서토론 준비 도구 - 화면용 스타일
   색상, 여백, 버튼/입력창 모양은 today-todo/css/style.css 의 값을 그대로 가져왔다.
   문서 작업 도구라 장식은 줄였다: 붉은 강조색 대신 --ink/--sat, 큰 둥근 카드 대신 얇은 테두리 면.
   ========================================================== */
@font-face { font-family: 'Paperlogy'; src: url('../fonts/Paperlogy-4Regular.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Paperlogy'; src: url('../fonts/Paperlogy-5Medium.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Paperlogy'; src: url('../fonts/Paperlogy-6SemiBold.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Paperlogy'; src: url('../fonts/Paperlogy-7Bold.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Paperlogy'; src: url('../fonts/Paperlogy-8ExtraBold.woff2') format('woff2'); font-weight: 800; font-style: normal; font-display: swap; }

:root {
  --font: 'Paperlogy', 'Pretendard', 'Noto Sans KR', sans-serif;

  --paper: #ECEEF5;
  --surface: #FFFFFF;
  --surface-2: #F5F5F8;
  --ink: #1A1B2E;
  --ink-soft: #8B8FA8;
  --ink-faint: #9CA3AF;
  --line: #F0F0F6;
  --line-strong: #E4E6F0;

  --sat: #2A3FA0;
  --sat-soft: #E7E9F7;
  /* 경고/주의 표시 - today-todo 의 --sun(주황)과 --accent-strong(진한 빨강)을 그대로 씀 */
  --sun: #F2A93C;
  --sun-soft: #FDF1DF;
  --danger: #C8294A;
  --ok: #1FCBA3;

  --shadow-card: 0 1px 2px rgba(26, 27, 46, 0.04), 0 10px 26px -14px rgba(26, 27, 46, 0.14);
  --shadow-lift: 0 20px 45px -20px rgba(26, 27, 46, 0.28);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 20px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--sat); }
.muted { color: var(--ink-soft); }
.small { font-size: 0.86rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- 상단 바 ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 24px;
  padding: 12px clamp(16px, 3vw, 32px);
}
.app-name { font-weight: 800; font-size: 1.05rem; text-decoration: none; color: var(--ink); white-space: nowrap; }
.topnav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topnav a {
  padding: 7px 12px; border-radius: 9px; text-decoration: none;
  color: var(--ink-soft); font-weight: 600; font-size: 0.92rem;
}
.topnav a:hover { background: var(--surface-2); color: var(--ink); }
.topnav a.active { background: var(--sat-soft); color: var(--sat); }

.main { max-width: 1200px; margin: 0 auto; padding: 28px clamp(16px, 3vw, 32px) 100px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.3; }
.page-head .sub { color: var(--ink-soft); font-size: 0.92rem; margin-top: 4px; }

/* ---------- 버튼 ---------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 9px;
  padding: 11px 18px; font-weight: 700; font-size: 0.92rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform .1s ease, background .15s ease, border-color .15s ease;
  min-height: 44px; white-space: nowrap; flex-shrink: 0; text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--sat); }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--ink-faint); }
.btn-quiet { background: transparent; color: var(--ink-soft); }
.btn-quiet:hover { color: var(--ink); background: var(--surface-2); }
.btn-danger { background: var(--surface); border-color: var(--line-strong); color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- 입력 ---------- */
.field { margin-bottom: 16px; }
.field > label, .field-label { display: block; font-size: 0.86rem; font-weight: 700; margin-bottom: 6px; color: var(--ink); }
.field .hint { font-size: 0.8rem; color: var(--ink-soft); margin-top: 5px; }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 10px; padding: 10px 12px; font-size: 0.95rem; color: var(--ink);
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.input-lg { font-size: 1.15rem; padding: 14px 16px; font-weight: 600; }
.input:focus, .textarea:focus, .select:focus, .btn:focus-visible, a:focus-visible, .choice input:focus-visible + span, [contenteditable]:focus {
  outline: 2px solid var(--sat); outline-offset: 2px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 760px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } }

/* 라디오/체크 선택지 */
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
  display: inline-flex; flex-direction: column; gap: 2px;
  padding: 9px 14px; border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 0.9rem;
}
.choice span small { font-weight: 400; color: var(--ink-soft); font-size: 0.78rem; }
.choice input:checked + span { border-color: var(--ink); background: var(--ink); color: #fff; }
.choice input:checked + span small { color: #D6D8E4; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.92rem; cursor: pointer; padding: 3px 0; }
.check input { width: 16px; height: 16px; accent-color: var(--ink); }

/* ---------- 면/섹션 ---------- */
.panel { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.section { margin-bottom: 32px; }
.section-title { font-size: 1.2rem; font-weight: 800; margin-bottom: 4px; }
.section-desc { font-size: 0.88rem; color: var(--ink-soft); margin-bottom: 14px; }
.sub-title { font-size: 1rem; font-weight: 700; margin: 18px 0 8px; }
.divider { border: 0; border-top: 1px solid var(--line-strong); margin: 20px 0; }
details.fold > summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
details.fold[open] > summary { margin-bottom: 10px; }

/* 상태 표시 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.74rem; font-weight: 700; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line-strong); white-space: nowrap;
}
.badge-ok { background: #E1FBF4; color: #0E6B55; border-color: #BFEFE2; }
.badge-warn { background: var(--sun-soft); color: #7A4A06; border-color: #F6DDB4; }
.badge-bad { background: #FDEAEF; color: var(--danger); border-color: #F7C9D4; }
.badge-info { background: var(--sat-soft); color: var(--sat); border-color: #D3D8F0; }
.notice { border: 1px solid var(--line-strong); border-left: 4px solid var(--sat); background: var(--surface); padding: 12px 16px; border-radius: 8px; font-size: 0.92rem; }
.notice-warn { border-left-color: var(--sun); background: #FFFBF4; }
.notice-bad { border-left-color: var(--danger); background: #FFF7F9; }
.notice + .notice { margin-top: 10px; }
.empty { color: var(--ink-soft); padding: 28px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); }

/* 표 */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line-strong); vertical-align: top; }
.table th { font-size: 0.8rem; color: var(--ink-soft); font-weight: 700; }

/* 목록 */
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain > li { padding: 12px 0; border-bottom: 1px solid var(--line-strong); }
.list-plain > li:last-child { border-bottom: 0; }
ul.bullets { margin: 4px 0; padding-left: 20px; }
ul.bullets li { margin: 3px 0; }

/* ---------- 홈 ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
@media (max-width: 980px) { .home-grid { grid-template-columns: 1fr; } }
.option-group { padding: 14px 0; border-top: 1px solid var(--line); }
.option-group:first-child { border-top: 0; padding-top: 0; }
.material-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.material-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropzone { border: 1px dashed var(--ink-faint); border-radius: 10px; padding: 16px; text-align: center; color: var(--ink-soft); background: var(--surface-2); font-size: 0.9rem; }
.dropzone.drag { border-color: var(--sat); background: var(--sat-soft); }

/* ---------- 진행 화면 ---------- */
.steps { list-style: none; padding: 0; margin: 0; }
.step { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; align-items: start; padding: 14px 0; border-bottom: 1px solid var(--line-strong); }
.step-mark { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-strong); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 800; color: var(--ink-faint); margin-top: 1px; }
.step.running .step-mark { border-color: var(--sat); color: var(--sat); }
.step.done .step-mark { background: var(--ink); border-color: var(--ink); color: #fff; }
.step.error .step-mark { border-color: var(--danger); color: var(--danger); }
.step.skipped { opacity: 0.55; }
.step-title { font-weight: 700; }
.step-detail { font-size: 0.86rem; color: var(--ink-soft); margin-top: 2px; }
.step-state { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.step.running .step-mark { animation: pulse 1.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .step.running .step-mark { animation: none; } }

/* ---------- 결과 대시보드 ---------- */
.book-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; align-items: start; }
/* 격자의 칸이 안의 표나 미리보기 폭 때문에 화면보다 넓어지지 않게 한다(min-width: 0) */
.book-layout > *, .print-layout > * { min-width: 0; }
@media (max-width: 900px) { .book-layout { grid-template-columns: minmax(0, 1fr); } .toc-panel { position: static !important; max-height: 11rem !important; } }
.book-layout.no-toc { grid-template-columns: minmax(0, 1fr); }
.print-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 1100px) { .print-layout { grid-template-columns: minmax(0, 1fr); } }
.toc-panel { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; font-size: 0.88rem; }
.toc-panel .toc-part { font-weight: 700; margin: 12px 0 4px; }
.toc-panel a { display: block; padding: 4px 8px; border-radius: 6px; text-decoration: none; color: var(--ink); }
.toc-panel a:hover { background: var(--surface-2); }
.toc-panel a.active { background: var(--sat-soft); color: var(--sat); }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line-strong); margin-bottom: 22px; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--ink-soft); font-weight: 600; font-size: 0.92rem; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); border-bottom-color: var(--ink); }
.book-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.88rem; color: var(--ink-soft); margin-top: 6px; }

.part-block { margin-bottom: 40px; }
.part-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border-bottom: 2px solid var(--ink); padding-bottom: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.part-head h2 { font-size: 1.3rem; font-weight: 800; }
.sec-block { padding: 18px 0 22px; border-bottom: 1px solid var(--line-strong); scroll-margin-top: 80px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sec-head h3 { font-size: 1.12rem; font-weight: 700; }
.core-q { margin: 8px 0 12px; padding: 10px 14px; background: var(--surface-2); border-radius: 8px; font-weight: 600; }
.item-label { font-size: 0.78rem; font-weight: 800; color: var(--ink-soft); letter-spacing: 0.02em; margin: 14px 0 6px; }
.claim { margin: 6px 0 10px; }
.claim .grounds { font-size: 0.9rem; color: #4A4E66; margin-top: 2px; }
.ai-note { border-left: 3px solid var(--ink-faint); padding: 2px 0 2px 12px; color: #4A4E66; font-size: 0.93rem; }
.ai-tag { font-size: 0.72rem; font-weight: 700; color: var(--ink-soft); border: 1px solid var(--line-strong); border-radius: 5px; padding: 0 5px; margin-right: 6px; white-space: nowrap; }
.speech { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 10px 14px; margin: 6px 0; }
.speech .kind { font-size: 0.76rem; font-weight: 700; color: var(--ink-soft); display: block; margin-bottom: 2px; }
.src-ref { font-size: 0.78rem; color: var(--sat); white-space: nowrap; }
.low-confidence { border-left: 3px solid var(--sun); padding-left: 12px; }
.regen-menu { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.editing [data-edit] { background: #FFFDF2; outline: 1px dashed var(--sun); border-radius: 4px; padding: 0 2px; cursor: text; }
.edited-mark { font-size: 0.7rem; color: #7A4A06; margin-left: 4px; }

/* ---------- 실시간 대응 ---------- */
.live-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .live-grid { grid-template-columns: 1fr; } }
.answer { border: 1px solid var(--line-strong); border-radius: 10px; padding: 14px 16px; background: var(--surface); margin-bottom: 10px; }
.answer-text { font-size: 1.02rem; line-height: 1.65; }
.answer-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- 모달, 토스트 ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 17, 26, 0.45); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; animation: fade-in 0.18s ease; }
.modal-sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: 14px; padding: 24px 22px; max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow-lift); animation: sheet-in 0.25s cubic-bezier(0.22, 1, 0.36, 1); }
.modal-title { font-size: 1.15rem; font-weight: 800; margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 0.9rem; box-shadow: var(--shadow-lift); animation: sheet-in 0.2s ease; max-width: 90vw; }
.toast.bad { background: var(--danger); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .modal-backdrop, .modal-sheet, .toast { animation: none; } }

/* ---------- 비밀번호 화면 ---------- */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate .panel { width: 100%; max-width: 380px; padding: 28px 24px; }
.gate h1 { font-size: 1.35rem; font-weight: 800; margin-bottom: 4px; }
.gate .sub { color: var(--ink-soft); font-size: 0.9rem; margin-bottom: 20px; }
.gate-error { font-size: 0.86rem; color: var(--danger); margin: -6px 0 12px; }

/* ---------- 인쇄 미리보기(화면) ---------- */
.print-preview { background: #D9DBE4; padding: 24px; border-radius: 10px; overflow: auto; max-height: 75vh; }
.print-preview .sheet { background: #fff; width: 210mm; min-height: 297mm; margin: 0 auto; padding: var(--print-margin, 14mm); box-shadow: var(--shadow-card); }
#print-root { display: none; }

/* ---------- 새 책 분석: 단계 제목, 조사 결과 보완 ---------- */
.step-title { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; font-weight: 800; margin: 4px 0 12px; }
.step-no { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 0.82rem; font-weight: 800; flex-shrink: 0; }
.mono { font-size: 0.86rem; line-height: 1.55; }
textarea.mono { font-family: var(--font); }
.is-missing { border-color: var(--sun); background: #FFFBF4; }
.is-missing-text { color: #7A4A06; }
.edit-item { display: grid; gap: 6px; padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); }
.edit-item .btn { justify-self: end; }
.pages-input { width: 150px; padding: 6px 10px; font-size: 0.85rem; }
.editor h3.sub-title:first-of-type { margin-top: 4px; }

/* ---------- 모바일(폭 760px 이하) ---------- */
@media (max-width: 760px) {
  /* 넓은 표는 표 안에서만 가로로 밀어 본다(화면 전체가 옆으로 밀리지 않게) */
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* 저장된 책 표는 한 줄이 카드 하나가 되도록 쌓는다 */
  .table.table-stack { display: block; overflow: visible; }
  .table-stack thead { display: none; }
  .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: auto; }
  .table-stack tr { border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; background: var(--surface); }
  .table-stack td { border-bottom: 0; padding: 3px 0; }
  .table-stack td[data-label]::before { content: attr(data-label) '  '; font-size: 0.74rem; font-weight: 700; color: var(--ink-soft); }
  .table-stack td.nowrap { white-space: normal; }
  /* 상단 바: 첫 줄에 이름과 로그아웃, 둘째 줄에 메뉴를 한 줄로(넘치면 옆으로 밀어서) */
  .topbar-inner { flex-wrap: wrap; gap: 4px 12px; padding: 8px 14px; }
  .app-name { order: 1; }
  #logoutBtn { order: 2; margin-left: auto; }
  .topnav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .topnav::-webkit-scrollbar { display: none; }
  .topnav a { white-space: nowrap; padding: 6px 10px; }
  .main { padding-top: 18px; }
  .page-head h1 { font-size: 1.4rem; }
  .panel { padding: 16px; }
  .tabs a { padding: 9px 11px; }
  .print-preview { padding: 10px; }
  .btn-row .btn { flex: 1 1 auto; }
}
