/* =========================================================================
   FactuLibre — styles.css
   Secciones: 1.Reset 2.Vars 3.Layout 4.Header 5.Hero 6.Tool 7.Form
   8.LineItems 9.Preview 10.AdSlots 11.Content 12.FAQ 13.Footer 14.Print
   15.Responsive
   ========================================================================= */

/* ---------- 1. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -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; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.15; letter-spacing: -0.01em; font-family: var(--display); }
ul { list-style: none; }
::selection { background: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
input, select, textarea { font: inherit; color: inherit; }

.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--ink); color: #fff;
  z-index: 9999; border-radius: 8px; font-weight: 600; font-size: .9rem;
}
.skip-link:focus { top: 1rem; }

/* ---------- 2. Vars ---------- */
:root {
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Manrope", var(--sans);

  --bg: #f6f7fb;
  --surface: #ffffff;
  --ink: #171a2b;
  --ink-soft: #565b73;
  --border: #e2e4ee;
  --accent: #2f5dfa;
  --accent-ink: #1d3ec2;
  --accent-soft: #ebf0ff;
  --ok: #17805a;
  --ok-soft: #e6f6ef;
  --warn: #b5460a;
  --warn-soft: #fdece2;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(23,26,43,.04), 0 8px 24px -12px rgba(23,26,43,.14);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --container: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --surface: #171a2b;
    --ink: #f2f3f8;
    --ink-soft: #a8abc2;
    --border: #2b2f47;
    --accent: #6b8bff;
    --accent-ink: #a9bbff;
    --accent-soft: #1c2440;
    --ok: #35c98d;
    --ok-soft: #103527;
    --warn: #ff9457;
    --warn-soft: #3a2314;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ---------- 3. Layout ---------- */
.container { max-width: var(--container); margin-inline: auto; padding-inline: 1.25rem; }
section { padding-block: clamp(2.5rem, 6vw, 4.5rem); }
.section-head { max-width: 640px; margin-bottom: 2rem; }
.section-head h2 { font-size: clamp(1.5rem, 3vw, 2.1rem); margin-bottom: .6rem; }
.section-head p { color: var(--ink-soft); font-size: 1.05rem; }
.eyebrow {
  display: inline-block; font-size: .78rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent-ink); background: var(--accent-soft);
  padding: .3rem .7rem; border-radius: 100px; margin-bottom: .9rem;
}

/* ---------- 4. Header ---------- */
.site-header { position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.site-header .container { display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-height: 64px; padding-block: .5rem; flex-wrap: wrap; row-gap: .4rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-family: var(--display); font-weight: 800; font-size: 1.15rem; }
.brand svg { flex-shrink: 0; }
.main-nav { display: flex; align-items: center; gap: 1.6rem; }
.main-nav a { font-size: .92rem; font-weight: 600; color: var(--ink-soft); transition: color .2s var(--ease-out); }
.main-nav a:hover { color: var(--ink); }
.nav-cta {
  background: var(--ink); color: var(--bg); padding: .6rem 1.1rem; border-radius: 100px;
  font-size: .88rem; font-weight: 700; transition: transform .2s var(--ease-out), opacity .2s;
}
.nav-cta:hover { transform: translateY(-1px); opacity: .92; }
.nav-toggle { display: none; }

/* ---------- 5. Hero ---------- */
.hero { padding-block: clamp(2.2rem, 6vw, 3.5rem) 1.5rem; }
.hero .container { max-width: 760px; text-align: center; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); margin-bottom: .9rem; }
.hero .lead { font-size: clamp(1.02rem, 2vw, 1.2rem); color: var(--ink-soft); max-width: 560px; margin-inline: auto; margin-bottom: 1.6rem; }
.hero-badges { display: flex; flex-wrap: wrap; gap: .55rem; justify-content: center; margin-top: 1.4rem; }
.badge {
  display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; font-weight: 600;
  color: var(--ink-soft); background: var(--surface); border: 1px solid var(--border);
  padding: .4rem .8rem; border-radius: 100px;
}
.badge svg { width: 14px; height: 14px; color: var(--ok); }

