:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --ink: #1d2433;
  --ink-2: #545c6b;
  --line: #ddd8cc;
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --accent: #b5452b;
  --ok: #2e7d4f;
  --warn: #9a6b00;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 4px 16px rgba(20, 30, 50, 0.06);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171d;
    --surface: #1c2029;
    --surface-2: #232834;
    --ink: #e8eaef;
    --ink-2: #a3aab8;
    --line: #333a48;
    --brand: #6ea8dc;
    --brand-ink: #0c1420;
    --accent: #e0826a;
    --ok: #6cc28f;
    --warn: #e0b04d;
    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(--ink);
  font: 16px/1.65 var(--font);
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.5rem, 1.1rem + 2vw, 2.2rem); letter-spacing: 0.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
small { color: var(--ink-2); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* ---------- header / footer ---------- */
.site-head { border-bottom: 1px solid var(--line); background: var(--surface); }
.site-head .wrap { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 14px; }
.site-head nav { margin-left: auto; display: flex; gap: 16px; font-size: 0.95rem; flex-wrap: wrap; }
.site-head nav a { color: var(--ink-2); text-decoration: none; }
.site-head nav a:hover { color: var(--brand); }
.site-foot { border-top: 1px solid var(--line); margin-top: 64px; padding: 28px 0 40px; color: var(--ink-2); font-size: 0.9rem; }
.site-foot a { color: var(--ink-2); }

.hero { padding: 36px 0 16px; }
.hero p { color: var(--ink-2); max-width: 720px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.badge { font-size: 0.8rem; border: 1px solid var(--line); background: var(--surface); padding: 2px 10px; border-radius: 999px; color: var(--ink-2); }

/* ---------- tool layout ---------- */
.tool { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .tool { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
fieldset { border: 0; padding: 0; margin: 0 0 20px; }
fieldset:last-child { margin-bottom: 0; }
legend { font-weight: 700; margin-bottom: 10px; padding: 0; font-size: 1rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.full { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--ink-2); }
input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="tel"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.amount-input { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hint { font-size: 0.8rem; color: var(--ink-2); }
.hint.bad { color: var(--accent); }
.hint.good { color: var(--ok); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 14px; font-size: 0.92rem; color: var(--ink-2); background: var(--surface); }
.seg input:checked + span { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -3px; }

.types { display: grid; gap: 8px; }
.type-opt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.type-opt:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--surface)); }
.type-opt input { margin-top: 5px; }
.type-opt b { display: block; }
.type-opt small { display: block; line-height: 1.5; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 0.92rem; }
.check input { margin-top: 5px; }

/* ---------- result ---------- */
.result { position: sticky; top: 16px; }
.result h2 { font-size: 1rem; color: var(--ink-2); font-weight: 600; }
.rows { margin: 0; }
.rows div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.rows dt { color: var(--ink-2); }
.rows dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.rows .minus dd { color: var(--accent); }
.rows .total { border-bottom: 0; padding-top: 12px; }
.rows .total dt { color: var(--ink); font-weight: 700; }
.rows .total dd { font-size: 1.6rem; color: var(--ink); }
.notes { list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.82rem; color: var(--ink-2); }
.notes li { padding-left: 1em; text-indent: -1em; }
.notes li::before { content: "・"; }
.upper { font-size: 0.85rem; color: var(--ink-2); margin-top: 4px; }

.btn { font: inherit; font-weight: 600; border-radius: 8px; padding: 10px 16px; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.danger { border-color: var(--accent); color: var(--accent); background: transparent; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.actions .btn { flex: 1 1 auto; }

/* ---------- content sections ---------- */
section.block { margin-top: 56px; }
.prose { max-width: 760px; }
.prose table, .data { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.prose th, .prose td, .data th, .data td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose th, .data th { background: var(--surface-2); font-weight: 600; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
details { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 12px 16px; margin-bottom: 10px; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }

.pro { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
@media (max-width: 800px) { .pro { grid-template-columns: 1fr; padding: 20px; } }
.pro ul { padding-left: 1.2em; margin: 0 0 1em; }
.price { font-size: 2rem; font-weight: 800; }
.price small { font-size: 0.9rem; font-weight: 400; }
.plans { display: grid; gap: 12px; }
.plan { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.plan.feature { border-color: var(--brand); }

.preview-wrap { margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: #e9e6df; padding: 16px; overflow: auto; }
.preview-wrap .lb-slip { transform-origin: top left; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 0.9rem; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; }

/* ---------- 單據（螢幕預覽與列印共用；固定淺色） ---------- */
.lb-slip {
  --s-ink: #111; --s-line: #333; --s-soft: #f2f2f2;
  background: #fff; color: var(--s-ink); width: 190mm; max-width: 100%; margin: 0 auto; padding: 10mm 10mm 8mm;
  font: 11pt/1.5 var(--font); box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}
.lb-slip-head { text-align: center; margin-bottom: 4mm; }
.lb-slip-head h2 { font-size: 20pt; letter-spacing: 0.3em; margin: 0 0 1mm; color: #111; }
.lb-slip-head p { margin: 0; font-size: 10.5pt; }
.lb-table { width: 100%; border-collapse: collapse; margin-bottom: 3mm; table-layout: fixed; }
.lb-table th, .lb-table td { border: 1px solid var(--s-line); padding: 2mm 2.5mm; text-align: left; vertical-align: middle; word-break: break-all; }
.lb-table th { background: var(--s-soft); width: 19%; font-weight: 600; font-size: 10pt; }
.lb-table td { font-size: 10.5pt; }
.lb-table small { display: block; font-size: 8pt; color: #555; }
.lb-money td { text-align: right; font-variant-numeric: tabular-nums; }
.lb-money th { width: 40%; }
.lb-net th, .lb-net td { font-weight: 700; font-size: 12pt; }
.lb-types .lb-check { display: inline-block; margin-right: 4mm; white-space: nowrap; font-size: 10pt; }
.lb-declare { font-size: 9.5pt; margin: 2mm 0 3mm; }
.lb-sign { display: grid; grid-template-columns: 1.3fr 1fr 1.3fr; gap: 4mm; font-size: 10.5pt; margin-bottom: 4mm; }
.lb-sign div { border-bottom: 1px solid var(--s-line); padding-bottom: 10mm; }
.lb-idcopy { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; }
.lb-idcopy div { border: 1px dashed #777; height: 48mm; display: grid; place-items: center; color: #888; font-size: 9pt; }

#print-area { display: none; }
@media print {
  @page { size: A4; margin: 8mm; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
  .lb-slip { box-shadow: none; width: auto; padding: 0; break-after: page; page-break-after: always; }
  .lb-slip:last-child { break-after: auto; page-break-after: auto; }
}
