/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8f9fc;
  --ink: #151d31;
  --ink-soft: #5b6272;
  --ink-faint: #8b93a3;
  --border: #e3e6ee;
  --border-strong: #d3d8e4;
  --accent: #146452;
  --accent-strong: #0f4d3f;
  --accent-soft: #e6f3ee;
  --danger: #b3432f;
  --danger-soft: #fbeee9;
  --navy: #16213a;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Sora", var(--sans);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 20px;
  --shadow-card: 0 1px 2px rgba(21, 29, 49, 0.04), 0 10px 30px -12px rgba(21, 29, 49, 0.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --surface: #161d2c;
    --surface-soft: #1b2334;
    --ink: #eef1f7;
    --ink-soft: #aab1c2;
    --ink-faint: #767e91;
    --border: #262f45;
    --border-strong: #313c56;
    --accent: #3fcaa3;
    --accent-strong: #6fe0bd;
    --accent-soft: #16302a;
    --danger: #e08066;
    --danger-soft: #33201b;
    --navy: #eef1f7;
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}
img, svg, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.15; font-family: var(--display); font-weight: 700; }
::selection { background: var(--accent-soft); color: var(--accent-strong); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* =============================================================
   3. Utilities
   ============================================================= */
.container { max-width: 1180px; margin-inline: auto; padding-inline: 1.25rem; }
.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--navy); color: #fff;
  z-index: 9999; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }
.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;
}

/* =============================================================
   4. Header
   ============================================================= */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .container {
  display: flex; align-items: center; justify-content: space-between;
  padding-block: 1rem;
}
.brand { display: flex; align-items: center; gap: .55rem; font-family: var(--display); font-weight: 700; font-size: 1.05rem; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: .95rem; font-weight: 800;
}
.header-nav { display: flex; align-items: center; gap: 1.4rem; }
.header-nav a {
  font-size: .9rem; color: var(--ink-soft); text-decoration: none; font-weight: 500;
}
.header-nav a:hover { color: var(--ink); }

.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  font-size: .9rem; color: var(--ink-soft); font-weight: 500;
  display: inline-flex; align-items: center; gap: .3rem;
}
.nav-dropdown-toggle:hover, .nav-dropdown-toggle[aria-expanded="true"] { color: var(--ink); }
.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + .6rem);
  left: 0;
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-card);
  padding: .4rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  z-index: 100;
}
.nav-dropdown-menu[hidden] { display: none; }
.nav-dropdown-menu a {
  padding: .55rem .7rem;
  border-radius: var(--radius-s);
  font-size: .88rem;
  color: var(--ink-soft);
  text-decoration: none;
}
.nav-dropdown-menu a:hover { background: var(--surface-soft); color: var(--ink); }

/* =============================================================
   5. Hero
   ============================================================= */
.hero { padding-block: 2.2rem 1.4rem; }
.hero h1 {
  font-size: clamp(1.7rem, 3.4vw, 2.5rem);
  max-width: 22ch;
  color: var(--navy);
}
.hero p.subtitle {
  margin-top: .6rem;
  color: var(--ink-soft);
  font-size: 1.05rem;
  max-width: 60ch;
}

/* =============================================================
   6. Tool card
   ============================================================= */
.tool-section { padding-bottom: 1.5rem; }
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-card);
  padding: clamp(1.1rem, 2.5vw, 1.9rem);
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.6rem;
}
@media (min-width: 960px) {
  .tool-card { grid-template-columns: 1.5fr 1fr; align-items: start; }
}

.field { display: flex; flex-direction: column; gap: .35rem; }
.field span { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  font: inherit;
  padding: .6rem .7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface-soft);
  color: var(--ink);
  width: 100%;
  transition: border-color .15s var(--ease-out), background .15s var(--ease-out);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
}

fieldset.party-fields {
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 1rem;
  display: grid;
  gap: .7rem;
}
fieldset.party-fields legend {
  font-size: .82rem;
  font-weight: 700;
  color: var(--navy);
  padding-inline: .3rem;
}

.form-grid.two-col {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
  margin-bottom: 1.1rem;
}
.form-grid.two-col.no-margin { margin-bottom: 0; }
@media (min-width: 620px) {
  .form-grid.two-col { grid-template-columns: 1fr 1fr; }
}

.amount-field-wrap { margin-bottom: 1.2rem; max-width: 320px; }

