/* 오프라인 사용 전제 — 외부 폰트 없이 기기 시스템 글꼴을 쓴다.
   벵골어·태국어가 □ 로 보이면 태블릿에 Noto Sans Bengali / Noto Sans Thai 설치 필요 (README 참고) */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #5d6576;
  --line: #d9dde5;
  --primary: #2457c5;
  --primary-ink: #ffffff;
  --selected: #e7eefc;
  --error: #c62828;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans", "Noto Sans KR", "Malgun Gothic",
    "Noto Sans Thai", "Leelawadee UI", "Noto Sans Bengali", "Nirmala UI", "Vrinda", sans-serif;
  font-size: 19px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); -webkit-tap-highlight-color: transparent; }
.wrap { max-width: 880px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 1.5rem; margin: 0 0 16px; line-height: 1.35; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; }
.sub { color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); padding: 28px 24px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* 언어 선택 */
.lang-card { max-width: 560px; margin: 8vh auto 0; text-align: center; padding: 40px 28px; }
.lang-card h1 { font-size: 1.8rem; margin-bottom: 4px; }
.lang-form { display: grid; gap: 16px; margin-top: 28px; }
.lang-select {
  font-size: 1.35rem; font-weight: 600; padding: 18px 52px 18px 20px; min-height: 68px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath d='M5 7l5 6 5-6' fill='none' stroke='%235d6576' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 18px center;
}
.lang-start { font-size: 1.25rem; min-height: 68px; width: 100%; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 진행률 */
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); transition: width .3s; }
.progress-text { margin: 6px 0 14px; color: var(--muted); font-size: .9rem; text-align: right; }

/* 문항 */
.question { border: 0; padding: 0; margin: 0 0 30px; min-width: 0; }
.question legend { font-weight: 600; font-size: 1.1rem; margin-bottom: 10px; padding: 0; }
.qnum { color: var(--muted); font-weight: 500; }
.req { color: var(--error); margin-left: 2px; }
.help { color: var(--muted); font-size: .92rem; margin: -4px 0 10px; }
.options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; min-height: 56px;
  border: 2px solid var(--line); border-radius: 12px; cursor: pointer;
}
.option input { width: 26px; height: 26px; flex: 0 0 auto; accent-color: var(--primary); }
.option:has(input:checked) { border-color: var(--primary); background: var(--selected); }

.likert { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.likert-opt {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center;
  gap: 4px; padding: 12px 6px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; min-height: 96px;
}
.likert-opt input { position: absolute; opacity: 0; pointer-events: none; }
.likert-num { font-size: 1.4rem; font-weight: 700; }
.likert-label { font-size: .85rem; color: var(--muted); line-height: 1.3; }
.likert-opt:has(input:checked) { border-color: var(--primary); background: var(--primary); }
.likert-opt:has(input:checked) .likert-num, .likert-opt:has(input:checked) .likert-label { color: var(--primary-ink); }
.likert-opt:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

/* 리커트 슬라이더 (app.js 가 .slider-on 을 붙이면 버튼 대신 보인다) */
.likert-slider { display: none; --thumb: 34px; }
.likert-wrap.slider-on .likert { display: none; }
.likert-wrap.slider-on .likert-slider { display: block; }
.likert-slider-value { min-height: 1.5em; margin: 0 0 4px; text-align: center; font-weight: 700; color: var(--primary); }
.likert-slider-value:empty::before { content: attr(data-empty); font-weight: 400; color: var(--muted); }
/* 손잡이 중심이 아래 라벨 칸의 가운데에 오도록 막대 폭·위치를 맞춘다 */
.likert-slider input[type="range"] {
  -webkit-appearance: none; appearance: none; display: block; height: var(--thumb); margin: 0;
  width: calc(100% - 100% / var(--cols) + var(--thumb)); margin-left: calc(100% / var(--cols) / 2 - var(--thumb) / 2);
  background: transparent; cursor: pointer;
}
.likert-slider input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 99px; background: var(--line); }
.likert-slider input[type="range"]::-moz-range-track { height: 8px; border-radius: 99px; background: var(--line); }
.likert-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; box-sizing: border-box; width: var(--thumb); height: var(--thumb); margin-top: calc(4px - var(--thumb) / 2);
  border: 3px solid #fff; border-radius: 50%; background: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.likert-slider input[type="range"]::-moz-range-thumb {
  box-sizing: border-box; width: var(--thumb); height: var(--thumb);
  border: 3px solid #fff; border-radius: 50%; background: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.likert-slider input.untouched::-webkit-slider-thumb { opacity: 0; }
