/* Partes de obra · Construcciones Sevilla
   La hoja del parte imita el impreso en papel: rejilla de líneas negras, cabeceras de bloque en mayúsculas, lo que escribe
   el encargado en azul bolígrafo y la marca roja de revisado. El resto de la aplicación es sobrio y de alto contraste
   (se usa a pie de obra, con sol). */
:root {
  --fondo: #eef0f2; --papel: #fff; --linea: #2b2b2b; --linea-suave: #c9ced4; --cabecera: #eceef0;
  --texto: #1b1f24; --gris: #5d6670; --tinta: #1c3faa; --tinta-suave: #e8edfb;
  --rojo: #c62828; --rojo-suave: #fdecec; --ambar: #9a6700; --ambar-suave: #fff4d6; --verde: #1b7f3b; --verde-suave: #e5f4ea;
  --oscuro: #1d2a3a; --boton: #1d2a3a; --radio: 6px;
  --letra: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mano: "Segoe Print", "Bradley Hand", "Comic Neue", "Chalkboard SE", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fondo); color: var(--texto); font: 15px/1.4 var(--letra); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--tinta); }
[hidden] { display: none !important; }
.cargando { padding: 40px; text-align: center; color: var(--gris); }

/* ------------------------------------------------------------ barra superior */
#barra { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 8px 14px;
  background: var(--oscuro); color: #fff; padding-top: max(8px, env(safe-area-inset-top)); }
