/* ============================================================
 * style.css · Compliance-factuurmodule
 * 纯本地样式：无外链字体、无 CDN、无图片依赖（logo 为字符 + CSS）
 * ============================================================ */

:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #131a24;
  --ink-2: #46536a;
  --ink-3: #5f6d85; /* WCAG AA：白底上 5.2:1（原 #6b7891 仅 4.45:1，实测不达标） */
  --line: #dbe1ec;
  --line-2: #eef1f7;
  --brand: #123a6b;
  --brand-2: #1c4f92;
  --ok: #10683c;
  --ok-bg: #e6f5ec;
  --bad: #9c1420;
  --bad-bg: #fdecee;
  --warn: #7a4a00;
  --warn-bg: #fff5e0;
  --focus: #0b63d6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 0 96px;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  overflow-x: hidden;
}

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.3; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); margin: 0 0 6px; }
p { margin: 0 0 8px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 60;
  background: var(--brand); color: #fff; padding: 12px 16px; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------------- topbar ---------------- */
.topbar {
  background: var(--brand);
  color: #fff;
  padding: 10px 0;
  position: sticky; top: 0; z-index: 30;
}
.topbar-in { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
  background: rgba(255, 255, 255, .16); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px;
}
.logo::before { content: "\2713"; }
.brand-txt { min-width: 0; }
.brand-txt strong { display: block; font-size: 16px; }
.brand-txt small { display: block; font-size: 12px; opacity: .85; }

.langswitch { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.langlabel { font-size: 12px; opacity: .85; }
.langbtn {
  min-height: 44px; padding: 8px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .45); background: transparent; color: #fff; font: inherit; font-size: 14px;
}
.langbtn[aria-pressed="true"] { background: #fff; color: var(--brand); border-color: #fff; font-weight: 600; }

/* ---------------- cards ---------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 16px 0; box-shadow: var(--shadow);
}
.hint { color: var(--ink-3); font-size: 13px; margin: 2px 0 8px; }
.card > .hint:first-of-type { margin-top: 0; }
.banner { border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin: 10px 0 0; }
.banner-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d9a8; }
.bannerslim { background: #eef4ff; color: #234; border: 1px solid #cfdffb; border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.src-line { margin-top: 10px; }
.src-line a { color: var(--brand-2); }

.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.seg {
  min-height: 44px; padding: 10px 18px; border-radius: 999px; cursor: pointer; font: inherit;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.seg[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

/* ---------------- checklist ---------------- */
.progress { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; }
.bar { flex: 1 1 auto; height: 10px; background: var(--line-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .2s ease, background .2s ease; }
.bar.warn > i { background: #d08a00; }
.pcount { flex: 0 0 auto; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.status { font-size: 14px; margin: 0 0 10px; min-height: 20px; }
.status.ok { color: var(--ok); font-weight: 600; }
.status.bad { color: var(--bad); font-weight: 600; }

.checklist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 6px; }
.checklist li { margin: 0; }
.chk {
  display: flex; align-items: flex-start; gap: 8px; width: 100%; text-align: left;
  min-height: 44px; padding: 8px 10px; border-radius: 10px; cursor: pointer; font: inherit; font-size: 13.5px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); line-height: 1.35;
}
.chk .mark { flex: 0 0 auto; font-weight: 700; }
.chk .txt { min-width: 0; overflow-wrap: anywhere; }
.chk.done { background: var(--ok-bg); border-color: #bfe3cd; color: #0d4f2e; }
.chk.done .mark { color: var(--ok); }
.chk.miss { background: var(--bad-bg); border-color: #f2c4c9; color: #7d1019; }
.chk.miss .mark { color: var(--bad); }
.chk.opt { background: #f6f7fa; color: var(--ink-3); }
.badge {
  display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 999px;
  background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d9a8; margin-left: 6px; white-space: nowrap;
}
.notices { margin-top: 12px; display: grid; gap: 8px; }
.notice { border: 1px solid #cfdffb; background: #eef4ff; color: #1d3a63; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.notice .src { display: block; font-size: 12px; margin-top: 4px; }
.notice a { color: var(--brand-2); }

/* ---------------- layout ---------------- */
.cols { display: grid; grid-template-columns: minmax(0, 1.02fr) minmax(0, .98fr); gap: 16px; align-items: start; }
.col-form, .col-doc { min-width: 0; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.field { min-width: 0; display: flex; flex-direction: column; }
.span2 { grid-column: 1 / -1; }
label { font-size: 13px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0; font-weight: 500; cursor: pointer; }
label.check input { width: 22px; height: 22px; flex: 0 0 auto; }

input[type="text"], input[type="email"], input[type="tel"], input[type="date"],
input[type="number"], select, textarea {
  width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: #fff; color: var(--ink); min-height: 44px;
}
textarea { min-height: 76px; resize: vertical; }
input.invalid { border-color: #d4595f; background: #fff8f8; }

.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn {
  min-height: 44px; padding: 10px 16px; border-radius: 10px; cursor: pointer; font: inherit;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.btn:hover { filter: brightness(.98); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-ghost { background: #fff; }
.btn-danger { color: var(--bad); border-color: #f2c4c9; }
.btn-sm { min-height: 44px; min-width: 44px; padding: 8px 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- lines ---------------- */
.lines { display: grid; gap: 10px; }
.lrow {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fbfcfe;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 8px; align-items: end;
}
.lrow .f-desc { grid-column: span 2; min-width: 0; }
.lrow .f-rm { display: flex; align-items: end; }
.lrow label { font-size: 12px; }
.lrow input, .lrow select { min-height: 44px; padding: 8px; }
.empty { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; color: var(--ink-3); font-size: 13.5px; background: #fbfcfe; }
.empty strong { display: block; color: var(--ink-2); margin-bottom: 2px; }
.empty p { margin: 0; }

/* ---------------- invoice document ---------------- */
.doc {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; font-size: 13.5px; overflow-wrap: anywhere;
}
.doc-head { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--brand); padding-bottom: 8px; }
.doc-title { font-size: 20px; letter-spacing: .08em; color: var(--brand); margin: 0; }
.doc-meta { font-size: 12px; color: var(--ink-2); text-align: right; }
.doc-meta strong { font-variant-numeric: tabular-nums; }
.doc-parties { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 12px 0; }
.doc-party h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin: 0 0 4px; }
.doc-party p { margin: 0 0 2px; font-size: 13px; }
.doc-name { font-weight: 600; }
.doc-tablewrap { margin: 10px 0; }
.doc-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12.5px; }
.doc-table th, .doc-table td { border-bottom: 1px solid var(--line-2); padding: 5px 3px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.doc-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.doc-table .num, .doc-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.c-desc { width: 32%; } .c-qty { width: 9%; } .c-unit { width: 9%; }
.c-price { width: 14%; } .c-base { width: 15%; } .c-rate { width: 8%; } .c-vat { width: 13%; }
.doc-totals { margin-top: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.doc-totalrow { display: flex; gap: 18px; justify-content: space-between; width: min(320px, 100%); font-variant-numeric: tabular-nums; }
.doc-grand { font-weight: 700; font-size: 15px; border-top: 2px solid var(--brand); padding-top: 4px; }
.doc-perrate { width: min(320px, 100%); margin: 6px 0; }
.doc-perrate .pr { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.doc-note { font-size: 12px; background: var(--warn-bg); border: 1px solid #f0d9a8; color: var(--warn); border-radius: 8px; padding: 8px 10px; margin: 10px 0 0; }
.doc-notes { margin-top: 10px; }
.doc-notes p { font-size: 12.5px; color: var(--ink-2); white-space: pre-wrap; margin: 0; }
.doc-disclaimer { margin-top: 12px; font-size: 11px; color: var(--ink-3); border-top: 1px solid var(--line-2); padding-top: 8px; }

/* ---------------- ledger ---------------- */
.ledger-count { font-size: 13px; color: var(--ink-2); margin: 0 0 8px; }
.tablewrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.datatable { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 460px; }
.datatable th, .datatable td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); text-align: left; }
.datatable th { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; }
.datatable td.num { text-align: right; font-variant-numeric: tabular-nums; }
.quarters { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin-top: 10px; }
.qcard { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fbfcfe; font-size: 13px; }
.qcard strong { display: block; margin-bottom: 4px; }
.qcard .qline { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }

/* ---------------- footer / actionbar / toast ---------------- */
.footer { padding-top: 8px; padding-bottom: 24px; font-size: 12.5px; color: var(--ink-3); }
.footer .src-title { font-weight: 600; color: var(--ink-2); margin-top: 12px; }
.srclist { margin: 4px 0 8px; padding-left: 18px; }
.srclist li { margin-bottom: 2px; }
.footer a { color: var(--brand-2); }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(16, 24, 40, .07);
  padding: 8px 0; padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.actionbar-in { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.savenote { margin-right: auto; font-size: 12.5px; color: var(--ink-3); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 50;
  background: #16233a; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13.5px; margin: 0; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .col-doc { order: 2; }
}
@media (max-width: 560px) {
  body { font-size: 15px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .doc { padding: 12px; font-size: 12.5px; }
  .doc-table { font-size: 11px; }
  .doc-table th, .doc-table td { padding: 4px 2px; }
  .doc-meta { text-align: left; }
  .lrow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lrow .f-desc { grid-column: 1 / -1; }
  .actionbar-in { justify-content: stretch; }
  .actionbar-in .btn { flex: 1 1 auto; }
  .savenote { flex: 1 1 100%; margin: 0 0 2px; text-align: center; }
}
@media (max-width: 380px) {
  .doc-table { font-size: 10px; }
  .doc-title { font-size: 17px; }
}

/* ---------------- dark mode ---------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --card: #171e29; --ink: #e9eef7; --ink-2: #b6c1d4; --ink-3: #93a0b6;
    --line: #2b3543; --line-2: #232c39; --ok: #7fd6a1; --ok-bg: #10281c; --bad: #ff9aa2;
    --bad-bg: #2a1417; --warn: #ffd08a; --warn-bg: #2a2110; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
  .topbar { background: #14263f; }
  .logo { background: rgba(255,255,255,.14); }
  .lrow, .empty, .qcard { background: #131a24; }
  .bannerslim { background: #14243c; color: #cfe0fb; border-color: #2c4670; }
  .banner-warn { border-color: #5c4a1e; }
  .notice { background: #14243c; color: #cfe0fb; border-color: #2c4670; }
  .chk.opt { background: #131a24; }
  .chk.done { background: var(--ok-bg); border-color: #24503a; color: #c8f0d8; }
  .chk.miss { background: var(--bad-bg); border-color: #5a2a30; color: #ffc9cd; }
  input[type="text"], input[type="email"], input[type="tel"], input[type="date"],
  input[type="number"], select, textarea, .btn, .seg, .chk { background: #131a24; color: var(--ink); }
  .seg[aria-pressed="true"] { background: #8fb4ff; border-color: #8fb4ff; color: #0c1220; }
  .btn-primary { background: #8fb4ff; border-color: #8fb4ff; color: #0c1220; }
  .actionbar { background: rgba(15, 20, 28, .97); }
  .doc { background: #fff; color: #131a24; }
}

/* ---------------- print ---------------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; padding: 0; font-size: 11pt; }
  .no-print, .topbar, .footer, .actionbar, .toast, .skip, #bac-intent { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .cols { display: block; }
  .col-doc { width: 100%; }
  .doc { border: 0; box-shadow: none; border-radius: 0; padding: 0; font-size: 10pt; }
  .doc-table { font-size: 9.5pt; }
  .doc-title { color: #000; }
  .doc-grand { border-top-color: #000; }
  .doc-note { background: #fff; color: #000; border: 1px solid #000; }
}
