:root { --blue: #1f5fbf; --blue-soft: #e8f0fc; --bg: #f2f4f7; --ink: #1d2129; --muted: #667085; --line: #8a94a6;
  --tabs-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px); }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); padding-bottom: calc(var(--tabs-h) + var(--safe-b));
  font: 16px/1.6 "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; -webkit-tap-highlight-color: transparent; }

/* 위 막대: 앱 이름(문서를 열면 문서 이름) + [⋮] */
.bar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 8px 6px 14px;
  background: rgba(255,255,255,.96); backdrop-filter: blur(8px); border-bottom: 1px solid #e4e7ec; }
.top { flex: 1 1 100%; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 44px; }
.logo { width: 28px; height: 28px; border-radius: 7px; flex: none; }
.app-name { font-weight: 700; font-size: 17px; }
.bar:has(#title:not(:empty)) .app-name { display: none; }
#title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { margin-left: auto; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: none; color: var(--ink); cursor: pointer; }
.icon-btn[aria-expanded="true"], .icon-btn:active { background: var(--blue-soft); color: var(--blue); }
.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-btn .ic circle { fill: currentColor; stroke: none; }

/* 아래 탭: 늘 쓰는 다섯 가지. 문서가 없을 때 문서용 탭은 흐리게 */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: #fff; border-top: 1px solid #e4e7ec; }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: none;
  color: #475467; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.tab:active { color: var(--blue); background: var(--blue-soft); }
.tab:focus-visible { outline: 3px solid #f2b705; outline-offset: -3px; }
body.editing #edit { color: var(--blue); }
body:not(.has-doc) .tabs .doc-only { opacity: .35; pointer-events: none; }
.tab .ic circle { fill: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1px solid #d0d5dd; border-radius: 12px; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.sm { min-height: 36px; padding: 0 10px; font-size: 14px; }
.btn:disabled { opacity: .45; }
.btn:focus-visible, .ed:focus-visible { outline: 3px solid #f2b705; outline-offset: 2px; }
body:not(.has-doc) .more .doc-only { display: none; }
/* Word 는 서명·도장만 안 된다. 고치는 문단·찾은 곳은 문단에 칠한다 */
body.editing section.dx p { cursor: text; }
.para-mark-dx { background: rgba(31,95,191,.12) !important; outline: 1px solid rgba(31,95,191,.5); }
.find-mark-dx { background: rgba(242,183,5,.45) !important; }
.dx-wrapper { background: transparent !important; padding: 0 !important; display: flex; flex-direction: column; align-items: center; }
.dx-wrapper > section.dx { margin: 0 auto 14px !important; box-shadow: 0 1px 4px rgba(0,0,0,.18) !important; }
/* 링크로 보내기를 끈 배포판(app.js LINK_ON)에선 링크 안내·버튼을 숨기고 파일 첨부 안내만 */
body.no-link .link-only, body:not(.no-link) .file-only { display: none; }
body.no-link #send-file { background: var(--blue); border-color: var(--blue); color: #fff; }

/* 찾기·바꾸기 줄: 메뉴 줄 안 맨 아래 한 줄을 다 차지(메뉴와 같이 위에 붙어 있음) */
.findbar { flex: 1 0 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 8px; border-top: 1px solid #d5dbe5; }
.findbar[hidden] { display: none; }
.findbar input { flex: 1 1 140px; min-height: 40px; padding: 0 10px; border: 1px solid #c3cad6; border-radius: 8px; font: inherit; }
::highlight(find) { background: #ffd54f; color: #000; }

#title:empty { display: none; }
#doc { padding: 12px 8px 24px; }
.empty { max-width: 520px; margin: 28px auto; padding: 28px 20px 20px; background: #fff; border-radius: 20px; text-align: center;
  box-shadow: 0 1px 3px rgba(16,24,40,.08); }
.empty .hero { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 6px 18px rgba(31,95,191,.25); }
.empty h1 { margin: 16px 0 4px; font-size: 22px; }
.big-actions { display: grid; gap: 10px; margin: 20px 0 16px; }
.btn.big { min-height: 54px; font-size: 17px; border-radius: 14px; }
.draft { margin: 18px 0 0; padding: 14px; background: #fff7e0; border: 1px solid #f2d27a; border-radius: 14px; text-align: left; font-size: 15px; }
.draft p { margin: 0 0 10px; overflow-wrap: anywhere; }
.draft .btn { margin-right: 6px; }
.tips { margin: 0; padding: 14px 0 0 18px; border-top: 1px solid #eaecf0; text-align: left; font-size: 14px; color: #344054; }
.tips li { margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 14px; }

/* 원본 모양 보기(rhwp SVG): 쪽마다 종이 한 장, 화면 폭에 맞춰 줄임 */
.sheet { width: min(100%, calc(var(--w, 794) * 1px)); margin: 0 auto 14px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); overflow: hidden; }
.sheet > svg { display: block; width: 100%; height: 100%; }
/* 고치기: 편집 중엔 쪽을 누를 수 있게, 누른 문단·찾은 말은 쪽 위에 칠한다 */
.sheet { position: relative; }
body.editing .sheet { cursor: text; outline: 2px dashed #9db8e8; outline-offset: -2px; }
.para-mark, .find-mark { position: absolute; pointer-events: none; }
.para-mark { background: rgba(31,95,191,.12); outline: 1px solid rgba(31,95,191,.5); }
.find-mark { background: rgba(242,183,5,.45); }
.para-edit { position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 30; padding: 10px 12px; background: #fff; border-top: 1px solid #d5dbe5; box-shadow: 0 -4px 14px rgba(0,0,0,.12); }
.para-edit[hidden] { display: none; }
.para-edit textarea { width: 100%; box-sizing: border-box; min-height: 72px; max-height: 40vh; padding: 8px 10px; border: 1px solid #c3cad6; border-radius: 8px; font: inherit; font-size: 16px; resize: vertical; }
.para-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.para-btns .cell-only { display: flex; gap: 6px; margin-left: auto; }
.para-btns .cell-only[hidden] { display: none; }
.loading { text-align: center; color: var(--muted); padding: 40px 16px; }

/* 편집 화면(글자 고치기): A4 폭 종이 */
.page { max-width: 794px; margin: 0 auto 16px; padding: 48px 56px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15);
  font-size: 10pt; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; }
.para { min-height: 1em; }
.page table { border-collapse: collapse; width: 100%; margin: 4px 0; table-layout: auto; }
.page td { border: 1px solid var(--line); padding: 4px 6px; vertical-align: top; }
.page img { max-width: 100%; height: auto; }
@media (max-width: 600px) { .page { padding: 20px 16px; } }

.btn.install { border-color: var(--blue); color: var(--blue); }
.btn[hidden] { display: none; }

/* 설치 방법 창 */
.help { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.help[hidden] { display: none; }
.help-box { width: 100%; max-width: 440px; background: #fff; border-radius: 16px; padding: 20px; }
.help-box h2 { margin: 0 0 8px; font-size: 19px; }
.help-box ol { padding-left: 22px; margin: 8px 0 16px; }
.help-box li { margin-bottom: 6px; }
.sign-pad { display: block; width: 100%; aspect-ratio: 600 / 240; margin: 8px 0; border: 2px dashed #c3cad6; border-radius: 10px;
  background: #fff; touch-action: none; }
.check input[type=range] { flex: 1; width: auto; height: auto; }
/* 서명 넣기: 점선 틀째 끌어 옮기고, 오른쪽 아래 동그라미로 크기를 바꾼다 */
#sig-ghost { position: fixed; z-index: 40; border: 2px dashed #1f4e8c; border-radius: 6px; background: rgba(31, 78, 140, .06);
  touch-action: none; user-select: none; cursor: move; }
#sig-ghost[hidden], #sig-bar[hidden] { display: none; }
#sig-ghost .grip::after { content: ''; position: absolute; inset: -13px; border-radius: 50%; }  /* 손가락 닿는 곳 48px */
#sig-ghost img { display: block; width: 100%; height: 100%; pointer-events: none; }
#sig-ghost .grip { position: absolute; right: -14px; bottom: -14px; width: 28px; height: 28px; border-radius: 50%;
  background: #1f4e8c; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: nwse-resize; }
#sig-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  justify-content: center; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #fff; box-shadow: 0 -2px 8px rgba(0,0,0,.15); }
#sig-bar .muted { flex: 1 1 100%; text-align: center; margin: 0; }
.recent-list { list-style: none; padding: 0; margin: 8px 0 14px; }
.recent-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 0; border-bottom: 1px solid #e3e7ee; }
.recent-list .recent-name { flex: 1 1 100%; justify-content: flex-start; text-align: left; word-break: break-all; }
.about-box { max-height: 88vh; overflow: auto; }
.about-box h3 { margin: 14px 0 4px; font-size: 16px; }
.about-box p, .about-box ul { margin: 0 0 6px; font-size: 15px; }

/* 펴기 창: 사진 위 네 귀퉁이 동그라미 */
#crop { z-index: 30; }
.crop-box { max-width: 640px; }
.crop-stage { position: relative; display: inline-block; margin: 8px 0 14px; touch-action: none; user-select: none; }
.crop-stage canvas { display: block; max-width: 100%; max-height: 60vh; }
#crop-line { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#crop-line polygon { fill: rgba(31, 78, 140, .15); stroke: var(--blue); stroke-width: 2; }
.hd { position: absolute; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%; border: 3px solid var(--blue);
  background: rgba(255, 255, 255, .55); touch-action: none; cursor: grab; }

/* 스캔 창 */
#scan { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
#scan[hidden] { display: none; }
.scan-box { width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; background: #fff; border-radius: 16px 16px 0 0; padding: 18px 16px 24px; }
.scan-box h2 { margin: 0 0 12px; font-size: 19px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; margin: 12px 0; min-height: 44px; }
.check input { width: 22px; height: 22px; }
#pages { list-style: none; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
#pages li { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid #d5dbe5; border-radius: 10px; counter-increment: pg; }
#pages .pg-no { flex: 1; align-self: center; text-align: center; font-size: 14px; color: #344054; }
#pages img { width: 100%; height: 150px; object-fit: contain; background: #f3f4f6; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 12px); transform: translateX(-50%); z-index: 40; max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 10px; background: #1d2129; color: #fff; font-size: 15px; }

@media print {
  .para-mark, .find-mark, .para-edit { display: none !important; }
  @page { size: A4; margin: 15mm; }
  body { background: #fff; }
  .bar, .tabs, #title, #scan, #toast, .empty, #sig-ghost, #sig-bar { display: none !important; }
  body { padding: 0; }
  #doc { padding: 0; }
  .page { max-width: none; margin: 0; padding: 0; box-shadow: none; break-after: page; }
  .page:last-child { break-after: auto; }
  @page { margin: 0; }  /* 원본 쪽 그림에 여백이 들어 있다 */
  .sheet { width: 100%; margin: 0; box-shadow: none; break-after: page; break-inside: avoid; }
  .sheet:last-child { break-after: auto; }
  .dx-wrapper { zoom: 1 !important; }
  .dx-wrapper > section.dx { margin: 0 !important; box-shadow: none !important; break-after: page; }
  .dx-wrapper > section.dx:last-child { break-after: auto; }
}

/* [⋮]: 오른쪽 위에서 내려오는 메뉴 */
.more { position: absolute; right: 8px; top: 52px; z-index: 7; min-width: 180px; display: flex; flex-direction: column; padding: 6px;
  background: #fff; border-radius: 14px; box-shadow: 0 10px 30px rgba(16,24,40,.18); }
.more[hidden] { display: none; }
.more .btn { justify-content: flex-start; border: 0; border-radius: 10px; min-height: 46px; font-size: 15px; }
.more .btn:active { background: var(--blue-soft); }

.kakao-note { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: #fff4d6; border: 1px solid #f2b705; }

/* PDF: 찾기·바꾸기는 아직 없음. 쪽은 캔버스로 그린다 */
body.is-pdf .no-pdf { display: none !important; }
.pdf-sheet { background: #fff; }
.pdf-sheet canvas { display: block; width: 100%; height: 100%; }
