/* =============================================================
 * style.css — 사고조사 분석 보조 도구
 * 톤: 차분한 안전보고서. 실패=경보색(red), pivot=강조(amber).
 * ============================================================= */

:root {
  --bg:        #f4f6f8;
  --panel:     #ffffff;
  --ink:       #1b2733;
  --ink-soft:  #5a6b7b;
  --line:      #d7dee5;

  --change:    #2f7d8f;
  --event:     #2b4a6f;
  --pivot:     #d98a04;
  --fail:      #d23c3c;
  --root:      #6b3fa0;

  --lane-change:  #eef6f7;
  --lane-event:   #eef2f7;
  --lane-barrier: #f6eef0;

  --font: "Pretendard", "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* display:flex 등이 hidden 속성을 덮지 않도록 */
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---------- 상단바 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 28px;
  background: linear-gradient(180deg, #233649, #1b2b3b);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 30px; line-height: 1;
  width: 46px; height: 46px; display: grid; place-items: center;
  background: rgba(255,255,255,.08); border-radius: 12px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.topbar .tbd { font-size: 12px; opacity: .55; font-weight: 400; }
.tagline { margin: 3px 0 0; font-size: 13px; opacity: .78; }
.badge {
  font-size: 12px; padding: 7px 13px; border-radius: 999px;
  background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.18);
  white-space: nowrap;
}

/* ---------- 작업 영역 (2단) ---------- */
.workspace { display: flex; align-items: stretch; min-height: calc(100vh - 80px); }

/* 좌: 조사 패널 */
.panel {
  width: 392px; flex-shrink: 0;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 20px; overflow-y: auto;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 15px; }

.depth-stepper { display: flex; gap: 4px; font-size: 10.5px; }
.depth-stepper span {
  padding: 3px 8px; border-radius: 6px; color: #aab6c1;
  background: #f0f3f6; border: 1px solid var(--line);
}
.depth-stepper span.on { color: #fff; background: var(--event); border-color: var(--event); }
.depth-stepper span[data-lv="3"].on { background: var(--root); border-color: var(--root); }

/* 메모 입력 */
.step-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 7px; }
#memo {
  width: 100%; font-family: inherit; font-size: 13.5px; line-height: 1.6;
  padding: 12px; border: 1.5px solid var(--line); border-radius: 10px;
  resize: vertical; color: var(--ink); background: #fcfdfe;
}
#memo:focus { outline: none; border-color: var(--event); }

.memo-chip {
  font-size: 13px; line-height: 1.6; color: var(--ink-soft);
  background: #f3f6fa; border: 1px solid var(--line); border-left: 3px solid var(--event);
  border-radius: 8px; padding: 11px 13px; margin-bottom: 16px;
}
.chip-label { display: block; font-size: 10.5px; font-weight: 700; color: var(--event); margin-bottom: 4px; letter-spacing: .04em; }

