:root {
  --fondo: #f5f6f8; --card: #fff; --borde: #e3e6ea; --texto: #1d2733; --tenue: #6b7685;
  --primario: #1f4e79; --primario-h: #173c5d; --peligro: #b3261e; --ok: #1e7b3c; --aviso: #fff4e0;
  --radio: 8px; --sombra: 0 1px 2px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--texto); background: var(--fondo); display: flex; min-height: 100vh; }
a { color: var(--primario); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }
h3 { font-size: 13px; margin: 18px 0 8px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; color: var(--tenue); }

/* Barra lateral */
.side { width: 210px; flex-shrink: 0; background: #16212e; color: #c9d2dc; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.marca { display: block; padding: 18px 18px 14px; color: #fff; font-weight: 650; font-size: 15px; }
.marca:hover { text-decoration: none; }
.marca-j { background: #fff; color: #16212e; padding: 2px 6px; border-radius: 5px; margin-right: 4px; font-weight: 800; }
.marca.grande { color: var(--texto); font-size: 18px; padding: 0 0 18px; }
.marca.grande .marca-j { background: var(--texto); color: #fff; }
.side nav { flex: 1; overflow-y: auto; }
.side nav a { display: flex; align-items: center; padding: 8px 18px; color: #c9d2dc; border-left: 3px solid transparent; }
.side nav a:hover { background: #1f2d3d; text-decoration: none; color: #fff; }
.side nav a.on { background: #223246; color: #fff; border-left-color: #6fa8dc; }
.nav-sep { padding: 16px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7d8a99; }
.badge { margin-left: auto; background: #e8a33d; color: #16212e; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.side-pie { padding: 14px 18px; font-size: 13px; border-top: 1px solid #263445; }
.side-pie a { color: #c9d2dc; }

main { flex: 1; min-width: 0; }
.top { display: flex; align-items: center; gap: 16px; padding: 16px 28px; background: var(--card); border-bottom: 1px solid var(--borde); position: sticky; top: 0; z-index: 5; }
.emp-sel { margin-left: auto; }
.contenido { padding: 22px 28px 60px; max-width: 1400px; }

/* Tarjetas y rejillas */
.card { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radio); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--sombra); }
.card.estrecho { max-width: 640px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; }
.grid-ver { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.grid-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 16px; }
@media (max-width: 1000px) { .grid-ver { grid-template-columns: 1fr; } .side { width: 170px; } }

/* Formularios */
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--tenue); font-weight: 500; }
label > input, label > select, label > textarea { display: block; margin-top: 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0 12px 0 0; color: var(--texto); }
label.inline.bloque { display: flex; margin-bottom: 6px; }
label.inline input { margin: 0; }
input, select, textarea { font: inherit; color: var(--texto); border: 1px solid #cfd5dc; border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { padding: 2px; height: 36px; width: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e6; border-color: #6fa8dc; }
input.n { text-align: right; }
input.corto, .corto { max-width: 90px; }
input.medio { max-width: 150px; }
fieldset { border: 0; padding: 0; margin: 0; }
.fila { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.fila > label { flex: 0 1 190px; }
.fila > label.crece { flex: 1 1 260px; }
.buscador { margin-bottom: 4px; }
small { font-weight: 400; }

/* Botones */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #cfd5dc; background: #fff; color: var(--texto); padding: 7px 13px; border-radius: 6px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn.primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.btn.primario:hover { background: var(--primario-h); }
.btn.peligro { color: var(--peligro); border-color: #e5b3b0; }
.btn.peligro:hover { background: #fdecea; }
.btn.mini { padding: 3px 8px; font-size: 12px; }
.btn.ancho { width: 100%; justify-content: center; margin-top: 6px; }
.btn.enlace { border-color: transparent; color: var(--primario); }
.acciones { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.acciones.pegajosa { position: sticky; bottom: 0; background: var(--card); padding: 12px 0 4px; border-top: 1px solid var(--borde); }
.derecha { margin-left: auto; }
form.inline { display: inline; }

/* Tablas */
.tabla { width: 100%; border-collapse: collapse; background: var(--card); }
.contenido > .tabla, form > .tabla:not(.lineas) { border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); }
.tabla th { text-align: left; font-size: 12px; font-weight: 600; color: var(--tenue); text-transform: uppercase; letter-spacing: .03em; padding: 9px 10px; border-bottom: 1px solid var(--borde); background: #fafbfc; }
.tabla td { padding: 9px 10px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
.tabla tfoot td { font-weight: 600; background: #fafbfc; border-bottom: 0; }
.tabla.compacta td, .tabla.compacta th { padding: 6px 8px; }
.tabla tr.inactiva td { opacity: .5; }
.tabla tr.aviso td { background: var(--aviso); }
.tabla .chk { width: 30px; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.vacio { text-align: center; color: var(--tenue); padding: 30px !important; }
.problema { font-size: 12px; color: #9a5b00; margin-top: 2px; }
.scroll-x { overflow-x: auto; }

/* Líneas de factura */
.tabla.lineas { margin-top: 8px; }
.tabla.lineas td { padding: 5px 6px; vertical-align: middle; }
.tabla.lineas textarea { resize: vertical; min-height: 36px; }
.tabla.lineas input, .tabla.lineas select { padding: 6px 7px; }
.w-n { width: 110px; } .w-dto { width: 76px; } .w-iva { width: 112px; }
.mover { cursor: grab; color: #aab3bf; width: 18px; user-select: none; }
.importe { font-weight: 600; white-space: nowrap; }
.lineas-acciones { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0 16px; }
.lineas-acciones select { width: auto; max-width: 420px; }
.ayuda { font-size: 12px; }
.totales { margin: 0 0 18px auto; max-width: 340px; }
.totales > div { display: flex; justify-content: space-between; padding: 4px 0; }
.totales #desglose div { display: flex; justify-content: space-between; font-size: 12px; color: var(--tenue); padding: 2px 0; }
.totales .t-total { border-top: 2px solid var(--texto); margin-top: 6px; padding-top: 8px; font-size: 18px; }

/* Etiquetas y avisos */
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 4px; color: #fff; background: var(--c, #556); letter-spacing: .03em; }
.etq { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: #e8eef6; color: var(--primario); margin-left: 4px; }
.etq.suave { background: #eef0f3; color: var(--tenue); }
.etq.aviso { background: #fff1d6; color: #8a5300; }
.etq.ok { background: #e3f4e8; color: var(--ok); }
.flash { padding: 10px 14px; border-radius: 6px; margin: 14px 28px 0; }
.contenido .flash, .login-box .flash { margin: 0 0 14px; }
.flash.ok { background: #e3f4e8; color: #14532d; border: 1px solid #b9e2c6; }
.flash.error { background: #fdecea; color: #7f1d1d; border: 1px solid #f3c1bd; }
.aviso-borrador { background: var(--aviso); border: 1px solid #f1d39b; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.rect-info { background: #f1f5fa; border-left: 3px solid var(--primario); padding: 10px 14px; border-radius: 4px; margin-bottom: 14px; }
.tenue { color: var(--tenue); }
.pequeno { font-size: 12px; }
.grande { font-size: 16px; }

/* Filtros y barra de acciones en lote */
.filtros { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filtros input[type=search] { width: 280px; }
.filtros input[type=date], .filtros input[type=month] { width: auto; }
.barra-lote { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--card); border: 1px solid var(--borde); border-radius: var(--radio); padding: 10px 14px; margin-bottom: 10px; position: sticky; top: 63px; z-index: 4; }
.barra-lote select, .barra-lote input[type=date] { width: auto; }
.barra-lote .sep { width: 1px; height: 24px; background: var(--borde); }

/* Ficha de factura */
.cab-factura { display: flex; justify-content: space-between; margin-bottom: 14px; }
.numero { font-size: 22px; font-weight: 700; }
.logo-prev { max-height: 70px; max-width: 260px; }
.rangos { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.rangos input, .rangos select { width: auto; }

/* Login */
body.login { align-items: center; justify-content: center; }
.login-box { background: var(--card); padding: 30px; border-radius: 12px; border: 1px solid var(--borde); width: 380px; box-shadow: 0 8px 30px rgba(16, 24, 40, .08); }
.login-box.ancho-inst { width: 560px; margin: 30px 0; }
.requisitos { list-style: none; padding: 0; }
.requisitos .ok { color: var(--ok); } .requisitos .mal { color: var(--peligro); font-weight: 600; }
[hidden] { display: none !important; }
.totales > #desglose { display: block; padding: 0; }
.tabla td.r { white-space: nowrap; }
label > input[type=radio], label > input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; vertical-align: -2px; }
.marca-logo { height: 30px; vertical-align: middle; margin-right: 6px; background: #fff; border-radius: 6px; padding: 2px 4px; }
.login-logo { text-align: center; margin-bottom: 18px; font-weight: 650; font-size: 18px; }
.login-logo img { max-width: 170px; display: block; margin: 0 auto 6px; }
.enviada { color: #c3c9d1; font-size: 15px; vertical-align: middle; }
.enviada.si { color: var(--ok); }
pre.log { background: #16212e; color: #c9d2dc; padding: 10px; border-radius: 6px; font-size: 11px; overflow-x: auto; margin-top: 12px; }
.aviso-fila { font-size: 12px; color: #9a5b00; margin-top: 2px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); margin-bottom: 16px; }
.tabs a { padding: 9px 16px; color: var(--tenue); border-bottom: 3px solid transparent; font-weight: 550; }
.tabs a.on { color: var(--texto); border-bottom-color: var(--primario); }
.tabs a:hover { text-decoration: none; color: var(--texto); }
.tabs .tab-accion { margin-left: auto; color: var(--primario); }
.mes-cab { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.mes-titulo { margin: 0 8px; font-size: 20px; min-width: 170px; text-align: center; }
.resumen-mes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 10px; }
.caja-res { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px 16px; border-left: 5px solid #c3c9d1; }
.caja-res span { display: block; font-size: 26px; font-weight: 700; }
.caja-res small { display: block; color: var(--tenue); font-size: 13px; }
.caja-res.pendiente { border-left-color: #c3c9d1; } .caja-res.preparada { border-left-color: #e8a33d; } .caja-res.emitida { border-left-color: var(--ok); }
.estado { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.estado.pendiente { background: #eef0f3; color: var(--tenue); }
.estado.preparada { background: #fff1d6; color: #8a5300; }
.estado.emitida { background: #e3f4e8; color: var(--ok); }

.opciones-auto { background: #f6f8fb; border: 1px solid var(--borde); border-radius: 6px; padding: 10px 14px; margin: 6px 0 12px; }

.paneles { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.panel { flex: 1 1 140px; background: var(--card); border: 1px solid var(--borde); border-radius: var(--radio); padding: 10px 14px; color: var(--texto); border-top: 4px solid #c3c9d1; }
.panel:hover { text-decoration: none; border-color: #9aa6b4; }
.panel.on { outline: 2px solid var(--primario); }
.panel b { display: block; font-size: 22px; }
.panel span { display: block; font-weight: 600; font-size: 13px; }
.panel small { color: var(--tenue); }
.panel.p-no_enviadas { border-top-color: #e8a33d; } .panel.p-enviadas { border-top-color: #4a90d9; }
.panel.p-sin_cobrar { border-top-color: #8a5300; } .panel.p-vencidas { border-top-color: var(--peligro); } .panel.p-cobradas { border-top-color: var(--ok); }
.estado.vencida { background: #fdecea; color: var(--peligro); }

.aviso-corregir { background: #eaf2fb; border-color: #9cc3e6; }