.marca-mini { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 600; white-space: nowrap; }
.marca-mini svg { width: 34px; height: 24px; }
#menu { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#menu a { color: #cfd8e3; text-decoration: none; padding: 6px 10px; border-radius: var(--radio); white-space: nowrap; }
#menu a.activo, #menu a:hover { background: rgba(255,255,255,.12); color: #fff; }
.red { width: 10px; height: 10px; border-radius: 50%; background: #3ecf6b; flex: none; }
.red.sin { background: #f0a500; }
.enlace { background: none; border: 0; color: #cfd8e3; cursor: pointer; padding: 6px; }
#barra .enlace:hover { color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 22px 0 10px; }

/* ------------------------------------------------------------ controles */
.boton { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: var(--radio);
  border: 1px solid var(--boton); background: var(--boton); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.boton.secundario { background: #fff; color: var(--boton); }
.boton.peligro { background: var(--rojo); border-color: var(--rojo); }
.boton.exito { background: var(--verde); border-color: var(--verde); }
.boton.mini { min-height: 34px; padding: 0 10px; font-size: 14px; }
.boton:disabled { opacity: .5; cursor: default; }
.campo { display: grid; gap: 4px; margin-bottom: 12px; }
.campo label { font-size: 13px; color: var(--gris); font-weight: 600; }
.campo input, .campo select, .campo textarea, .filtros input, .filtros select {
  min-height: 42px; padding: 8px 10px; border: 1px solid var(--linea-suave); border-radius: var(--radio); background: #fff; }
.fila-botones { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filtros { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tarjeta { background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--cabecera); color: var(--gris); white-space: nowrap; }
.chip.borrador { background: var(--cabecera); }
.chip.enviado { background: var(--tinta-suave); color: var(--tinta); }
.chip.validado { background: var(--verde-suave); color: var(--verde); }
.chip.rechazado, .chip.conflicto, .chip.mal { background: var(--rojo-suave); color: var(--rojo); }
.chip.ambar { background: var(--ambar-suave); color: var(--ambar); }
.vacio { color: var(--gris); padding: 18px; text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------------------ tablas de oficina */
.tabla { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.tabla th, .tabla td { padding: 9px 10px; border-bottom: 1px solid #eceff2; text-align: left; vertical-align: top; }
.tabla th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--gris); background: #f7f8f9; }
.tabla tr.clic { cursor: pointer; }
.tabla tr.clic:hover td { background: #f7f9fc; }
.desplaza { overflow-x: auto; }

/* ------------------------------------------------------------ entrada */
.entrada { max-width: 380px; margin: 8vh auto; }
.entrada .logo-grande { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; color: var(--oscuro); }
.entrada .logo-grande svg { width: 72px; height: 50px; }
.error { color: var(--rojo); font-weight: 600; }

/* ============================================================ LA HOJA DEL PARTE (como el papel) */
.hoja { background: var(--papel); max-width: 860px; margin: 0 auto; padding: 18px 18px 22px; box-shadow: 0 2px 10px rgba(0,0,0,.12);
  border-radius: 2px; position: relative; }
.hoja .revisado { position: absolute; top: 6px; right: 12px; width: 48px; height: 48px; color: var(--rojo); transform: rotate(-8deg); }
.membrete { display: grid; grid-template-columns: 1fr 1.25fr; gap: 14px; align-items: start; margin-bottom: 12px; }
.empresa { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; }
.empresa svg { width: 64px; height: 44px; color: #444; grid-row: span 2; }
.empresa .c1 { font-weight: 700; letter-spacing: .14em; font-size: 15px; color: #555; }
.empresa .c2 { font-weight: 800; letter-spacing: .12em; font-size: 30px; line-height: 1; color: #fff;
  -webkit-text-stroke: 1.3px #333; paint-order: stroke; text-shadow: 1px 1px 0 #333; }
.empresa .dir { grid-column: 1 / -1; font-size: 11px; font-style: italic; color: #555; line-height: 1.3; }
.recuadro { border: 1.5px solid var(--linea); padding: 4px 10px 8px; }
.recuadro .titulo { font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.recuadro .par { display: grid; grid-template-columns: auto 1fr auto minmax(70px, .6fr); gap: 4px 6px; align-items: end; margin-top: 4px; }
.recuadro .et { font-size: 13px; padding-bottom: 4px; }
.punteado { border: 0; border-bottom: 1px dotted #555; background: transparent; padding: 2px 2px; min-height: 30px; width: 100%; min-width: 0;
  color: var(--tinta); font-family: var(--mano); font-size: 17px; }
select.punteado { appearance: none; -webkit-appearance: none; cursor: pointer; }
.punteado:focus { outline: none; background: var(--tinta-suave); }
.punteado.fijo { display: flex; align-items: end; }

.bloque { margin-top: 12px; }
.bloque > .rotulo { font-size: 13px; font-weight: 800; letter-spacing: .04em; margin: 0 0 3px; display: flex; justify-content: space-between; align-items: end; gap: 8px; }
.rejilla { border: 1.5px solid var(--linea); }
.rejilla .cab, .rejilla .lin { display: grid; }
.rejilla .cab > div { background: var(--cabecera); border-right: 1px solid var(--linea); border-bottom: 1px solid var(--linea);
  font-size: 11.5px; text-transform: uppercase; text-align: center; padding: 3px 4px; line-height: 1.15; display: flex; align-items: end; justify-content: center; }
.rejilla .lin > * { border-right: 1px solid var(--linea); border-bottom: 1px solid var(--linea-suave); min-height: 34px; min-width: 0; }
.rejilla .cab > div:last-child, .rejilla .lin > *:last-child { border-right: 0; }
.rejilla .lin:last-child > * { border-bottom: 0; }
.rejilla .lin.mal > * { background: var(--rojo-suave); }
.rejilla .lin.ambar > * { background: var(--ambar-suave); }
.celda { border: 0; background: transparent; padding: 4px 6px; color: var(--tinta); font-family: var(--mano); font-size: 16px; width: 100%; }
input.celda { text-align: center; }
input.celda.izq { text-align: left; }
.celda:focus { outline: 2px solid var(--tinta); outline-offset: -2px; background: var(--tinta-suave); }
.celda.calc { color: #555; font-family: var(--letra); font-size: 14px; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.recurso { display: flex; align-items: center; gap: 6px; text-align: left; cursor: pointer; justify-content: space-between; padding: 3px 2px 3px 7px; }
.c-hoy { display: flex; flex-direction: column; justify-content: center; }
.solo-movil { display: none; }
.recurso .nom { color: var(--tinta); font-family: var(--mano); font-size: 16px; line-height: 1.15; }
.recurso .det { color: var(--gris); font: 12px var(--letra); }
.recurso .op { color: var(--tinta); font-family: var(--mano); font-size: 14px; }
.quitar { flex: none; border: 0; background: none; color: #9aa3ad; font-size: 20px; width: 28px; height: 28px; cursor: pointer; border-radius: 50%; }
.quitar:hover { color: var(--rojo); background: var(--rojo-suave); }
.ap { display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--tinta); font-family: var(--mano); }
.anadir { display: block; width: 100%; border: 0; border-top: 1px dashed var(--linea-suave); background: #fafbfc; color: var(--tinta);
  font-weight: 600; padding: 10px; cursor: pointer; text-align: left; }
.anadir:hover { background: var(--tinta-suave); }
.nota-linea { font: 12px var(--letra); color: var(--gris); padding: 0 6px 3px; grid-column: 1 / -1; border-right: 0 !important; min-height: 0 !important; }
.nota-linea.mal { color: var(--rojo); font-weight: 600; }
.chip-alb { font: 600 11px var(--letra); color: var(--tinta); background: var(--tinta-suave); border-radius: 4px; padding: 1px 5px; margin-left: 4px; white-space: nowrap; }

/* columnas de cada bloque (como el impreso: nombre · código · horas/cantidades · trabajo) */
.mo .cab, .mo .lin { grid-template-columns: 2.2fr .75fr .7fr .55fr .55fr 2fr; }
.mat .cab, .mat .lin { grid-template-columns: 2.2fr .75fr .8fr .8fr .8fr 1.5fr; }
.maq .cab, .maq .lin { grid-template-columns: 2.5fr .75fr .7fr .9fr .7fr 1.9fr; }
.aux .cab, .aux .lin { grid-template-columns: 2.4fr .75fr .8fr 1.2fr 2fr; }
.c-cod { font-size: 12px !important; color: #444 !important; }
.det { color: var(--gris); font: 12px var(--letra); }

.comentarios { display: grid; grid-template-columns: 1fr 160px 130px; border: 1.5px solid var(--linea); }
.comentarios textarea { border: 0; border-right: 1px solid var(--linea); min-height: 130px; resize: vertical; padding: 4px 8px; color: var(--tinta);
  font-family: var(--mano); font-size: 16px; line-height: 26px;
  background: repeating-linear-gradient(transparent 0 25px, var(--linea-suave) 25px 26px); background-position-y: 3px; }
.comentarios textarea:focus { outline: none; }
.firma { display: grid; grid-template-rows: auto 1fr auto; border-right: 1px solid var(--linea); }
.firma:last-child { border-right: 0; }
.firma .t { background: var(--cabecera); text-align: center; font-size: 12px; font-weight: 700; padding: 3px; border-bottom: 1px solid var(--linea); }
.firma .n { color: var(--tinta); font-family: var(--mano); text-align: center; padding: 8px 4px; font-size: 15px; display: flex; align-items: center; justify-content: center; }
.firma .s { font-size: 10px; text-transform: uppercase; color: #555; padding: 2px 6px; border-top: 1px solid var(--linea-suave); }

.documentos { margin-top: 14px; border: 1.5px dashed var(--linea-suave); border-radius: 4px; padding: 10px; }
.documentos .lista { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.doc { width: 112px; border: 1px solid var(--linea-suave); border-radius: 6px; overflow: hidden; background: #fafbfc; font-size: 12px; position: relative; }
.doc .mini { height: 84px; display: flex; align-items: center; justify-content: center; background: #eef1f4; color: var(--gris); font-weight: 700; overflow: hidden; }
.doc .mini img { width: 100%; height: 100%; object-fit: cover; }
.doc .pie { padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc .clase { position: absolute; top: 4px; left: 4px; }
.estado-doc { display: block; width: 100%; border: 0; border-top: 1px solid var(--linea-suave); background: var(--ambar-suave); color: var(--ambar);
  font: 600 12px var(--letra); padding: 6px 4px; cursor: pointer; text-align: center; }
.estado-doc.listo { background: var(--tinta); color: #fff; }
.estado-doc.hecho { background: var(--verde-suave); color: var(--verde); cursor: default; }
.doc { width: 132px; }
.doc .quitar { position: absolute; top: 2px; right: 2px; background: rgba(255,255,255,.85); }

.acciones-parte { max-width: 860px; margin: 14px auto 0; display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.acciones-parte .estado { color: var(--gris); font-size: 14px; }
.total-parte { font-variant-numeric: tabular-nums; font-weight: 700; }
.mensajes { max-width: 860px; margin: 0 auto 12px; }
.mensaje { padding: 10px 12px; border-radius: var(--radio); margin-bottom: 8px; font-size: 14px; }
.mensaje.mal { background: var(--rojo-suave); color: var(--rojo); }
.mensaje.ambar { background: var(--ambar-suave); color: var(--ambar); }
.mensaje.bien { background: var(--verde-suave); color: var(--verde); }
.mensaje ul { margin: 4px 0 0; padding-left: 18px; }

/* ------------------------------------------------------------ selector de recursos y ventanas */
#capa { position: fixed; inset: 0; z-index: 50; background: rgba(15,20,28,.45); display: flex; align-items: flex-end; justify-content: center; }
.ventana { background: #fff; width: min(680px, 100%); max-height: 92vh; display: flex; flex-direction: column; border-radius: 14px 14px 0 0;
  padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 700px) { #capa { align-items: center; } .ventana { border-radius: 14px; } }
.ventana .cabeza { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; gap: 10px; }
.ventana .cabeza h3 { margin: 0; font-size: 17px; }
.ventana .cuerpo { overflow-y: auto; padding: 0 16px 12px; }
.ventana .pie { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px 14px; border-top: 1px solid #eceff2; flex-wrap: wrap; }
.buscador { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--linea-suave); border-radius: var(--radio); margin-bottom: 8px; }
.opcion { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-bottom: 1px solid #f0f2f4; cursor: pointer; border-radius: 6px; }
.opcion:hover { background: #f5f7fa; }
.opcion.sel { background: var(--tinta-suave); }
.opcion.no { opacity: .55; cursor: not-allowed; }
.opcion .marca { width: 22px; height: 22px; border: 2px solid var(--linea-suave); border-radius: 5px; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; }
.opcion.sel .marca { background: var(--tinta); border-color: var(--tinta); }
.opcion .txt { flex: 1; min-width: 0; }
.opcion .txt b { display: block; font-weight: 600; }
.opcion .txt small { color: var(--gris); }
.grupo-tit { font-size: 12px; text-transform: uppercase; color: var(--gris); font-weight: 700; margin: 12px 0 4px; }

/* lectura del albarán */
.leyendo { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 30px 10px; text-align: center; color: var(--gris); }
.girando { width: 38px; height: 38px; border: 4px solid var(--tinta-suave); border-top-color: var(--tinta); border-radius: 50%; animation: gira 0.9s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
.alb-cab { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.alb-lineas { width: 100%; border-collapse: collapse; margin-top: 8px; }
.alb-lineas th { font-size: 12px; color: var(--gris); text-align: left; padding: 4px; }
.alb-lineas td { padding: 3px; vertical-align: middle; }
.alb-lineas select, .alb-lineas input { width: 100%; min-height: 38px; padding: 4px 6px; border: 1px solid var(--linea-suave); border-radius: 5px; background: #fff; }
.alb-lineas .leido { font-size: 12px; color: var(--gris); display: block; margin-top: 2px; }
.vista-doc { max-height: 220px; overflow: hidden; border-radius: 6px; margin-bottom: 10px; background: #eef1f4; text-align: center; }
.vista-doc img { max-width: 100%; max-height: 220px; }

#aviso { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; background: #222; color: #fff; padding: 10px 16px;
  border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
#aviso.ver { opacity: 1; }

/* ------------------------------------------------------------ inicio del encargado */
.obras-enc { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.obra-enc { background: #fff; border-radius: 10px; padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); display: grid; gap: 8px; }
.obra-enc .cod { font-size: 13px; color: var(--gris); font-weight: 700; }
.obra-enc .nom { font-size: 18px; font-weight: 700; }
.pendientes-envio { background: var(--ambar-suave); color: var(--ambar); padding: 10px 12px; border-radius: var(--radio); margin-bottom: 12px; font-weight: 600; }

/* ------------------------------------------------------------ cuadro de mando */
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 16px; }
.kpi { background: #fff; border-radius: 10px; padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.kpi .et { font-size: 12px; color: var(--gris); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .s { font-size: 13px; color: var(--gris); }
.barra-apilada { display: flex; height: 14px; border-radius: 4px; overflow: hidden; background: #eef0f2; min-width: 120px; gap: 2px; }
.barra-apilada span { display: block; height: 100%; }
.leyenda { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--gris); margin: 6px 0 10px; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.medidor { display: flex; align-items: center; gap: 8px; }
.medidor .pista { flex: 1; height: 8px; background: #eef0f2; border-radius: 4px; overflow: hidden; min-width: 80px; }
.medidor .pista span { display: block; height: 100%; background: var(--f-maq); border-radius: 4px; }
.medidor.bajo .pista span { background: var(--ambar); }
.graf-dias { width: 100%; height: 150px; }
.dos-col { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .dos-col { grid-template-columns: 1.4fr 1fr; } }
/* familias: huecos 1-4 de la paleta categórica validada (orden fijo; la cifra en € va siempre al lado) */
:root { --f-mo: #2a78d6; --f-maq: #eb6834; --f-mat: #1baf7a; --f-aux: #eda100; }

/* ------------------------------------------------------------ móvil: la hoja se apila sin perder el aire de impreso */
@media (max-width: 640px) {
  main { padding: 10px; }
  .hoja { padding: 12px 10px 16px; }
  .membrete { grid-template-columns: 1fr; gap: 8px; }
  .empresa .c2 { font-size: 24px; }
  .recuadro .par { grid-template-columns: auto 1fr; }
  .rejilla .cab { display: none !important; }
  .solo-movil { display: flex; }
  .acciones-parte .solo-escritorio { display: none; }
  .acciones-parte .boton { padding: 0 12px; }
  .rejilla .c-cod, .mo .c-ht { display: none !important; }
  .rejilla .lin { border-bottom: 1.5px solid var(--linea); }
  .rejilla .lin:last-child { border-bottom: 0; }
  .mo .lin { grid-template-columns: 1fr 66px 66px; }
  .mo .c-trab, .mat .c-nom, .mat .c-lug, .maq .c-nom, .maq .c-trab, .aux .c-lug, .aux .c-trab { grid-column: 1 / -1; border-right: 0 !important; }
  .mat .lin, .maq .lin { grid-template-columns: 1fr 1fr 1fr; }
  .aux .lin { grid-template-columns: 1fr 90px; }
  .aux .c-hoy { border-right: 0 !important; }
  .mo .c-he, .mat .c-tot, .maq .c-tot { border-right: 0 !important; }
  .c-hn, .c-he, .c-or, .c-hoy, .c-tot { display: flex !important; flex-direction: column; justify-content: center; }
  .c-hn::before, .c-he::before, .c-or::before, .c-hoy::before, .c-tot::before { font: 10px var(--letra); color: var(--gris); text-transform: uppercase; text-align: center; padding-top: 2px; }
  .c-hn::before { content: "Horas"; } .c-he::before { content: "H. extra"; }
  .c-or::before { content: "Origen"; } .c-hoy::before { content: "Hoy"; } .c-tot::before { content: "Total"; }
  .aux .c-hoy::before { content: "Cantidad"; }
  .comentarios { grid-template-columns: 1fr 1fr; }
  .comentarios textarea { grid-column: 1 / -1; border-right: 0; border-bottom: 1px solid var(--linea); }
  .alb-cab { grid-template-columns: 1fr 1fr; }
  .alb-cab .campo:first-child { grid-column: 1 / -1; }
  .tabla.apila thead { display: none; }
  .tabla.apila tr { display: grid; grid-template-columns: 1fr auto; padding: 8px 10px; border-bottom: 1px solid #eceff2; }
  .tabla.apila td { border: 0; padding: 2px 0; }
  .acciones-parte { position: sticky; bottom: 0; background: var(--fondo); padding: 10px 0 max(10px, env(safe-area-inset-bottom)); }
  .acciones-parte .fila-botones { width: 100%; }
  .acciones-parte [data-enviar] { flex: 1; }
}
@media print {
  #barra, .acciones-parte, .anadir, .quitar, .documentos button, .mensajes { display: none !important; }
  body { background: #fff; } main { padding: 0; } .hoja { box-shadow: none; }
}
