/* 警察法規速查 — 外觀（依 ChatGPT 設計規格：現代警務藍 × 高可讀性）
   尺寸以 rem 表示（1rem = 16px），讓手機的系統文字放大也能生效。 */
:root {
  --accent: #24476D;        /* 警務深藍 */
  --accent-text: #ffffff;
  --bg: #F5F7FA;            /* 頁面背景 */
  --surface: #ffffff;       /* 卡片背景 */
  --text: #172B4D;          /* 主要文字 */
  --muted: #526579;         /* 次要文字 */
  --line: #D9E1E8;          /* 分隔線 */
  --warn-bg: #FFF5D6;       /* 提醒框背景 */
  --warn-line: #EBCF86;
  --warn-text: #5C3D00;
  --mark: #FFF0A8;          /* 關鍵字標示 */
  --shadow: 0 2px 8px rgba(0, 0, 0, .06);
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 1rem/1.7 var(--font);
}
body[data-view="article"] { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
a { color: var(--accent); }
svg.ico { width: 1.25rem; height: 1.25rem; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
svg.ico.fill { fill: currentColor; }

/* ---------- 頂端列 ---------- */
.appbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--accent); color: var(--accent-text);
  padding-top: env(safe-area-inset-top);
}
.topbar {
  height: 3.5rem; display: grid; grid-template-columns: 3rem 1fr 3rem; align-items: center;
  padding: 0 .5rem;
}
.brand {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  color: inherit; text-decoration: none;
  font-size: 1.125rem; line-height: 1.45; font-weight: 700; letter-spacing: .02em;
}
.brand-icon { width: 2rem; height: 2rem; border-radius: 8px; flex: none; display: block; }
.icon-btn {
  width: 2.75rem; height: 2.75rem; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; color: inherit; padding: 0; border-radius: 50%; cursor: pointer; text-decoration: none;
}
.icon-btn:active { background: rgba(255, 255, 255, .16); }
.icon-btn svg.ico { width: 1.5rem; height: 1.5rem; }
body[data-view="home"] #backBtn { visibility: hidden; }
body[data-view="home"] #searchIcon,
body[data-view="search"] #searchIcon { visibility: hidden; }

.searchbar { display: none; padding: .25rem 1rem 1rem; }
body[data-view="home"] .searchbar,
body[data-view="search"] .searchbar { display: block; }
.search { position: relative; }
.search-ico { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: var(--muted); display: flex; pointer-events: none; }
.search input {
  width: 100%; height: 3.25rem; padding: 0 .9rem 0 2.75rem; font: inherit; font-size: 1rem;
  border: 0; border-radius: 12px; background: #fff; color: var(--text); box-shadow: var(--shadow);
}
.search input::placeholder { color: var(--muted); opacity: .8; }

.page { max-width: 760px; margin: 0 auto; padding: 1.25rem 1rem 1rem; }
.copyright { margin-top: .5rem; }
.disclaimer {
  max-width: 760px; margin: 0 auto; padding: .5rem 1rem 1.75rem;
  font-size: .875rem; line-height: 1.6; color: var(--muted);
}

/* ---------- 文字 ---------- */
h1 { font-size: 1.375rem; line-height: 1.41; font-weight: 700; margin: .25rem 0 .25rem; }
.sub { color: var(--muted); font-size: .875rem; line-height: 1.57; margin: 0 0 .75rem; }
.crumbs { color: var(--muted); font-size: .875rem; line-height: 1.57; margin: 0 0 .25rem; }
.crumbs a { color: var(--muted); }
.cat-title {
  display: flex; align-items: center; gap: .5rem; margin: 1.5rem 0 .625rem;
  font-size: 1.0625rem; line-height: 1.47; font-weight: 700; color: var(--accent);
}
.cat-title svg.ico { width: 1.375rem; height: 1.375rem; }
mark { background: var(--mark); color: inherit; padding: 0 1px; border-radius: 3px; font-weight: 600; }

