/* ClauseCheck: 색은 모두 토큰으로 정의합니다. 포인트 색은 로즈 #BE123C (다크 모드에서는 더 밝은 #FB7185). */
:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --ink: #0F172A;
  --muted: #475569;
  --line: #E2E8F0;
  --line-strong: #CBD5E1;
  --accent: #BE123C;
  --accent-ink: #FFFFFF;
  --accent-soft: #FFF1F2;
  --focus: #BE123C;
  --serif: Georgia, "Times New Roman", "Noto Serif KR", "Nanum Myeongjo", "Batang", serif;
  --sans: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  /* 심각도 */
  --sev-high-ink: #9F1239;
  --sev-high-bg: #FFE4E6;
  --sev-high-mark: rgba(190, 18, 60, 0.16);
  --sev-mid-ink: #92400E;
  --sev-mid-bg: #FEF3C7;
  --sev-mid-mark: rgba(217, 119, 6, 0.22);
  --sev-low-ink: #334155;
  --sev-low-bg: #E2E8F0;
  --sev-low-mark: rgba(100, 116, 139, 0.22);
  --warn-ink: #7C2D12;
  --warn-bg: #FFF7ED;
  --radius: 1rem;
  --radius-sm: 0.6rem;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1220;
    --surface: #111A2E;
    --surface-2: #17223A;
    --ink: #E2E8F0;
    --muted: #B4C0D0;
    --line: #263247;
    --line-strong: #374257;
    --accent: #FB7185;
    --accent-ink: #1F0712;
    --accent-soft: #2A1420;
    --focus: #FDA4AF;
    --sev-high-ink: #FDA4AF;
    --sev-high-bg: #3A1522;
    --sev-high-mark: rgba(251, 113, 133, 0.28);
    --sev-mid-ink: #FCD34D;
    --sev-mid-bg: #3B2A0A;
    --sev-mid-mark: rgba(252, 211, 77, 0.22);
    --sev-low-ink: #CBD5E1;
    --sev-low-bg: #1E293B;
    --sev-low-mark: rgba(148, 163, 184, 0.25);
    --warn-ink: #FED7AA;
    --warn-bg: #2A1C10;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #111A2E;
  --surface-2: #17223A;
  --ink: #E2E8F0;
  --muted: #B4C0D0;
  --line: #263247;
  --line-strong: #374257;
  --accent: #FB7185;
  --accent-ink: #1F0712;
  --accent-soft: #2A1420;
  --focus: #FDA4AF;
  --sev-high-ink: #FDA4AF;
  --sev-high-bg: #3A1522;
  --sev-high-mark: rgba(251, 113, 133, 0.28);
  --sev-mid-ink: #FCD34D;
  --sev-mid-bg: #3B2A0A;
  --sev-mid-mark: rgba(252, 211, 77, 0.22);
  --sev-low-ink: #CBD5E1;
  --sev-low-bg: #1E293B;
  --sev-low-mark: rgba(148, 163, 184, 0.25);
  --warn-ink: #FED7AA;
  --warn-bg: #2A1C10;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.65;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
h1, h2, h3 { font-family: var(--serif); line-height: 1.25; margin: 0 0 0.6em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.75rem, 4.2vw, 2.75rem); }
h2 { font-size: clamp(1.45rem, 3vw, 2rem); }
h3 { font-size: 1.15rem; }
h4 { font-size: 1.05rem; margin: 0 0 0.5em; font-family: var(--sans); font-weight: 700; }
p { margin: 0 0 0.9em; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 1rem; top: -4rem; background: var(--surface); color: var(--ink);
  padding: 0.6rem 1rem; border-radius: var(--radius-sm); z-index: 100; box-shadow: var(--shadow);
}
.skip-link:focus { top: 0.75rem; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 760px; }
.section { padding: 64px 0; }
.section.alt { background: var(--surface-2); }
.section-kicker {
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; color: var(--accent);
  margin: 0 0 0.5rem; text-transform: none;
}
.section-sub { color: var(--muted); max-width: 46rem; }
.fine { font-size: 0.875rem; color: var(--muted); }
.status { font-size: 0.9rem; color: var(--muted); margin: 0; min-height: 1.2em; }