/* 버튼 */
.btn {
  font-family: inherit; font-weight: 600; cursor: pointer;
  border-radius: 9px; border: 1.5px solid var(--line); background: var(--panel);
  color: var(--ink); transition: all .16s ease;
}
.btn.primary { width: 100%; margin-top: 11px; padding: 12px; font-size: 14px;
  background: var(--event); color: #fff; border-color: var(--event); }
.btn.primary:hover { background: #1f3a59; }
.btn.small { margin-top: 10px; padding: 8px 14px; font-size: 12.5px;
  background: var(--pivot); color: #fff; border-color: var(--pivot); }
.btn.small:hover { background: #c07c04; }
.btn.ghost { padding: 8px 13px; font-size: 12.5px; color: var(--ink-soft); }
.btn.ghost:hover { border-color: #b7c2cd; }

/* 질문 카드 */
.questions { display: flex; flex-direction: column; gap: 12px; }
.q-card {
  border: 1.5px solid var(--line); border-radius: 11px; padding: 13px 14px;
  background: #fcfdfe; animation: slideIn .35s ease;
}
.q-card.active { border-color: var(--pivot); box-shadow: 0 2px 10px rgba(217,138,4,.14); }
.q-card.done { background: #f4f7fa; opacity: .92; }
.q-head { display: flex; gap: 9px; align-items: flex-start; }
.q-icon {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff;
  background: var(--pivot);
}
.q-card.done .q-icon { background: #3a9d63; }
.q-prompt { font-size: 13.5px; font-weight: 600; line-height: 1.45; }
.q-why { font-size: 11.5px; color: var(--ink-soft); margin: 6px 0 0 29px; font-style: italic; }
.q-answer {
  width: 100%; margin-top: 10px; font-family: inherit; font-size: 12.5px; line-height: 1.55;
  padding: 9px 11px; border: 1.5px solid var(--line); border-radius: 8px;
  resize: vertical; background: #fff; color: var(--ink);
}
.q-answer:focus { outline: none; border-color: var(--pivot); }
.q-answer-done {
  font-size: 12.5px; color: var(--ink); line-height: 1.55; margin: 9px 0 0 29px;
  padding-left: 10px; border-left: 2px solid #cdd6df;
}
.q-effect { font-size: 11px; color: #b5730a; font-weight: 600; margin: 7px 0 0 29px; }

.q-complete {
  border: 1.5px dashed #8fbf9f; background: #eef6ef; border-radius: 11px;
  padding: 14px; font-size: 13px; color: #2e7d4f; text-align: center; line-height: 1.6;
}
.q-complete span { font-size: 11.5px; color: var(--ink-soft); }

.panel-controls { display: flex; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }

/* 우: 캔버스 영역 */
.canvas-wrap { flex: 1; min-width: 0; padding: 18px 28px 28px; }
.canvas-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 14px;
}
.canvas-head h2 { margin: 0; font-size: 16px; }
.summary { margin: 6px 0 0; color: var(--ink-soft); font-size: 14px; max-width: 60ch; min-height: 20px; }
.depth-wrap { text-align: right; flex-shrink: 0; }
.depth-caption { display: block; font-size: 11px; color: var(--ink-soft); margin-bottom: 5px; }
.depth-tag {
  display: inline-block; font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #f0f3f6; color: var(--ink-soft);
}
.depth-tag.shallow { background: #fdecec; color: var(--fail);  border-color: #f3c9c9; }
.depth-tag.mid     { background: #fff5e6; color: #b5730a;       border-color: #f0d9ad; }
.depth-tag.deep    { background: #eef6ef; color: #2e7d4f;       border-color: #c5e2cd; }

.canvas {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 8px; overflow-x: auto; box-shadow: 0 1px 3px rgba(27,39,51,.06); min-height: 420px;
}
.placeholder { display: grid; place-items: center; min-height: 404px; color: #aab6c1; font-size: 15px; }
.placeholder b { color: var(--event); }
.swimlane { width: 100%; height: auto; display: block; min-width: 720px; }

/* ---------- SVG: 레인 ---------- */
.lane-band { fill: transparent; }
.lane-change   .lane-band { fill: var(--lane-change); }
.lane-event    .lane-band { fill: var(--lane-event); }
.lane-barrier  .lane-band { fill: var(--lane-barrier); }
.lane-divider  { stroke: var(--line); stroke-width: 1; stroke-dasharray: 4 4; }
.lane-label    { font-size: 14px; font-weight: 700; fill: var(--ink); }
.lane-sublabel { font-size: 11px; fill: var(--ink-soft); }
.lane-change  .lane-label { fill: var(--change); }
.lane-event   .lane-label { fill: var(--event); }
.lane-barrier .lane-label { fill: var(--fail); }

/* ---------- SVG: 사건 흐름 ---------- */
.flow-arrow { stroke: #9fb0c0; stroke-width: 2.5; }
.arrow-head { fill: #9fb0c0; }
.event-node       { fill: var(--event); stroke: #fff; stroke-width: 3; }
.event-node.pivot { fill: var(--pivot); r: 21px; }
.event-time { font-size: 12px; font-weight: 700; fill: var(--ink-soft); }
.event-text { font-size: 12.5px; fill: var(--ink); }
.event.pivot .event-time { fill: var(--pivot); }

/* ---------- SVG: 연결선 / 카드 ---------- */
.connector { stroke: #c2ccd6; stroke-width: 1.5; stroke-dasharray: 3 3; }
.card rect { fill: var(--panel); stroke: var(--line); stroke-width: 1.2; }
.card-title { font-size: 12.5px; font-weight: 700; }
.card-body  { font-size: 11.5px; fill: var(--ink-soft); }

.change-card rect  { stroke: #bcd9de; fill: #f6fbfc; }
.change-card .card-title { fill: var(--change); }

.barrier-card.failed rect { stroke: #e6b3b3; fill: #fdf3f3; }
.barrier-card.failed .card-title { fill: var(--fail); }
.barrier-card.ok rect { stroke: #bcdcc4; fill: #f3faf5; }
.barrier-card.ok .card-title { fill: #2e7d4f; }

.fail-mark circle { fill: var(--fail); }
.fail-mark text   { fill: #fff; font-size: 13px; font-weight: 700; }

/* ---------- SVG: 원인 사다리 ---------- */
.ladder-spine { stroke: var(--ink-soft); stroke-width: 2; }
.ladder-arrow-head { fill: var(--ink-soft); }
.ladder-caption { font-size: 11.5px; fill: var(--ink-soft); font-style: italic; }

.ladder-box { fill: var(--panel); stroke-width: 1.6; }
.ladder-box.direct       { stroke: var(--event); fill: #f3f6fa; }
.ladder-box.contributing { stroke: var(--pivot); fill: #fff8ec; }
.ladder-box.root         { stroke: var(--root);  fill: #f5f0fb; }
.ladder-box.empty { stroke: #c7d0d9; stroke-dasharray: 6 5; fill: #fafbfc; }
.ladder-tag { font-size: 12px; font-weight: 800; letter-spacing: .02em; }
.ladder-tag.direct       { fill: var(--event); }
.ladder-tag.contributing { fill: #b5730a; }
.ladder-tag.root         { fill: var(--root); }
.ladder-body  { font-size: 13px; fill: var(--ink); }
.ladder-ghost { font-size: 12.5px; fill: #aab6c1; font-style: italic; }

/* ---------- 새로 채워진 요소 강조 ---------- */
.swimlane .is-new { animation: fadeUp .5s ease; }
.swimlane .is-new rect { animation: flash 1.5s ease; }
@keyframes fadeUp { from { opacity: 0; } to { opacity: 1; } }
@keyframes flash {
  0%   { filter: drop-shadow(0 0 0 transparent); }
  35%  { filter: drop-shadow(0 0 7px var(--pivot)); }
  100% { filter: drop-shadow(0 0 0 transparent); }
}
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 범례 ---------- */
.legend {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  margin-top: 14px; font-size: 12px; color: var(--ink-soft);
}
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.change { background: var(--change); }
.dot.event  { background: var(--event); }
.dot.pivot  { background: var(--pivot); }
.dot.fail   { background: var(--fail); }
.legend-note { margin-left: auto; font-style: italic; opacity: .8; }

.btn.small.report { background: var(--root); border-color: var(--root); }
.btn.small.report:hover { background: #5a3489; }

/* ---------- 보고서 모달 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,30,40,.55); display: flex;
  align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto;
}
.modal-box {
  background: var(--panel); width: 100%; max-width: 800px; border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; animation: slideIn .25s ease;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-sub { font-size: 12px; color: var(--ink-soft); font-weight: 400; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn.small { margin-top: 0; }

.report-body { padding: 26px 30px 36px; line-height: 1.65; font-size: 14px; color: var(--ink); }
.report-body h1 { font-size: 21px; margin: 0 0 6px; }
.report-body h2 { font-size: 16px; margin: 26px 0 8px; padding-bottom: 6px; border-bottom: 2px solid #eceff2; }
.report-body h3 { font-size: 14px; margin: 16px 0 6px; color: var(--event); }
.report-body p  { margin: 8px 0; }
.report-body ul { margin: 6px 0; padding-left: 22px; }
.report-body li { margin: 3px 0; }
.report-body blockquote {
  margin: 12px 0; padding: 10px 14px; background: #f7f4fb;
  border-left: 3px solid var(--root); border-radius: 6px; color: var(--ink-soft); font-size: 13px;
}
.report-body hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.report-body table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
.report-body th, .report-body td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.report-body th { background: #f3f6fa; font-weight: 700; }
.report-body tbody tr:nth-child(even) { background: #fafbfc; }

/* ---------- 상단바 우측 / 사용법 버튼 ---------- */
.topbar-right { display: flex; align-items: center; gap: 12px; }
.help-btn {
  font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  color: #fff; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
  padding: 7px 13px; border-radius: 999px; transition: background .15s ease;
}
.help-btn:hover { background: rgba(255,255,255,.22); }

/* ---------- 모드 토글 ---------- */
.mode-toggle { display: flex; gap: 6px; margin-bottom: 14px; background: #eef2f6; padding: 4px; border-radius: 10px; }
.mode-btn {
  flex: 1; font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 8px 10px; border-radius: 7px; border: none; background: transparent; color: var(--ink-soft);
  transition: all .15s ease;
}
.mode-btn.active { background: var(--panel); color: var(--event); box-shadow: 0 1px 3px rgba(27,39,51,.12); }

/* ---------- 오류 배너 ---------- */
.flow-error {
  margin-bottom: 12px; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; line-height: 1.5;
  background: #fdecec; color: var(--fail); border: 1px solid #f3c9c9;
}

/* ---------- 로딩 스피너 ---------- */
.spinner {
  width: 34px; height: 34px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid #dde4ea; border-top-color: var(--event); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 반응형 ---------- */
@media (max-width: 920px) {
  .workspace { flex-direction: column; }
  .panel { width: 100%; border-right: none; border-bottom: 1px solid var(--line); }
}