.likert-slider input.untouched::-moz-range-thumb { opacity: 0; }
.likert-slider input[type="range"]:focus-visible { outline: 3px solid var(--primary); outline-offset: 4px; border-radius: 99px; }
.has-error .likert-slider input[type="range"]::-webkit-slider-runnable-track { background: var(--error); }
.has-error .likert-slider input[type="range"]::-moz-range-track { background: var(--error); }
.likert-slider-labels {
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); margin-top: 4px;
  text-align: center; font-size: .8rem; line-height: 1.3; color: var(--muted); overflow-wrap: anywhere;
}
.likert-slider-labels b { display: block; font-size: 1.05rem; color: var(--text); }
.likert-slider-labels .on, .likert-slider-labels .on b { color: var(--primary); font-weight: 700; }
.likert-slider-labels .ko-sub { font-size: .7rem; }
.section-intro { margin: -6px 0 22px; padding: 12px 14px; background: var(--selected); border-radius: 10px; }

.input {
  font: inherit; width: 100%; padding: 14px 16px; border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
}
.input:focus { outline: none; border-color: var(--primary); }
.input-number { max-width: 220px; }
.unit { margin-left: 8px; color: var(--muted); }
.input-other { margin-top: 10px; }
.input-other[disabled] { display: none; }

.has-error .option, .has-error .likert-opt, .has-error .input { border-color: var(--error); }
.error { color: var(--error); font-weight: 600; margin: 8px 0 0; }
.error-summary { background: #fdecea; color: var(--error); padding: 12px 16px; border-radius: 10px; font-weight: 600; }

/* 한국어 병기 (조사원 확인용) */
.ko-sub { display: block; font-size: .78rem; font-weight: 400; color: #8a91a0; line-height: 1.35; margin-top: 2px; }
h1 .ko-sub { font-size: .95rem; margin-top: 4px; }
legend .ko-sub { margin-top: 4px; }
.likert-label .ko-sub { font-size: .72rem; }
.likert-opt:has(input:checked) .ko-sub { color: rgba(255,255,255,.8); }

/* 버튼 */
.actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; }
.wrap-actions { flex-wrap: wrap; justify-content: flex-start; }
.btn {
  font: inherit; font-weight: 600; padding: 16px 30px; min-height: 58px; min-width: 140px; border-radius: 12px;
  border: 2px solid transparent; cursor: pointer; text-decoration: none; text-align: center; display: inline-flex;
  align-items: center; justify-content: center;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--line); }
.btn[disabled] { opacity: .6; }
.start-over { text-align: center; margin-top: 22px; }
.start-over .link-home { margin: 0 auto; }
.link-home {
  font: inherit; font-size: .9rem; color: var(--muted); background: none; border: 0; text-decoration: underline;
  cursor: pointer; display: block; text-align: center; margin-top: 22px; padding: 10px;
}

.consent-body { white-space: pre-line; max-height: 55vh; overflow-y: auto; padding-right: 6px; }
.done { text-align: center; padding: 56px 24px; }
.done .btn { margin-top: 18px; }