/* 상단 바 */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-height: 44px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-family: var(--serif); font-size: 1.2rem; font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-family: var(--serif); font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.topnav { display: none; gap: 4px; margin-left: 12px; }
.topnav a { color: var(--muted); text-decoration: none; padding: 10px 12px; border-radius: var(--radius-sm); min-height: 44px; display: inline-flex; align-items: center; }
.topnav a:hover { color: var(--ink); background: var(--surface-2); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.topbar-actions .btn { white-space: nowrap; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: 0.92rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.file-btn { position: relative; }
.file-btn input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

/* 히어로 */
.hero { padding: 56px 0 40px; background: radial-gradient(1200px 400px at 85% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.hero-inner { max-width: 820px; }
.eyebrow { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.9rem; }
.lead { font-size: 1.12rem; color: var(--muted); max-width: 40rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 22px 0 14px; }
.hero-note { font-size: 0.9rem; color: var(--muted); }

/* 카드 */
.card-grid { display: grid; gap: 16px; grid-template-columns: 1fr; margin-top: 28px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow);
}
.card p { color: var(--muted); margin: 0; }

/* 단계 */
.steps { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 16px; counter-reset: none; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; position: relative; }
.step h3 { margin-top: 6px; }
.step p { color: var(--muted); margin: 0; }
.step-num {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-family: var(--serif);
}

/* 점검 영역 */
.app-section { background: var(--bg); }
.disclaimer {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 18px; border-radius: var(--radius-sm);
  background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--line-strong); margin-bottom: 20px; font-size: 0.95rem;
}
.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab {
  min-height: 44px; padding: 10px 16px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 650; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.input-card, .result, .history-head, .history-list, .block {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.input-card { padding: 22px; display: grid; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.grow { flex: 1 1 220px; }
.field-row { display: flex; flex-wrap: wrap; gap: 14px; }
label { font-weight: 600; font-size: 0.95rem; }
.field > label { font-weight: 650; }
input[type="text"], input[type="password"], select, textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 10px 12px; min-height: 44px; width: 100%; max-width: 100%;
}
textarea { min-height: 220px; resize: vertical; font-family: var(--mono); font-size: 0.92rem; line-height: 1.6; white-space: pre-wrap; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--accent); }
.field-meta { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); }
.count { font-variant-numeric: tabular-nums; }
.input-actions, .inline-actions, .result-actions, .history-head .inline-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.options { border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 12px 16px; }
.options summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; }
.options > *:not(summary) { margin-top: 10px; }
.check-grid { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check-grid legend { font-weight: 650; margin-bottom: 6px; }
.check-grid label, .inline-check, .pick-list label {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 500; cursor: pointer;
}
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: 0 0 auto; }
.submit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.submit-row .btn.primary { min-width: 160px; }

/* 결과 */
.result { margin-top: 24px; padding: 22px; display: grid; gap: 18px; }
.result-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 14px; align-items: flex-start; }
.result-head h3 { margin: 0; }
.score-card { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; background: var(--surface-2); border-radius: var(--radius); padding: 18px; }
.score { display: flex; align-items: baseline; gap: 4px; min-width: 140px; }
.score-num { font-family: var(--serif); font-size: 3.4rem; font-weight: 700; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.score-of { color: var(--muted); font-weight: 600; }
.score-body { flex: 1 1 260px; min-width: 0; }
.score-grade { font-size: 1.05rem; margin-bottom: 8px; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0 0 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 0.88rem; font-weight: 650; min-height: 32px; }
.sev-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.sev-높음 { color: var(--sev-high-ink); background: var(--sev-high-bg); }
.sev-중간 { color: var(--sev-mid-ink); background: var(--sev-mid-bg); }
.sev-참고 { color: var(--sev-low-ink); background: var(--sev-low-bg); }
.chip.sev-높음, .chip.sev-중간, .chip.sev-참고 { font-weight: 650; }
.notice-warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 0.92rem; margin: 0; }

