:root {
  --bg: #f6f7f9; --card: #fff; --text: #1f2937; --muted: #5b6472; --line: #d1d5db; --accent: #1d6fd1; --accent-text: #fff;
  --ok: #15803d; --ok-bg: #e7f6ec; --issue: #b42318; --issue-bg: #fdecea; --na: #6b7280; --na-bg: #eef0f3;
  --check: #a15c00; --check-bg: #fff4e0; --bar: #e5e7eb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827; --card: #1f2937; --text: #e5e7eb; --muted: #a5adba; --line: #374151; --accent: #4c9bf0; --accent-text: #0b1220;
    --ok: #4ade80; --ok-bg: #12301f; --issue: #f87171; --issue-bg: #3a1717; --na: #a5adba; --na-bg: #2a3443;
    --check: #fbbf24; --check-bg: #3a2c0b; --bar: #374151;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif; font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
a { color: var(--accent); }

.top { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.top h1 { margin: 0; font-size: 1.35rem; line-height: 1.3; }
.crumb { font-size: .9em; }
.summary { color: var(--muted); margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
main { max-width: 960px; margin: 0 auto; padding: 14px 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; min-width: 0; }
.card h2 { margin: 0 0 8px; font-size: 1.1rem; }
.hint { color: var(--muted); font-size: .9em; }
.note-box { border-left: 4px solid var(--accent); }
.warn { background: var(--check-bg); color: var(--text); border: 1px solid var(--check); border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; }

button, .btn { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:focus-visible, .btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.file input { display: none; }

input[type=text], input[type=number], input[type=date], input[type=search], textarea, select {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
label { cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-weight: 600; font-size: .95em; }
.field input, .field select, .field textarea { width: 100%; }

/* 首頁 */
.hub { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.tool { display: flex; flex-direction: column; gap: 6px; color: inherit; text-decoration: none; }
.tool:hover { border-color: var(--accent); }
.tool h2 { color: var(--accent); }
.tool .who { color: var(--muted); font-size: .9em; }

/* 進度條 */
.bar { height: 8px; background: var(--bar); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.bar.big { height: 12px; }

/* 檢查表 */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input[type=search] { flex: 1 1 180px; min-width: 0; }
details.sec { background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; }
details.sec > summary { list-style: none; cursor: pointer; padding: 10px 14px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary .t { font-weight: 700; }
details.sec > summary .c { color: var(--muted); font-size: .9em; white-space: nowrap; }
details.sec > summary .bar { grid-column: 1 / -1; }
details.sec > summary::after { content: none; }
.items { list-style: none; margin: 0; padding: 0 14px 6px; }
.item { border-top: 1px solid var(--line); padding: 10px 0; }
.item .q { margin-bottom: 6px; }
.item .q b { color: var(--muted); font-weight: 400; font-size: .85em; margin-right: 4px; }
.item .h { color: var(--muted); font-size: .88em; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.seg button { padding: 4px 10px; font-size: .92em; }
.seg button[aria-pressed=true][data-s=ok] { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.seg button[aria-pressed=true][data-s=issue] { background: var(--issue-bg); border-color: var(--issue); color: var(--issue); font-weight: 700; }
.seg button[aria-pressed=true][data-s=na] { background: var(--na-bg); border-color: var(--na); color: var(--na); font-weight: 700; }
.item.st-issue { box-shadow: inset 3px 0 0 var(--issue); padding-left: 8px; }
.item textarea { min-height: 2.2em; }
.issue-list { margin: 0; padding-left: 1.3em; }
.issue-list li { margin-bottom: 6px; }
.issue-list .sec-name { color: var(--muted); font-size: .88em; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 6px 0; }
.stats .ok { color: var(--ok); } .stats .issue { color: var(--issue); } .stats .na { color: var(--na); }
.print-status { display: none; }

/* 農舍 */
.q-row { border-top: 1px solid var(--line); padding: 10px 0; }
.q-row:first-of-type { border-top: 0; }
.q-row .lbl { font-weight: 600; display: block; margin-bottom: 4px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.inline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.inline input { width: 9em; }
.verdict { font-size: 1.25rem; font-weight: 700; padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; }
.r-pass { color: var(--ok); background: var(--ok-bg); }
.r-check { color: var(--check); background: var(--check-bg); }
.r-fail { color: var(--issue); background: var(--issue-bg); }
.res-list { list-style: none; margin: 0; padding: 0; }
.res-list li { border-top: 1px solid var(--line); padding: 8px 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.tag { display: inline-block; font-size: .82em; font-weight: 700; padding: 1px 8px; border-radius: 99px; white-space: nowrap; align-self: start; }
.res-list .why { color: var(--muted); font-size: .92em; grid-column: 2; }
.res-group { margin: 12px 0 2px; font-size: 1rem; }
.rules-tbl { width: 100%; border-collapse: collapse; font-size: .9em; }
.rules-tbl th, .rules-tbl td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
.scroll { overflow-x: auto; }

/* 物件介紹 */
.meter { display: flex; align-items: center; gap: 10px; }
.meter .bar { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: .85em; border: 1px solid var(--line); border-radius: 99px; padding: 1px 10px; }
.chip.on { border-color: var(--ok); color: var(--ok); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tabs button[aria-selected=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.out { width: 100%; min-height: 260px; font-family: inherit; white-space: pre-wrap; }
.print-out { display: none; white-space: pre-wrap; }
.drafts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.drafts select { flex: 1 1 160px; min-width: 0; }
.drafts input { flex: 1 1 140px; min-width: 0; }

footer { text-align: center; color: var(--muted); padding: 20px 16px 28px; font-size: .9em; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); z-index: 10; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  body { font-size: 15px; }
  .top h1 { font-size: 1.2rem; }
  .card { padding: 10px 12px; }
  .items { padding: 0 12px 6px; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  :root { --bg: #fff; --card: #fff; --text: #000; --muted: #444; --line: #bbb; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .no-print, .toast { display: none !important; }
  .top { border: 0; padding: 0 0 6px; }
  main { max-width: none; padding: 0; }
  .card, details.sec { border: 1px solid #bbb; break-inside: avoid-page; }
  details.sec > .items { display: block !important; }
  .item { break-inside: avoid; }
  .seg, .item textarea { display: none; }
  .print-status { display: block; font-size: .95em; }
  .bar { border: 1px solid #999; }
  .print-out { display: block; }
  .out { display: none; }
  a { color: #000; text-decoration: none; }
}

/* 客製化服務資訊：頁尾低調小字，不擋操作；顏色沿用父層，深淺色都看得清；列印時隱藏 */
.custom-ad { margin: 6px auto 0; padding: 0 12px; max-width: 60em; font-size: 12px; line-height: 1.6; color: inherit; text-align: center; overflow-wrap: anywhere; }
.custom-ad a { color: inherit; text-decoration: underline; }
@media print { .custom-ad { display: none !important; } }
