:root {
  --azul: #1f3864; --azul2: #2f5597; --verde: #548235; --verdeclaro: #e2efda;
  --amarillo: #fff2cc; --naranja: #c65911; --gris: #f3f4f6; --borde: #d9d9d9;
  --texto: #1a1a1a; --suave: #6b7280; --rojo: #c00000;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 Arial, Helvetica, sans-serif; color: var(--texto); background: #fafafa; }
header { display: flex; align-items: center; gap: 24px; background: var(--azul); color: #fff; padding: 10px 16px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.marca { font-weight: 700; letter-spacing: .5px; }
.marca span { font-weight: 400; opacity: .8; margin-left: 6px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav a { color: #fff; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
nav a.activo, nav a:hover { background: rgba(255,255,255,.15); }
.usuario { font-size: 13px; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 12px; } h2 { font-size: 17px; margin: 18px 0 8px; }
.tarjeta { background: #fff; border: 1px solid var(--borde); border-radius: 10px; padding: 16px; }
.estrecha { max-width: 380px; margin: 60px auto; }
.suave { color: var(--suave); }
label { display: block; margin: 10px 0; font-size: 13px; color: #333; }
input, select, textarea { font: inherit; padding: 7px 8px; border: 1px solid var(--borde); border-radius: 6px; width: 100%; background: #fff; }
button { font: inherit; background: var(--azul2); color: #fff; border: 0; border-radius: 6px; padding: 8px 14px; cursor: pointer; }
button.sec { background: #fff; color: var(--azul2); border: 1px solid var(--azul2); padding: 4px 10px; }
button.peligro { background: #fff; color: var(--rojo); border: 1px solid var(--rojo); padding: 2px 8px; }
.error { color: var(--rojo); min-height: 1em; }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.fila > * { width: auto; }
.tabla-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--borde); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { background: var(--azul); color: #fff; text-align: left; padding: 6px 8px; font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
th.coste { background: var(--verde); }
td { border-bottom: 1px solid #eee; padding: 3px 6px; vertical-align: middle; }
td.num, th.num { text-align: right; white-space: nowrap; }
td input, td select { padding: 4px 6px; border-color: transparent; background: transparent; }
td input:hover, td input:focus, td select:hover, td select:focus { border-color: var(--borde); background: #fff; }
td input.num { text-align: right; }
td.coste { background: var(--verdeclaro); }
tr.inactiva td { color: #aaa; } tr.inactiva td input { color: #aaa; }
tr.total td { font-weight: 700; background: var(--amarillo); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--gris); font-size: 12px; }
.chip.firmado { background: #dcfce7; } .chip.borrador { background: var(--amarillo); }
.lista-obras { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.obra { cursor: pointer; } .obra:hover { border-color: var(--azul2); }
.resultado { font-size: 18px; } .resultado b { color: var(--azul); }
.aviso { background: var(--amarillo); padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
@media (max-width: 700px) { header { gap: 8px; } main { padding: 10px; } }

/* presupuesto */
tr.enlace { cursor: pointer; } tr.enlace:hover td { background: #eef3fb; }
.cab-pres { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
table.pres td { vertical-align: top; }
table.pres tr.capitulo td { background: #fff2cc; border-top: 2px solid #bf9000; }
table.pres tr.partida td { border-top: 1px solid #ccc; }
table.pres tr.linea td { color: #444; font-size: 12px; }
table.pres th.sep, table.pres td.sep { width: 6px; background: #000; padding: 0; }
textarea.desc { font-size: 11px; color: #555; border-color: transparent; resize: vertical; margin-top: 2px; }
textarea.desc:hover, textarea.desc:focus { border-color: var(--borde); }
tr.noincl td, tr.nosuma td, tr.noincl input, tr.nosuma input { color: #aaa !important; font-style: italic; }
tr.interna td { background: #f7f7f7; }
label.mini { display: inline; font-size: 11px; color: #555; margin: 0 4px 0 0; }
label.mini input { width: auto; }
.solo-imprimir { display: none; }
@media print {
  header, .no-imprimir, nav, button { display: none !important; }
  .solo-imprimir { display: block; }
  body { background: #fff; } main { padding: 0; max-width: none; }
  .tabla-wrap { border: 0; overflow: visible; }
  input, textarea, select { border: 0 !important; background: transparent !important; padding: 0 !important; resize: none; }
  th { background: #ddd !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.pres tr.capitulo td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  tr.noincl td, tr.noincl input { color: #999 !important; }
  ::placeholder { color: transparent !important; }
  @page { size: A4 landscape; margin: 12mm; }
}

/* fases del presupuesto */
.fases { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.fase { flex: 1; min-width: 180px; background: var(--gris); border-radius: 8px; padding: 8px 10px; }
.fase-item { display: block; margin-top: 4px; font-weight: 700; color: var(--azul2); text-decoration: none; }
.fase-item:hover { text-decoration: underline; }
.flecha { align-self: center; color: var(--suave); font-size: 20px; }

/* arrastrar y soltar */
.zona-arrastre { border: 2px dashed var(--azul2); border-radius: 10px; padding: 22px; text-align: center; color: var(--azul2); background: #f5f8fd; cursor: pointer; margin: 6px 0 12px; }
.zona-arrastre.encima { background: #dce8fa; border-style: solid; }
.zona-arrastre.ocupada { opacity: .6; pointer-events: none; }
.zona-arrastre.mini-zona { padding: 8px 14px; margin: 0; font-size: 13px; }

/* navegación de obra */
nav a.ultimo { background: #fff2cc; color: var(--azul); font-weight: 700; margin-left: auto; }
.barra-obra { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; background: #fff; border: 1px solid var(--borde); border-radius: 8px; padding: 6px 8px; margin-bottom: 12px; position: sticky; top: 48px; z-index: 4; }
.barra-obra a { text-decoration: none; color: var(--azul2); padding: 4px 10px; border-radius: 6px; white-space: nowrap; }
.barra-obra a:hover { background: #eef3fb; }
.barra-obra a.activo { background: var(--azul2); color: #fff; }
.barra-obra a.f-contrato { border: 1px solid #b7dfb9; } .barra-obra a.f-ejecucion { border: 1px solid #f1d58a; }

/* trámites */
.tramite { border-left: 5px solid var(--borde); }
.tramite.e-concedido { border-left-color: #2e7d32; } .tramite.e-presentado { border-left-color: var(--azul2); }
.tramite.e-requerido, .tramite.e-denegado { border-left-color: var(--rojo); } .tramite.e-pendiente, .tramite.e-preparando { border-left-color: #bf9000; }
table.datos { width: auto; margin: 4px 0; } table.datos th { position: static; background: var(--gris); color: #333; font-weight: 600; vertical-align: top; }
table.datos td { border-bottom: 1px solid #eee; }
details summary { cursor: pointer; margin: 6px 0; }

/* certificaciones */
table.cert tr.bloque td { background: var(--azul); color: #fff; font-weight: 700; letter-spacing: .5px; }
table.cert td.mes { background: #fffbe6; }
table.cert tr.oculta { display: none; }
button.mini-btn { padding: 1px 6px; font-size: 11px; margin-left: 6px; }
.firmas { display: none; justify-content: space-between; margin-top: 40px; gap: 20px; }
.firmas > div { flex: 1; border-top: 1px solid #000; padding-top: 6px; font-size: 12px; text-align: center; min-height: 60px; }
@media print { .firmas { display: flex !important; } table.cert td.mes { background: none; } }

/* actas y libro */
.lienzo { border: 2px dashed var(--azul2); border-radius: 8px; width: 100%; max-width: 600px; height: auto; touch-action: none; background: #fff; }
.acta-doc { font-size: 14px; line-height: 1.55; max-width: 820px; }
.acta-doc ul { padding-left: 22px; }
.firmas-acta { display: flex; gap: 40px; margin-top: 30px; } .firmas-acta > div { flex: 1; border-top: 1px solid #999; padding-top: 6px; text-align: center; }
.libro-sub td input { min-width: 90px; }
@media print {
  body.solo-libro #vista > *:not(.libro-sub) { display: none !important; }
  body.solo-libro .libro-sub { display: block !important; }
  .acta-doc { border: 0; }
  .firmas-acta { display: flex !important; }
}

.resumen-caps table { width: auto; min-width: 60%; } .resumen-caps tr.grupo td { background: #dbe5f1; }
.resumen-caps tr.gran-total td { background: #c6e0b4; font-size: 14px; }

table.pres tr.cab-rep th { position: static; background: var(--azul); }
table.pres tr.cab-rep th.coste { background: var(--verde); }
tbody.resumen-pres tr.grupo td { background: #dbe5f1; } tbody.resumen-pres tr.gran-total td { background: #c6e0b4; font-size: 14px; }
tbody.resumen-pres td { border-top: 1px solid #ddd; }

.desc-imp { font-size: 11px; color: #444; font-weight: 400; margin-top: 2px; white-space: pre-wrap; }
table.mediciones td { vertical-align: top; }

.contr-cant { font-size: 11px; color: #888; font-weight: 400; white-space: nowrap; }
.contr-cant.difiere { color: #b45309; }
.panel-ahorro { border: 1px solid #bf9000; background: #fffbea; padding: 10px; border-radius: 8px; margin: 8px 0; }
.panel-ahorro td.pos { color: #166534; } .panel-ahorro td.neg { color: #b91c1c; }

table.agentes input, table.agentes select { min-width: 70px; }
.boton-enlace { padding: 6px 12px; border: 1px solid var(--azul2); border-radius: 6px; text-decoration: none; }
.documento-oficial { max-width: 760px; background: #fff; padding: 30px 40px; border: 1px solid #ddd; font-size: 14px; line-height: 1.5; }
.documento-oficial .hueco { color: #999; }
.firmas-agentes { display: grid; grid-template-columns: 1fr 1fr; gap: 24px 40px; margin-top: 30px; }
.firma-agente .hueco-firma { height: 60px; border-bottom: 1px solid #333; margin-bottom: 4px; }
.barra-progreso { height: 10px; background: #e5e7eb; border-radius: 5px; overflow: hidden; margin-bottom: 6px; }
.barra-progreso div { height: 100%; background: #16a34a; }
table.hoja-ruta tr.hecho td { background: #f0fdf4; }
table.hoja-ruta input.nota-ruta { width: 220px; }
@media print { .documento-oficial { border: 0; padding: 0; max-width: none; } }

.guia-paso { margin-top: 4px; font-size: 13px; }
.guia-paso summary { cursor: pointer; color: var(--azul2); }
.guia-paso ol { margin: 6px 0 6px 18px; padding: 0; }
