:root {
  --bg: #f4f5f6; --panel: #fff; --ink: #1d2327; --muted: #66707a; --line: #dfe3e7; --soft: #eef1f3;
  --accent: #1f5f8b; --accent-ink: #fff; --ok: #1e7b4f; --warn: #a86400; --neg: #b3261e;
  --okbg: #e6f4ec; --warnbg: #fff4e0; --negbg: #fde9e7;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 18px; margin: 22px 0 8px; } h3 { font-size: 15px; margin: 22px 0 8px; } h4 { font-size: 13px; margin: 14px 0 6px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .neg { color: var(--neg); } .warn { color: var(--warn); } .error { color: var(--neg); } .b { font-weight: 600; }
.boot { padding: 40px; color: var(--muted); }
code { background: var(--soft); padding: 1px 4px; border-radius: 3px; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px; background: #17232c; color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar a { color: #cfd8de; text-decoration: none; }
.brand { font-weight: 700; color: #fff !important; white-space: nowrap; } .brand span { font-weight: 400; color: #9fb0bb; font-size: 12px; margin-left: 6px; }
.topbar nav { display: flex; gap: 4px; } .topbar nav a { padding: 6px 10px; border-radius: 4px; } .topbar nav a.on { background: #2c3e4a; color: #fff; }
.me { margin-left: auto; display: flex; gap: 8px; align-items: center; font-size: 13px; }
.me .badge { background: #2c3e4a; color: #dbe5eb; }
main { padding: 18px 24px 60px; max-width: 1500px; margin: 0 auto; }
.crumbs { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.inline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 12px; border-radius: 5px; cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.3; }
button:hover, .btn:hover { border-color: #b9c2ca; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--neg); border-color: #e8b4af; }
button.small, .btn.small { padding: 3px 8px; font-size: 12px; }
button.icon { border: none; background: none; padding: 2px 6px; color: var(--muted); }
button.icon:hover { color: var(--neg); }
button.link { border: none; background: none; color: #cfd8de; padding: 0; text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 4px; padding: 5px 7px; background: #fff; color: var(--ink); max-width: 100%; }
input:disabled, select:disabled, textarea:disabled { background: var(--soft); color: var(--muted); }
textarea { width: 100%; resize: vertical; }
.numwrap { display: inline-flex; align-items: center; gap: 4px; }
input.num { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.suffix { color: var(--muted); font-size: 12px; white-space: nowrap; }
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.field > input:not(.num), .field > select { width: 100%; }
.field.wide, .wide { grid-column: 1 / -1; }
.lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.hint { color: var(--muted); font-size: 11px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); gap: 16px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.banner { background: var(--warnbg); border: 1px solid #f0d6a8; padding: 8px 12px; border-radius: 6px; }
.choice { display: flex; flex-direction: column; gap: 4px; background: var(--soft); padding: 8px 10px; border-radius: 6px; margin: 6px 0 10px; }
.checklist { display: flex; flex-direction: column; gap: 3px; max-height: 220px; overflow: auto; border: 1px solid var(--line); padding: 8px; border-radius: 5px; }
.seg { display: inline-flex; } .seg button { border-radius: 0; } .seg button:first-child { border-radius: 5px 0 0 5px; } .seg button:last-child { border-radius: 0 5px 5px 0; } .seg button.on { background: var(--soft); font-weight: 600; }

.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.card .tablewrap, .modal .tablewrap { border: none; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfb; white-space: nowrap; }
.table.compact th, .table.compact td { padding: 5px 7px; }
.table .r, .r { text-align: right; white-space: nowrap; }
.table tr.group td { background: var(--soft); font-weight: 600; }
.table tr.total td { font-weight: 700; border-top: 2px solid #c9d0d6; }
.table tr.sub td:first-child { padding-left: 22px; }
.table tfoot td { font-weight: 700; background: #fafbfb; }
.table tr.click { cursor: pointer; } .table tr.click:hover td { background: #f6f9fb; }
.table tr.rowerr td { background: var(--negbg); }
.table tr.hl td { background: var(--warnbg); }
.formula { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: #33414b; }
.table td.formula { max-width: 420px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: var(--soft); color: var(--ink); white-space: nowrap; }
.badge.aprobado, .badge.en_ejecucion { background: var(--okbg); color: var(--ok); }
.badge.cotizado { background: #e5eef6; color: var(--accent); }
.badge.cerrado { background: #e9e9e9; color: #555; }
.badge.warn { background: var(--warnbg); color: var(--warn); }
.badge.neg { background: var(--negbg); color: var(--neg); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 6px 0 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.dot { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; text-align: center; color: #fff; }
.dot.err { background: var(--neg); } .dot.warn { background: var(--warn); }
.recorrido { margin: 6px 0 14px; }
.recorrido-etapas { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.recorrido-etapas ol { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.recorrido-etapas li a, .recorrido-etapas li > span, .recorrido .tablero { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); text-decoration: none; color: var(--ink); white-space: nowrap; font-size: 13px; }
.recorrido .tablero { font-weight: 600; }
.recorrido .tablero.on, .recorrido-etapas li.on a { border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); font-weight: 600; }
.recorrido .n { display: inline-block; min-width: 20px; height: 20px; line-height: 20px; border-radius: 10px; text-align: center; font-size: 11px; background: var(--soft); color: var(--muted); font-weight: 700; }
.recorrido li.ok .n { background: var(--ok); color: #fff; }
.recorrido li.todo .n { background: #f5e6cc; color: var(--warn); }
.recorrido li.aviso a { border-color: #f0d6a8; }
.steps li.aviso { border-color: #f0d6a8; }
.tabs.sub { margin: 8px 0 0; }
.modalidades { gap: 10px 14px; margin: 8px 0 12px; }
.modalidades > div { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.modalidades p { margin: 6px 0 0; }
@media (max-width: 760px) { .modalidades { grid-template-columns: 1fr; } }
.busy { opacity: .6; pointer-events: none; transition: opacity .15s; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; } .kpi .v { font-size: 22px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; } .kpi .s { font-size: 12px; color: var(--muted); }
.kpi.warn { border-color: #f0c98a; background: #fffaf0; } .kpi.neg .v { color: var(--neg); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin: 0 0 10px; }
.facts dt { font-size: 12px; color: var(--muted); } .facts dd { margin: 0; font-weight: 600; }
.steps { padding-left: 0; list-style: none; display: flex; gap: 8px; flex-wrap: wrap; }
.steps li { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
.steps li.ok { border-color: #b7dcc6; } .steps li.ok a { color: var(--ok); } .steps li.todo a { color: var(--warn); }
.steps a { font-weight: 600; text-decoration: none; }

.alerts { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 4px; }
.alerts li { padding: 6px 10px; border-radius: 5px; font-size: 13px; }
.alerts li.error { background: var(--negbg); } .alerts li.warning { background: var(--warnbg); } .alerts li.info { background: #edf3f8; }
.alerts.ok { color: var(--ok); background: var(--okbg); padding: 6px 10px; border-radius: 5px; }
.calcbox { border-radius: 6px; padding: 10px 12px; margin: 10px 0; border: 1px solid var(--line); background: #fafbfb; display: flex; flex-direction: column; gap: 4px; }
.calcbox.good { border-color: #b7dcc6; background: #f3faf6; } .calcbox.bad { border-color: #efb7b1; background: #fdf3f2; }
.calcbox .formula { font-size: 14px; }

.split { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
.split .list { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; max-height: 75vh; overflow: auto; position: sticky; top: 64px; }
.split .list a { padding: 8px 10px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: 13px; }
.split .list a.on { background: #e5eef6; }
.split .detail h2 { margin-top: 0; }

.overlay { position: fixed; inset: 0; background: rgba(15, 25, 32, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal { background: var(--panel); border-radius: 10px; width: 640px; max-width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { width: 980px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; }
.modal .body { padding: 14px 16px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal footer > span { margin-right: auto; }
.toast { position: fixed; bottom: 20px; right: 20px; padding: 10px 16px; border-radius: 6px; color: #fff; z-index: 100; max-width: 520px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.toast.ok { background: var(--ok); } .toast.err { background: var(--neg); }

.login { display: flex; justify-content: center; padding-top: 12vh; }
.login .card { width: 360px; max-width: calc(100vw - 32px); display: flex; flex-direction: column; gap: 6px; }
.login h1 { margin: 0; }

.gantt { display: grid; grid-template-columns: 220px minmax(0, 1fr); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-top: 14px; font-size: 12px; }
.g-scroll { overflow-x: auto; }
.g-row, .g-head, .g-head2 { height: 30px; border-bottom: 1px solid var(--line); position: relative; display: flex; }
.g-head, .g-head2 { background: #fafbfb; }
.g-head { height: 34px; }
.g-head > div, .g-head2 > div { flex: none; text-align: center; border-right: 1px solid var(--line); color: var(--muted); line-height: 1.2; padding-top: 3px; }
.g-head > div { width: var(--w); } .g-head > div.off { background: #eceef0; }
.g-head2 > div { text-align: left; padding-left: 6px; line-height: 26px; }
.g-names .g-row.name { padding: 0 8px; line-height: 30px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.g-off { position: absolute; top: 0; bottom: 0; background: #f2f3f5; }
.g-bar { position: absolute; top: 6px; height: 18px; background: var(--accent); color: #fff; border-radius: 4px; font-size: 11px; line-height: 18px; text-align: center; overflow: hidden; }
.g-bar.err { background: var(--neg); }
.g-ms { position: absolute; top: 8px; width: 14px; height: 14px; background: #d08a00; transform: rotate(45deg); }

.chart { margin: 8px 0 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.chart svg { width: 100%; height: 160px; display: block; }
.chart rect.pos { fill: #5b8fb5; } .chart rect.neg { fill: #c9584e; }
.chart .axis { stroke: #333; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .cushion { stroke: #d08a00; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.chart figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
details { margin-top: 16px; } summary { cursor: pointer; font-weight: 600; }
.quote h2 { margin-top: 4px; }

@media (max-width: 900px) {
  main { padding: 12px 16px 40px; }
  .cols, .split { grid-template-columns: minmax(0, 1fr); }
  .split .list { position: static; max-height: 240px; }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { gap: 10px; padding: 0 12px; } .brand span, .me > span:first-child { display: none; }
  .gantt { grid-template-columns: 130px minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .kpi .v { font-size: 18px; }
}
@media print {
  .topbar, .tabs, .toolbar, button, .btn { display: none !important; }
  body { background: #fff; }
}

.table td.name { min-width: 180px; }
.table.cash td:first-child { white-space: nowrap; }
.modal .body { overflow-x: auto; }
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; row-gap: 4px; }
  .me { margin-left: 0; } .me .badge { display: none; }
}
.chart rect.min { fill: #7a1f17; }
.numwrap { flex-wrap: wrap; }
input.num.invalid { border-color: var(--neg); background: var(--negbg); }
.numerr { flex-basis: 100%; color: var(--neg); font-size: 11px; max-width: 260px; }
.integrity { border-radius: 6px; padding: 8px 12px; margin: 8px 0; border: 1px solid var(--line); }
.integrity.completo { background: var(--okbg); border-color: #b7dcc6; }
.integrity.incompleto { background: var(--warnbg); border-color: #f0d6a8; }
.integrity.invalido { background: var(--negbg); border-color: #efb7b1; }
.integrity ul { margin: 4px 0; padding-left: 18px; font-size: 13px; }
.cfstatus .badge { margin-top: 3px; }
.difflist { margin: 2px 0; padding-left: 14px; }
.difflist li.add { color: var(--ok); } .difflist li.del { color: var(--neg); }
.lose { margin-top: 6px; background: var(--warnbg); padding: 4px 6px; border-radius: 4px; }
.banner.source-congelado { background: var(--okbg); border-color: #b7dcc6; }
.banner.source-recalculado { background: var(--negbg); border-color: #efb7b1; }

/* Expediente, adjuntos y proveedores (fase 1 de la ampliación) */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 6px; }
@media (max-width: 800px) { .grid4 { grid-template-columns: 1fr 1fr; } }
fieldset.recinto { border: 1px solid var(--line); border-radius: 6px; margin: 0 0 12px; padding: 8px 12px 12px; }
fieldset.recinto legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
.savebar { position: sticky; bottom: 0; display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); box-shadow: 0 -2px 6px rgba(0,0,0,.05); z-index: 5; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px; border: 2px dashed var(--line); border-radius: 8px; background: var(--soft); cursor: pointer; text-align: center; }
.dropzone:hover { border-color: var(--accent); }
.dropzone input[type=file] { display: none; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.thumbs img { width: 120px; height: 90px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); background: var(--panel); }
ul.links { list-style: none; padding: 0; margin: 0 0 8px; } ul.links li { padding: 3px 0; }
input.search { width: 100%; max-width: 420px; margin: 0 0 12px; }
tr.muted td { color: var(--muted); }

/* Abastecimiento (fase 2 de la ampliación) */
.card.soft { background: var(--soft); box-shadow: none; }
.rfq { border-top: 1px solid var(--line); padding: 10px 0; }
.rfq:first-of-type { border-top: 0; }
tr.chosen td { background: var(--okbg); }
input.short { width: 70px; }
table.alts td { vertical-align: top; }

/* Propuesta comercial (fase 4 de la ampliación) */
a.btn.disabled { opacity: .45; pointer-events: none; }
.work { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; border-top: 1px solid var(--line); }
.thumbs .pick { display: flex; flex-direction: column; gap: 4px; width: 130px; }
.thumbs .pick label { display: flex; gap: 4px; align-items: flex-start; }

/* Asistente (modo simulado) */
.banner.simulado { background: #fff1c2; border-color: #e3c25a; margin-bottom: 10px; }
.asistente .card { margin-bottom: 12px; }
.asistente tr.sel td { background: #f3f7fb; }
.asistente details summary { cursor: pointer; }
.card.warnbox { border-color: #f0d6a8; background: #fffaf0; }
/* Navegación única: el historial va al final de la barra; el presupuesto en edición, siempre visible */
.presupuesto-actual .historial.on { font-weight: 600; }
.recorrido-etapas li a, .recorrido-etapas li > span, .recorrido .tablero { padding: 5px 7px; gap: 5px; font-size: 12.5px; }
.recorrido-etapas ol { gap: 3px; }
.presupuesto-actual { margin: 0 0 4px; }
.presupuesto-otro { margin: 6px 0; }
.caminos .disp { font-size: 12px; }
