/* Fuente Metropolis (Chris Simpson, dominio público), servida desde la propia herramienta. */
@font-face {
    font-family: "Metropolis";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("fuentes/metropolis-latin-400-normal.woff2") format("woff2"), url("fuentes/metropolis-latin-400-normal.woff") format("woff");
}
@font-face {
    font-family: "Metropolis";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("fuentes/metropolis-latin-500-normal.woff2") format("woff2"), url("fuentes/metropolis-latin-500-normal.woff") format("woff");
}
@font-face {
    font-family: "Metropolis";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("fuentes/metropolis-latin-600-normal.woff2") format("woff2"), url("fuentes/metropolis-latin-600-normal.woff") format("woff");
}
@font-face {
    font-family: "Metropolis";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("fuentes/metropolis-latin-700-normal.woff2") format("woff2"), url("fuentes/metropolis-latin-700-normal.woff") format("woff");
}

/* Paleta: Palladian #EEE9DF, Oatmeal #C9C1B1, Blue Fantastic #2C3B4D, Burning Flame #FFB162,
   Truffle Trouble #A35139, Abyssal Anchorfish Blue #1B2632. El resto son tonos intermedios de esos colores. */
:root {
    --fondo: #EEE9DF;
    --superficie: #FBF9F5;
    --campo: #FFFFFF;
    --borde: #C9C1B1;
    --borde-suave: #E6E0D4;
    --cabecera-tabla: #F2EEE6;
    --fila-resaltada: #F6F2EB;
    --texto: #1B2632;
    --texto-suave: #5B6470;
    --texto-apagado: #9A9385;
    --primario: #2C3B4D;
    --primario-oscuro: #1B2632;
    --sobre-primario: #EEE9DF;
    --acento: #FFB162;
    --acento-oscuro: #F59E45;
    --oscuro: #1B2632;
    --ok: #3F6B4F;
    --ok-fondo: #E1E9DD;
    --alerta: #A35139;
    --alerta-fondo: #FCE4CB;
    --error: #A35139;
    --error-fondo: #F6DDD5;
    /* Rojo de las diferencias (filas que no cuadran), para reconocerlas de un vistazo. */
    --rojo: #B3261E;
    --rojo-fondo: #FBE4E1;
    --radio: 8px;
    /* En pantallas grandes la página crece hasta este ancho para que quepan las tablas. */
    --ancho-maximo: 1680px;
    --fuente: "Metropolis", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    /* Metropolis tiene cifras de ancho variable: en las columnas de importes se usa la del sistema, de ancho fijo. */
    --fuente-numeros: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--fuente);
    font-size: 15px;
    color: var(--texto);
    background: var(--fondo);
}

/* Cabecera */
.cabecera {
    background: var(--oscuro);
    color: var(--sobre-primario);
}

.cabecera .contenido {
    max-width: var(--ancho-maximo);
    margin: 0 auto;
    padding: 0.8rem 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: center;
}

.cabecera .marca {
    color: var(--acento);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.cabecera nav a {
    color: var(--borde);
    text-decoration: none;
}

.cabecera nav a:hover { color: var(--sobre-primario); }
.cabecera nav { display: flex; align-items: center; gap: 1rem; }
.cabecera .salir { margin: 0; }
.cabecera .salir button { background: none; border: 1px solid var(--borde); color: var(--borde); border-radius: 6px; padding: .25rem .75rem; cursor: pointer; font: inherit; }
.cabecera .salir button:hover { color: var(--sobre-primario); border-color: var(--sobre-primario); }

a { color: var(--primario); }
a:hover { color: var(--alerta); }

main {
    max-width: var(--ancho-maximo);
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.5rem; }
h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; }

section[id] { scroll-margin-top: 4rem; }

/* Tarjeta del formulario */
.tarjeta {
    background: var(--superficie);
    border: 1px solid var(--borde);
    border-radius: var(--radio);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.formulario {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem 1.25rem;
    align-items: end;
}

.campo label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--texto-suave);
    margin-bottom: 0.3rem;
}

