/* =============================================================
   모바일 우선. 결재자 연령대를 고려해 글자와 터치 영역을 크게 잡는다.
   화면설계서 §6: 입력 필드 48px 이상, 버튼 터치 영역 44×44px 이상.
   ============================================================= */

:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #1d4ed8;
  --accent-weak: #eff6ff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --radius: 10px;

  /* 결재 단계별 색상 (화면설계서 S-03) */
  --role-applicant: #6b7280;
  --role-branch: #f59e0b;
  --role-director: #10b981;
  --role-sg: #3b82f6;
  --role-chair: #8b5cf6;
}

* { box-sizing: border-box; }

/*
 * ⚠ `hidden` 속성은 어떤 display 지정보다 우선한다.
 *
 * 브라우저 기본 스타일의 `[hidden] { display: none }` 은 **작성자 스타일에 무조건 진다.**
 * 그래서 `.modal { display: grid }` 같은 규칙 하나가 `hidden` 을 통째로 무력화한다.
 * 2026-07-31 에 실제로 그렇게 되어, 결재 화면을 열자마자 반려·보완 요청 모달이
 * 항상 떠 있었다. curl 검증은 HTML 에 `hidden` 이 있으니 통과했다.
 *
 * 앞으로 같은 실수를 원천 차단한다.
 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  /* iOS 노치 */
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── 헤더 · 푸터 ───────────────────────────────────────── */
.site-head {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}
.site-head .org { font-weight: 700; font-size: 15px; }

.site-foot {
  margin-top: 40px;
  padding: 20px 0 32px;
  color: var(--muted);
  font-size: 13px;
}
.site-foot p { margin: 0; }

main { padding-top: 20px; }

/* ── 진행률 ───────────────────────────────────────────── */
.steps { margin-bottom: 20px; }
.steps-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.steps-title { font-size: 20px; font-weight: 700; margin: 0; }
.steps-count { color: var(--muted); font-size: 14px; }
.steps-bar {
  height: 6px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.steps-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .25s ease;
}

/* ── 카드 ────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 16px;
}
.card > h2 {
  font-size: 16px;
  margin: 0 0 14px;
}

/* ── 폼 ──────────────────────────────────────────────── */
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }

.field > label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.req { color: var(--danger); margin-left: 2px; }

.field input[type="text"],
.field input[type="tel"],
.field input[type="email"],
.field input[type="date"],
.field select,
.field textarea {
  width: 100%;
  /* 화면설계서 §6: 48px 이상 */
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  /* 16px 미만이면 iOS 가 확대한다 */
  font-size: 16px;
  font-family: inherit;
}
.field textarea { min-height: 96px; resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.field .hint {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.field .err {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--danger);
  font-weight: 600;
}
.field.has-error input,
.field.has-error select { border-color: var(--danger); }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 420px) {
  .field-row { grid-template-columns: 1fr; }
}

/* ── 동의 + 서명 ──────────────────────────────────────── */
.agree {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  background: #fff;
}
.agree-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  /* 터치 영역 확보 */
  min-height: 44px;
  cursor: pointer;
}
.agree-check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 2px 0 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
}
.agree-check span { font-size: 14.5px; }

.sign-box { margin-top: 12px; }
.sign-canvas-wrap {
  position: relative;
  border: 2px dashed #94a3b8;
  border-radius: 8px;
  background: #fff;
  /* 서명하기 편한 높이 */
  aspect-ratio: 5 / 2;
  overflow: hidden;
  touch-action: none;
}
.sign-canvas-wrap.filled { border-style: solid; border-color: var(--ok); }
.sign-canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.sign-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #94a3b8;
  font-size: 15px;
  pointer-events: none;
}
.sign-canvas-wrap.filled .sign-placeholder { display: none; }

.sign-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

/* ── 버튼 ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 50px;
  min-width: 44px;
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1e40af; }
.btn-ghost { background: #fff; color: var(--text); border-color: #cbd5e1; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}
.actions .grow { flex: 1; }

/* 임시저장 — 눈에 보이는 버튼으로 둔다 (2026-07-30 확정) */
.save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 12px 14px;
  background: var(--accent-weak);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}