.result-grid { display: grid; gap: 18px; grid-template-columns: 1fr; align-items: start; }
.finding-panel, .contract-panel { min-width: 0; }
.finding-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; max-height: none; }
.finding-item {
  width: 100%; text-align: left; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; min-height: 44px;
  display: grid; gap: 4px;
}
.finding-item:hover { border-color: var(--line-strong); }
.finding-item[aria-current="true"] { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.finding-item .fi-title { font-weight: 650; }
.finding-item .fi-where { font-size: 0.85rem; color: var(--muted); }
.finding-item .fi-matched { font-size: 0.85rem; color: var(--muted); font-family: var(--mono); overflow-wrap: anywhere; }
.finding-empty { color: var(--muted); font-size: 0.95rem; }

.contract-view {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px; max-height: 520px; overflow: auto; font-size: 0.96rem; line-height: 1.8;
}
.contract-view .clause { margin: 0 0 14px; white-space: pre-wrap; position: relative; padding: 4px 6px; border-radius: 6px; }
.contract-view .clause.flash { animation: flash 1.6s ease-out; }
.contract-view .clause-no { font-size: 0.72rem; color: var(--muted); font-family: var(--mono); margin-right: 6px; user-select: none; }
mark.hl { color: var(--ink); background: var(--sev-low-mark); border-bottom: 2px solid var(--sev-low-ink); border-radius: 3px; padding: 0 1px; cursor: pointer; }
mark.hl.sev-높음 { background: var(--sev-high-mark); border-bottom-color: var(--sev-high-ink); }
mark.hl.sev-중간 { background: var(--sev-mid-mark); border-bottom-color: var(--sev-mid-ink); }
mark.hl.sev-참고 { background: var(--sev-low-mark); border-bottom-color: var(--sev-low-ink); }
mark.hl.active { outline: 2px solid var(--focus); }
@keyframes flash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }

.block { margin-top: 0; padding: 20px; display: grid; gap: 12px; }
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.checklist li { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.checklist .ck-title { font-weight: 650; }
.checklist .ck-why { grid-column: 2; font-size: 0.92rem; color: var(--muted); margin: 0; }
.checklist .ck-box { grid-row: span 2; font-family: var(--mono); color: var(--muted); }
.pick-list { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.pick-list legend { font-weight: 650; margin-bottom: 4px; }
.pick-list #nego-list, .pick-list #ai-items { display: grid; gap: 4px; }
.email-out { min-height: 260px; font-family: var(--sans); font-size: 0.95rem; white-space: pre-wrap; }
.preview-box { display: grid; gap: 6px; }
.preview-label { font-weight: 650; margin: 0; font-size: 0.92rem; }
.preview {
  margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm); padding: 12px; font-family: var(--mono); font-size: 0.85rem; max-height: 220px; overflow: auto; line-height: 1.55;
}
.preview.tall { max-height: 420px; }
.ai-block .notice-warn { margin-bottom: 0; }
.ai-out { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.ai-out li { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--bg); }
.ai-out .ai-label { font-size: 0.8rem; color: var(--muted); margin: 0 0 4px; font-weight: 650; }
.ai-out p { margin: 0 0 6px; white-space: pre-wrap; }

/* 이력 */
.history-head { padding: 18px; display: grid; gap: 12px; margin-bottom: 14px; }
.history-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0; overflow: hidden; }
.history-list li { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 18px; border-top: 1px solid var(--line); }
.history-list li:first-child { border-top: 0; }
.history-list .hi-title { font-weight: 650; margin: 0; }
.history-list .hi-meta { margin: 0; font-size: 0.88rem; color: var(--muted); }
.history-list .hi-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* 2열 레이아웃 (넓은 화면) */
@media (min-width: 900px) {
  .topnav { display: flex; }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .steps { grid-template-columns: repeat(3, 1fr); }
  .result-grid { grid-template-columns: 300px minmax(0, 1fr); }
  .finding-list { max-height: 560px; overflow: auto; padding-right: 4px; }
  .contract-view { max-height: 560px; }
  .section { padding: 84px 0; }
}
@media (min-width: 1200px) {
  .card-grid { grid-template-columns: repeat(4, 1fr); }
}

.footer { border-top: 1px solid var(--line); padding: 36px 0; background: var(--surface); }
.footer-inner { display: grid; gap: 18px; }
.footer-brand { margin: 0 0 4px; font-family: var(--serif); }
.faq { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 18px; margin-bottom: 12px; }
.faq summary { cursor: pointer; font-weight: 650; min-height: 56px; display: flex; align-items: center; }
.faq p { color: var(--muted); padding-bottom: 16px; margin: 0; }
@media (min-width: 900px) { .footer-inner { grid-template-columns: 1fr 1fr; } }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 90;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px); font-size: 0.95rem;
}

/* 인쇄: 결과 보고서만 남깁니다 */
#print-area { display: none; }
@media print {
  @page { margin: 16mm; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  body { background: #fff !important; color: #000 !important; }
  #print-pre { white-space: pre-wrap; font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; font-size: 11pt; line-height: 1.6; color: #000; margin: 0; }
}

/* 움직임 줄이기 */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 작은 화면 여백과 줄바꿈 보정 */
@media (max-width: 480px) {
  .hero { padding-top: 40px; }
  .brand-text small { display: none; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 8px 12px; font-size: 0.9rem; }
  .btn { white-space: normal; }
  .input-card, .result, .block { padding: 16px; }
}