.campo input {
    width: 100%;
    font: inherit;
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--borde);
    border-radius: 6px;
    background: var(--campo);
}

.acciones button {
    width: 100%;
    padding: 0.6rem 1.2rem;
    border: 0;
    border-radius: 6px;
    background: var(--acento);
    color: var(--oscuro);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.acciones button:hover { background: var(--acento-oscuro); }

/* Avisos */
.aviso {
    padding: 0.75rem 1rem;
    border-radius: var(--radio);
    background: var(--alerta-fondo);
    border: 1px solid var(--alerta);
}

.aviso.error { background: var(--error-fondo); border-color: var(--error); }
.aviso.ok { background: var(--ok-fondo); border-color: var(--ok); }
.aviso p { margin: 0; }
.aviso ul { margin: 0.5rem 0 0; padding-left: 1.2rem; }

.nota { color: var(--texto-suave); font-size: 0.9rem; }
.archivo { color: var(--texto-suave); }

/* Cifras resumen */
/* Todas las cajas en una fila y la cifra siempre a la misma altura, aunque el título ocupe dos líneas. */
.cifras {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 0.5rem;
    margin: 1rem 0;
}

.cifra {
    display: flex;
    flex-direction: column;
    background: var(--superficie);
    border: 1px solid var(--borde);
    border-left: 4px solid var(--borde);
    border-radius: var(--radio);
    padding: 0.6rem 0.75rem;
}

.cifra span { display: block; font-size: 0.8rem; color: var(--texto-suave); }
.cifra strong { display: block; font-size: 1.35rem; margin-top: auto; padding-top: 0.3rem; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
    .cifras { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.cifra small { display: block; font-size: 0.8rem; color: var(--texto-suave); margin-top: 0.2rem; }
.cifra.destacada { border-left-color: var(--acento); }
.cifra.ok { border-left-color: var(--ok); }
.cifra.alerta { border-left-color: var(--alerta); }

/* Navegación entre secciones */
.secciones {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.6rem 0;
    background: var(--fondo);
}

.secciones a {
    padding: 0.35rem 0.8rem;
    border: 1px solid var(--borde);
    border-radius: 999px;
    background: var(--superficie);
    color: var(--texto);
    text-decoration: none;
    font-size: 0.9rem;
}

.secciones a:hover { border-color: var(--primario); color: var(--primario); }

/* Tablas */
.tabla {
    overflow-x: auto;
    background: var(--superficie);
    border: 1px solid var(--borde);
    border-radius: var(--radio);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

th, td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--borde-suave);
    text-align: right;
    white-space: nowrap;
    vertical-align: top;
}

/* Los títulos de columna pueden partirse en dos líneas para que la tabla ocupe menos ancho. */
thead th {
    white-space: normal;
    vertical-align: bottom;
    background: var(--cabecera-tabla);
    font-size: 0.8rem;
    color: var(--texto-suave);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

tbody th { text-align: left; font-weight: 500; }
td:not(.texto):not(.observaciones) { font-family: var(--fuente-numeros); }
tbody tr:hover { background: var(--fila-resaltada); }
td.neto { font-weight: 600; }
tr.apagada { color: var(--texto-apagado); }

tr.total th, tr.total td {
    font-weight: 700;
    border-top: 2px solid var(--borde);
    background: var(--cabecera-tabla);
}

/* Desplegables dentro de las tablas */
details summary {
    cursor: pointer;
    color: var(--primario);
    list-style: none;
}

details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸ "; color: var(--texto-suave); }
details[open] summary::before { content: "▾ "; }

table.desglose {
    margin: 0.5rem 0 0.25rem;
    border: 1px solid var(--borde-suave);
    font-size: 0.85rem;
    color: var(--texto);
}

table.desglose th, table.desglose td { padding: 0.3rem 0.6rem; text-align: left; }
table.desglose td:nth-child(n+2) { text-align: right; }
table.desglose.lista td { text-align: left; }

thead th:first-child { text-align: left; }
td.texto { text-align: left; }

/* Primera columna fija al desplazar la tabla en pantallas estrechas */
table.liquidacion > tbody > tr > th:first-child,
table.liquidacion > thead > tr > th:first-child {
    position: sticky;
    left: 0;
    background: var(--superficie);
    z-index: 1;
}
table.liquidacion > thead > tr > th:first-child { background: var(--cabecera-tabla); }
/* Los nombres largos pasan a dos líneas en lugar de ensanchar la tabla. */
table.liquidacion > tbody > tr > th:first-child { white-space: normal; min-width: 14rem; }

/* En pantallas medianas, columnas algo más juntas. */
@media (max-width: 1500px) {
    th, td { padding: 0.45rem 0.55rem; }
}
table.liquidacion > tbody > tr.total > th:first-child { background: var(--cabecera-tabla); }

@media (max-width: 700px) {
    body { font-size: 14px; }
    table.liquidacion > tbody > tr > th:first-child { white-space: normal; min-width: 11rem; max-width: 14rem; }
}

/* Edición */
.enlace-editar { margin: 0.4rem 0; font-size: 0.85rem; white-space: normal; }
.etiqueta {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    background: var(--borde-suave);
    color: var(--texto-suave);
    font-size: 0.75rem;
    font-weight: 500;
}
.etiqueta.debajo { display: block; width: fit-content; margin: 0.2rem 0 0 auto; white-space: nowrap; }
tr.cambiada { background: #FFF1DF; }
tr.cambiada:hover { background: #FFE6C7; }

.en-linea {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.en-linea input, table.actos select, table.actos input {
    font: inherit;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--borde);
    border-radius: 6px;
    background: var(--campo);
}
.en-linea button, .boton-secundario {
    font: inherit;
    padding: 0.35rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
}
.en-linea button { border: 0; background: var(--primario); color: var(--sobre-primario); font-weight: 600; }
.en-linea button:hover { background: var(--primario-oscuro); }
.boton-secundario { border: 1px solid var(--borde); background: var(--campo); color: var(--texto); }
.boton-secundario:hover { border-color: var(--primario); color: var(--primario); }
input.importe { width: 7rem; text-align: right; }
table.actos select { max-width: 15rem; }
thead th.texto { text-align: left; }
table.actos td.texto { white-space: normal; }
.etiqueta.aviso-etiqueta { background: var(--alerta-fondo); color: var(--alerta); margin: 0 0.4rem 0 0; }
table.actos td.observaciones { max-width: 22rem; font-size: 0.85rem; color: var(--texto-suave); }

.descarga { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
a.boton {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    border-radius: 6px;
    background: var(--primario);
    color: var(--sobre-primario);
    font-weight: 600;
    text-decoration: none;
}
a.boton:hover { background: var(--primario-oscuro); color: var(--sobre-primario); }

/* Facturas de los profesionales */
button.boton {
    padding: 0.55rem 1.1rem;
    border: 0;
    border-radius: 6px;
    background: var(--primario);
    color: var(--sobre-primario);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
button.boton:hover { background: var(--primario-oscuro); }
button.boton.imprimir { background: var(--acento); color: var(--oscuro); font-weight: 700; }
button.boton.imprimir:hover { background: var(--acento-oscuro); }

.formulario-facturas { display: grid; gap: 1rem; }
.formulario-facturas .campo { max-width: 260px; }
.acciones-facturas { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin: 0; }
input.numero-factura { width: 6rem; font: inherit; padding: 0.3rem 0.4rem; border: 1px solid var(--borde); border-radius: 6px; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* La factura usa Helvetica/Arial, como el PDF que se descarga. */
.factura {
    font-family: Helvetica, Arial, sans-serif;
    --f-azul: #1b5e82;
    --f-azul-claro: #dcebf7;
    width: 100%;
    max-width: 210mm;
    min-height: 270mm;
    margin: 1.5rem auto;
    padding: 14mm 14mm 12mm;
    display: flex;
    flex-direction: column;
    gap: 9mm;
    background: #fff;
    color: #111;
    border: 1px solid var(--borde);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    font-size: 11pt;
}
.factura p { margin: 0; }
.factura .num { text-align: right; white-space: nowrap; }

.f-cabecera { display: flex; justify-content: space-between; gap: 2rem; }
.f-emisor p { line-height: 1.5; }
.f-nombre { font-size: 19pt; font-weight: 700; font-style: italic; letter-spacing: 0.02em; margin-bottom: 0.2rem !important; }
.f-nif { font-weight: 700; font-style: italic; margin-bottom: 0.6rem !important; }
.f-titulo { text-align: right; }
.f-palabra { font-family: Georgia, "Times New Roman", serif; font-size: 30pt; font-weight: 700; color: #8fb8de; letter-spacing: 0.06em; }
.f-titulo dl { display: grid; grid-template-columns: auto auto; gap: 0.2rem 0.6rem; margin: 0.8rem 0 0; }
.f-titulo dt { font-weight: 700; }
.f-titulo dd { margin: 0; text-align: left; }

.f-cliente { width: 60%; padding: 0.5rem 0.7rem; border: 1px solid #333; line-height: 1.45; }
.f-cliente-nombre { font-weight: 700; }

.f-conceptos { flex: 1; border: 1px solid #333; border-collapse: collapse; }
.f-conceptos th { background: var(--f-azul-claro); text-align: left; font-size: 12pt; padding: 0.35rem 0.6rem; border-bottom: 1px solid #333; }
.f-conceptos th.num { text-align: right; }
.f-conceptos td { text-align: left; white-space: normal; padding: 1rem 0.6rem; border-bottom: 0; }
.f-conceptos td.num { border-left: 1px solid #333; width: 9rem; }

.f-pie { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem; }
.f-pago { font-size: 10pt; line-height: 1.6; }
.f-exenta { font-weight: 700; font-size: 9pt; }
.f-totales { width: auto; border-collapse: collapse; }
.f-totales th { text-align: left; padding: 0.2rem 0.8rem 0.2rem 0; border: 0; }
.f-totales td { min-width: 8rem; padding: 0.2rem 0.6rem; background: var(--f-azul-claro); border: 1px solid #9ab; }
.f-totales td.negativo { color: #c00; }
.f-total th, .f-total td { font-weight: 700; font-size: 12pt; }

@page { size: A4; margin: 0; }
@media print {
    body { background: #fff; }
    .cabecera, main > h1, .no-imprimir { display: none !important; }
    main { padding: 0 !important; margin: 0 !important; max-width: none !important; }
    .factura { margin: 0; border: 0; box-shadow: none; max-width: none; min-height: 297mm; height: 297mm; break-after: page; page-break-after: always; }
    .factura:last-of-type { break-after: auto; page-break-after: auto; }
    .factura .f-conceptos th, .factura .f-totales td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
a.boton.boton-pdf { padding: 0.3rem 0.7rem; font-size: 0.85rem; background: var(--primario); }

/* Diferencias: fila en rojo y etiqueta con su origen (Seoga o Caja). */
tr.diferencia > th, tr.diferencia > td { background: var(--rojo-fondo); }
tr.diferencia > th:first-child { box-shadow: inset 4px 0 0 var(--rojo); }
tbody tr.diferencia:hover > th, tbody tr.diferencia:hover > td { background: #F8D4CF; }
.origen {
    display: inline-block;
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    background: var(--rojo);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--fuente);
}

.opcional { font-weight: 400; color: var(--texto-suave); }
