:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e3e5e9;
  --line-strong: #c9cdd3;
  --text: #1b1d21;
  --sub: #5f6670;
  --muted: #9aa0a8;
  --accent: #2563eb;
  --accent-soft: #e8effd;
  --accent-text: #1d4ed8;
  --ok: #e6f4ea; --ok-text: #1e6b34;
  --wait: #fdf3dc; --wait-text: #8a5a00;
  --no: #fde8e8; --no-text: #a32020;
  --gray: #eef0f2; --gray-text: #4b525b;
  --radius: 12px;
  --th: #e8eef7;
  --th-text: #33435c;
  --th-line: #cdd7e6;
  --hover: #f7f9fc;
  color-scheme: light;
}
/* 어두운 화면 (오른쪽 위 해/달 버튼) */
:root[data-theme="dark"] {
  --bg: #121418;
  --card: #1c1f25;
  --line: #2c3038;
  --line-strong: #3d424c;
  --text: #e8eaed;
  --sub: #a7adb6;
  --muted: #7b828c;
  --accent: #3b82f6;
  --accent-soft: #1d2a44;
  --accent-text: #8ab4ff;
  --ok: #173322; --ok-text: #7fd69a;
  --wait: #3a2e12; --wait-text: #f2c66d;
  --no: #3d1c1c; --no-text: #f39b9b;
  --gray: #2a2e35; --gray-text: #c3c8cf;
  --th: #252c37;
  --th-text: #c5cfdd;
  --th-line: #36404e;
  --hover: #252a32;
  color-scheme: dark;
}
:root[data-theme="dark"] .login-logo { mix-blend-mode: normal; background: #fff; border-radius: 8px; padding: 6px 10px; }
:root[data-theme="dark"] .btn.danger { border-color: #6b2b2b; }
.theme-btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; width: 36px; height: 36px; cursor: pointer;
  font-size: 18px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.theme-btn:hover { background: var(--gray); }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Pretendard, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
html { -webkit-tap-highlight-color: transparent; }
/* 내용이 짧은 쪽(설정·내 정보)에서 스크롤 막대가 사라져 메뉴가 옆으로 밀리지 않게 자리를 늘 비워 둔다 */
html { scrollbar-gutter: stable; }
@supports not (scrollbar-gutter: stable) { html { overflow-y: scroll; } }
a { color: var(--accent-text); text-decoration: none; }

/* 머리 */
#top { background: var(--nav-bg); border-bottom: 1px solid var(--nav-line); position: sticky; top: 0; z-index: 10; color: #fff; }
#top .in { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
#top .brand { font-weight: 700; font-size: 17px; color: #fff; }
#top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#top nav a { white-space: nowrap; padding: 6px 10px; border-radius: 8px; color: rgba(255,255,255,0.82); font-size: 15px; }
#top nav a.on { background: rgba(255,255,255,0.18); color: #fff; font-weight: 600; }
#top nav a:hover { background: rgba(255,255,255,0.12); color: #fff; }
#top .who { font-size: 14px; color: rgba(255,255,255,0.78); display: flex; gap: 10px; align-items: center; }

main { max-width: 1200px; margin: 0 auto; padding: 16px 16px 80px; }
main.narrow { max-width: 520px; }

/* 기본 부품 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.sub { color: var(--sub); font-size: 14px; }
.muted { color: var(--muted); font-size: 13px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 14px; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--card);
  border-radius: 10px; padding: 9px 14px; cursor: pointer; font-size: 15px; white-space: nowrap; }
.btn:hover { background: var(--gray); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(0.95); }
.btn.danger { color: var(--no-text); border-color: #f0b8b8; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; }
.btn.small { padding: 5px 10px; font-size: 14px; border-radius: 8px; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns.two { display: grid; grid-template-columns: 1fr 1fr; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 14px; font-weight: 600; color: var(--th-text); margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; background: var(--card); font-size: 16px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; }

/* ---------- 아이폰(사파리) 보정 ----------
   사파리는 입력칸에 자기 모양(둥근 그림자, 고정 최소 너비, 가운데 정렬 날짜)을 입혀서
   두 칸짜리 줄에서 칸이 넘치거나 높이가 들쭉날쭉해진다. 기본 모양을 걷어내고 크기를 고정한다. */
input, select, textarea, button { -webkit-appearance: none; appearance: none; }
input, select, textarea { border-radius: 10px; }
input[type=checkbox] { -webkit-appearance: auto; appearance: auto; }
input, select, textarea { min-width: 0; max-width: 100%; box-shadow: none; -webkit-text-fill-color: currentColor; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select {
  height: 46px; line-height: 1.25;
}
input[type=date], input[type=time] { display: block; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; min-height: 1.25em; }
input::-webkit-datetime-edit { padding: 0; }
input::-webkit-inner-spin-button, input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
input[disabled], textarea[disabled], select[disabled] { opacity: 1; -webkit-text-fill-color: var(--sub); color: var(--sub); background: var(--gray); }
select {
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23888' stroke-width='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
label.f { min-width: 0; }
label.f > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 아주 좁은 아이폰(SE·미니)에서는 한 줄에 한 칸 */
@media (max-width: 345px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
/* 아이폰 홈 막대(아래쪽)와 노치에 가리지 않게 */
main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
#top .in { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

.tag { display: inline-block; padding: 2px 9px; border-radius: 7px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.tag.ok { background: var(--ok); color: var(--ok-text); }
.tag.wait { background: var(--wait); color: var(--wait-text); }
.tag.no { background: var(--no); color: var(--no-text); }
.tag.gray { background: var(--gray); color: var(--gray-text); }
.tag.blue { background: var(--accent-soft); color: var(--accent-text); }

/* 출석 스위치 */
.toggle-line { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle-line:last-child { border-bottom: 0; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 8px 14px; cursor: pointer; font-size: 15px; color: var(--sub); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.seg button.on.absent { background: #6b7280; }
.chip { border: 1px solid var(--line-strong); background: var(--card); border-radius: 8px; padding: 4px 10px; font-size: 14px; cursor: pointer; color: var(--sub); min-width: 46px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.weeknav { display: inline-flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.weeknav button { border: 0; background: none; padding: 6px 10px; cursor: pointer; font-size: 16px; color: var(--sub); border-radius: 8px; }
.weeknav button:hover { background: var(--gray); }
.weeknav button[disabled] { opacity: 0.3; cursor: default; background: none; }
.seg button[disabled] { cursor: default; }
.seg button[disabled]:not(.on) { color: var(--muted); }
textarea[disabled] { background: var(--gray); color: var(--sub); }
.weeknav span { font-weight: 600; font-size: 15px; padding: 0 4px; }

/* 구역장 명단 */
.member { padding: 12px 0; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; }
.member .nm { font-weight: 600; }
.member .pr { font-size: 14px; color: var(--sub); margin-top: 4px; white-space: pre-wrap; }
.member textarea { margin-top: 8px; min-height: 60px; }

.visit-check { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 12px; cursor: pointer; font-weight: 600; }
.visit-check input { width: 22px; height: 22px; margin: 0; accent-color: var(--wait-text); }
.visit-check.on { background: var(--wait); border-color: var(--wait-text); color: var(--wait-text); }
.notice { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 15px; }
.notice.wait { background: var(--wait); color: var(--wait-text); }
.notice.no { background: var(--no); color: var(--no-text); }
.notice.ok { background: var(--ok); color: var(--ok-text); }
.notice.blue { background: var(--accent-soft); color: var(--accent-text); }

/* 컴퓨터 화면 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat-btn { text-align: left; cursor: pointer; font: inherit; color: inherit; }
.stat-btn:hover { border-color: var(--accent); }
.stat-btn .k { color: var(--accent-text); }
.panel { max-width: 560px; }
.stat { padding: 0; overflow: hidden; }
.stat .k { color: var(--th-text); font-size: 14px; font-weight: 600; background: var(--th); padding: 6px 14px; border-bottom: 1px solid var(--th-line); }
.stat .v { padding: 8px 14px 10px; }
/* 항목 이름 칸: 값과 구분되게 바탕색을 깐다 */
.lbl { display: inline-block; font-size: 13px; font-weight: 600; color: var(--th-text); background: var(--th); border-radius: 6px; padding: 1px 8px; margin-bottom: 4px; }
.card > h2, .card > .row > h2 { color: var(--th-text); }
.card > h2 { background: var(--th); margin: -16px -16px 14px; padding: 10px 16px; border-bottom: 1px solid var(--th-line); border-radius: var(--radius) var(--radius) 0 0; }
.stat .v { font-size: 24px; font-weight: 700; }
.tbl-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
table.tbl th { text-align: left; font-weight: 600; color: var(--th-text); font-size: 14px; background: var(--th); border-bottom: 1px solid var(--th-line) !important; }
table.tbl th, table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr.click { cursor: pointer; }
table.tbl tr.click:hover td { background: var(--hover); }
table.tbl td.wrap { white-space: pre-wrap; min-width: 200px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

table.tbl input[type=checkbox] { width: 20px; height: 20px; }
@media (max-width: 1000px) {
  table.tbl th, table.tbl td { padding: 12px 8px; }
  table.tbl .opt { display: none; }
}
.split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.loglist { font-size: 14px; }
.loglist div { padding: 6px 0; border-bottom: 1px solid var(--line); }

.panel-bg { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,0.35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.panel { background: var(--card); border-radius: 14px; padding: 18px; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; }

.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { font-size: 24px; text-align: center; margin-bottom: 4px; }
.login .sub { text-align: center; margin-bottom: 20px; }
.login-logo { display: block; width: 120px; height: auto; margin: 20px auto 0; mix-blend-mode: multiply; }

/* ---------- 인쇄 양식 (A4 세로) ---------- */
#print-area { display: none; }
.sheet { width: 190mm; min-height: 270mm; margin: 0 auto 10mm; background: #fff; color: #000; font-family: "Malgun Gothic", Pretendard, sans-serif;
  font-size: 10.5pt; padding: 4mm 0; page-break-after: always; break-after: page; position: relative; }
.sheet:last-child { page-break-after: auto; break-after: auto; }
.sheet table { border-collapse: collapse; width: 100%; }
.sheet td, .sheet th { border: 1px solid #000; padding: 1.5mm 2mm; font-weight: 400; vertical-align: middle; }
.sheet .head { display: grid; grid-template-columns: 46mm 1fr 46mm; align-items: center; gap: 3mm; margin-bottom: 3mm; }
.sheet .head h1 { font-size: 19pt; font-weight: 700; letter-spacing: 0.6mm; text-align: center; margin: 0; white-space: nowrap; }
.sheet .lab { width: 16mm; text-align: center; font-size: 9pt; white-space: nowrap; padding-left: 1mm; padding-right: 1mm; }
.sheet .box { border: 2px solid #000; }
.sheet .info td { height: 8mm; }
.sheet .visit td { height: 18mm; }
.sheet .list th { font-size: 9.5pt; height: 9mm; }
.sheet .list td { height: 8.6mm; font-size: 10pt; }
.sheet .list .no { width: 7mm; text-align: center; font-size: 9pt; }
.sheet .list .nm { width: 26mm; }
.sheet .list .att { width: 11mm; text-align: center; white-space: nowrap; padding: 0; }
.sheet .list .pr { font-size: 9pt; line-height: 1.25; }
.sheet .foot { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 3mm; font-size: 9pt; }
.sheet .foot .church { display: flex; align-items: flex-end; gap: 2mm; }
.sheet .foot .church-name { font-size: 15pt; font-weight: 700; color: #444; letter-spacing: 0.5mm; }
.login-church { text-align: center; margin-top: 20px; font-size: 17px; font-weight: 700; color: var(--sub); }
.ci-box { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; border: 1px dashed var(--line-strong); border-radius: 10px;
  padding: 12px; margin: 4px 0 8px; background: #fff; }
.ci-box img { max-height: 56px; max-width: 100%; }
.ci-box .ci-name { font-size: 18px; font-weight: 700; color: #444; }
.sheet .foot .church img { height: 14mm; width: auto; display: block; }

.print-preview #print-area { display: block; }
.print-preview #app, .print-preview #top { display: none; }
.print-bar { position: sticky; top: 0; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; gap: 8px; justify-content: center; z-index: 5; }
.print-preview body, body.print-preview { background: #e5e7eb; }

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  body { background: #fff !important; }
  .no-print, .print-bar, #app, #top { display: none !important; }
  #print-area { display: block !important; }
  .sheet { margin: 0; min-height: auto; }
}

@media (max-width: 600px) {
  #top .in { gap: 8px; padding: 8px 12px; }
  #top nav { order: 3; flex: 0 0 100%; overflow-x: auto; flex-wrap: nowrap; }
  #top .who { flex: 1; justify-content: flex-end; font-size: 13px; }
  main { padding: 12px 12px 80px; }
}

/* 위쪽 메뉴 띠: 본문과 구분되는 짙은 남색 */
:root { --nav-bg: #1e3a6e; --nav-line: #16305c; }
:root[data-theme="dark"] { --nav-bg: #18233a; --nav-line: #2a3a5a; }
#top .who a { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
#top .theme-btn { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.3); }
#top .theme-btn:hover { background: rgba(255,255,255,0.22); }

/* 한 가지 색 아이콘: 글자 색을 그대로 따른다 */
.ti { font-size: 1.1em; vertical-align: -0.12em; line-height: 1; }
#top nav a .ti { margin-right: 2px; }
h1 .ti { color: var(--accent-text); margin-right: 2px; }
.theme-btn .ti { font-size: 18px; vertical-align: 0; color: #fff; }
.pager { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.pager .btn.small { min-width: 36px; }
.install-btn { margin-top: 12px; color: var(--accent-text); border-color: var(--accent); }
.install-steps { padding-left: 20px; margin: 8px 0 12px; line-height: 1.8; }
.install-steps .ti { font-size: 1.2em; }
/* 작은 보조 버튼 (지난주 것 가져오기 등) */
.btn.tiny { padding: 3px 9px; font-size: 13px; border-radius: 7px; gap: 4px; color: var(--accent-text); border-color: var(--line-strong); }
.btn.tiny .ti { font-size: 14px; }
.tag.answered { font-size: 12px; padding: 1px 7px; vertical-align: 1px; }
.btn.tiny.ans.on { color: var(--ok-text); border-color: var(--ok-text); background: var(--ok); }
/* 동그란 아바타 */
.av { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; object-fit: cover; flex: none;
  vertical-align: middle; background: var(--gray); }
.av-init { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; line-height: 1; }
.me-card { display: flex; gap: 14px; align-items: center; }
.crop-canvas { width: 280px; height: 280px; max-width: 100%; border-radius: 12px; touch-action: none; cursor: grab; background: #000; }
.nm-wrap { display: inline-flex; align-items: center; gap: 8px; vertical-align: middle; }
#top .who .av { border: 1px solid rgba(255,255,255,0.5); }
/* 크기 막대는 기본 모양을 살린다 (아이폰 보정에서 입력칸 모양을 걷어낼 때 함께 지워지지 않게) */
input[type=range] { -webkit-appearance: auto; appearance: auto; height: auto; accent-color: var(--accent); }
@media (max-width: 600px) {
  #top .who .where { display: none; } /* 휴대폰에서는 교구·구역을 빼고 이름만 */
  #top .who { white-space: nowrap; }
}
/* 켜고 끄는 스위치 */
.switch-line { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
input.switch { -webkit-appearance: none; appearance: none; flex: none; width: 50px; height: 30px; border-radius: 999px; background: var(--line-strong);
  position: relative; cursor: pointer; transition: background .15s; border: 0; }
input.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .15s; }
input.switch:checked { background: var(--accent); }
input.switch:checked::after { left: 23px; }
/* 10인치 태블릿 세로(폭 800 안팎): 메뉴 한 줄, 숫자 카드 한 줄 */
@media (max-width: 900px) {
  #top .in { gap: 10px; }
  #top nav a { padding: 6px 8px; font-size: 14px; }
  #top .who .where { display: none; }
  #top .who { white-space: nowrap; font-size: 13px; }
  .stat .v { font-size: 20px; white-space: nowrap; }
}
