:root {
    --azul: #1e3a8a;
    --azul-fuerte: #1d4ed8;
    --azul-suave: #eef2ff;
    --tinta: #0f172a;
    --gris: #64748b;
    --linea: #e6e8ee;
    --fondo: #f1f5f9;
    --blanco: #fff;
    --rojo: #dc2626;
    --rojo-suave: #fef2f2;
    --radio: 12px;
    --radio-sm: 8px;
    --sombra: 0 1px 2px rgba(15,23,42,0.06), 0 6px 20px rgba(15,23,42,0.05);
    --ancho-menu: 240px;
}

*, *::before, *::after { box-sizing: border-box; }
html { overflow-x: hidden; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    background: var(--fondo);
    color: var(--tinta);
    line-height: 1.5;
}

.ico {
    width: 1.05em;
    height: 1.05em;
    vertical-align: -0.15em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}

.layout { display: flex; align-items: stretch; min-height: 100vh; }

.sidebar {
    width: var(--ancho-menu);
    flex: none;
    background: var(--azul);
    color: #fff;
    padding: 1.2rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: width 0.2s ease;
}
.sidebar-cab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    margin-bottom: 0.7rem;
}
.sidebar .logo {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #fff;
    text-decoration: none;
    padding: 0.3rem 0.4rem;
    min-width: 0;
}
.sidebar .logo .rotulo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.colapsar {
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    padding: 0.35rem;
    border-radius: var(--radio-sm);
    cursor: pointer;
    line-height: 0;
    flex: none;
}
.colapsar:hover { background: rgba(255,255,255,0.22); }
.colapsar .ico { width: 1.2rem; height: 1.2rem; transition: transform 0.2s ease; }
.sidebar .enlaces { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.sidebar .enlaces a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #cdd8f5;
    text-decoration: none;
    padding: 0.6rem 0.7rem;
    border-radius: var(--radio-sm);
    font-size: 0.93rem;
    transition: background 0.15s, color 0.15s;
}
.sidebar .enlaces a:hover { background: rgba(255,255,255,0.12); color: #fff; }
.sidebar .enlaces a.activo { background: rgba(255,255,255,0.18); color: #fff; font-weight: 600; }
.sidebar .enlaces .salir { margin-top: auto; }

.submenu { display: flex; flex-direction: column; }
.submenu-toggle {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    color: #cdd8f5;
    font: inherit;
    font-size: 0.93rem;
    padding: 0.6rem 0.7rem;
    border-radius: var(--radio-sm);
    text-align: left;
    transition: background 0.15s, color 0.15s;
}
.submenu-toggle:hover { background: rgba(255,255,255,0.12); color: #fff; }
.submenu-toggle.activo { background: rgba(255,255,255,0.18); color: #fff; font-weight: 600; }
.submenu-toggle .flecha { margin-left: auto; transition: transform 0.15s; }
.submenu.abierto .submenu-toggle .flecha { transform: rotate(90deg); }
.sidebar .subenlaces { display: none; flex-direction: column; gap: 0.15rem; margin-top: 0.15rem; }
.submenu.abierto .subenlaces { display: flex; }
.sidebar .subenlaces a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #b9c6ef;
    text-decoration: none;
    padding: 0.5rem 0.7rem 0.5rem 1.7rem;
    border-radius: var(--radio-sm);
    font-size: 0.88rem;
    transition: background 0.15s, color 0.15s;
}
.sidebar .subenlaces a:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar .subenlaces .ico { width: 0.95em; height: 0.95em; }

.plegado .submenu-toggle { justify-content: center; padding-left: 0; padding-right: 0; }
.plegado .submenu-toggle .flecha { display: none; }
.plegado .sidebar .subenlaces a { justify-content: center; padding-left: 0; padding-right: 0; }

.plegado .sidebar { width: 76px; }
.plegado .sidebar .rotulo { display: none; }
.plegado .sidebar-cab { flex-direction: column; gap: 0.5rem; }
.plegado .sidebar .logo { justify-content: center; padding: 0.3rem; }
.plegado .sidebar .enlaces a { justify-content: center; padding-left: 0; padding-right: 0; }
.plegado .colapsar .ico { transform: rotate(180deg); }

.topbar-movil {
    display: none;
    align-items: center;
    gap: 0.7rem;
    background: var(--azul);
    color: #fff;
    padding: 0.65rem 1rem;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-movil .logo { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; letter-spacing: 0.03em; }
.menu-toggle {
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    padding: 0.4rem;
    border-radius: var(--radio-sm);
    cursor: pointer;
    line-height: 0;
}
.menu-toggle .ico { width: 1.4rem; height: 1.4rem; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 25;
}
.sidebar-overlay.activo { display: block; }

.contenido {
    flex: 1;
    min-width: 0;
    max-width: 940px;
    margin: 1.75rem auto;
    padding: 0 1.25rem;
}
h1 { font-size: 1.55rem; margin: 0.2rem 0 1rem; }
h2 { font-size: 1.15rem; }

.aviso {
    background: var(--rojo-suave);
    color: #991b1b;
    border: 1px solid #fecaca;
    padding: 0.75rem 1rem;
    border-radius: var(--radio-sm);
    margin-bottom: 1rem;
}
.aviso-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--azul-suave);
    color: #1e3a8a;
    border: 1px solid #c7d2fe;
    padding: 0.75rem 1rem;
    border-radius: var(--radio-sm);
    margin-bottom: 1rem;
    font-size: 0.92rem;
}
.form-confirmar { display: inline; margin: 0; }
@media print {
    .aviso-preview { display: none; }
}

.boton, .boton-secundario {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 1.1rem;
    border-radius: var(--radio-sm);
    border: none;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.05s;
}
.boton { background: var(--azul); color: #fff; }
.boton:hover { background: var(--azul-fuerte); }
.boton:active, .boton-secundario:active { transform: translateY(1px); }
.boton-secundario { background: #eef1f6; color: #334155; }
.boton-secundario:hover { background: #e2e7ef; }
.enlace-borrar {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: none;
    color: var(--rojo);
    cursor: pointer;
    font-size: 0.88rem;
    padding: 0.2rem 0;
}
.enlace-borrar:hover { text-decoration: underline; }

.login-caja {
    max-width: 360px;
    margin: 4.5rem auto;
    background: var(--blanco);
    padding: 2.2rem;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    text-align: center;
}
.login-caja h1 { color: var(--azul); margin: 0.2rem 0; letter-spacing: 0.04em; }
.login-sub { color: var(--gris); margin-top: 0; }
.login-caja form { text-align: left; margin-top: 1rem; }
.login-caja .boton { width: 100%; margin-top: 1.2rem; }

.cabecera-seccion {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1.75rem;
}

.tabla-scroll { overflow-x: auto; }
.tabla {
    width: 100%;
    border-collapse: collapse;
    background: var(--blanco);
    border: 1px solid var(--linea);
    border-radius: var(--radio);
    overflow: hidden;
    box-shadow: var(--sombra);
}
.tabla th, .tabla td {
    padding: 0.8rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--linea);
    white-space: nowrap;
}
.tabla tr:last-child td { border-bottom: none; }
.tabla th {
    background: #f8fafc;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gris);
}
.tabla tbody tr:hover { background: var(--azul-suave); }
.tabla .acciones { display: flex; gap: 1rem; align-items: center; }
.tabla .acciones a { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--azul); text-decoration: none; }
.tabla .acciones a:hover { text-decoration: underline; }
.tabla .acciones form { display: inline; margin: 0; }
.vacio {
    color: var(--gris);
    background: var(--blanco);
    border: 1px dashed var(--linea);
    border-radius: var(--radio);
    padding: 1.5rem;
    text-align: center;
}

.formulario {
    background: var(--blanco);
    padding: 1.6rem;
    border: 1px solid var(--linea);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
}
label { display: block; font-size: 0.82rem; font-weight: 600; color: #475569; margin: 0.7rem 0 0.25rem; }
input[type="text"], input[type="password"], select {
    width: 100%;
    padding: 0.6rem 0.7rem;
    border: 1px solid #cdd3df;
    border-radius: var(--radio-sm);
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--azul-fuerte);
    box-shadow: 0 0 0 3px rgba(29,78,216,0.15);
}
fieldset { border: 1px solid var(--linea); border-radius: var(--radio); padding: 0.6rem 1.1rem 1.1rem; margin: 0; }
legend { font-weight: 700; color: var(--azul); padding: 0 0.4rem; font-size: 0.95rem; }
.checkbox-linea { display: flex; align-items: center; gap: 0.55rem; font-size: 0.88rem; color: #475569; margin-top: 0.9rem; cursor: pointer; }
.checkbox-linea input { width: auto; }
.nota-legal {
    margin-top: 1.2rem;
    padding: 0.7rem 0.9rem;
    background: #f8fafc;
    border-left: 3px solid var(--azul);
    border-radius: var(--radio-sm);
    font-size: 0.82rem;
    color: #475569;
    font-style: italic;
}
.dos-columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.tres-columnas { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; margin-top: 0.75rem; }

.tabla-lineas { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
.tabla-lineas th { text-align: left; font-size: 0.78rem; color: var(--gris); padding: 0.35rem; text-transform: uppercase; letter-spacing: 0.03em; }
.tabla-lineas td { padding: 0.2rem; }

.botones-final {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.7rem;
    margin-top: 1.6rem;
}

.acciones-documento {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.7rem;
    margin-bottom: 1.1rem;
}
.papel {
    background: var(--blanco);
    padding: 2.5rem;
    border: 1px solid var(--linea);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
}
.papel-cabecera {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.6rem;
    border-bottom: 2px solid var(--azul);
    padding-bottom: 0.7rem;
}
.papel-cabecera h2 { color: var(--azul); margin: 0; letter-spacing: 0.05em; }
.papel-num { text-align: right; font-size: 0.9rem; }
.papel-partes { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin: 1.3rem 0; }
.parte-titulo { font-size: 0.78rem; color: var(--gris); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.3rem; }
.papel-datos-entrega { font-size: 0.9rem; margin: 1.2rem 0; }
.papel-datos-entrega div { margin: 0.15rem 0; }

.papel-tabla { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
.papel-tabla th {
    background: #f1f5f9;
    text-align: left;
    padding: 0.55rem;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #475569;
}
.papel-tabla td { padding: 0.55rem; border-bottom: 1px solid var(--linea); }
.papel-tabla .num { text-align: right; }
.num { text-align: right; white-space: nowrap; }

.papel-totales {
    margin: 1.5rem 0 0 auto;
    width: fit-content;
    min-width: 200px;
    border: 1px solid var(--linea);
    border-radius: var(--radio-sm);
    overflow: hidden;
}
.fila-total {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.35rem 0.7rem;
    border-bottom: 1px solid var(--linea);
    font-size: 0.9rem;
    white-space: nowrap;
}
.fila-total:last-child { border-bottom: none; }
.fila-total > span:first-child { color: var(--gris); }
.total-grande {
    background: var(--azul-suave);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--azul);
    border-top: 2px solid var(--azul);
}
.total-grande > span:first-child { color: var(--azul); }
.tabla-iva { width: 100%; border-collapse: collapse; margin: 0.6rem 0; font-size: 0.85rem; }
.tabla-iva th, .tabla-iva td { border: 1px solid var(--linea); padding: 0.35rem 0.55rem; }
.tabla-iva th { background: #f8fafc; }

.papel-pie { margin-top: 1.5rem; font-size: 0.9rem; color: #334155; }
.papel-firma { margin-top: 2.5rem; font-size: 0.9rem; }
.caja-firma { border: 1px solid #cdd3df; height: 72px; margin-top: 0.4rem; border-radius: var(--radio-sm); }

.factura-cab {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    border-bottom: 3px solid var(--azul);
    padding-bottom: 1rem;
}
.emisor { font-size: 0.85rem; color: #334155; line-height: 1.55; }
.emisor-nombre {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--azul);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}
.marca { text-align: right; }
.marca-titulo { font-size: 1.9rem; font-weight: 800; color: var(--azul); letter-spacing: 0.14em; }
.marca-tipo { font-size: 0.8rem; color: var(--gris); text-transform: uppercase; letter-spacing: 0.06em; }
.marca-num { font-size: 0.9rem; color: var(--gris); }

.tipos-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1.3rem; }
.tarjeta-tipo {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
    background: var(--blanco);
    border: 1px solid var(--linea);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 1.4rem;
    text-decoration: none;
    color: var(--tinta);
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.tarjeta-tipo:hover { border-color: var(--azul-fuerte); box-shadow: 0 8px 26px rgba(30,58,138,0.14); }
.tarjeta-tipo:active { transform: translateY(1px); }
.tarjeta-tipo .ico { width: 2.1rem; height: 2.1rem; color: var(--azul); }
.tt-nombre { font-weight: 700; font-size: 1.1rem; }
.tt-desc { font-size: 0.85rem; color: var(--gris); }
.tt-serie { font-size: 0.8rem; font-weight: 600; color: var(--azul); margin-top: auto; }

.parte-nombre { font-weight: 700; font-size: 1rem; margin-bottom: 0.15rem; }
.parte-meta { justify-self: end; width: fit-content; }
.meta-fila {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid var(--linea);
    font-size: 0.85rem;
    white-space: nowrap;
}
.meta-fila span { color: var(--gris); }

.pago {
    clear: both;
    margin-top: 1.5rem;
    background: #f8fafc;
    border: 1px solid var(--linea);
    border-radius: var(--radio-sm);
    padding: 1rem 1.1rem;
    font-size: 0.88rem;
    line-height: 1.7;
}
.pago-titulo { font-weight: 700; color: var(--azul); margin-bottom: 0.3rem; }

.papel-banda {
    margin-top: 2rem;
    border-top: 1px solid var(--linea);
    padding-top: 0.8rem;
    font-size: 0.74rem;
    color: var(--gris);
    text-align: center;
}

.papel.proforma { position: relative; overflow: hidden; }
.papel.proforma::after {
    content: "PROFORMA";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 5.5rem;
    font-weight: 900;
    color: rgba(100, 116, 139, 0.12);
    letter-spacing: 0.2em;
    white-space: nowrap;
    pointer-events: none;
    z-index: 1;
    user-select: none;
}

.badge-proforma {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.12rem 0.45rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    vertical-align: middle;
}

@media (max-width: 820px) {
    .topbar-movil { display: flex; }
    .menu-toggle { padding: 0.55rem; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 0 10px 40px rgba(15,23,42,0.35);
    }
    .sidebar.abierto { transform: none; }
    .colapsar { display: none; }
    .plegado .sidebar { width: var(--ancho-menu); }
    .plegado .sidebar .rotulo { display: inline; }
    .plegado .sidebar-cab { flex-direction: row; }
    .plegado .sidebar .logo { justify-content: flex-start; }
    .plegado .sidebar .enlaces a { justify-content: flex-start; padding-left: 0.7rem; padding-right: 0.7rem; }
    .plegado .submenu-toggle { justify-content: flex-start; padding-left: 0.7rem; padding-right: 0.7rem; }
    .plegado .submenu-toggle .flecha { display: inline; }
    .plegado .sidebar .subenlaces a { justify-content: flex-start; padding-left: 1.7rem; padding-right: 0.7rem; }
    .dos-columnas, .tres-columnas { grid-template-columns: 1fr; }
    .papel-partes { grid-template-columns: 1fr; }
    .tipos-grid { grid-template-columns: 1fr; }
    .papel { padding: 1.4rem; }
    .contenido { margin: 1.1rem auto; }
    .parte-meta { margin-left: 0; }
    .marca-titulo { font-size: 1.4rem; letter-spacing: 0.1em; }
    h1 { font-size: 1.3rem; }
    .botones-final { flex-direction: column; align-items: stretch; }
    .botones-final .boton,
    .botones-final .boton-secundario { justify-content: center; }
    .acciones-documento { flex-direction: column; }
    .acciones-documento .boton,
    .acciones-documento .boton-secundario,
    .acciones-documento .form-confirmar { width: 100%; }
    .acciones-documento .form-confirmar .boton { width: 100%; }
    .login-caja { margin: 2rem auto; padding: 1.5rem; }
    .tabla-lineas th, .tabla-lineas td { font-size: 0.82rem; }
    .tabla-lineas input[type="text"], .tabla-lineas select { font-size: 0.85rem; padding: 0.45rem 0.5rem; min-width: 70px; }
    fieldset { padding: 0.5rem 0.8rem 0.8rem; }
    .papel.proforma::after { font-size: 3.5rem; }
}

@media (max-width: 480px) {
    .contenido { padding: 0 0.7rem; }
    .papel { padding: 0.9rem; }
    .formulario { padding: 1rem; }
    .marca-titulo { font-size: 1.15rem; letter-spacing: 0.06em; }
    .emisor-nombre { font-size: 0.95rem; }
    h1 { font-size: 1.1rem; }
    .factura-cab { gap: 0.5rem; padding-bottom: 0.7rem; }
    .papel-tabla th, .papel-tabla td { padding: 0.35rem; font-size: 0.78rem; }
    .fila-total { font-size: 0.82rem; padding: 0.4rem 0.65rem; }
    .total-grande { font-size: 1rem; }
    .pago { padding: 0.7rem; font-size: 0.82rem; }
    .papel-banda { font-size: 0.66rem; }
    .tarjeta-tipo { padding: 1rem; }
    .tt-nombre { font-size: 0.95rem; }
    .tabla th, .tabla td { padding: 0.5rem 0.6rem; font-size: 0.82rem; }
    .boton, .boton-secundario { font-size: 0.85rem; padding: 0.55rem 0.85rem; }
    .cabecera-seccion { gap: 0.5rem; }
    .cabecera-seccion h2 { font-size: 1rem; }
    .nota-legal { font-size: 0.76rem; padding: 0.55rem 0.7rem; }
    .aviso-preview { font-size: 0.82rem; padding: 0.6rem 0.8rem; }
    .login-caja { margin: 1.5rem 0.5rem; }
}

@page { margin: 10mm 12mm; }
@media print {
    .sidebar, .sidebar-overlay, .topbar-movil, .acciones-documento, .aviso, .aviso-preview { display: none !important; }
    .ico { display: none !important; }
    .layout { display: block; }
    body { background: #fff; margin: 0; }
    .contenido { margin: 0; max-width: 100%; padding: 0; }
    .papel { box-shadow: none; border: none; padding: 0; display: flex; flex-direction: column; min-height: 240mm; }
    .papel.proforma::after { content: none; }
    .papel-pie-grupo { margin-top: auto; }
    .tabla-scroll { overflow: visible; }
    .papel-tabla { width: 100%; }
    .papel-tabla .num { text-align: right; }
    .num { white-space: nowrap; }
    .papel-partes { grid-template-columns: 1fr auto; gap: 1rem; }
    .parte-meta { justify-self: end; width: fit-content; }
    .meta-fila { gap: 0.8rem; padding: 0.15rem 0; }
    .papel-totales { width: fit-content; min-width: 200px; }
    .fila-total { gap: 0.8rem; padding: 0.25rem 0.6rem; }
}
