/* =============================================================
   Weighted Word Count - single stylesheet
   ============================================================= */

/* 1. Tokens ---------------------------------------------------- */
:root {
  --bg: #f7f8f7;
  --surface: #ffffff;
  --surface-2: #f1f4f3;
  --text: #17201e;
  --text-muted: #5b6763;
  --border: #dfe5e3;
  --border-strong: #9fb0ab;
  --accent: #0f766e;
  --accent-strong: #0b5a54;
  --accent-soft: #e3f2ef;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 12px;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-6: 2rem;
  --content-width: 960px;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101514;
    --surface: #161d1b;
    --surface-2: #1c2422;
    --text: #e7eeec;
    --text-muted: #9aa8a4;
    --border: #2a3532;
    --border-strong: #52645f;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: #123430;
    --danger: #f97066;
    --danger-soft: #3a1714;
  }
}

/* 2. Reset & base ---------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  overflow-x: clip;
}
img, svg { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
p { text-wrap: pretty; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -0.015em; text-wrap: balance; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* 3. Utilities ------------------------------------------------- */
.skip-link {
  position: fixed; top: -100px; left: 1rem; z-index: 99;
  padding: .6rem 1rem; background: var(--surface); color: var(--text);
  border-radius: 8px; border: 1px solid var(--border);
}
.skip-link:focus { top: 1rem; }
.container { width: 100%; max-width: var(--content-width); margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

/* 4. Typography ------------------------------------------------ */
h1 { font-size: clamp(1.5rem, 1.1rem + 2vw, 2.25rem); margin-bottom: .35rem; }
h2 { font-size: 1.35rem; margin: 2rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: 1.25rem 0 .4rem; }
.prose p, .prose ul, .prose ol, .prose table { margin-bottom: .9rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin-bottom: .3rem; }
.prose code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .05em .3em; border-radius: 4px; }
.lead { color: var(--text-muted); margin-bottom: 1rem; }

