/* Obras Finansierra — estilos. El color --c lo fija cada constructor. */
:root {
  --c: #1f5f8b;
  --c-suave: color-mix(in srgb, var(--c) 10%, white);
  --c-medio: color-mix(in srgb, var(--c) 22%, white);
  --c-oscuro: color-mix(in srgb, var(--c) 80%, black);
  --fondo: #f4f5f7;
  --panel: #ffffff;
  --texto: #1d2329;
  --suave: #5f6b76;
  --borde: #dde1e6;
  --borde-fuerte: #c5cbd2;
  --ok: #15803d;
  --ok-suave: #e7f6ec;
  --aviso: #b45309;
  --aviso-suave: #fff4e0;
  --error: #b91c1c;
  --error-suave: #fdecec;
  --info: #2563eb;
  --info-suave: #eaf1fe;
  --radio: 8px;
  --sombra: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .05);
  --mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
a { color: var(--c); }
code { font-family: var(--mono); font-size: .9em; background: #eef0f3; padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
[hidden] { display: none !important; }
.suave { color: var(--suave); }
.ayuda { color: var(--suave); font-size: .86rem; margin: .2em 0 .8em; }
.nota { color: var(--suave); font-size: .86rem; margin-left: .6em; }
.error { color: var(--error); background: var(--error-suave); padding: .6em .8em; border-radius: var(--radio); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: .85em; }
.fila { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.espacio { flex: 1; }
.oculto-movil { }
.solo-movil { display: none; }
.selector-cap { padding: .7rem; border-bottom: 1px solid var(--borde); }

/* ------------------------------------------------------------ controles */
label { display: block; font-size: .85rem; color: var(--suave); margin-bottom: .7rem; }
label > input, label > select, label > textarea { margin-top: .25rem; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--texto);
  background: #fff;
  border: 1px solid var(--borde-fuerte);
  border-radius: 6px;
  padding: .5em .65em;
  min-height: 2.4em;
}
textarea { min-height: 5em; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--c-medio); border-color: var(--c); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; margin: 0 .4em 0 0; accent-color: var(--c); }
input[type=color] { padding: 2px; width: 4rem; height: 2.4em; }
label.check { display: flex; align-items: center; color: var(--texto); font-size: .92rem; cursor: pointer; }
fieldset { border: 1px solid var(--borde); border-radius: var(--radio); padding: 1rem 1.1rem .4rem; margin: 0 0 1rem; background: var(--panel); }
legend { font-weight: 600; padding: 0 .4em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  font: inherit; font-size: .92rem; font-weight: 500;
  padding: .5em .95em; min-height: 2.4em;
  border-radius: 6px; border: 1px solid var(--borde-fuerte);
  background: #fff; color: var(--texto);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f2f4f6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primario { background: var(--c); border-color: var(--c); color: #fff; }
.btn.primario:hover { background: var(--c-oscuro); }
.btn.peligro { color: var(--error); border-color: #e7b4b4; }
.btn.peligro:hover { background: var(--error-suave); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.plano { border-color: transparent; background: transparent; }
.btn.plano:hover { background: #eceef1; }
.btn.peq { font-size: .82rem; padding: .25em .6em; min-height: 2em; }
.btn.grande { font-size: 1rem; padding: .7em 1.3em; }
.btn-icono { border: 0; background: transparent; cursor: pointer; padding: .3em; border-radius: 4px; color: var(--suave); font-size: 1rem; line-height: 1; }
.btn-icono:hover { background: #eceef1; color: var(--texto); }

.chip { display: inline-block; padding: .1em .55em; border-radius: 999px; font-size: .76rem; font-weight: 600; background: #eceef1; color: var(--suave); white-space: nowrap; }
.chip.ok { background: var(--ok-suave); color: var(--ok); }
.chip.aviso { background: var(--aviso-suave); color: var(--aviso); }
.chip.error { background: var(--error-suave); color: var(--error); padding: .1em .55em; }
.chip.info { background: var(--info-suave); color: var(--info); }
.chip.c { background: var(--c-suave); color: var(--c-oscuro); }

/* -------------------------------------------------------------- acceso */
.pantalla-acceso { min-height: 100vh; display: grid; place-items: center; grid-template-columns: minmax(0, 1fr); justify-items: center; padding: 1.5rem 1rem; background: linear-gradient(160deg, var(--c-suave), var(--fondo) 60%); }
.tarjeta-acceso { min-width: 0; width: 100%; max-width: 420px; background: var(--panel); border-radius: 12px; box-shadow: var(--sombra); padding: 1.8rem 1.6rem; }
.tarjeta-acceso.ancha { max-width: 640px; }
.tarjeta-acceso fieldset { background: #fafbfc; }
.marca { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.2rem; }
.marca-logo { width: 38px; height: 38px; border-radius: 9px; background: var(--c); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; }
.marca b { font-size: 1.15rem; }
.pestanas-acceso { display: flex; border-bottom: 1px solid var(--borde); margin-bottom: 1.2rem; }
.pestanas-acceso button { flex: 1; background: none; border: 0; padding: .7em; font: inherit; color: var(--suave); cursor: pointer; border-bottom: 2px solid transparent; }
.pestanas-acceso button.activa { color: var(--c); border-color: var(--c); font-weight: 600; }
.rejilla-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .9rem; }
.rejilla-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 .9rem; }

/* ------------------------------------------------------------ armazón */
.barra {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  height: 56px; padding: 0 1rem;
  background: var(--panel); border-bottom: 1px solid var(--borde);
}
.barra .marca { margin: 0; }
.barra .marca img { max-height: 36px; max-width: 140px; object-fit: contain; }
.barra nav { display: flex; gap: .2rem; }
.barra nav a { padding: .45em .8em; border-radius: 6px; color: var(--suave); text-decoration: none; font-size: .93rem; }
.barra nav a:hover { background: #f0f2f4; color: var(--texto); }
.barra nav a.activa { background: var(--c-suave); color: var(--c-oscuro); font-weight: 600; }
.usuario { font-size: .88rem; color: var(--suave); }
.contenido { max-width: 1280px; margin: 0 auto; padding: 1.4rem 1rem 4rem; }
.aviso-banda { padding: .6rem 1rem; text-align: center; font-size: .92rem; }
.aviso-banda.aviso { background: var(--aviso-suave); color: var(--aviso); }
.aviso-banda.error { background: var(--error-suave); color: var(--error); }

.panel { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); }
.panel-cuerpo { padding: 1.1rem 1.2rem; }
.cabecera-vista { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.cabecera-vista h1 { margin: 0; }

/* ------------------------------------------------------------- tablas */
.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabla th { text-align: left; font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; color: var(--suave); padding: .55rem .6rem; border-bottom: 1px solid var(--borde); background: #fafbfc; position: sticky; top: 0; }
.tabla td { padding: .55rem .6rem; border-bottom: 1px solid #eef0f2; vertical-align: top; }
.tabla tr.clicable { cursor: pointer; }
.tabla tr.clicable:hover td { background: #f7f9fb; }

/* ----------------------------------------------------- lista presupuestos */
.zona-subida {
  border: 2px dashed var(--borde-fuerte); border-radius: 12px; background: var(--panel);
  padding: 1.6rem 1rem; text-align: center; cursor: pointer; transition: .15s;
}
.zona-subida:hover, .zona-subida.encima { border-color: var(--c); background: var(--c-suave); }
.zona-subida b { display: block; font-size: 1.05rem; margin-bottom: .25rem; }
.tarjetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.tarjeta-p { padding: 1rem 1.1rem; cursor: pointer; display: flex; flex-direction: column; gap: .45rem; }
.tarjeta-p:hover { border-color: var(--c); }
.tarjeta-p h3 { margin: 0; font-size: 1rem; }
.tarjeta-p .importe { font-size: 1.25rem; font-weight: 700; }
.barra-progreso { height: 6px; border-radius: 3px; background: #eceef1; overflow: hidden; }
.barra-progreso > i { display: block; height: 100%; background: var(--c); }
.vacio { text-align: center; padding: 3rem 1rem; color: var(--suave); }

/* ----------------------------------------------------------- editor */
.editor-cab { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .8rem; }
.editor-cab .titulo { font-size: 1.25rem; font-weight: 700; border: 1px solid transparent; background: transparent; padding: .2em .35em; flex: 1; min-width: 220px; }
.editor-cab .titulo:hover { border-color: var(--borde); }
.estado-guardado { font-size: .82rem; color: var(--suave); white-space: nowrap; }
.estado-guardado.error { color: var(--error); background: none; padding: 0; }
.pestanas { display: flex; gap: .2rem; border-bottom: 1px solid var(--borde); margin-bottom: 1rem; overflow-x: auto; }
.pestanas button { background: none; border: 0; border-bottom: 2px solid transparent; padding: .65em 1em; font: inherit; color: var(--suave); cursor: pointer; white-space: nowrap; }
.pestanas button.activa { color: var(--c); border-color: var(--c); font-weight: 600; }
.pestanas .chip { margin-left: .35em; }

.editor-cuerpo { display: grid; grid-template-columns: 290px 1fr; gap: 1rem; align-items: start; }
.arbol { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; padding: .5rem; }
.arbol-nodo { display: flex; align-items: center; gap: .3rem; padding: .35rem .45rem; border-radius: 6px; cursor: pointer; font-size: .88rem; }
.arbol-nodo:hover { background: #f2f4f6; }
.arbol-nodo.activo { background: var(--c-suave); color: var(--c-oscuro); font-weight: 600; }
.arbol-nodo .cod { font-family: var(--mono); font-size: .78rem; color: var(--suave); min-width: 2.8em; }
.arbol-nodo .nom { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arbol-nodo .imp { font-size: .78rem; color: var(--suave); font-variant-numeric: tabular-nums; }
.arbol-nodo .punto { width: 7px; height: 7px; border-radius: 50%; background: var(--aviso); flex: none; }
.arbol-total { border-top: 1px solid var(--borde); margin-top: .4rem; padding: .6rem .45rem .2rem; font-size: .88rem; display: flex; justify-content: space-between; font-weight: 600; }

.barra-herr { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; padding: .6rem .7rem; border-bottom: 1px solid var(--borde); background: #fafbfc; border-radius: var(--radio) var(--radio) 0 0; }
.barra-herr input[type=search] { width: 220px; min-height: 2.1em; padding: .3em .6em; }
.cap-cab { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem .4rem; }
.cap-cab input.nombre-cap { font-weight: 700; font-size: 1.05rem; border-color: transparent; background: transparent; }
.cap-cab input.nombre-cap:hover { border-color: var(--borde); }
.cap-cab input.cod-cap { width: 6.5em; font-family: var(--mono); font-size: .85rem; border-color: transparent; background: transparent; }
.cap-cab input.cod-cap:hover { border-color: var(--borde); }

.partidas { width: 100%; border-collapse: collapse; font-size: .9rem; }
.partidas th { font-size: .74rem; text-transform: uppercase; letter-spacing: .02em; color: var(--suave); text-align: left; font-weight: 600; padding: .45rem .5rem; border-bottom: 1px solid var(--borde); }
.partidas td { padding: .45rem .5rem; border-bottom: 1px solid #eef0f2; vertical-align: middle; }
.partidas tr.p-fila:hover td { background: #f8fafb; }
.partidas tr.p-fila.abierta td { background: var(--c-suave); }
.partidas tr.p-fila.excluida td { opacity: .5; text-decoration: line-through; }
.partidas tr.subcap td { background: #f5f6f8; font-weight: 600; cursor: pointer; }
.partidas .col-sel { width: 28px; }
.partidas .col-cod { width: 105px; font-family: var(--mono); font-size: .78rem; color: var(--suave); }
.partidas .col-ud { width: 44px; }
.partidas .col-num { width: 92px; text-align: right; }
.partidas .col-precio { width: 112px; }
.partidas .col-ref { width: 82px; text-align: right; color: var(--suave); font-size: .82rem; }
.partidas .col-acc { width: 30px; }
.resumen-p { cursor: pointer; }
.resumen-p b { font-weight: 600; }
.resumen-p .texto-corto { color: var(--suave); font-size: .82rem; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.marcas { display: inline-flex; gap: .25rem; margin-left: .3rem; vertical-align: middle; }
.precio-ref { cursor: pointer; border-bottom: 1px dotted var(--borde-fuerte); }
.precio-ref:hover { color: var(--c); border-color: var(--c); }
input.precio { text-align: right; font-variant-numeric: tabular-nums; padding: .35em .5em; min-height: 2.1em; font-weight: 600; }
input.precio.vacio { background: var(--aviso-suave); border-color: #f0c88a; }

.detalle { padding: .9rem 1rem 1.1rem; background: #fbfcfd; border-bottom: 2px solid var(--c-medio); }
.detalle .rejilla-det { display: grid; grid-template-columns: 140px 90px 1fr; gap: 0 .8rem; }
.mediciones { width: 100%; border-collapse: collapse; font-size: .85rem; margin: .3rem 0 .6rem; }
.mediciones th { font-size: .72rem; color: var(--suave); text-align: left; padding: .25rem .3rem; font-weight: 600; text-transform: uppercase; }
.mediciones td { padding: .15rem .2rem; }
.mediciones input { min-height: 1.95em; padding: .2em .4em; font-size: .85rem; }
.mediciones input.n { text-align: right; width: 5.6em; }
.mediciones td.parcial { text-align: right; font-variant-numeric: tabular-nums; padding-right: .5rem; color: var(--suave); }
.mediciones tfoot td { font-weight: 700; border-top: 1px solid var(--borde); padding-top: .35rem; }
.acciones-det { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.lista-inc { margin: .3rem 0 .6rem; padding: 0; list-style: none; }
.lista-inc li { padding: .45rem .6rem; border-radius: 6px; margin-bottom: .35rem; font-size: .87rem; }
.lista-inc li.error { background: var(--error-suave); color: #7f1d1d; }
.lista-inc li.aviso { background: var(--aviso-suave); color: #78350f; }
.lista-inc li.info { background: var(--info-suave); color: #1e3a8a; }
.lista-inc li .prop { display: block; margin-top: .15rem; opacity: .9; }

/* Revisión */
.incidencia { display: grid; grid-template-columns: 6px 1fr auto; gap: .9rem; padding: .8rem 1rem; border-bottom: 1px solid #eef0f2; }
.incidencia .franja { border-radius: 3px; }
.incidencia .franja.error { background: var(--error); }
.incidencia .franja.aviso { background: var(--aviso); }
.incidencia .franja.info { background: var(--info); }
.incidencia .partida-ref { font-size: .82rem; color: var(--suave); }
.incidencia .acciones { display: flex; gap: .3rem; align-items: start; flex-wrap: wrap; justify-content: flex-end; }

/* Resumen */
.resumen-tabla td { padding: .45rem .6rem; }
.resumen-tabla tr.total td { font-weight: 700; border-top: 2px solid var(--texto); font-size: 1.05rem; }
.resumen-tabla tr.total td:last-child { color: var(--c); font-size: 1.2rem; }
.resumen-tabla tr.sub td { font-weight: 600; border-top: 1px solid var(--borde); }

/* Exportar */
.pasos { display: grid; gap: 1rem; }
.paso { display: grid; grid-template-columns: 42px 1fr; gap: 1rem; padding: 1.1rem 1.2rem; }
.paso .n { width: 34px; height: 34px; border-radius: 50%; background: var(--c-suave); color: var(--c-oscuro); font-weight: 700; display: grid; place-items: center; }
.paso.hecho .n { background: var(--ok); color: #fff; }
.paso h3 { margin-bottom: .3rem; }

/* Modal */
.modal-fondo { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); z-index: 100; display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px; max-height: calc(100vh - 2rem); overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.ancho { max-width: 820px; }
.modal-cab { display: flex; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--borde); }
.modal-cab h2 { margin: 0; flex: 1; }
.modal-cuerpo { padding: 1.1rem 1.2rem; }
.modal-pie { display: flex; gap: .5rem; justify-content: flex-end; padding: .9rem 1.2rem; border-top: 1px solid var(--borde); background: #fafbfc; border-radius: 0 0 12px 12px; }

.avisos-flotantes { position: fixed; bottom: 1rem; right: 1rem; z-index: 200; display: grid; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.toast { background: #1d2329; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--sombra); font-size: .9rem; }
.toast.error { background: var(--error); }
.toast.ok { background: var(--ok); }

.ajustes-rejilla { display: grid; grid-template-columns: 220px 1fr; gap: 1.2rem; align-items: start; }
.menu-lateral a { display: block; padding: .5rem .75rem; border-radius: 6px; color: var(--suave); text-decoration: none; cursor: pointer; }
.menu-lateral a.activa { background: var(--c-suave); color: var(--c-oscuro); font-weight: 600; }
.vista-logo { display: flex; align-items: center; gap: 1rem; padding: 1rem; border: 1px dashed var(--borde-fuerte); border-radius: var(--radio); margin-bottom: 1rem; }
.vista-logo img { max-height: 60px; max-width: 220px; }
.muestra-color { display: inline-block; width: 1.2em; height: 1.2em; border-radius: 4px; vertical-align: middle; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.kpi { padding: .9rem 1rem; }
.kpi .v { font-size: 1.5rem; font-weight: 700; }
.kpi .e { font-size: .8rem; color: var(--suave); }

/* ----------------------------------- arquitecto, enlaces y versiones */
.respuesta { margin-top: .6rem; padding: .5rem .7rem; border-left: 3px solid var(--c); background: var(--c-suave); border-radius: 0 6px 6px 0; }
.arq { max-width: 900px; }
.arq-obs { grid-template-columns: 6px 1fr 0; }
.enlace-url { font-family: var(--mono); font-size: .8rem; overflow-wrap: anywhere; background: #f3f5f7; padding: .3rem .5rem; border-radius: 4px; }
.dif-mas { color: var(--error); }
.dif-menos { color: var(--ok); }
.comparativa td.num, .comparativa th.num { white-space: nowrap; }
.comparativa tr.nueva td { background: var(--ok-suave); }
.comparativa tr.quitada td { background: var(--error-suave); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.3); }
.comparativa tr.sub td { font-weight: 600; border-top: 1px solid var(--borde-fuerte); }
.tabla-scroll { overflow-x: auto; }

/* --------------------------------------------------------------- móvil */
@media (max-width: 900px) {
  .editor-cuerpo { grid-template-columns: 1fr; }
  .arbol { display: none; }
  .solo-movil { display: block; }
  .ajustes-rejilla { grid-template-columns: 1fr; }
  .menu-lateral { display: flex; overflow-x: auto; gap: .2rem; }
  .menu-lateral a { white-space: nowrap; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .barra { gap: .5rem; padding: 0 .6rem; }
  .barra nav a { padding: .4em .5em; font-size: .85rem; }
  .oculto-movil { display: none !important; }
  .contenido { padding: 1rem .75rem 4rem; }
  .rejilla-2, .rejilla-3 { grid-template-columns: 1fr; }
  .detalle .rejilla-det { grid-template-columns: 1fr 1fr; }
  .detalle .rejilla-det > :last-child { grid-column: 1 / -1; }
  /* La tabla de partidas pasa a tarjetas */
  .partidas thead { display: none; }
  .partidas, .partidas tbody, .partidas tr, .partidas td { display: block; width: 100%; }
  .partidas tr.p-fila { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "sel cod acc" "res res res" "can pre imp" "pp bb bb"; gap: .2rem .5rem; padding: .6rem .4rem; border-bottom: 1px solid var(--borde); }
  .partidas tr.p-fila td { border: 0; padding: 0; width: auto; }
  .partidas td.col-sel { grid-area: sel; }
  .partidas td.col-cod { grid-area: cod; width: auto; }
  .partidas td.col-acc { grid-area: acc; }
  .partidas td.resumen-p { grid-area: res; }
  .partidas td.col-ud { display: none; }
  .partidas td.c-can { grid-area: can; text-align: left; width: auto; }
  .partidas td.c-pre { grid-area: pre; width: auto; }
  .partidas td.c-imp { grid-area: imp; width: auto; align-self: center; }
  .partidas td.c-pp { grid-area: pp; text-align: left; width: auto; font-size: .78rem; }
  .partidas td.c-bb { grid-area: bb; text-align: left; width: auto; font-size: .78rem; }
  .partidas td.c-pp span::before { content: "Proyecto: "; }
  .partidas td.c-bb span::before { content: "Mi banco: "; }
  .cap-cab { flex-wrap: wrap; }
  .cap-cab input.nombre-cap { flex: 1 1 100% !important; order: -1; }
  .partidas td.c-can::before { content: attr(data-ud) " "; color: var(--suave); font-size: .8rem; }
  .mediciones input.n { width: 4.2em; }
  .mediciones .c-com { min-width: 7em; }
  .barra-herr input[type=search] { width: 100%; }
  .incidencia { grid-template-columns: 5px 1fr; }
  .incidencia .acciones { grid-column: 2; justify-content: flex-start; }
}
@media print {
  .barra, .pestanas, .barra-herr, .arbol { display: none !important; }
}
