/* 예진이 — 종이 문진표 디자인 시스템 (2026-11)
   환자가 쓴 것은 볼펜 손글씨, 예진이가 정리한 것은 타이핑된 기록지.
   토큰·규칙 설명은 저장소 DESIGN.md 참고. */
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css');
@import url('https://fonts.googleapis.com/css2?family=Gowun+Batang:wght@400;700&family=Nanum+Pen+Script&display=swap');

:root {
  --desk: #e6ece8;          /* 접수대 바닥 */
  --paper: #fcfdfb;         /* 문진표 종이 */
  --paper-tint: #f0f5f1;    /* 서식 칸 머리 */
  --ink: #14211d;           /* 인쇄 잉크 */
  --ink-soft: #4b5b55;      /* 보조 글 */
  --rule: #c3d0c9;          /* 서식 줄 */
  --rule-strong: #7f948b;
  --green: #0e6b55;         /* 병원 초록 */
  --green-deep: #0a4f40;
  --pen: #1c3f94;           /* 환자 볼펜 */
  --stamp: #c4311f;         /* 도장 인주 */
  --marker: #ffe96b;        /* 형광펜 */
  --amber: #a85a05;

  --serif: 'Gowun Batang', 'Nanum Myeongjo', 'Noto Serif KR', serif;
  --sans: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --hand: 'Nanum Pen Script', 'Gowun Batang', cursive;

  /* 예전 변수 이름 — 아직 인라인으로 쓰는 곳이 있어 새 값에 묶어 둔다 */
  --primary: var(--green);
  --primary-dark: var(--green-deep);
  --emergency: var(--stamp);
  --urgent: var(--amber);
  --warning: #7a6200;
  --routine: var(--green);
  --bg: var(--desk);
  --surface: var(--paper);
  --border: var(--rule);
  --text: var(--ink);
  --text-muted: var(--ink-soft);
  --radius: 3px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--desk);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
a { color: var(--green-deep); }
button, input, textarea, select { font-family: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.9em; }

.hidden { display: none !important; }
.mt-auto { margin-top: auto; }
.mt-16 { margin-top: 16px; }
.num { font-variant-numeric: tabular-nums; }

/* ── 화면 틀 ─────────────────────────────── */
.page {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 16px 24px;
}
.page-wide { max-width: 1120px; padding: 0 28px 40px; }
.page-mid { max-width: 820px; }

/* 상단 줄: 로고와 화면 이동 */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 0 14px;
}
.wordmark {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: var(--serif); font-weight: 700; font-size: 19px;
  color: var(--ink); text-decoration: none; letter-spacing: -0.01em;
}
/* 병원 초록 십자 — 글자 대신 CSS로 그린다 */
.wordmark::before {
  content: ''; width: 18px; height: 18px; flex: none;
  background:
    linear-gradient(var(--green), var(--green)) center / 100% 34% no-repeat,
    linear-gradient(var(--green), var(--green)) center / 34% 100% no-repeat;
}
.topbar-links { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.textlink {
  background: none; border: none; cursor: pointer;
  font-size: 14px; color: var(--ink-soft); text-decoration: underline;
  text-decoration-color: var(--rule-strong); text-underline-offset: 3px;
  padding: 6px 8px;
}
.textlink:hover { color: var(--ink); text-decoration-color: var(--ink); }

/* 종이 한 장 */
.sheet {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 1px 0 #fff inset, 0 10px 24px -18px rgba(20, 33, 29, 0.55);
}
.sheet-pad { padding: 22px 22px 24px; }
.sheet + .sheet { margin-top: 16px; }

/* 서식 머리: 제목과 오른쪽 작은 칸 */
.form-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 20px 22px 14px;
  border-bottom: 2px solid var(--ink);
}
.form-title { font-family: var(--serif); font-weight: 700; font-size: 26px; line-height: 1.25; letter-spacing: -0.02em; }
.form-sub { font-size: 14px; color: var(--ink-soft); margin-top: 4px; }
.form-meta { font-size: 12.5px; color: var(--ink-soft); text-align: right; line-height: 1.5; white-space: nowrap; }
.form-meta b { color: var(--ink); font-weight: 600; }