/* ---------- 6. Tool card / generator ---------- */
.tool-section { padding-top: .5rem; }
.tool-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow); overflow: hidden;
}
.tool-grid { display: grid; grid-template-columns: 1fr; }
@media (min-width: 960px) {
  .tool-grid { grid-template-columns: 1.15fr 1fr; align-items: stretch; }
  .tool-form-pane { border-right: 1px solid var(--border); }
}
.tool-form-pane, .tool-preview-pane { min-width: 0; }
.tool-form-pane { padding: clamp(1.25rem, 3vw, 2rem); }
.tool-preview-pane {
  padding: clamp(1.25rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--bg) 60%, var(--surface));
  display: flex; flex-direction: column; gap: 1rem;
}

.form-fieldset { border: 0; padding: 0; margin: 0 0 1.75rem; min-width: 0; }
.form-fieldset:last-child { margin-bottom: 0; }
.form-fieldset > legend {
  font-family: var(--display); font-weight: 800; font-size: 1.02rem;
  display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; padding: 0;
}
.form-fieldset > legend .step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent-ink); font-size: .78rem; font-weight: 800;
}

/* ---------- 7. Form ---------- */
.field-grid { display: grid; grid-template-columns: 1fr; gap: .9rem; }
@media (min-width: 560px) { .field-grid.cols-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 720px) { .field-grid.cols-3 { grid-template-columns: 1.4fr 1fr 1fr; } }

.field { display: flex; flex-direction: column; gap: .35rem; }
.field label { font-size: .82rem; font-weight: 700; color: var(--ink-soft); }
.field label .opt { font-weight: 500; color: var(--ink-soft); opacity: .7; }
.field label .req { color: var(--warn); }
.field input, .field select, .field textarea {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .62rem .75rem; background: var(--surface); font-size: .95rem;
  transition: border-color .15s var(--ease-out), box-shadow .15s var(--ease-out);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none;
}
.field textarea { resize: vertical; min-height: 4.5em; }
.field.has-error input, .field.has-error select { border-color: var(--warn); }
.field-error { font-size: .78rem; color: var(--warn); min-height: 1em; }

/* ---------- 8. Line items ---------- */
.lines-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table.lines { width: 100%; border-collapse: collapse; min-width: 640px; }
table.lines th {
  text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft); font-weight: 700; padding: .6rem .6rem; background: var(--accent-soft);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.lines td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.lines tr:last-child td { border-bottom: 0; }
table.lines input, table.lines select { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .55rem; font-size: .9rem; background: var(--surface); }
table.lines input:focus, table.lines select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.col-desc { min-width: 200px; }
.col-num { width: 92px; }
.col-pct { width: 84px; }
.line-total-cell { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.line-remove {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; color: var(--ink-soft); transition: background .15s, color .15s;
}
.line-remove:hover { background: var(--warn-soft); color: var(--warn); }

.add-line-btn {
  margin-top: .75rem; display: inline-flex; align-items: center; gap: .4rem;
  font-size: .88rem; font-weight: 700; color: var(--accent-ink);
  border: 1px dashed var(--accent); border-radius: 100px; padding: .5rem 1rem;
  transition: background .15s var(--ease-out);
}
.add-line-btn:hover { background: var(--accent-soft); }

.totals-row { display: flex; justify-content: flex-end; margin-top: 1rem; }
.totals-box { width: 100%; max-width: 320px; font-size: .92rem; }
.totals-box .t-row { display: flex; justify-content: space-between; padding: .32rem 0; color: var(--ink-soft); }
.totals-box .t-row.grand { border-top: 1px solid var(--border); margin-top: .4rem; padding-top: .6rem; font-size: 1.15rem; font-weight: 800; color: var(--ink); }
.totals-box .t-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }

.irpf-toggle-row { display: flex; align-items: center; gap: .6rem; margin: 1.1rem 0 .3rem; }
.irpf-toggle-row select { max-width: 110px; }

/* ---------- 9. Preview ---------- */
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.preview-toolbar h2 { font-size: 1rem; font-family: var(--sans); font-weight: 700; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border-radius: 100px; padding: .8rem 1.4rem; font-weight: 700; font-size: .95rem;
  transition: transform .18s var(--ease-out), box-shadow .18s var(--ease-out), opacity .18s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 28px -10px color-mix(in srgb, var(--accent) 75%, transparent); }
