/* ============================================================
   COTIZAFÁCIL — estilos
   ============================================================ */
:root {
  --fondo: #f4f5f8;
  --superficie: #ffffff;
  --texto: #1b1f2a;
  --suave: #5d6475;
  --borde: #dde0e8;
  --primario: #1f4fd1;
  --primario-osc: #173ea6;
  --oro: #f2b705;
  --oro-osc: #c99700;
  --peligro: #c62f2f;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(20, 25, 40, .06), 0 4px 16px rgba(20, 25, 40, .06);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--texto);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fondo); line-height: 1.45; }
h1, h2, h3 { line-height: 1.15; }
a { color: var(--primario); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: .6em 1.1em; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--borde); background: var(--superficie); color: var(--texto);
  text-decoration: none; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #b8bdcc; }
.btn-primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.btn-primario:hover { background: var(--primario-osc); }
.btn-oro { background: var(--oro); border-color: var(--oro); color: #231a00; }
.btn-oro:hover { background: var(--oro-osc); border-color: var(--oro-osc); }
.btn-suave { background: #eef1f7; border-color: transparent; }
.btn-bloque { width: 100%; margin-top: .6rem; }
.btn-grande { font-size: 1.1rem; padding: .85em 1.6em; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-x {
  border: 0; background: none; font-size: 1.3rem; line-height: 1; cursor: pointer;
  color: var(--suave); padding: .2em .45em; border-radius: 6px;
}
.btn-x:hover { background: #fde8e8; color: var(--peligro); }
.enlace { border: 0; background: none; color: var(--primario); cursor: pointer; font: inherit; padding: 0; margin-top: .5rem; }

/* ---------- Barra superior ---------- */
.barra {
  display: flex; justify-content: space-between; align-items: center;
  padding: .7rem 1.2rem; background: var(--superficie); border-bottom: 1px solid var(--borde);
}
.marca { font-weight: 800; font-size: 1.3rem; color: var(--texto); text-decoration: none; letter-spacing: -.02em; }
.marca span { color: var(--primario); }
.barra-acciones { display: flex; gap: .6rem; align-items: center; }
.insignia { font-size: .8rem; font-weight: 700; padding: .25em .7em; border-radius: 99px; background: #eef1f7; color: var(--suave); }
.insignia.es-pro { background: #fff4cc; color: #7a5c00; }

.herramientas {
  display: flex; flex-wrap: wrap; gap: .5rem; padding: .8rem 1.2rem;
  position: sticky; top: 0; z-index: 5; background: var(--fondo);
}
.herramientas #btnWhatsapp { margin-left: auto; }
.btn-whatsapp { color: #0f7a3f; }
.btn-whatsapp:hover { border-color: #25d366; }

/* ---------- Editor ---------- */
.editor {
  display: grid; grid-template-columns: minmax(320px, 440px) 1fr; gap: 1.2rem;
  padding: 0 1.2rem 2rem; align-items: start;
}
.formulario fieldset {
  border: 1px solid var(--borde); border-radius: var(--radio); background: var(--superficie);
  padding: 1rem; margin: 0 0 1rem;
}
.formulario legend { font-weight: 700; padding: 0 .4rem; }
.rejilla { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.rejilla .ancho { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; font-weight: 600; color: var(--suave); }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--texto); width: 100%;
  padding: .5em .6em; border: 1px solid var(--borde); border-radius: 7px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primario); outline-offset: -1px; border-color: transparent; }
input:disabled { background: #f3f4f7; cursor: not-allowed; }
input[type="color"] { padding: .15em; height: 2.4em; }
input[type="file"] { font-size: .8rem; padding: .35em; }
textarea { resize: vertical; }
.pista { font-size: .82rem; color: var(--suave); margin: .5rem 0 0; }
.chip-pro {
  align-self: flex-start; font-size: .68rem; font-weight: 800; padding: .1em .5em; border-radius: 4px;
  background: var(--oro); color: #231a00; cursor: pointer; margin-top: -.1rem;
}
.tabla-lineas { width: 100%; border-collapse: collapse; margin-bottom: .6rem; }
.tabla-lineas th { text-align: left; font-size: .78rem; color: var(--suave); padding: 0 .2rem .3rem; }
.tabla-lineas td { padding: .2rem; }
.tabla-lineas td:nth-child(2) { width: 16%; }
.tabla-lineas td:nth-child(3) { width: 26%; }
.tabla-lineas td:nth-child(4) { width: 2.2rem; }

/* ---------- Hoja (vista previa y PDF) ---------- */
.vista { position: sticky; top: 4rem; }
/* overflow: clip (no hidden) recorta la marca de agua girada sin anular la altura mínima
   automática de aspect-ratio: con hidden, un presupuesto largo quedaba cortado (sin el total).
   hidden queda solo para navegadores antiguos que no conocen clip. */
.hoja {
  --acento: #1f4fd1;
  position: relative; overflow: hidden; overflow: clip;
  background: #fff; color: #1b1f2a; box-shadow: var(--sombra); border-radius: 4px;
  width: 100%; max-width: 820px; aspect-ratio: 210 / 297; margin: 0 auto;
  padding: 7% 7.5%; font-size: clamp(10px, 1.25vw, 14px);
  display: flex; flex-direction: column;
}
.h-cabecera { display: flex; justify-content: space-between; gap: 2em; padding-bottom: 1.5em; border-bottom: 3px solid var(--acento); }
.h-emisor { font-size: .9em; color: #4a5162; }
.h-logo { max-height: 4.5em; max-width: 12em; object-fit: contain; display: block; margin-bottom: .6em; }
.h-nombre { font-size: 1.35em; font-weight: 800; color: #1b1f2a; margin-bottom: .2em; }
.h-doc { text-align: right; font-size: .9em; color: #4a5162; white-space: nowrap; }
.h-titulo { font-size: 2em; font-weight: 800; color: var(--acento); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .2em; }
.h-cliente { margin: 1.6em 0; font-size: .9em; color: #4a5162; }
.h-etq { font-size: .75em; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--acento); margin-bottom: .3em; }
.h-etq-in { font-weight: 600; }
.h-cliente-nombre { font-size: 1.15em; font-weight: 700; color: #1b1f2a; }
.h-tabla { width: 100%; border-collapse: collapse; }
.h-tabla th {
  background: var(--acento); color: #fff; text-align: left; font-size: .82em;
  padding: .6em .8em; text-transform: uppercase; letter-spacing: .04em;
}
.h-tabla td { padding: .65em .8em; border-bottom: 1px solid #e6e8ee; vertical-align: top; }
.h-tabla .der { text-align: right; white-space: nowrap; }
.h-tabla .vacio { text-align: center; color: #9aa0ad; font-style: italic; }
.h-totales { margin-left: auto; width: 45%; min-width: 16em; margin-top: 1em; }
.h-fila { display: flex; justify-content: space-between; padding: .35em .8em; }
.h-total { margin-top: .3em; background: color-mix(in srgb, var(--acento) 10%, #fff); font-size: 1.2em; font-weight: 800; color: var(--acento); border-radius: 4px; padding: .55em .8em; }
.h-notas { margin-top: 2em; font-size: .88em; color: #4a5162; border-top: 1px solid #e6e8ee; padding-top: 1em; }
.h-pie { margin-top: auto; padding-top: 1.5em; text-align: center; font-size: .78em; color: #9aa0ad; }
.h-agua {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 7em; font-weight: 900; color: rgba(31, 79, 209, .06);
  transform: rotate(-30deg); pointer-events: none; white-space: nowrap;
}

/* ---------- Diálogos ---------- */
.dialogo {
  border: 0; border-radius: 14px; padding: 1.6rem; width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.dialogo::backdrop { background: rgba(15, 20, 35, .45); }
.dialogo h2 { margin: 0 0 .6rem; }
.dialogo-cerrar { position: absolute; top: .6rem; right: .7rem; }
.dialogo-cerrar button { border: 0; background: none; font-size: 1.6rem; cursor: pointer; color: var(--suave); }
.dialogo hr { border: 0; border-top: 1px solid var(--borde); margin: 1.2rem 0; }
.oro { color: var(--oro-osc); }
.lista-check { list-style: none; padding: 0; margin: 1rem 0; }
.lista-check li { padding: .3rem 0 .3rem 1.7rem; position: relative; }
.lista-check li::before { content: "✓"; position: absolute; left: 0; font-weight: 800; color: #1a9a52; }
.precio-grande { font-size: 1.5rem; font-weight: 800; margin: .4rem 0 0; }
.mensaje { color: var(--peligro); font-size: .9rem; min-height: 1.2em; margin: .6rem 0 0; }
.historial { list-style: none; padding: 0; margin: 1rem 0 0; max-height: 60vh; overflow: auto; }
.historial li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .4rem .6rem; padding: .7rem 0; border-bottom: 1px solid var(--borde); }
.historial li > div:first-child { display: flex; flex-direction: column; align-items: flex-start; gap: .15rem; min-width: 0; flex: 1 1 11rem; }
.historial li > div:first-child strong { max-width: 100%; overflow-wrap: anywhere; }
.historial .pista { margin: 0; }
.hist-botones { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.hist-botones .btn { padding: .35em .7em; font-size: .82rem; }
.hist-botones select { width: auto; font-size: .82rem; padding: .3em .4em; }

/* Estado del presupuesto (Pendiente / Aceptado / Rechazado) */
.estado { font-size: .72rem; font-weight: 700; padding: .1em .6em; border-radius: 99px; background: #fff4cc; color: #7a5c00; }
.estado-aceptado { background: #dcf5e6; color: #146c3a; }
.estado-rechazado { background: #fde8e8; color: var(--peligro); }
.hist-aceptado { margin: .4rem 0 0; padding: .5rem .7rem; border-radius: 8px; background: #dcf5e6; color: #146c3a; font-size: .88rem; font-weight: 600; overflow-wrap: anywhere; }

/* Copia de seguridad */
.hist-copia { margin-top: 1rem; }
.hist-copia .pista { margin: 0 0 .5rem; }
.hist-copia-botones { display: flex; flex-wrap: wrap; gap: .4rem; }
.hist-copia-botones .btn { flex: 1 1 8rem; }

.aviso {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, calc(100% + 3rem));
  background: #1b1f2a; color: #fff; padding: .7rem 1.2rem; border-radius: 8px;
  font-weight: 600; transition: transform .25s; z-index: 50; max-width: calc(100vw - 32px);
}
.aviso.visible { transform: translate(-50%, 0); }

/* ---------- Móvil ---------- */
@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; padding: 0 16px 2rem; }
  .vista { position: static; }
  .hoja { font-size: 2.3vw; }
  .herramientas, .barra { padding-left: 16px; padding-right: 16px; }
  .herramientas #btnWhatsapp { margin-left: 0; }
  .herramientas .btn { padding: .55em .9em; }
  .dialogo { padding: 1.3rem 1.1rem; }
}

/* ---------- Impresión / PDF ---------- */
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .no-imprimir, dialog { display: none !important; }
  .editor { display: block; padding: 0; }
  .vista { position: static; }
  .hoja {
    /* min-height (no height): si no cabe en una página, sigue en la siguiente en vez de cortarse. */
    box-shadow: none; border-radius: 0; max-width: none; width: 210mm; min-height: 297mm;
    aspect-ratio: auto; padding: 16mm 17mm; font-size: 10.5pt;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    -webkit-box-decoration-break: clone; box-decoration-break: clone;
  }
  .h-tabla tr, .h-totales { break-inside: avoid; }
}

/* ============================================================
   PÁGINA DE VENTA (index.html)
   ============================================================ */
.contenedor { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.web .barra { background: transparent; border: 0; max-width: 1080px; margin: 0 auto; padding: 1rem 20px; }
.heroe { display: grid; grid-template-columns: 1.1fr 1fr; gap: 3rem; align-items: center; padding: 3rem 0 4rem; }
.heroe h1 { font-size: clamp(2rem, 4.5vw, 3.2rem); letter-spacing: -.03em; margin: 0 0 1rem; }
.heroe h1 em { font-style: normal; color: var(--primario); }
.heroe p { font-size: 1.15rem; color: var(--suave); margin: 0 0 1.6rem; }
.heroe .nota { font-size: .88rem; margin-top: .8rem; }
.maqueta { background: #fff; border-radius: 8px; box-shadow: 0 30px 80px rgba(31, 79, 209, .18); padding: 1.6rem; transform: rotate(1.5deg); }
.maqueta .m-titulo { color: var(--primario); font-weight: 800; font-size: 1.4rem; letter-spacing: .04em; }
.maqueta .m-linea { height: .6rem; background: #eef1f7; border-radius: 4px; margin: .5rem 0; }
.maqueta .m-barra { height: 1.6rem; background: var(--primario); border-radius: 3px; margin: 1rem 0 .6rem; }
.maqueta .m-total { display: flex; justify-content: space-between; font-weight: 800; color: var(--primario); background: #e9eefb; padding: .6rem .8rem; border-radius: 4px; margin-top: 1rem; }
.seccion { padding: 3.5rem 0; }
.seccion h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); text-align: center; margin: 0 0 .6rem; letter-spacing: -.02em; }
.seccion .sub { text-align: center; color: var(--suave); margin: 0 auto 2.4rem; max-width: 560px; }
.tarjetas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; }
.tarjeta { background: #fff; border-radius: var(--radio); padding: 1.5rem; box-shadow: var(--sombra); }
.tarjeta h3 { margin: .4rem 0 .5rem; font-size: 1.1rem; }
.tarjeta p { margin: 0; color: var(--suave); }
.icono { font-size: 1.8rem; }
.precios { display: grid; grid-template-columns: repeat(2, minmax(0, 360px)); gap: 1.2rem; justify-content: center; }
.plan { background: #fff; border-radius: 14px; padding: 2rem; box-shadow: var(--sombra); border: 2px solid transparent; display: flex; flex-direction: column; }
.plan.destacado { border-color: var(--oro); }
.plan h3 { margin: 0; }
.plan .cifra { font-size: 2.2rem; font-weight: 800; margin: .6rem 0; }
.plan .cifra small { font-size: 1rem; color: var(--suave); font-weight: 600; }
.plan .lista-check { flex: 1; }
.faq details { background: #fff; border-radius: var(--radio); padding: 1rem 1.2rem; margin-bottom: .7rem; box-shadow: var(--sombra); }
.faq summary { font-weight: 700; cursor: pointer; }
.faq p { color: var(--suave); margin: .7rem 0 0; }
.faq { max-width: 720px; margin: 0 auto; }
.pie { text-align: center; padding: 2rem 0 3rem; color: var(--suave); font-size: .9rem; }
.pie a { color: var(--suave); }
.texto-legal { max-width: 720px; margin: 0 auto; padding: 2rem 20px 4rem; }

@media (max-width: 860px) {
  .heroe { grid-template-columns: 1fr; padding-top: 1.5rem; }
  .maqueta { transform: none; }
  .tarjetas, .precios { grid-template-columns: 1fr; }
}

/* utilidades
   Sustituyen a los atributos style="..." del HTML. La CSP de _headers
   (style-src sin 'unsafe-inline') bloquea los style="..." escritos en el HTML,
   así que cualquier ajuste suelto de estilo tiene que ser una clase de aquí. */

/* Anchos de las líneas de la maqueta (index.html y páginas de oficios) */
.an-30 { width: 30%; }
.an-35 { width: 35%; }
.an-45 { width: 45%; }
.an-55 { width: 55%; }
.an-70 { width: 70%; }
.an-80 { width: 80%; }
.an-85 { width: 85%; }
.an-90 { width: 90%; }
.an-92 { width: 92%; }

/* Para las páginas de oficios (herramientas/generar.js), cuando se pasen a clases */
.mt-16 { margin-top: 1.6rem; }
.tarjeta-tabla { --acento: var(--primario); overflow-x: auto; }

/* Pie mínimo del editor (app.html); no sale en el PDF gracias a .no-imprimir */
.pie-app { padding: .5rem 0 1.5rem; font-size: .82rem; }
.solo-lector {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; padding: 0; border: 0;
}
.seccion .sub.mt-16 { margin-top: 1.6rem; }
