:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #16203a;
  --muted: #707d93;
  --line: #e4e9f1;
  --line-soft: #eef1f7;
  --brand: #1b56a4;        /* azul VeriFactu */
  --brand-dark: #143f78;
  --brand-soft: #eaf1fb;
  --ok: #12936a;
  --vf: #e0241b;
  --yellow: #f4b400;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(16,30,60,.06);
  --shadow: 0 1px 3px rgba(16,30,60,.06), 0 10px 30px rgba(16,30,60,.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header / footer ---------- */
.site-header { background: var(--panel); border-bottom: 1px solid var(--line); }
.site-footer { background: var(--panel); border-top: 1px solid var(--line); margin-top: 2.5rem; }
.wrap { max-width: 1600px; margin: 0 auto; padding: 1rem 1.4rem; display: flex; align-items: center; gap: 1rem; }
.brand { display: inline-flex; }
.site-logo { height: 36px; width: auto; display: block; }
.site-footer p { color: var(--muted); font-size: .82rem; margin: 0; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1600px;
  margin: 1.6rem auto;
  padding: 0 1.4rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.6rem;
  align-items: start;
}
@media (max-width: 920px) { .layout { grid-template-columns: 1fr; } }

/* ---------- Panel formulario ---------- */
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* Control segmentado (Factura/Presupuesto) */
.doc-type {
  display: inline-flex;
  background: var(--line-soft);
  border-radius: 11px;
  padding: 4px;
  gap: 3px;
  margin-bottom: 1.4rem;
}
.doc-type label {
  margin: 0; flex-direction: row; align-items: center;
  padding: .5rem 1.1rem; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: .85rem; color: var(--muted);
  transition: background .15s, color .15s;
}
.doc-type input { display: none; }
.doc-type label:has(input:checked) { background: #fff; color: var(--brand); box-shadow: var(--shadow-sm); }

/* Secciones tipo tarjeta */
fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.4rem 1.1rem 0.7rem;
  margin: 0 0 1.1rem;
  position: relative;
}
legend {
  font-weight: 700; font-size: .66rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--brand-dark); background: var(--brand-soft);
  padding: .28rem .7rem; border-radius: 7px; margin-left: -.2rem;
}