.btn-primary:active { transform: translateY(0); }
.btn-primary[disabled] { opacity: .55; pointer-events: none; box-shadow: none; }
.btn-ghost { background: var(--surface); border: 1px solid var(--border); color: var(--ink); }
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn-block { width: 100%; }
.btn-lg { padding: 1rem 1.6rem; font-size: 1.02rem; }

.invoice-preview-scroll { flex: 1; overflow: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); background: #fff; }
.invoice-sheet {
  width: 100%; aspect-ratio: 210 / 297; background: #fff; color: #1a1a1a;
  padding: 8%; font-size: .68rem; line-height: 1.45;
}
.invoice-sheet * { color: inherit; }
.invoice-top { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 5%; }
.invoice-top .doc-title { font-size: 1.7em; font-weight: 800; font-family: var(--display); letter-spacing: -.01em; }
.invoice-top .doc-meta { text-align: right; font-size: .95em; }
.invoice-top .doc-meta div { margin-bottom: .15em; }
.invoice-parties { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 5%; }
.invoice-parties .party { max-width: 46%; }
.invoice-parties .party h4 { font-size: .78em; text-transform: uppercase; letter-spacing: .06em; color: #6a6f85; margin-bottom: .4em; font-family: var(--sans); }
.invoice-parties .party p { margin: 0; white-space: pre-line; }
.invoice-parties .party .name { font-weight: 700; font-size: 1.05em; margin-bottom: .15em; }
table.invoice-lines { width: 100%; border-collapse: collapse; margin-bottom: 4%; }
table.invoice-lines th {
  text-align: left; font-size: .82em; text-transform: uppercase; letter-spacing: .03em; color: #6a6f85;
  border-bottom: 1.5px solid #d8dae4; padding: .5em .3em; font-weight: 700;
}
table.invoice-lines td { padding: .5em .3em; border-bottom: .75px solid #eceef4; }
table.invoice-lines th:not(:first-child), table.invoice-lines td:not(:first-child) { text-align: right; white-space: nowrap; }
.invoice-bottom { display: flex; justify-content: space-between; gap: 1rem; }
.invoice-notes { max-width: 52%; font-size: .95em; color: #4a4f66; white-space: pre-line; }
.invoice-totals { min-width: 42%; }
.invoice-totals .r { display: flex; justify-content: space-between; padding: .28em 0; gap: .6em; }
.invoice-totals .r > span:first-child { min-width: 0; }
.invoice-totals .r > span:last-child { white-space: nowrap; flex-shrink: 0; }
.invoice-totals .r.sub { color: #6a6f85; }
.invoice-totals .r.grand { border-top: 1.5px solid #1a1a1a; margin-top: .3em; padding-top: .5em; font-weight: 800; font-size: 1.15em; }
.iva-base-note { color: #9599ad; font-size: .92em; }
.invoice-footer-note { margin-top: 6%; padding-top: 3%; border-top: .75px solid #eceef4; font-size: .82em; color: #8a8fa3; }

.invoice-empty-hint { padding: 1.2rem; font-size: .85rem; color: var(--ink-soft); text-align: center; }

/* ---------- 10. Ad slots ---------- */
.ad-slot {
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  min-height: 90px; display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font-size: .78rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; background: color-mix(in srgb, var(--bg) 50%, var(--surface));
  margin-block: 1.75rem;
}

/* ---------- 11. Content sections ---------- */
.steps { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
@media (min-width: 720px) { .steps { grid-template-columns: repeat(3, 1fr); } }
.step-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.step-card .step-num {
  width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font-weight: 800; margin-bottom: .9rem;
}
.step-card h3 { font-size: 1.05rem; margin-bottom: .4rem; }
.step-card p { color: var(--ink-soft); font-size: .92rem; }

.prose { max-width: 760px; color: var(--ink-soft); font-size: 1.02rem; }
.prose p { margin-bottom: 1rem; }
.prose strong { color: var(--ink); }

.audience-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 1rem; }
@media (min-width: 720px) { .audience-grid { grid-template-columns: repeat(5,1fr); } }
.audience-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem .9rem; text-align: center; font-size: .88rem; font-weight: 700;
}
.audience-card svg { width: 26px; height: 26px; margin: 0 auto .55rem; display: block; color: var(--accent); }

.related-grid { display: grid; grid-template-columns: 1fr; gap: .85rem; }
@media (min-width: 640px) { .related-grid { grid-template-columns: repeat(2,1fr); } }
@media (min-width: 960px) { .related-grid { grid-template-columns: repeat(3,1fr); } }
.related-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem; display: flex; align-items: flex-start; gap: .8rem;
}
.related-card svg { width: 22px; height: 22px; color: var(--accent); flex-shrink: 0; margin-top: .1rem; }
.related-card h3 { font-size: .95rem; margin-bottom: .25rem; }
.related-card p { font-size: .82rem; color: var(--ink-soft); }
.related-card .soon { display: inline-block; margin-top: .5rem; font-size: .72rem; font-weight: 700; color: var(--accent-ink); background: var(--accent-soft); padding: .15rem .5rem; border-radius: 100px; }

/* ---------- 12. FAQ ---------- */
.faq-list { max-width: 780px; border-top: 1px solid var(--border); }
.faq-item { border-bottom: 1px solid var(--border); }
.faq-item summary {
  cursor: pointer; list-style: none; padding: 1.1rem .2rem; font-weight: 700; font-size: 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary .chev { flex-shrink: 0; transition: transform .2s var(--ease-out); color: var(--accent); }
.faq-item[open] summary .chev { transform: rotate(180deg); }
.faq-item p { padding: 0 .2rem 1.1rem; color: var(--ink-soft); max-width: 680px; }

/* ---------- 13. Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding-block: 2.5rem 3rem; margin-top: 1rem; }
.footer-grid { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.footer-brand p { color: var(--ink-soft); font-size: .88rem; max-width: 320px; margin-top: .6rem; }
.footer-cols { display: flex; gap: 3rem; flex-wrap: wrap; }
.footer-col h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin-bottom: .8rem; }
.footer-col a, .footer-col span { display: block; font-size: .9rem; padding-block: .3rem; color: var(--ink-soft); }
.footer-col a:hover { color: var(--accent-ink); }
.footer-bottom { border-top: 1px solid var(--border); padding-top: 1.4rem; font-size: .82rem; color: var(--ink-soft); display: flex; justify-content: space-between; flex-wrap: wrap; gap: .6rem; }

/* Legal pages */
.legal-page main { padding-block: 2.5rem 4rem; }
.legal-page .container { max-width: 760px; }
.legal-page h1 { font-size: 2rem; margin-bottom: .5rem; }
.legal-page .updated { color: var(--ink-soft); font-size: .88rem; margin-bottom: 2rem; }
.legal-page h2 { font-size: 1.15rem; margin: 1.8rem 0 .6rem; }
.legal-page p, .legal-page li { color: var(--ink-soft); margin-bottom: .8rem; }
.legal-page ul { list-style: disc; padding-left: 1.3rem; }
.legal-page .todo { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: .2rem .5rem; font-size: .85em; font-weight: 700; }

/* ---------- 14. Print ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff !important; }
  /* Remove everything from layout flow except the invoice sheet itself.
     display:none (not visibility:hidden) so the document collapses to a
     single page instead of leaving blank pages behind hidden content. */
  .site-header, .site-footer, main > *:not(.tool-section) { display: none !important; }
  .tool-section { padding: 0 !important; }
  .tool-section .container > *:not(.tool-card) { display: none !important; }
  .tool-card { box-shadow: none !important; border: 0 !important; border-radius: 0 !important; }
  .tool-grid { display: block !important; }
  .tool-form-pane { display: none !important; }
  .tool-preview-pane { display: block !important; padding: 0 !important; background: none !important; }
  .tool-preview-pane > *:not(.invoice-preview-scroll) { display: none !important; }
  .invoice-preview-scroll { overflow: visible !important; border: 0 !important; border-radius: 0 !important; }
  #invoiceSheet {
    width: 100% !important; aspect-ratio: auto !important; padding: 0 !important;
    font-size: 11.5px;
  }
}

/* ---------- 15. Responsive helpers ---------- */
@media (max-width: 719px) {
  .main-nav { display: none; }
}
@media (max-width: 479px) {
  .brand { font-size: 1rem; gap: .4rem; }
  .brand svg { width: 22px; height: 22px; }
  .nav-cta { padding: .55rem .9rem; font-size: .8rem; }
}
.container.narrow { max-width: 780px; }