/* 예전 헤더(.header) — 가운데 로고 묶음을 서식 제목으로 */
.header { padding: 26px 0 14px; text-align: left; }
.header .logo { display: none; }
.header h1 { font-family: var(--serif); font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; }
.header p { font-size: 15px; color: var(--ink-soft); margin-top: 6px; }

h1, h2 { font-family: var(--serif); letter-spacing: -0.02em; }

/* ── 버튼 ─────────────────────────────── */
.btn {
  display: block; width: 100%;
  padding: 15px 18px;
  border: 1.5px solid transparent; border-radius: 3px;
  font-size: 16px; font-weight: 650; line-height: 1.3;
  cursor: pointer; text-align: center; text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-primary:hover { background: var(--green-deep); border-color: var(--green-deep); }
.btn-ghost { background: transparent; border-color: var(--rule-strong); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); background: var(--paper); }
.btn-emergency, .btn-danger { background: var(--stamp); border-color: var(--stamp); color: #fff; }
.btn-danger:hover { background: #a02616; border-color: #a02616; }
.btn-emergency { font-size: 19px; padding: 19px; }
.btn-inline { display: inline-block; width: auto; padding: 9px 16px; font-size: 14px; }
.btn:disabled, .btn[disabled] {
  background: var(--paper-tint) !important; border-color: var(--rule) !important;
  color: #8b9a94 !important; cursor: not-allowed;
}

/* ── 입력 칸 ─────────────────────────────── */
.field, .field-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label, .field-row label { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.hint { font-size: 12.5px; font-weight: 400; color: var(--ink-soft); }
.input,
.field input, .field-row input {
  width: 100%;
  padding: 12px 12px; font-size: 16px;
  background: #fff; border: 1px solid var(--rule-strong); border-radius: 2px;
}
.input:focus, .field input:focus, .field-row input:focus, textarea:focus {
  outline: 2px solid var(--pen); outline-offset: 0; border-color: var(--pen);
}
input::placeholder, textarea::placeholder { color: #9aa8a2; }
input[type=checkbox] { accent-color: var(--green); width: 17px; height: 17px; flex: none; }

/* 파일 고르기 — 브라우저 기본 버튼을 서식 버튼으로 */
input[type=file] { padding: 9px; font-size: 14px; background: var(--paper-tint); border-style: dashed; cursor: pointer; }
input[type=file]::file-selector-button {
  margin-right: 12px; padding: 8px 14px; cursor: pointer;
  background: var(--paper); color: var(--ink); font: inherit; font-weight: 600; font-size: 13.5px;
  border: 1px solid var(--rule-strong); border-radius: 2px;
}

/* 탭 (로그인/회원가입, 약관) */
.auth-tabs, .tabs { display: flex; border-bottom: 2px solid var(--ink); margin-bottom: 22px; gap: 2px; }
.auth-tab, .tab {
  flex: 1; padding: 11px 12px 10px; cursor: pointer; text-align: center; text-decoration: none;
  font-size: 15px; font-weight: 600; color: var(--ink-soft);
  background: transparent; border: 1px solid transparent; border-bottom: none; border-radius: 3px 3px 0 0;
}
.auth-tab.active, .tab.active { color: var(--paper); background: var(--ink); }

.link-btn { background: none; border: none; color: var(--green-deep); font-size: 13.5px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; padding: 0; }
.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0; color: var(--ink-soft); font-size: 12.5px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--rule); }

/* 알림 한 줄 */
.msg { font-size: 14px; padding: 10px 12px 10px 14px; margin-bottom: 14px; border-left: 3px solid var(--rule-strong); background: var(--paper-tint); line-height: 1.55; }
.msg-err { border-left-color: var(--stamp); background: #fbeeeb; color: #7d1e12; }
.msg-ok { border-left-color: var(--green); background: #e8f3ee; color: var(--green-deep); }
.msg-info { border-left-color: var(--pen); background: #eef1f9; color: #1a3172; }

/* 유의 사항 상자 (※ 서식 안내) */
.disclaimer, .notice {
  border: 1px solid var(--rule-strong); background: var(--paper);
  padding: 14px 16px; font-size: 14px; line-height: 1.7; color: var(--ink);
  margin: 16px 0;
}
.disclaimer strong, .notice strong { font-weight: 700; }
.disclaimer > strong:first-child, .notice > strong:first-child { display: block; margin-bottom: 4px; }
.notice-warn { border-color: var(--stamp); border-left-width: 4px; }
.notice-ok { border-color: var(--green); border-left-width: 4px; }
.notice-err { border-color: var(--stamp); border-left-width: 4px; background: #fbeeeb; color: #7d1e12; }

/* 동의 칸 */
.consent-box { border: 1px solid var(--rule-strong); padding: 4px 14px; margin: 6px 0 16px; background: #fff; }
.consent-item { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; line-height: 1.6; cursor: pointer; padding: 10px 0; }
.consent-item + .consent-item { border-top: 1px dashed var(--rule); }
.consent-item input { margin-top: 3px; }
.consent-item .req { color: var(--stamp); font-weight: 600; }

/* 항목: 값 표 */
.kv { width: 100%; border-collapse: collapse; }
.kv th, .kv td { border-bottom: 1px solid var(--rule); padding: 11px 0; vertical-align: top; text-align: left; font-size: 15px; }
.kv th { width: 104px; padding-right: 12px; font-weight: 600; font-size: 13.5px; color: var(--ink-soft); white-space: nowrap; padding-top: 12.5px; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: none; }
.info-row { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--rule); font-size: 15px; }
.info-row:last-child { border-bottom: none; }
.info-row .label { color: var(--ink-soft); font-size: 13.5px; font-weight: 600; }
.info-row .value { font-weight: 500; text-align: right; overflow-wrap: anywhere; }

/* 장부 표 */
table.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
table.ledger th { text-align: left; padding: 8px 10px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); background: var(--paper-tint); border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule-strong); white-space: nowrap; }
table.ledger td { padding: 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }

.section-title { font-family: var(--serif); font-weight: 700; font-size: 19px; letter-spacing: -0.01em; margin: 0 0 12px; }
.loading { color: var(--ink-soft); padding: 36px 0; font-size: 15px; }
.empty { padding: 36px 0; color: var(--ink-soft); font-size: 15px; line-height: 1.7; }

/* ── 응급도 도장 ─────────────────────────────── */
.stamp, .badge {
  display: inline-block; padding: 3px 10px 2px;
  font-family: var(--serif); font-weight: 700; font-size: 14px; letter-spacing: 0.04em; line-height: 1.4;
  border: 2px solid currentColor; border-radius: 3px;
  transform: rotate(-2deg); background: transparent; white-space: nowrap;
}
.stamp-EMERGENCY, .badge-EMERGENCY { color: var(--stamp); }
.stamp-URGENT, .badge-URGENT { color: var(--amber); }
.stamp-WARNING, .badge-WARNING { color: var(--warning); }
.stamp-ROUTINE, .badge-ROUTINE { color: var(--green); }
.stamp-lg { font-size: 19px; padding: 6px 16px 4px; border-width: 3px; }

/* ── 통증 눈금 (NRS 0~10) ─────────────────────────────── */
.nrs { display: grid; grid-template-columns: repeat(11, 1fr); border: 1px solid var(--rule-strong); background: #fff; max-width: 420px; }
.nrs span, .nrs button {
  appearance: none; border: none; background: none; border-left: 1px solid var(--rule);
  text-align: center; padding: 7px 0; font-size: 13.5px; font-variant-numeric: tabular-nums; color: var(--ink-soft);
}
.nrs > :first-child { border-left: none; }
.nrs .on { background: var(--ink); color: #fff; font-weight: 700; }
.nrs-ends { display: flex; justify-content: space-between; max-width: 420px; font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.nrs-pick { max-width: none; }
.nrs-pick button { cursor: pointer; padding: 14px 0; font-size: 16px; color: var(--ink); }
.nrs-pick button:hover { background: var(--paper-tint); }
.nrs-pick button.on { background: var(--pen); color: #fff; }
.nrs-pick + .nrs-ends { max-width: none; }

/* ── 진료 기록지 (보고서) ─────────────────────────────── */
.chart .kv td { font-size: 15.5px; line-height: 1.65; }
.chart ul { list-style: none; }
.chart li { padding-left: 14px; position: relative; }
.chart li::before { content: '·'; position: absolute; left: 2px; font-weight: 700; }
.chart-ask { margin-top: 18px; padding: 16px 0 4px; border-top: 2px solid var(--ink); }
.chart-ask h3 { font-family: var(--serif); font-size: 17px; margin-bottom: 10px; }
.chart-ask li { padding: 0 0 0 30px; margin-bottom: 10px; font-size: 16px; line-height: 1.7; }
.chart-ask li::before { content: ''; left: 2px; top: 6px; width: 15px; height: 15px; border: 1.5px solid var(--ink); background: #fff; }
.chart-ask li span { background: linear-gradient(transparent 58%, var(--marker) 58%); padding: 0 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.chart-flag { display: flex; gap: 16px; align-items: flex-start; }
.chart-flag .stamp { flex: none; margin-top: 2px; }
.chart-flag small { display: block; color: var(--ink-soft); font-size: 14px; margin-top: 3px; }
.chart-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 36px; }
@media (max-width: 860px) { .chart-2col { grid-template-columns: 1fr; } }

/* 절취선 아래: 병원에 건네는 쪽지 */
.tear {
  margin-top: 4px; padding: 22px;
  border-top: 2px dashed var(--rule-strong); position: relative; background: var(--paper-tint);
}
.tear::before {
  content: '자르는 선'; position: absolute; top: -10px; left: 22px; padding: 0 8px;
  font-size: 11.5px; color: var(--ink-soft); background: var(--paper);
}
.tear h3 { font-family: var(--serif); font-size: 18px; margin-bottom: 4px; }
.qr-box { display: inline-block; padding: 12px; background: #fff; border: 1px solid var(--ink); line-height: 0; }
.qr-box canvas { max-width: 100%; height: auto !important; }

.report-footer, .fineprint {
  font-size: 12.5px; color: var(--ink-soft); line-height: 1.7;
  padding: 16px 2px 0; margin-top: 16px; border-top: 1px solid var(--rule);
}

/* 예전 보고서 칸(.report-section) — 관리자 화면 등에서 아직 쓴다 */
.report-wrap { padding: 0; }
.report-section { background: var(--paper); border: 1px solid var(--rule); border-radius: 3px; padding: 18px 20px; margin-bottom: 14px; }
.report-section h3 { font-family: var(--serif); font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.report-section p, .report-section li { font-size: 15px; line-height: 1.65; }
.report-section ul { padding-left: 18px; }

/* ── 문진 (채팅) ─────────────────────────────── */
.chat-wrap { flex: 1; display: flex; flex-direction: column; }
.progress-bar { height: 3px; background: var(--rule); }
.progress-fill { height: 100%; background: var(--ink); transition: width 0.3s ease; }
.messages { display: flex; flex-direction: column; padding: 6px 22px 8px; counter-reset: q; }

/* 질문은 인쇄된 문항, 답은 줄 위에 쓴 손글씨 */
.bubble { max-width: none; border-radius: 0; }
.bubble-ai {
  counter-increment: q; position: relative;
  padding: 16px 0 0 34px; font-size: 16.5px; font-weight: 600; line-height: 1.55;
}
.bubble-ai::before {
  content: counter(q) '.'; position: absolute; left: 0; top: 16px; width: 28px;
  font-family: var(--serif); font-weight: 700; font-variant-numeric: tabular-nums;
}
.bubble-user {
  margin: 4px 0 0 34px; padding: 2px 4px 1px;
  font-family: var(--hand); font-size: 25px; line-height: 1.35; color: var(--pen);
  border-bottom: 1px solid var(--rule-strong);
  animation: write 0.35s ease-out;
}
@keyframes write { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.input-area {
  position: sticky; bottom: 0; z-index: 2;
  margin-top: 18px; padding: 16px 22px 18px;
  background: var(--paper-tint); border-top: 2px solid var(--ink);
  display: flex; flex-direction: column; gap: 10px;
}
.input-area:empty { display: none; }
.choices { display: flex; flex-direction: column; max-height: 46vh; overflow-y: auto; border: 1px solid var(--rule-strong); background: #fff; }
.choice-btn {
  width: 100%; display: flex; align-items: flex-start; gap: 11px;
  padding: 12px 14px; text-align: left; font-size: 16px; line-height: 1.45;
  background: #fff; border: none; border-bottom: 1px solid var(--rule); cursor: pointer;
}
.choice-btn:last-child { border-bottom: none; }
.choice-btn::before {
  content: ''; flex: none; width: 17px; height: 17px; margin-top: 3px;
  border: 1.5px solid var(--ink); background: #fff;
}
@media (hover: hover) { .choice-btn:hover { background: var(--paper-tint); } }
.choice-btn.selected { background: #eef1f9; font-weight: 600; }
.choice-btn.selected::before {
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 17 17'%3E%3Cpath d='M2.5 8.5l4 4.5 8-10.5' fill='none' stroke='%231c3f94' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 15px no-repeat;
}
.input-note { font-size: 13.5px; color: var(--ink-soft); }

.slider-wrap { display: flex; flex-direction: column; gap: 4px; }
.text-input-wrap { display: flex; gap: 8px; align-items: stretch; }
.text-input-wrap textarea {
  flex: 1; min-width: 0; padding: 10px 12px; resize: none;
  font-family: var(--hand); font-size: 24px; line-height: 1.3; color: var(--pen);
  background: #fff; border: 1px solid var(--rule-strong); border-radius: 2px;
}
.text-input-wrap textarea::placeholder { font-family: var(--sans); font-size: 15px; }
.send-btn {
  flex: none; padding: 0 18px; font-size: 15px; font-weight: 650; cursor: pointer;
  background: var(--green); color: #fff; border: none; border-radius: 2px;
}
.send-btn:hover { background: var(--green-deep); }

/* ── 응급 안내 (전체 화면) ─────────────────────────────── */
.redflag-overlay {
  position: fixed; inset: 0; z-index: 100; overflow-y: auto;
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  padding: 32px max(24px, calc((100vw - 520px) / 2));
}
.redflag-overlay.EMERGENCY { background: var(--stamp); color: #fff; }
.redflag-overlay.URGENT { background: var(--amber); color: #fff; }
.redflag-overlay.WARNING { background: var(--marker); color: var(--ink); }
.redflag-overlay .flag-icon { display: none; }
.redflag-overlay h2 { font-size: 34px; line-height: 1.25; margin-bottom: 16px; }
.redflag-overlay p { font-size: 17px; line-height: 1.65; margin-bottom: 16px; }
.redflag-overlay .action { font-size: 19px; font-weight: 700; margin-bottom: 28px; }
.redflag-overlay .btn { max-width: 360px; }
.redflag-overlay .btn-emergency { background: #fff; color: var(--stamp); border-color: #fff; margin-bottom: 12px; }
.redflag-overlay .btn-plain { background: transparent; color: inherit; border-color: currentColor; }

/* ── 회사 정보 (모든 화면 아래) ─────────────────────────────── */
.site-footer {
  margin-top: 40px; padding: 18px 0 34px; border-top: 1px solid var(--rule);
  font-size: 12.5px; line-height: 1.75; color: var(--ink-soft);
}
.site-footer b { color: var(--ink); font-weight: 600; }
.site-footer a { color: var(--ink-soft); }
.site-footer nav { margin-bottom: 6px; display: flex; gap: 14px; flex-wrap: wrap; }

@media (max-width: 480px) {
  .page { padding: 0 12px 20px; }
  .form-head { padding: 16px 16px 12px; flex-direction: column; align-items: flex-start; gap: 6px; }
  .form-meta { text-align: left; white-space: normal; }
  .form-title { font-size: 23px; }
  .sheet-pad { padding: 18px 16px 20px; }
  .messages { padding: 4px 16px 8px; }
  .input-area { padding: 14px 16px 16px; }
  .tear { padding: 20px 16px; }
  .kv th { width: 78px; white-space: normal; }
  .page-wide { padding: 0 12px 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* 기록지가 한 단으로 이어질 때 두 표 사이 줄을 잇는다 */
.chart .kv tr:last-child th, .chart .kv tr:last-child td { border-bottom: 1px solid var(--rule); }
.btn + .btn { margin-top: 10px; }
.btn-inline + .btn-inline { margin-top: 0; }
