:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #f5a400;
  --brand-ink: #1c1f24;
  --accent: #1f5fbf;
  --mark: #ffe58a;
  --law: #1f5fbf;
  --admrul: #7a3fbf;
  --kosha: #0f8a5f;
  --danger: #c0392b;
  --radius: 12px;
  --tabbar-h: 60px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1c1f24;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #2d3137;
    --mark: #7a5d00;
    --law: #7fb0ff;
    --admrul: #c49bff;
    --kosha: #4fd1a1;
    --accent: #7fb0ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  padding-bottom: calc(var(--tabbar-h) + var(--ad-h, 0px) + env(safe-area-inset-bottom)); /* --ad-h: 앱 하단 배너 광고 높이 */
}
a { color: var(--accent); }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  min-height: 52px; padding: env(safe-area-inset-top) 12px 0;
  background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: none; color: inherit; padding: 8px; margin-left: -8px; border-radius: 50%; }

main { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; overflow-x: clip; }
/* 별표의 표 선(────)·점선(……)처럼 끊을 곳 없는 긴 글자가 화면 폭을 넓히지 않게(넓어지면 아래 탭 메뉴가 화면 밖으로 밀림) */
.card, .hit, .card h3, .news-item .t, .recent-item .t, .inq-text, .sec h4 { overflow-wrap: anywhere; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px;
}
.tabbar a.active { color: var(--text); font-weight: 700; }
.tabbar a.active svg { stroke: var(--brand); stroke-width: 2.2; }

/* 검색 */
.searchbox { position: sticky; top: 52px; z-index: 5; background: var(--bg); padding: 4px 0 8px; margin-top: -4px; }
.searchbox form { display: flex; gap: 8px; }
.searchbox input {
  flex: 1; min-width: 0; font-size: 17px; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text);
}
.searchbox input:focus { outline: none; border-color: var(--brand); }
.btn {
  border: 0; border-radius: var(--radius); padding: 0 16px; min-height: 44px;
  background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 15px;
}
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; text-decoration: none;
}
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .n { opacity: .7; margin-left: 4px; font-size: 12px; }

.section-title { font-size: 13px; color: var(--muted); margin: 18px 0 6px; font-weight: 600; }
.summary { font-size: 13px; color: var(--muted); margin: 6px 2px 10px; }