/* Inputs y labels */
label {
  display: flex; flex-direction: column; gap: .35rem;
  font-size: .72rem; font-weight: 600; color: var(--muted);
  letter-spacing: .01em; margin-bottom: .8rem;
}
label.check, label.consent { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
label.check { min-height: 42px; margin-bottom: .8rem; }
input, select {
  font: inherit; font-size: .9rem; height: 42px; padding: 0 .75rem;
  border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--ink); width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type="file"] { height: auto; padding: .5rem; font-size: .82rem; }
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input::placeholder, textarea::placeholder { color: #aab3c4; }
textarea {
  font: inherit; font-size: .9rem; padding: .6rem .75rem; width: 100%;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
  resize: vertical; min-height: 72px; transition: border-color .15s, box-shadow .15s;
}
textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
/* Checkboxes: que no se estiren como los inputs de texto */
input[type="checkbox"] {
  width: 18px; height: 18px; min-width: 18px; flex: none;
  padding: 0; margin: 0; accent-color: var(--brand); cursor: pointer;
}
/* Uploader de logo */
.logo-field { margin-bottom: 1rem; }
.field-label { display: block; font-size: .72rem; font-weight: 600; color: var(--muted); margin-bottom: .4rem; }
.file-upload { display: flex; align-items: center; gap: .65rem; border: 1px dashed #c4d2e6; border-radius: 10px; padding: .55rem .6rem; background: #fbfcfe; }
.file-input { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.file-btn { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: .45rem; margin: 0 !important; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .45rem .8rem; font-size: .82rem; font-weight: 600; color: var(--brand-dark); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.file-btn:hover { background: var(--brand-soft); border-color: var(--brand); }
.file-thumb { height: 30px; width: auto; max-width: 64px; object-fit: contain; border-radius: 5px; border: 1px solid var(--line-soft); background: #fff; }
.file-name { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-clear { margin-left: auto; flex: none; background: none; border: 0; color: var(--vf); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 0 .2rem; }
.file-clear:hover { color: #a3160f; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; align-items: end; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .7rem; align-items: end; }
.req { color: var(--vf); font-weight: 700; }

/* Tipo de cliente (segmentado pequeño) */
.cliente-tipo { display: inline-flex; background: var(--line-soft); border-radius: 9px; padding: 3px; gap: 2px; margin-bottom: 1rem; }
.cliente-tipo label { margin: 0; flex-direction: row; align-items: center; padding: .4rem .8rem; border-radius: 7px; font-size: .8rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.cliente-tipo input { display: none; }
.cliente-tipo label:has(input:checked) { background: #fff; color: var(--brand); box-shadow: var(--shadow-sm); }

/* Líneas */
.linea { display: grid; grid-template-columns: 2fr .55fr .6fr .8fr .55fr .85fr auto; gap: .4rem; align-items: end; margin-bottom: .55rem; }
.linea label { margin: 0; }
.linea .del { background: none; border: 0; color: var(--vf); font-size: 1.3rem; cursor: pointer; padding: 0 .3rem; height: 42px; }
@media (max-width: 560px) { .linea { grid-template-columns: 1fr 1fr; } }

/* Campos de factura rectificativa */
.rect-fields { margin-top: .4rem; padding-top: .9rem; border-top: 1px dashed var(--line); }
.inv-rect { margin: 0 0 1rem; padding: .55rem .8rem; background: #fdf3f2; border-left: 3px solid var(--vf); border-radius: 0 8px 8px 0; font-size: .8rem; color: var(--ink); }

/* Botones */
button { cursor: pointer; font: inherit; border-radius: 9px; border: 1px solid transparent; }
.btn-ghost { background: var(--brand-soft); color: var(--brand-dark); border: 1px dashed #b9cdeb; padding: .55rem .9rem; font-weight: 600; font-size: .85rem; width: 100%; }
.btn-ghost:hover { background: #e1ecfb; }
.btn-primary { background: var(--brand); color: #fff; padding: 0 1.4rem; height: 48px; font-weight: 700; font-size: 1rem; box-shadow: 0 6px 16px rgba(27,86,164,.25); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--ink); color: #fff; height: 42px; padding: 0 1rem; font-weight: 600; font-size: .85rem; }
.actions { margin: .3rem 0 1.4rem; }

/* Captura email */
.capture { background: var(--brand-soft); border-color: #cfe0f6; }
.capture legend { background: var(--brand); color: #fff; }
.hint { font-size: .8rem; color: var(--muted); margin: .1rem 0 .7rem; font-weight: 500; }
.consent { font-size: .74rem; }
.consent a, .hint a { color: var(--brand); }
.lead-ok { color: var(--ok); font-weight: 700; margin: .5rem 0 0; font-size: .85rem; }

/* ---------- Invoice preview ---------- */
.preview-panel { position: sticky; top: 1.2rem; }
.invoice {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2.2rem; box-shadow: var(--shadow); font-size: .9rem;
}
.inv-head { display: flex; justify-content: space-between; gap: 1rem; padding-bottom: 1.1rem; border-bottom: 2px solid var(--brand); }
.inv-emisor { display: flex; flex-direction: column; gap: .12rem; }
.inv-emisor strong { font-size: 1.05rem; }
.inv-logo { max-width: 150px; max-height: 70px; object-fit: contain; margin-bottom: .5rem; }
.inv-meta { text-align: right; }
.inv-meta h1 { margin: 0 0 .35rem; font-size: 1.55rem; font-weight: 800; letter-spacing: .02em; color: var(--brand); }
.inv-cliente { display: flex; flex-direction: column; gap: .12rem; margin: 1.1rem 0; }
.muted { color: var(--muted); font-size: .78rem; }

.inv-table { width: 100%; border-collapse: collapse; margin: .7rem 0; }
.inv-table th { text-align: left; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); padding: .5rem .3rem; }
.inv-table td { padding: .5rem .3rem; border-bottom: 1px solid var(--line-soft); }
.inv-table td:nth-child(n+2), .inv-table th:nth-child(n+2) { text-align: right; white-space: nowrap; }

.inv-totales { margin-left: auto; width: 62%; min-width: 250px; margin-top: .6rem; }
.inv-totales > div { display: flex; justify-content: space-between; padding: .28rem 0; font-size: .88rem; }
.inv-totales > div[hidden] { display: none; }
#p_iva_desglose { display: contents; }
.inv-totales .t-row { display: flex; justify-content: space-between; padding: .28rem 0; font-size: .88rem; }
.inv-totales .total { border-top: 2px solid var(--ink); margin-top: .35rem; padding-top: .55rem; font-weight: 800; font-size: 1.2rem; }

.inv-mencion { margin: 1.1rem 0 0; padding: .65rem .85rem; background: #fbfcfe; border-left: 3px solid var(--brand); border-radius: 0 8px 8px 0; font-size: .8rem; color: var(--ink); }
.inv-notas { margin: 1.1rem 0 0; font-size: .82rem; color: var(--ink); }
.inv-pago { margin-bottom: .4rem; }
.inv-pago .muted { font-weight: 600; }
.inv-notas-text { margin: 0; white-space: pre-wrap; color: #444f63; }

/* ---- Bloque VeriFactu (teaser) ---- */
.inv-verifactu { position: relative; display: flex; align-items: center; gap: 1.1rem; margin-top: 1.7rem; padding-top: 1.1rem; border-top: 1px dashed var(--line); min-height: 110px; }
.vf-content { display: flex; align-items: center; gap: 1.1rem; transition: filter .25s ease; }
.inv-verifactu:not(.revealed) .vf-content { filter: blur(7px); opacity: .85; pointer-events: none; user-select: none; }
#qr { width: 96px; height: 96px; }
.vf-info { display: flex; flex-direction: column; gap: .35rem; }
.vf-logo-img { height: 32px; width: auto; align-self: flex-start; }
.vf-info code { font-size: .68rem; color: var(--muted); word-break: break-all; }

.vf-lock { position: absolute; inset: 1.1rem 0 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .45rem; }
.inv-verifactu.revealed .vf-lock { display: none; }
.btn-verifactu { background: #fff; color: var(--ink); border: 1px solid var(--line); padding: .55rem 1.1rem; font-weight: 700; font-size: .95rem; display: inline-flex; align-items: center; gap: .5rem; box-shadow: 0 4px 16px rgba(16,30,60,.16); }
.btn-verifactu:hover { background: #f7f9ff; border-color: var(--brand); }
.btn-vf-logo { height: 20px; width: auto; }
.vf-lock-hint { font-size: .72rem; color: var(--muted); font-weight: 500; }
.vf-note { margin: .8rem 0 0; font-size: .78rem; color: var(--muted); }
.vf-note a { color: var(--brand); }

/* ---------- Barra de acción fija ---------- */
body { padding-bottom: 86px; }
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: rgba(255,255,255,.92);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(16,30,60,.08);
}
.action-bar-inner {
  max-width: 1600px; margin: 0 auto; padding: .85rem 1.4rem;
  display: flex; align-items: center; justify-content: flex-end; gap: 1.2rem;
}
.action-hint { font-size: .82rem; color: var(--muted); font-weight: 500; text-align: right; }
.action-hint.ready { color: var(--ok); font-weight: 600; }
.btn-generar {
  background: var(--brand); color: #fff; height: 50px; padding: 0 2.2rem;
  font-weight: 700; font-size: 1rem; border-radius: 11px; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(27,86,164,.32); transition: background .15s, box-shadow .15s;
}
.btn-generar:hover:not(:disabled) { background: var(--brand-dark); }
.btn-generar:disabled { background: #c5cdda; color: #eef1f6; cursor: not-allowed; box-shadow: none; }
@media (max-width: 560px) {
  .action-bar-inner { flex-direction: column-reverse; gap: .6rem; align-items: stretch; }
  .btn-generar { width: 100%; }
  .action-hint { text-align: center; }
  body { padding-bottom: 130px; }
}

/* ---------- Pop-up de registro ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 1.2rem;
  background: rgba(16,30,60,.55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: vfFade .2s ease;
}
.modal-overlay[hidden] { display: none; }
.modal {
  position: relative; background: #fff; border-radius: 18px;
  max-width: 470px; width: 100%; padding: 2rem 1.8rem 1.5rem;
  box-shadow: 0 30px 80px rgba(16,30,60,.35); animation: vfPop .25s ease;
  max-height: 92vh; overflow-y: auto;
}
.modal-close { position: absolute; top: .7rem; right: .9rem; background: none; border: 0; font-size: 1.7rem; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--ink); }
.modal h2 { margin: 0 0 .4rem; font-size: 1.4rem; }
.modal-sub { margin: 0 0 1.2rem; color: var(--muted); font-size: .92rem; }
.modal-features { list-style: none; padding: 0; margin: 0 0 1.4rem; display: grid; gap: .55rem; }
.modal-features li { display: flex; align-items: flex-start; gap: .55rem; font-size: .88rem; }
.modal-features li::before { content: "✓"; color: var(--brand); font-weight: 800; flex: none; }
.modal-vf { height: 14px; width: auto; vertical-align: middle; margin: 0 1px; }
.modal-form { display: flex; gap: .5rem; margin-bottom: .7rem; }
.modal-form input { flex: 1; }
.btn-reg { background: var(--brand); color: #fff; padding: 0 1.2rem; height: 42px; font-weight: 700; white-space: nowrap; box-shadow: 0 6px 16px rgba(27,86,164,.3); }
.btn-reg:hover { background: var(--brand-dark); }
.modal-consent { flex-direction: row; font-size: .74rem; color: var(--muted); display: flex; gap: .45rem; align-items: center; }
.modal-consent a { color: var(--brand); }
.modal-foot { font-size: .74rem; color: var(--muted); text-align: center; margin: 1.1rem 0 0; }
.modal-ok { color: var(--ok); font-weight: 700; text-align: center; margin: 1rem 0 0; }
@keyframes vfFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes vfPop { from { transform: translateY(14px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Print ---------- */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .layout { display: block; margin: 0; padding: 0; max-width: none; }
  .preview-panel { position: static; }
  .invoice { border: 0; box-shadow: none; border-radius: 0; padding: 0; }
}