/* 무입력 경고 */
.idle-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.idle-overlay[hidden] { display: none; }
.idle-box { background: #fff; border-radius: var(--radius); padding: 28px; max-width: 420px; text-align: center; }
.idle-count { font-size: 2.2rem; font-weight: 700; margin: 8px 0 18px; }

/* 언어 화면 우측 상단 '관리' 버튼 — 응답자 눈에 덜 띄게 작고 흐리게 */
.admin-link {
  position: fixed; top: 14px; right: 16px; z-index: 5; font-size: .85rem; color: var(--muted); text-decoration: none;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); opacity: .75;
}
.admin-link:hover, .admin-link:focus-visible { opacity: 1; color: var(--text); }

/* 관리자 */
.page-admin .wrap { max-width: 1400px; }
.page-admin .card { margin-top: 18px; }
.page-admin .card > h2:first-child { margin-top: 0; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.admin-head h1 { margin-bottom: 4px; }
.admin-head-actions { display: flex; gap: 10px; }
.admin-head-actions .btn { min-height: 46px; min-width: 0; padding: 10px 18px; font-size: .9rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card-head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card-head-actions .btn { min-height: 40px; min-width: 0; padding: 8px 16px; font-size: .88rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 18px 0; }
.stats div { background: var(--card); border-radius: 10px; padding: 14px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stats .stat-main { background: var(--primary); }
.stats .stat-main b, .stats .stat-main span { color: var(--primary-ink); }
.stats b { display: block; font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: .8rem; }
.stats small { display: block; margin-top: 2px; color: var(--muted); font-size: .75rem; }
.qr-dialog-image svg { display: block; width: 100%; height: auto; }
.qr-dialog { width: min(90vw, 520px); padding: 20px; border: 0; border-radius: 16px; text-align: center; cursor: zoom-out; }
.qr-dialog h2 { margin: 0 0 12px; font-size: 1.05rem; }
.qr-dialog h2 .sub { display: block; font-size: .85rem; font-weight: 400; }
.qr-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.qr-dialog-image { background: #fff; line-height: 0; }
.qr-dialog .qr-url { margin: 14px 0 4px; }
.qr-url code { font-size: 1.05rem; word-break: break-all; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.table-scroll { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 10px; }
.response-table thead th { position: sticky; top: 0; background: #eef1f6; z-index: 2; white-space: nowrap; }
.response-table td { min-width: 90px; max-width: 280px; }
.response-table tbody tr:nth-child(even) td { background: #fafbfc; }
.response-table tbody tr:hover td { background: var(--selected); }
.response-table .sticky-col { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
.response-table thead .sticky-col { z-index: 3; background: #eef1f6; }
.th-sub { display: block; font-weight: 400; font-size: .75rem; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.missing { font-size: .85rem; max-height: 240px; overflow-y: auto; }

@media (max-width: 600px) {
  :root { font-size: 17px; }
  .card { padding: 20px 16px; }
  /* 폰 폭: minmax(0,…) 로 칸 폭을 균등 고정해야 러시아어 긴 라벨이 화면 밖으로 밀리지 않는다 */
  .likert { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .likert-opt { min-height: 84px; padding: 8px 2px; }
  .likert-label { font-size: .8rem; overflow-wrap: anywhere; hyphens: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .btn { min-width: 0; padding: 14px 18px; flex: 1; }
}

/* 아주 좁은 폰: 척도를 세로 목록으로 (러시아어·벵골어 라벨이 단어 중간에서 끊기지 않게) */
@media (max-width: 480px) {
  .likert { grid-template-columns: 1fr; gap: 8px; }
  .likert-opt { flex-direction: row; align-items: center; text-align: left; gap: 14px; min-height: 56px; padding: 10px 16px; }
  .likert-num { font-size: 1.2rem; min-width: 1.2em; text-align: center; }
  .likert-label { font-size: .95rem; overflow-wrap: normal; hyphens: manual; }
  .likert-label .ko-sub { font-size: .78rem; }
}