/* ---------- 按鈕 ---------- */
button, .btn {
  font: inherit; font-size: 1rem; font-weight: 600; min-height: 3rem; padding: 0 1rem; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--accent); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; line-height: 1.4;
}
button:active, .btn:active { background: #eaf0f6; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:active { background: #1b3957; }
button[disabled] { opacity: .4; cursor: default; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.btn-row > * { min-width: 0; }
.link-btn { min-height: 2.75rem; border: 0; background: none; color: var(--muted); font-weight: 500; font-size: .875rem; padding: 0 .5rem; }

/* ---------- 卡片 ---------- */
.card-list { display: grid; gap: .625rem; }
.card {
  display: flex; align-items: center; gap: .75rem; padding: 1rem; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.card:active { background: #eef3f8; }
.card .main { flex: 1; min-width: 0; }
.card .chev { color: var(--muted); }
.card .title { font-size: 1.0625rem; line-height: 1.47; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.card.hit .title { font-size: 1.1875rem; line-height: 1.53; font-weight: 700; color: var(--accent); }
.card .meta { color: var(--muted); font-size: .875rem; line-height: 1.57; }
.card .snip { color: var(--text); font-size: 1rem; line-height: 1.69; margin-top: .125rem; overflow-wrap: anywhere; }
.card.hit .snip { opacity: .92; }
.nb { white-space: nowrap; }
.badge { color: #8a5a00; font-weight: 600; }

.result-count { color: var(--muted); font-size: .9375rem; margin: 0 0 .75rem; }
.scope { font-size: .875rem; color: var(--muted); margin: 0 0 .5rem; }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; line-height: 1.8; }

/* ---------- 提醒框 ---------- */
.notice {
  background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-text);
  border-radius: 10px; padding: .875rem; margin: .75rem 0; font-size: .9375rem; line-height: 1.6;
}
.notice .head { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.notice ol { list-style: none; margin: .5rem 0 0; padding: 0; font-size: .875rem; }
.notice li + li { margin-top: .375rem; }
.notice a { color: var(--warn-text); }

/* ---------- 法規頁 ---------- */
.jump-label { font-weight: 700; font-size: 1rem; margin: 1rem 0 .375rem; }
.jump { display: flex; gap: .625rem; margin: 0 0 1rem; }
.jump input {
  flex: 1; min-width: 0; height: 3rem; padding: 0 .9rem; font: inherit; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text);
}

details.group {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin: .625rem 0; overflow: hidden;
  box-shadow: var(--shadow);
}
details.group > summary {
  min-height: 3.5rem; padding: .5rem 1rem; cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: .75rem;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary .t { flex: 1; min-width: 0; }
details.group > summary .name { display: block; font-size: 1rem; line-height: 1.56; font-weight: 700; }
details.group > summary .range { display: block; font-size: .875rem; line-height: 1.57; color: var(--muted); }
details.group > summary .chev { color: var(--muted); transition: transform .15s; }
details.group[open] > summary .chev { transform: rotate(90deg); }
.plain-group { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.toc { list-style: none; margin: 0; padding: 0; }
.toc .sub-head { padding: .625rem 1rem .125rem; color: var(--muted); font-size: .875rem; font-weight: 700; border-top: 1px solid var(--line); }
.toc a {
  display: flex; align-items: center; gap: .75rem; min-height: 3rem; padding: .375rem 1rem;
  text-decoration: none; color: inherit; border-top: 1px solid var(--line);
}
.toc a:active { background: #eef3f8; }
.toc .no { flex: 0 0 4.4em; font-size: 1rem; line-height: 1.56; font-weight: 700; color: var(--accent); }
.toc .pv { flex: 1; min-width: 0; color: var(--muted); font-size: .9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 條文頁 ---------- */
.article-actions { margin: .75rem 0; }
.article-actions button { min-height: 3rem; }
.article {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem; margin: .75rem 0 1rem; box-shadow: var(--shadow);
}
.article .para { display: flex; gap: .625rem; margin: 0 0 .75rem; font-size: 1.125rem; line-height: 1.78; }
.article .para:last-child { margin-bottom: 0; }
.article .para .n { flex: 0 0 1.4em; color: var(--muted); font-size: .9375rem; padding-top: .1rem; }
.article .para .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.article .line { display: block; }
.article .line.item { margin-top: .5rem; padding-left: 1.5em; text-indent: -1.5em; }
.article .line.sub-item { margin-top: .5rem; padding-left: 3em; text-indent: -1.5em; }

.pager-fixed {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  background: rgba(245, 247, 250, .96); border-top: 1px solid var(--line);
  padding: .625rem 1rem calc(.625rem + env(safe-area-inset-bottom));
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.pager-fixed .btn-row { max-width: 728px; margin: 0 auto; }

/* ---------- 其他 ---------- */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: 1.5rem 0 .625rem; }
.list-head .cat-title { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(6.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(23, 43, 77, .94); color: #fff; padding: .5rem 1rem; border-radius: 999px;
  font-size: .875rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