.invoice-meta {
  display: grid;
  gap: .8rem;
  grid-template-columns: 1fr;
  margin-bottom: 1.2rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
@media (min-width: 620px) {
  .invoice-meta { grid-template-columns: repeat(3, 1fr); }
}

.line-items { display: grid; gap: .7rem; margin-bottom: .7rem; }
.line-row {
  display: grid;
  gap: .6rem;
  grid-template-columns: 1fr;
  padding: .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface-soft);
  position: relative;
}
@media (min-width: 720px) {
  .line-row { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; }
}
.btn-remove-row {
  justify-self: end;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  color: var(--ink-soft);
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-remove-row:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.btn-remove-row:disabled { opacity: .35; cursor: not-allowed; }

.btn-add-line {
  align-self: start;
  font-size: .88rem;
  font-weight: 600;
  color: var(--accent-strong);
  padding: .5rem .3rem;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}
.btn-add-line:hover { color: var(--accent); }

.irpf-select {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
  max-width: 420px;
}

/* --- Receipt panel --- */
.receipt-panel {
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius-m);
  padding: 1.4rem;
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}
@media (prefers-color-scheme: dark) {
  .receipt-panel { background: #0b1120; border: 1px solid var(--border); }
}
.receipt-panel h2 {
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: rgba(255,255,255,.65);
  font-family: var(--sans);
  font-weight: 700;
}
#receipt { display: flex; flex-direction: column; gap: .55rem; }
.receipt-empty { color: rgba(255,255,255,.55); font-size: .9rem; }
.receipt-line, .receipt-row {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: .9rem;
}
.receipt-line-label { color: rgba(255,255,255,.75); }
.receipt-line-label em { color: rgba(255,255,255,.45); font-style: normal; font-size: .8rem; }
.receipt-line-value { font-variant-numeric: tabular-nums; }
.receipt-divider { height: 1px; background: rgba(255,255,255,.14); margin-block: .2rem; }
.receipt-row strong { font-variant-numeric: tabular-nums; font-weight: 600; }
.receipt-row .pos { color: #7fe3c1; }
.receipt-row .neg { color: #f2a98f; }
.receipt-total { font-size: 1.15rem; padding-top: .3rem; }
.receipt-total strong { color: #fff; font-size: 1.35rem; }

.btn-primary {
  margin-top: .3rem;
  width: 100%;
  padding: .85rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-s);
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
  transition: background .15s var(--ease-out), transform .15s var(--ease-out);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-primary:active:not(:disabled) { transform: scale(.98); }
.btn-primary:disabled { opacity: .6; cursor: progress; }

.tool-message {
  font-size: .85rem;
  min-height: 1.2em;
}
[data-state="error"] .tool-message { color: #f2a98f; }
[data-state="done"] .tool-message::before { content: "✓ "; }

.privacy-badge {
  margin-top: 1rem;
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  font-size: .88rem;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  border-radius: var(--radius-m);
  padding: .85rem 1rem;
}
.privacy-badge strong { color: var(--accent-strong); }

/* =============================================================
   7. Ad slots
   ============================================================= */
.ad-slot {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-m);
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  font-size: .8rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-block: 2rem;
}
.ad-slot--leaderboard { min-height: 90px; }
.ad-slot--incontent { min-height: 250px; }
.ad-slot--footer { min-height: 90px; margin-bottom: 0; margin-top: 2rem; }

/* --- Desktop sidebar (skyscraper) ads --- */
.ad-slot--sidebar { display: none; }
@media (min-width: 1600px) {
  .ad-slot--sidebar {
    display: flex;
    position: fixed;
    top: 110px;
    width: 160px;
    min-height: 600px;
    max-height: calc(100vh - 130px);
    z-index: 10;
    margin: 0;
  }
  .ad-slot--sidebar-left { left: 24px; }
  .ad-slot--sidebar-right { right: 24px; }
}
.ad-slot--dialog { min-height: 250px; margin: 0; }
.ad-slot--toast { min-height: 60px; margin: 0; font-size: .72rem; }

/* --- Download interstitial (dialog) --- */
.ad-dialog {
  border: none;
  border-radius: var(--radius-l);
  padding: 0;
  max-width: 340px;
  width: calc(100% - 2rem);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-card);
}
.ad-dialog::backdrop { background: rgba(10, 14, 26, 0.55); }
.ad-dialog-inner { padding: 1.1rem; display: flex; flex-direction: column; gap: .9rem; }
.ad-dialog-head, .ad-toast-head { display: flex; justify-content: space-between; align-items: center; }
.ad-dialog-head span, .ad-toast-head span {
  font-size: .74rem; font-weight: 700; color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: .05em;
}
.ad-dialog-close, .ad-toast-close {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font-size: .9rem;
  border: 1px solid var(--border-strong);
  transition: color .15s, background .15s;
}
.ad-dialog-close:hover, .ad-toast-close:hover { color: var(--ink); background: var(--surface-soft); }
.ad-dialog-footer { display: flex; justify-content: flex-end; }
.btn-secondary {
  padding: .55rem 1rem;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-strong);
  font-weight: 600;
  font-size: .86rem;
  color: var(--ink-soft);
  transition: background .15s, color .15s;
}
.btn-secondary:hover { background: var(--surface-soft); color: var(--ink); }

/* --- Corner toast --- */
.ad-toast {
  position: fixed;
  right: 1rem; bottom: 1rem;
  width: min(270px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-card);
  padding: .75rem;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transform: translateY(14px);
  opacity: 0;
  transition: transform .3s var(--ease-out), opacity .3s var(--ease-out);
}
.ad-toast.is-visible { transform: translateY(0); opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .ad-toast { transition: opacity .2s linear; transform: none; }
}

/* =============================================================
   8. Content / SEO
   ============================================================= */
.content-section { padding-block: 1.5rem; }
.content-section h2 {
  font-size: clamp(1.3rem, 2.4vw, 1.7rem);
  color: var(--navy);
  margin-bottom: .8rem;
}
.content-section h3 {
  font-size: 1.05rem;
  color: var(--navy);
  margin-top: 1.4rem;
  margin-bottom: .5rem;
}
.content-section p, .content-section li {
  color: var(--ink-soft);
  max-width: 72ch;
}
.content-section ul { padding-left: 1.2rem; display: grid; gap: .4rem; margin-top: .5rem; }
.content-prose { display: grid; gap: .9rem; }

.disclaimer {
  margin-top: 1.5rem;
  padding: 1rem 1.1rem;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
  font-size: .9rem;
  color: var(--ink-soft);
}

/* --- Comparison table --- */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin-block: 1rem;
  font-size: .9rem;
  overflow-x: auto;
  display: block;
}
.compare-table thead, .compare-table tbody { display: table; width: 100%; table-layout: fixed; }
.compare-table th, .compare-table td {
  border: 1px solid var(--border);
  padding: .6rem .7rem;
  text-align: left;
  vertical-align: top;
  color: var(--ink-soft);
}
.compare-table th { background: var(--surface-soft); color: var(--navy); font-weight: 700; }
.compare-table td:first-child { font-weight: 600; color: var(--navy); width: 30%; }

/* --- Cross-link to other tools --- */
.tools-cross-link { margin-top: 2rem; }
.tools-cross-link h2 { font-size: clamp(1.2rem, 2vw, 1.4rem); color: var(--navy); margin-bottom: .8rem; }
.tools-cross-link-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.tool-card-link {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
  text-decoration: none;
  transition: border-color .15s var(--ease-out), transform .15s var(--ease-out);
}
.tool-card-link:hover { border-color: var(--accent); transform: translateY(-2px); }
.tool-card-link strong { color: var(--navy); font-size: 1rem; }
.tool-card-link span { color: var(--ink-soft); font-size: .85rem; }

/* --- FAQ --- */
.faq { margin-top: 1.6rem; display: grid; gap: .6rem; max-width: 72ch; }
.faq details {
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
  padding: .2rem .1rem;
}
.faq summary {
  cursor: pointer;
  list-style: none;
  padding: .85rem 1rem;
  font-weight: 600;
  color: var(--navy);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  font-size: 1.3rem;
  color: var(--accent);
  flex-shrink: 0;
  transition: transform .2s var(--ease-out);
}
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p {
  padding: 0 1rem 1rem;
  color: var(--ink-soft);
}

/* =============================================================
   9. Footer
   ============================================================= */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  padding-block: 1.6rem;
  color: var(--ink-faint);
  font-size: .85rem;
}
.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem 1.4rem;
  justify-content: space-between;
  align-items: center;
}
.footer-links { display: flex; gap: 1.1rem; flex-wrap: wrap; }
.footer-links a { text-decoration: none; color: var(--ink-faint); }
.footer-links a:hover { color: var(--ink-soft); }

/* =============================================================
   10. Legal pages
   ============================================================= */
.legal-page { padding-block: 2.5rem; max-width: 72ch; }
.legal-page h1 { margin-bottom: 1rem; }
.legal-page h2 { margin-top: 1.6rem; margin-bottom: .5rem; font-size: 1.15rem; color: var(--navy); }
.legal-page p, .legal-page li { color: var(--ink-soft); margin-bottom: .6rem; }