.card {
  display: block; background: var(--surface); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; color: inherit; text-decoration: none;
  border: 1px solid var(--line);
}
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.card h3 { font-size: 16px; margin: 6px 0 4px; line-height: 1.4; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; color: #fff; }
.badge.law { background: var(--law); }
.badge.admrul { background: var(--admrul); }
.badge.kosha { background: var(--kosha); }
@media (prefers-color-scheme: dark) { .badge { color: #111; } }
.hit {
  display: block; padding: 8px 10px; margin-top: 6px; border-radius: 8px;
  background: var(--bg); color: inherit; text-decoration: none; font-size: 14px;
}
.hit b { font-size: 13px; color: var(--accent); margin-right: 4px; }
.more { font-size: 13px; color: var(--muted); margin-top: 6px; }

.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.error { color: var(--danger); background: var(--surface); border-radius: var(--radius); padding: 12px; border: 1px solid var(--line); }
.loading { text-align: center; color: var(--muted); padding: 24px; }
.load-more { width: 100%; margin: 6px 0 12px; }

/* 문서 보기 */
.doc-head { background: var(--surface); border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); }
.doc-head h2 { font-size: 18px; margin: 6px 0; line-height: 1.4; }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.doc-actions a { text-decoration: none; display: inline-flex; align-items: center; }
.doc-tools { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-size: 14px; }
.doc-tools .spacer { flex: 1; }
.sec { padding: 14px 2px; border-bottom: 1px solid var(--line); scroll-margin-top: 64px; }
.sec h4 { margin: 0 0 4px; font-size: 15px; }
.sec h4 .lbl { color: var(--accent); margin-right: 6px; }
.sec p { margin: 0; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; font-size: 15px; }
.sec.matched { background: color-mix(in srgb, var(--mark) 22%, transparent); border-radius: 8px; padding-inline: 8px; }
.sec.dim { display: none; }
.sec a.src { font-size: 12px; }

/* 소식 */
.news-item { display: block; padding: 12px 2px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.news-item .t { font-size: 15px; line-height: 1.45; }
.news-item .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.news-item .soon, .doc-head .soon { color: var(--danger); font-weight: 700; }
/* 법령 개정 화면(js/revision.js) */
.rev-text { white-space: pre-wrap; font-size: 14px; line-height: 1.65; margin-top: 6px; }
.rev-legend { font-size: 12.5px; color: var(--muted); margin: 4px 0 10px; }
.rev-pair { border-top: 1px solid var(--line); padding: 10px 0; display: grid; gap: 8px; }
@media (min-width: 640px) { .rev-pair { grid-template-columns: 1fr 1fr; } }
.rev-side { font-size: 14px; line-height: 1.6; white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.rev-tag { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; white-space: normal; }
.rev-old { background: rgba(192, 57, 43, .14); color: var(--danger); text-decoration: line-through; border-radius: 3px; }
.rev-new { background: rgba(46, 157, 91, .2); color: inherit; font-weight: 700; border-radius: 3px; }
.rev-legend .rev-old, .rev-legend .rev-new { padding: 0 4px; }
.shortcuts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.small-btn { min-height: 34px; padding: 0 12px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; text-decoration: none; border-radius: 999px; }
.news-filter { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin: 8px 0; }
.news-filter .row { display: flex; gap: 8px; align-items: center; }
.news-filter .row + .row { margin-top: 8px; }
.news-filter input { min-width: 0; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
.news-filter input[type="search"] { flex: 1; }
.news-filter .dates input { flex: 1; }
.news-filter .dates span { color: var(--muted); }
.news-filter .presets { padding-bottom: 0; }
.news-filter .presets .chip { font: inherit; font-size: 13px; cursor: pointer; }
.qtag { display: inline-block; font-size: 11px; background: var(--bg); border-radius: 6px; padding: 1px 6px; color: var(--text); }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); margin: 8px 2px; }

/* 정보 */
.info-block { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); font-size: 14px; }
.info-block h3 { margin: 0 0 8px; font-size: 15px; }
.info-block dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.info-block dt { color: var(--muted); }
.info-block dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.info-block input { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; background: var(--bg); color: var(--text); margin: 6px 0; }
.small { font-size: 12px; color: var(--muted); }
.info-block.notice { border-left: 4px solid var(--brand); }
.info-block .sources { margin: 8px 0 0; padding-left: 18px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.doc-source { font-size: 12px; color: var(--muted); margin: 16px 2px 0; }

/* 조문 즐겨찾기·공유 */
.sec-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.sec-actions .src { margin-left: auto; }
.sec-btn {
  display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted);
  font: inherit; font-size: 13px; cursor: pointer;
}
.sec-btn svg { width: 16px; height: 16px; }
.sec-btn.on { color: var(--text); border-color: var(--brand); }
.sec-btn.on svg { fill: var(--brand); stroke: var(--brand); }

/* 오프라인 안내·알림 */
.offline-note {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; font-size: 14px;
}
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--ad-h, 0px) + env(safe-area-inset-bottom) + 12px); z-index: 20;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 999px; font-size: 14px;
}

/* 첫 실행 약관 동의 */
body.gated .tabbar { display: none; }
body.gated { padding-bottom: env(safe-area-inset-bottom); }
.consent h2 { font-size: 19px; margin: 8px 0 4px; }
.consent .check { display: flex; align-items: center; gap: 10px; font-size: 15px; min-height: 44px; cursor: pointer; }
.consent .check input { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.consent .check.all {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; margin: 14px 0 6px;
}
.consent-item { position: relative; border-bottom: 1px solid var(--line); padding: 4px 2px 8px; }
.consent-item .more-link { position: absolute; right: 2px; top: 16px; font-size: 13px; }
.consent-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 4px 0 6px; background: var(--surface); }
.consent-table th, .consent-table td { border: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }
.consent-table th { color: var(--muted); font-weight: 600; }
.consent-changes { margin: 4px 0 8px; padding-left: 20px; font-size: 14px; line-height: 1.55; }
.consent .agree { width: 100%; margin: 16px 0 8px; }
.consent .agree:disabled { opacity: .45; }