/* 5. Components ------------------------------------------------ */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.site-header .container { display: flex; align-items: center; justify-content: space-between; gap: 0 1rem; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; min-height: 44px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand img { width: 26px; height: 26px; }
.site-nav { display: flex; gap: 0 .5rem; flex-wrap: wrap; font-size: .925rem; }
.site-nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 .35rem; color: var(--text-muted); text-decoration: none; white-space: nowrap; }
.site-nav a:hover { color: var(--accent); }
.lang-switch { display: flex; gap: .25rem; font-size: .8125rem; font-weight: 600; }
.lang-switch a, .lang-switch span { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 .5rem; border: 1px solid var(--border); border-radius: 8px; line-height: 1.4; }
.lang-switch a { color: var(--text-muted); text-decoration: none; }
.lang-switch a:hover { color: var(--accent); border-color: var(--accent); }
.lang-switch [aria-current] { color: var(--text); background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--text);
  transition: background .2s var(--ease-out), border-color .2s var(--ease-out);
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #06201d; } }
.btn-small { min-height: 44px; padding: .3rem .8rem; font-size: .875rem; }
.btn-link { display: inline-flex; align-items: center; min-height: 44px; border: 0; background: none; color: var(--accent); padding: 0; font-weight: 500; text-decoration: underline; cursor: pointer; vertical-align: middle; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: .25rem; font-size: .875rem; }
.field > span { color: var(--text-muted); font-weight: 500; }
input[type="text"], input[type="number"], input[type="email"], input[type="date"], select {
  min-height: 44px; padding: .45rem .6rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); width: 100%; min-width: 0;
}
summary { display: list-item; min-height: 44px; padding: .55rem 0; cursor: pointer; }
.input-affix { display: flex; align-items: stretch; }
.input-prefix {
  display: inline-flex; align-items: center; padding: 0 .6rem; min-width: 2.5rem; justify-content: center;
  border: 1px solid var(--border); border-right: 0; border-radius: 8px 0 0 8px; background: var(--surface-2); color: var(--text-muted); font-weight: 600;
}
.input-affix input { border-radius: 0 8px 8px 0; }
.name-edit { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.name-edit label { flex: 1 0 100%; font-size: .875rem; color: var(--text-muted); font-weight: 500; }
.name-edit input { flex: 1 1 12rem; width: auto; }
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* Tool card */
.hero { padding-top: 1.25rem; padding-bottom: .5rem; }
.tool-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.step { padding: .75rem 0; border-top: 1px solid var(--border); }
.step:first-child { border-top: 0; padding-top: 0; }
.step-title { font-size: 1rem; margin: 0 0 .5rem; display: flex; align-items: center; gap: .5rem; }
.step-num {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 700;
}
.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem;
  min-height: 132px; padding: 1rem; text-align: center; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
  transition: border-color .2s var(--ease-out), background .2s var(--ease-out);
}
.dropzone:hover, .dropzone.is-over, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone:focus-within .dz-btn { outline: 2px solid var(--accent); outline-offset: 3px; }
.dz-btn { pointer-events: none; padding: .6rem 1.25rem; font-size: 1.02rem; }
.dz-btn svg { width: 20px; height: 20px; }
.dz-hint { font-size: .875rem; color: var(--text-muted); }
.upload-alt { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; margin-top: .6rem; }
.file-help { font-size: .9rem; }
.file-help summary { color: var(--accent); font-weight: 600; }
.file-help ul { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.file-help li { margin-bottom: .35rem; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; background: #fef0c7; color: #7a2e0e; font-size: .75rem; font-weight: 700; letter-spacing: .02em; }
@media (prefers-color-scheme: dark) { .badge { background: #4e2a0a; color: #fedf89; } }
.formats { font-size: .82rem; color: var(--text-muted); margin-top: .5rem; }
.status { margin-top: .6rem; padding: .55rem .75rem; border-radius: 8px; font-size: .9rem; background: var(--accent-soft); }
.status.is-error { background: var(--danger-soft); color: var(--danger); }
.status.is-warn { background: #fef0c7; color: #7a2e0e; margin: 0 0 .8rem; }
@media (prefers-color-scheme: dark) { .status.is-warn { background: #4e2a0a; color: #fedf89; } }
.field-error { color: var(--danger); font-size: .8rem; font-weight: 500; }
input[aria-invalid="true"] { border-color: var(--danger); outline-color: var(--danger); }
/* Inline link inside a sentence: normal line height, 44px tap area via ::after. */
.formats .btn-link { display: inline; min-height: 0; position: relative; vertical-align: baseline; font-size: inherit; }
.formats .btn-link::after { content: ""; position: absolute; left: -4px; right: -4px; top: 50%; height: 44px; transform: translateY(-50%); }
.file-list { margin-top: .4rem; font-size: .85rem; color: var(--text-muted); }

.grid-head { display: grid; grid-template-columns: 1fr; gap: .6rem; margin-bottom: .6rem; }
.client-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.pct-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.pct-grid .field input { text-align: right; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 10px; margin: .4rem 0 .8rem; }
table.data { border-collapse: collapse; width: 100%; font-size: .9rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: .45rem .6rem; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { background: var(--surface-2); font-weight: 600; font-size: .8rem; color: var(--text-muted); }
table.data tfoot td { font-weight: 700; border-bottom: 0; }
table.data input { min-height: 44px; width: 6.5rem; text-align: right; }
table.data .pct-inline { display: none; }
#manual table.data td:first-child { white-space: normal; }
#manual table.data input { width: 6rem; }

.result-total {
  display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: baseline;
  padding: .8rem 1rem; border-radius: 10px; background: var(--accent-soft); margin-bottom: .8rem;
}
.result-total .big { font-size: 1.6rem; font-weight: 800; color: var(--accent-strong); }
.result-client { display: flex; align-items: center; gap: .5rem; margin: -.3rem 0 .8rem; font-size: .875rem; }
.result-client > span { color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.result-client select { width: auto; max-width: 100%; flex: 0 1 auto; }
#result { scroll-margin-top: .75rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
#result .result-actions { align-items: stretch; }
#result .result-actions .btn { flex: 1 1 0; min-width: 0; padding-left: .75rem; padding-right: .75rem; text-align: center; }
#pdf-note { flex: 1 0 100%; }
#pdf-note:empty { display: none; }
.pdf-details { margin: .5rem 0 .25rem; }
.pdf-details summary, .pct-details summary { font-weight: 600; color: var(--accent); }
.pdf-details > p { margin: .25rem 0 .5rem; }
.result-reset { margin-top: .25rem; }
.invoice-fields { display: grid; grid-template-columns: 1fr; gap: .5rem; margin: .6rem 0; }
.rates summary { font-weight: 600; }
.rates-edit { margin-left: .35rem; color: var(--accent); text-decoration: underline; font-weight: 500; }
.rates-body { padding-top: .5rem; }
.pct-details { margin: .6rem 0 .25rem; }
.pct-details .pct-grid { margin-bottom: .6rem; }
#storage-note { margin-top: .5rem; }
.files-details summary { font-weight: 600; }

.privacy-badge { display: flex; gap: .5rem; align-items: flex-start; margin-top: .9rem; font-size: .875rem; color: var(--text-muted); }
.privacy-badge svg { flex: none; width: 18px; height: 18px; margin-top: .15rem; color: var(--accent); }
.privacy-check { display: block; margin-top: var(--space-2); }
.result-figure { margin: var(--space-6) 0; }
.result-shot { display: block; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.result-figure figcaption { margin-top: var(--space-2); font-size: .875rem; color: var(--text-muted); }
.noscript-note { padding: .75rem; border-radius: 8px; background: var(--danger-soft); color: var(--danger); }

/* Ad slots (ref 18 §6). Hidden unless lib/site.js enables ads. */
.ad-slot {
  display: none;
  margin: var(--space-6) auto; max-width: 728px; padding: var(--space-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  contain: layout;
}
.ads-on .ad-slot { display: block; }
.ad-slot__label { display: block; margin-bottom: var(--space-2); font-size: .75rem; letter-spacing: .04em; color: var(--text-muted); }
/* Reserved height = the banner size lib/ads-config.js loads there: in-content
   300x250; below the result 728x90, or 320x50 under 760px (lib/site.js unitFor). */
.ad-slot__unit { min-height: 250px; }
.ad-slot[data-ad-after-result] .ad-slot__unit { min-height: 90px; }
@media (max-width: 759px) { .ad-slot[data-ad-after-result] .ad-slot__unit { min-height: 50px; } }
/* The below-result slot stays hidden until there is a result (lib/site.js sets data-ad-ready). */
.ads-on .ad-slot[data-ad-after-result]:not([data-ad-ready]) { display: none; }
.ad-slot[data-ad-state="empty"] { display: none; }
@media (prefers-reduced-motion: reduce) { .ad-slot * { animation: none !important; transition: none !important; } }

/* Ad consent notice: small card at the bottom, no backdrop, never a modal. */
.consent {
  position: fixed; z-index: 50; left: 12px; right: 12px; bottom: 12px;
  max-width: 640px; margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem;
  padding: .7rem .9rem; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: .875rem; line-height: 1.4;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
.consent[hidden] { display: none; }
.consent__text { flex: 1 1 18rem; margin: 0; }
.consent__text a { color: var(--accent); }
.consent__actions { flex: 1 1 auto; display: flex; gap: .5rem; justify-content: flex-end; }
.consent__actions .btn { flex: 1 1 0; white-space: nowrap; }
@media (min-width: 540px) { .consent__actions { flex: 0 0 auto; } .consent__actions .btn { flex: 0 0 auto; min-width: 7.5rem; } }
@media (prefers-reduced-motion: no-preference) {
  .consent:not([hidden]) { animation: consent-in .25s var(--ease-out); }
  @keyframes consent-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

/* FAQ */
.faq details { border: 1px solid var(--border); border-radius: 10px; padding: 0 .9rem; margin-bottom: .5rem; background: var(--surface); }
.faq summary { font-weight: 600; }
.faq details p { margin: 0 0 .75rem; }

/* 6. Sections -------------------------------------------------- */
main { padding-bottom: 2rem; }
.steps-list, .prose .steps-list { display: grid; gap: .75rem; grid-template-columns: 1fr; padding: 0; list-style: none; }
.steps-list li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; }
.steps-list svg { width: 26px; height: 26px; color: var(--accent); margin-bottom: .35rem; }
.more-links { display: grid; gap: .6rem; grid-template-columns: 1fr; padding: 0; list-style: none; }
.more-links a { display: block; padding: .8rem 1rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); text-decoration: none; color: var(--text); }
.more-links a:hover { border-color: var(--accent); }
.page-article { padding-top: 1.25rem; }
.site-footer { border-top: 1px solid var(--border); padding: 1.25rem 0 2rem; font-size: .875rem; color: var(--text-muted); background: var(--surface); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-bottom: .5rem; }
.site-footer a { color: var(--text-muted); }

/* 8. Responsive ------------------------------------------------ */
@media (max-width: 539px) {
  /* Result tables: one block per band, no horizontal scroll. */
  .table-stack { border: 0; overflow: visible; }
  .data-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .data-stack, .data-stack tbody, .data-stack tfoot { display: block; }
  .data-stack tr {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 .5rem;
    padding: .5rem .7rem; margin-bottom: .4rem; border: 1px solid var(--border); border-radius: 10px;
  }
  table.data.data-stack td { display: block; padding: 0; border: 0; text-align: left; white-space: normal; }
  table.data.data-stack td:first-child { grid-column: 1 / -1; font-weight: 600; margin-bottom: .15rem; }
  table.data.data-stack .col-pct { display: none; }
  table.data.data-stack .pct-inline { display: inline; font-weight: 500; color: var(--text-muted); }
  .data-stack td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; font-weight: 500; color: var(--text-muted); }
  .data-stack tfoot tr { background: var(--accent-soft); border-color: transparent; }
}
@media (max-width: 719px) {
  /* Brand + language switch on one row; the nav wraps below, nothing cut off. */
  .brand { order: 1; }
  .lang-switch { order: 2; }
  .site-nav {
    order: 3; flex: 1 0 100%; flex-wrap: wrap; gap: 0 .15rem;
    margin: 0 -16px; padding: 0 10px; border-top: 1px solid var(--border);
  }
}
@media (min-width: 540px) {
  .pct-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .invoice-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 720px) {
  .tool-card { padding: 1.25rem 1.5rem; }
  .grid-head { grid-template-columns: 2fr 1fr 1fr; align-items: end; }
  .steps-list, .more-links { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Print: keep only the result */
@media print {
  .site-header, .site-footer, .ad-slot, .consent, .dropzone, .no-print { display: none !important; }
}