.save-bar .save-msg {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}
.save-bar .save-msg strong { color: var(--ok); }

/* ── 알림 상자 ────────────────────────────────────────── */
.note {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid;
}
.note-info  { background: var(--accent-weak); border-color: #bfdbfe; }
.note-warn  { background: #fffbeb; border-color: #fde68a; }
.note-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.note p:first-child { margin-top: 0; }
.note p:last-child { margin-bottom: 0; }

/* ── 결재선 미리보기 ──────────────────────────────────── */
.line-list { list-style: none; margin: 0; padding: 0; }
.line-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.line-list li:last-child { border-bottom: 0; }
.line-no {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 99px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--role-applicant);
}
.line-no.r-BRANCH_HEAD  { background: var(--role-branch); }
.line-no.r-ORG_DIRECTOR { background: var(--role-director); }
.line-no.r-SEC_GENERAL  { background: var(--role-sg); }
.line-no.r-CHAIR        { background: var(--role-chair); }
.line-role { font-size: 13px; color: var(--muted); }
.line-name { font-weight: 600; }
.line-merged { font-size: 12px; color: var(--muted); }

/* 신청자 화면은 역할만 보여 준다 (실명 비공개). 이때 역할이 그 줄의 본문이다. */
.line-list.roles-only .line-role { font-size: 15px; font-weight: 600; color: var(--text); }

/* ── 확인 요약 ────────────────────────────────────────── */
.summary { list-style: none; margin: 0; padding: 0; }
.summary li {
  display: flex;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.summary li:last-child { border-bottom: 0; }
.summary dt, .summary .k {
  flex: 0 0 92px;
  color: var(--muted);
  font-size: 14px;
}
.summary .v { flex: 1; font-weight: 500; word-break: break-all; }

/* ── 배지 ────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 99px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

/* ── 결재 화면 (S-03) ─────────────────────────────────── */
.approve-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.approve-receipt { margin: 0; font-size: 13px; color: var(--muted); }
.approve-title { margin: 2px 0 0; font-size: 20px; }
.approve-dday { margin: 6px 0 0; font-size: 13px; font-weight: 700; color: var(--muted); }
.approve-dday.over { color: var(--danger); }

.line-list li.line-current { background: var(--accent-weak); border-radius: 8px; padding-left: 8px; }
.line-comment { font-size: 13px; color: var(--muted); }
.line-when { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* 문서 미리보기 — 기본은 축소, [전체보기]에서 원래 폭 */
.doc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.doc-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  background: #fff;
  /* 세로로 다 펼치면 결재 버튼이 한참 아래로 밀린다 */
  max-height: 60vh;
  -webkit-overflow-scrolling: touch;
}
.doc-frame.zoomed { max-height: none; }
.doc-frame .form-page { width: 100%; }
.doc-frame.zoomed .form-page { width: 900px; max-width: none; }

/* ── 서명 선택 ────────────────────────────────────────── */
.sign-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
@media (max-width: 420px) {
  .sign-choice { grid-template-columns: 1fr; }
}
.sign-option {
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* 화면설계서 §6: 결재자 연령대를 고려한 큰 터치 영역 */
  min-height: 88px;
  padding: 12px;
  border: 2px solid #cbd5e1;
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.sign-option.selected { border-color: var(--accent); background: var(--accent-weak); }
.sign-option-title { font-weight: 700; }
.sign-option-preview { max-height: 54px; object-fit: contain; align-self: flex-start; }
.sign-option .hint { margin: 0; }
.sign-option-empty { border-style: dashed; }

/* ── 하단 액션 바 ─────────────────────────────────────── */
.action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 12px 0;
  margin-top: 18px;
  background: linear-gradient(to bottom, rgba(248,250,252,0), var(--bg) 30%);
}
.action-bar .grow { flex: 1; }
.btn-danger-text { color: var(--danger); }

/* ── 모달 ────────────────────────────────────────────── */
body.modal-open { overflow: hidden; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  background: rgba(15, 23, 42, .45);
  padding: 0;
}
@media (min-width: 560px) {
  .modal { place-items: center; padding: 20px; }
}
.modal-box {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow: auto;
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 560px) {
  .modal-box { border-radius: var(--radius); }
}
.modal-box h2 { margin: 0 0 12px; font-size: 18px; }

.radio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}
.radio-row input[type="radio"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* ── 결재함 (S-04) ────────────────────────────────────── */
.inbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.inbox-actions { display: flex; gap: 8px; }

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { border-bottom: 1px solid var(--line); }
.doc-list li:last-child { border-bottom: 0; }
.doc-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  /* 터치 영역 */
  min-height: 60px;
  padding: 10px 4px;
  color: inherit;
  text-decoration: none;
}
.doc-list li.is-late { background: #fffbeb; }
.doc-main { display: flex; flex-direction: column; }
.doc-name { font-weight: 700; }
.doc-sub { font-size: 13px; color: var(--muted); }
.doc-meta { display: flex; align-items: center; gap: 8px; }
.doc-days { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ── 상단 메뉴 ────────────────────────────────────────── */
.site-head .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.site-user { font-size: 13px; color: var(--muted); }

.site-nav {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
}
.site-nav .wrap {
  display: flex;
  gap: 4px;
  padding-top: 4px;
}
.site-nav a {
  /* 결재자 연령대를 고려한 터치 영역 */
  padding: 12px 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.site-nav a.on { color: var(--accent); border-bottom-color: var(--accent); }

/* ── 카운터 (S-01) ────────────────────────────────────── */
.counters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 520px) {
  .counters { grid-template-columns: repeat(2, 1fr); }
}
.counter {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: inherit;
  text-decoration: none;
}
.counter:hover { border-color: var(--accent); }
.counter-dot { width: 9px; height: 9px; border-radius: 99px; }
.counter-label { font-size: 13px; color: var(--muted); }
.counter-value { font-size: 24px; font-weight: 800; line-height: 1.1; }

/* ── 탭 · 필터 (S-04) ─────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.tabs a {
  padding: 10px 14px;
  border-radius: 99px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.tabs a.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.filter-bar input[type="search"] {
  flex: 1 1 180px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
}
.filter-bar select {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
  font-family: inherit;
}
.mini-select {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  font-family: inherit;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
}

/* ── 표 ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.mini-table th, .mini-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.mini-table th {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.mini-table .hint { margin: 0; font-size: 12px; }
.row-off { opacity: .5; }
.row-warn { background: #fffbeb; }

/* ── 타임라인 (S-05) ──────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.timeline li:last-child { border-bottom: 0; }
.timeline-when { flex: 0 0 84px; color: var(--muted); font-size: 13px; }
.timeline-what { flex: 1; }
.timeline-what .hint { display: inline; margin-left: 6px; font-size: 12px; }
.timeline-ip { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ── 관리자 ──────────────────────────────────────────── */
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.admin-nav a {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.admin-nav a:hover { border-color: var(--accent); color: var(--accent); }

/* 막대 그래프 — 사용자 이익대표자 추이 */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
  padding-top: 18px;
}
.bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  position: relative;
}
.bar-fill {
  width: 100%;
  min-height: 2px;
  background: var(--danger);
  border-radius: 3px 3px 0 0;
}
.bar-n { position: absolute; top: -16px; font-size: 11px; color: var(--muted); }
.bar-label { margin-top: 4px; font-size: 11px; color: var(--muted); }

/* ── 저장 서명 미리보기 ───────────────────────────────── */
.stored-sign {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  text-align: center;
}
.stored-sign img { max-width: 100%; max-height: 120px; object-fit: contain; }

/* ── 접수 완료 ────────────────────────────────────────── */
.receipt {
  text-align: center;
  padding: 24px 16px;
}
.receipt-no {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: .5px;
  margin: 12px 0;
  word-break: break-all;
}