/* 문의하기 · 답변 팝업 */
.inq-new textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); resize: vertical;
}
.inq-new .inq-count { text-align: right; }
.inq-new .btn { width: 100%; margin-top: 4px; }
.inq-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.inq-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; margin-top: 4px; }
.inq-text.quoted { color: var(--muted); font-size: 14px; max-height: 8em; overflow: auto; border-left: 3px solid var(--line); padding-left: 8px; margin: 6px 0 10px; }
.inq-answer { background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-top: 8px; }
.inq-answer div { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; font-size: 15px; }
.reply-dialog {
  width: min(92vw, 480px); border: 0; border-radius: var(--radius); padding: 18px 16px 16px;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.reply-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.reply-dialog h3 { margin: 0 0 2px; font-size: 17px; }
.reply-dialog .inq-answer { max-height: 45vh; overflow: auto; }
.reply-dialog .btn { width: 100%; margin-top: 14px; }
.update-dialog .btn { width: 100%; }

/* 저장 탭 */
.fav-row { display: flex; align-items: flex-start; gap: 4px; }
.fav-row .hit { flex: 1; min-width: 0; }
.fav-row .remove { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.fav-row .pin { margin: 6px 0 0; color: var(--muted); font-size: 12px; white-space: nowrap; opacity: .55; }
.fav-row .pin.on { opacity: 1; }
.fav-row.locked .hit { width: 100%; text-align: left; border: 0; font-family: inherit; color: var(--muted); cursor: pointer; }
.row-title { display: flex; align-items: center; justify-content: space-between; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; padding: 0; }
.card.recent { padding: 4px 14px 4px 8px; }
.hint-inline { font-weight: 400; margin-left: 4px; }
.recent-tools { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 8px; }
.check-all { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: 40px; cursor: pointer; }
.check-all input, .recent-row .pick { width: 20px; height: 20px; accent-color: var(--brand); flex: none; margin: 0; }
.recent-tools .btn:disabled { opacity: .45; }
.recent-row { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.recent-row:last-child { border-bottom: 0; }
.recent-row .pick { margin-left: 4px; }
.recent-row .recent-item { flex: 1; min-width: 0; border-bottom: 0; }
.app-dialog {
  width: min(88vw, 420px); border: 0; border-radius: var(--radius); padding: 18px 16px 14px;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.app-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.app-dialog p { margin: 0 0 16px; font-size: 15px; line-height: 1.55; }
.help-btn { margin: 0 -8px 0 auto; }
body.gated .help-btn { display: none; }
.help-dialog { max-height: 82vh; flex-direction: column; }
.help-dialog[open] { display: flex; }
.help-dialog h3 { margin: 0 0 6px; font-size: 17px; }
.help-body { overflow: auto; font-size: 14px; line-height: 1.55; }
.help-body h4 { margin: 14px 0 4px; font-size: 14.5px; }
.help-body ul { margin: 0; padding-left: 18px; }
.help-body li { margin: 3px 0; }
.help-dialog .btn { width: 100%; margin-top: 14px; flex: none; }
.feedback-dialog h3 { margin: 0 0 4px; font-size: 17px; }
.feedback-dialog .small { margin: 0 0 10px; }
.feedback-dialog textarea { width: 100%; box-sizing: border-box; font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: inherit; }
.faces { display: flex; gap: 8px; margin: 10px 0; }
.face { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: inherit; font: inherit; font-size: 13px; }
.face span { font-size: 28px; line-height: 1; }
.feedback-dialog .later { width: 100%; }
.dialog-actions { display: flex; gap: 8px; }
.dialog-actions .btn { flex: 1; }
.btn.danger { background: var(--danger); color: #fff; }
.recent-item { display: flex; align-items: center; gap: 8px; padding: 10px 0; color: inherit; text-decoration: none; border-bottom: 1px solid var(--line); }
.recent-item:last-child { border-bottom: 0; }
.recent-item .t { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .d { flex: none; font-size: 12px; color: var(--muted); }
.small-empty { padding: 20px 12px; font-size: 14px; }

/* 앱 안 PDF 뷰어(저장 기능 없음) */
.pdf-view {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: #525659; color: var(--text);
}
.pdf-view[open] { display: flex; flex-direction: column; }
.pdf-bar {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  /* 앱은 Capacitor가 넣는 --safe-area-inset-top도 본다(전체 화면 창에서 env 값이 0이면 버튼이 상태 표시줄에 깔림) */
  padding: calc(max(env(safe-area-inset-top), var(--safe-area-inset-top, 0px)) + 8px) 12px 8px;
}
.pdf-find { display: flex; align-items: center; gap: 6px; background: var(--surface); padding: 0 12px 8px; }
.pdf-find[hidden] { display: none; }
.pdf-find input { flex: 1; min-width: 0; font-size: 16px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
.pdf-find .btn { padding: 0 12px; }
.pdf-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.pdf-title { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.pdf-pages { flex: 1; overflow: auto; padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px); }
.pdf-pages canvas { display: block; width: var(--pdf-zoom, 100%); margin: 0 auto 8px; background: #fff; }
