:root {
  --bg: #f7f8fa;
  --surface: #fff;
  --text: #1b2330;
  --muted: #566074;
  --border: #d9dee7;
  --accent: #0b5fd6;
  --accent-text: #fff;
  --ok: #0a7a3d;
  --warn: #8a5a00;
  --err: #b3261e;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1b212b;
    --text: #e8ecf3;
    --muted: #a3adbf;
    --border: #2f3846;
    --accent: #6aa5ff;
    --accent-text: #0b1220;
    --ok: #4cc983;
    --warn: #e5b055;
    --err: #ff8a80;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }

/* header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; padding-top: 10px; padding-bottom: 10px; }
.logo { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .92rem; }
.search { position: relative; margin-left: auto; }
.search input { width: 190px; }
#busca-resultados { position: absolute; right: 0; top: 100%; z-index: 5; list-style: none; margin: 4px 0 0; padding: 4px; width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
#busca-resultados a, #busca-resultados span { display: block; padding: 6px 8px; }

.breadcrumb { font-size: .85rem; color: var(--muted); padding: 14px 0 0; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; }
.breadcrumb li + li::before { content: "›"; margin-right: 4px; }

h1 { font-size: 1.7rem; line-height: 1.25; margin: .6em 0 .3em; }
h2 { font-size: 1.3rem; margin: 1.6em 0 .4em; }
h3 { font-size: 1.1rem; }
.intro { font-size: 1.05rem; color: var(--muted); margin-top: 0; }

/* tool UI */
.tool, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; display: block; }
input, select, textarea {
  width: 100%; font: inherit; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--text); min-height: 44px;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 10px 0 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.field-error { color: var(--err); font-size: .85rem; min-height: 1.2em; margin: 2px 0 0; }
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; padding: 9px 16px; min-height: 44px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; display: inline-block;
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.result { margin-top: 16px; border-top: 1px dashed var(--border); padding-top: 14px; }
.result .big { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.result table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.result th, .result td { padding: 6px 4px; text-align: left; border-bottom: 1px solid var(--border); }
.result td:last-child, .result th:last-child { text-align: right; }
.good { color: var(--ok); }
.note { font-size: .85rem; color: var(--muted); }
.qr-out { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.qr-out svg, .qr-out canvas { width: 220px; height: 220px; background: #fff; border-radius: 8px; padding: 8px; border: 1px solid var(--border); }
.code { word-break: break-all; font: .85rem/1.4 ui-monospace, Consolas, monospace; background: var(--bg); padding: 10px; border-radius: 8px; border: 1px solid var(--border); }

/* ads: reserve height to prevent layout shift */
.ad-wrap { margin: 28px 0; min-height: 280px; text-align: center; }
.ad-wrap small { display: block; color: var(--muted); font-size: .7rem; letter-spacing: .05em; text-transform: uppercase; }
.ad-wrap ins { display: block; min-height: 250px; }

.explainer p, .explainer li { max-width: 70ch; }
.faq details { border-bottom: 1px solid var(--border); padding: 10px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.related { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); padding: 0; list-style: none; }
.related a { display: block; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-decoration: none; font-weight: 600; }

.hub-list { list-style: none; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.hub-list a { display: block; height: 100%; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-decoration: none; color: var(--text); }
.hub-list strong { display: block; color: var(--accent); }
.hub-list span { font-size: .88rem; color: var(--muted); }

.consent { position: fixed; inset: auto 0 0 0; z-index: 20; background: var(--surface); border-top: 2px solid var(--border); padding: 14px 16px; box-shadow: 0 -4px 16px rgba(0,0,0,.15); }
.consent[hidden] { display: none; }
.consent .wrap { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.consent p { margin: 0; flex: 1 1 320px; font-size: .9rem; }
.consent button { flex: 0 0 auto; min-width: 120px; }

.site-footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 20px 0 80px; font-size: .88rem; color: var(--muted); }
.site-footer a { margin-right: 14px; }

@media print {
  .site-header, .site-footer, .ad-wrap, .consent, .actions, .breadcrumb, .related, .faq { display: none !important; }
  body { background: #fff; color: #000; }
}

/* generic calculators */
.table-scroll { overflow-x: auto; max-height: 420px; overflow-y: auto; }
.result table.wide th, .result table.wide td { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.result table.wide th:first-child, .result table.wide td:first-child { text-align: left; }
.result pre.code { white-space: pre-wrap; max-height: 360px; overflow: auto; margin: 8px 0; }
.chart { width: 100%; height: auto; color: var(--muted); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .85rem; margin: 4px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
textarea { min-height: 160px; resize: vertical; }
input[type=color] { padding: 2px; }
.wide-field { grid-column: 1 / -1; }
.result .big { overflow-wrap: anywhere; }

/* file tools */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px 16px; text-align: center; cursor: pointer; background: var(--bg); position: relative; }
.dropzone.drag, .dropzone:focus-visible { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.dropzone label { cursor: pointer; margin: 0; }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; min-height: 0; }
.status { min-height: 1.4em; margin: 8px 0; font-size: .92rem; }
.status.err { color: var(--err); }
.status.ok { color: var(--ok); }
.sort-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.sort-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.sort-item.dragging { opacity: .4; }
.sort-item .info { flex: 1; min-width: 0; font-size: .92rem; overflow-wrap: anywhere; }
.sort-item .info small { display: block; color: var(--muted); }
.sort-item img, .sort-item canvas { max-width: 56px; max-height: 56px; border-radius: 4px; flex: none; }
.sort-bar { display: flex; gap: 4px; flex: none; }
.sort-bar button { min-width: 44px; padding: 6px 8px; }
.sort-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.sort-grid .sort-item { flex-direction: column; align-items: center; text-align: center; }
.sort-grid .sort-item canvas { max-width: 140px; max-height: 180px; background: #fff; border: 1px solid var(--border); }
.result .saved { font-weight: 600; }
.neg { color: var(--warn); }

/* avoid layout shift when a result renders on load (e.g. text counters) */
.tool .result { min-height: 10rem; }

/* legal/usage notice below calculators; kept in print output on purpose */
.disclaimer { margin: 16px 0; padding: 12px 14px; border: 1px solid var(--border); border-left: 4px solid var(--warn); border-radius: var(--radius); background: var(--surface); font-size: .92rem; }
@media print { .disclaimer { display: block !important; border: 1px solid #000; } }

/* Data tables inside the explainer (worked examples) */
.explainer table { width: 100%; border-collapse: collapse; font-size: .92rem; margin: 10px 0; }
.explainer th, .explainer td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.explainer th { font-weight: 600; background: var(--bg); }
.explainer table.wide td:not(:first-child), .explainer table.wide th:not(:first-child) { white-space: nowrap; font-variant-numeric: tabular-nums; }
.explainer .table-scroll { max-height: none; }
