/* Identidad JPAZ: azul marino, naranja distintivo y grises; Barlow para títulos y menús */
@font-face { font-family: "Barlow"; src: url("fonts/Barlow-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("fonts/BarlowCondensed-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --navy: #1f2a44; --navy-2: #2b3a5c; --navy-3: #3a4c74; --orange: #f7931e; --orange-d: #b35f00;
  --gray: #8c8c8c; --gray-soft: #bdbdbd; --green: #26703a; --red: #b42318;
  --bg: #f3f4f6; --card: #ffffff; --line: #dfe2e7; --text: #1b2130; --muted: #5d6576; --soft: #eef0f4;
  --ok-bg: #e5f3e8; --warn-bg: #fff1df; --bad-bg: #fde8e8;
  --titulo: "Barlow Condensed", "Arial Narrow", "Segoe UI", sans-serif;
  --ui: "Barlow", "Segoe UI", system-ui, sans-serif;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; font-size: 15px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--navy-2); text-decoration: none; }
a:hover { color: var(--orange-d); text-decoration: underline; }

/* ---------- barra lateral por bloques */
.layout { display: grid; grid-template-columns: 262px 1fr; min-height: 100vh; }
nav.side { background: var(--navy); color: #fff; padding: 18px 0 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; font-family: var(--ui); }
nav.side .brand { padding: 0 20px 14px; }
nav.side .brand img { width: 200px; display: block; margin-left: -6px; }
nav.side .brand .app { font-family: var(--titulo); font-size: 30px; letter-spacing: .08em; color: #fff; margin-top: 4px; line-height: 1; }
nav.side .brand .app::after { content: ""; display: block; width: 38px; height: 3px; background: var(--orange); margin-top: 5px; border-radius: 2px; }
nav.side .brand .emp { font-size: 12.5px; color: #c9cfdb; margin-top: 6px; line-height: 1.3; }
nav.side .brand .emp b { color: var(--orange); font-weight: 500; }
.bloque { margin: 5px 12px; padding: 5px 0 6px; border-radius: 10px; background: rgba(255,255,255,.04); }
.bloque h4 { margin: 4px 14px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--gray-soft); font-weight: 500;
  display: flex; align-items: center; gap: 7px; }
.bloque h4 svg { width: 15px; height: 15px; stroke: var(--orange); }
nav.side a.nv { display: flex; align-items: center; gap: 10px; margin: 1px 6px; padding: 7px 12px; color: #e9edf5; font-size: 16px;
  border-radius: 8px; border-left: 4px solid transparent; transition: background .15s, transform .15s, border-color .15s; }
nav.side a.nv:hover { background: rgba(255,255,255,.12); border-left-color: rgba(247,147,30,.7); color: #fff; text-decoration: none; transform: translateX(3px); }
nav.side a.nv.on { background: rgba(247,147,30,.18); border-left-color: var(--orange); color: #fff; }
nav.side a.nv .ct { margin-left: auto; background: var(--orange); color: var(--navy); font-size: 12px; border-radius: 10px; padding: 0 7px; }
/* catálogos: botones que sobresalen */
.bloque.cat { background: rgba(247,147,30,.08); border: 1px solid rgba(247,147,30,.35); }
.bloque.cat h4 { color: var(--orange); }
.catgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px 8px 2px; }
.catgrid a { display: block; text-align: center; padding: 8px 4px; border-radius: 8px; background: rgba(255,255,255,.08); color: #fff; font-size: 13.5px; line-height: 1.2;
  border: 1px solid rgba(255,255,255,.12); transition: transform .15s, background .15s, border-color .15s; }
.catgrid a:hover { background: var(--orange); color: var(--navy); border-color: var(--orange); transform: scale(1.05); text-decoration: none; }
.catgrid a.on { background: var(--orange); color: var(--navy); }
.quien { margin-top: auto; padding: 12px 20px 0; border-top: 1px solid rgba(255,255,255,.12); font-size: 13.5px; color: #c9cfdb; }
.quien b { color: #fff; font-weight: 500; font-size: 15px; }
.quien a { color: var(--orange); margin-right: 12px; }

main { padding: 26px 32px 70px; min-width: 0; }
h1 { font-family: var(--titulo); font-weight: 700; font-size: 30px; margin: 0 0 4px; color: var(--navy); letter-spacing: .01em; }
.sub { color: var(--muted); margin: 0 0 20px; font-size: 15px; }
.flash { background: #fff6e8; border: 1px solid #f6c27a; border-left: 5px solid var(--orange); padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; margin-bottom: 18px; }
.card h2 { font-family: var(--titulo); font-weight: 700; font-size: 21px; margin: 0 0 14px; color: var(--navy); }
.card h2::after { content: ""; display: block; width: 34px; height: 3px; background: var(--orange); margin-top: 4px; border-radius: 2px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ---------- indicadores de inicio */
.kpi { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--navy); border-radius: 10px; padding: 16px 18px; }
.kpi.acc { border-top-color: var(--orange); }
.kpi .l { font-family: var(--ui); color: #39414f; font-size: 15.5px; letter-spacing: .02em; }
.kpi .v { font-family: var(--titulo); font-size: 34px; font-weight: 700; margin-top: 4px; color: var(--navy); font-variant-numeric: tabular-nums; }
.kpi .n { color: var(--muted); font-size: 14px; margin-top: 4px; }

table { border-collapse: collapse; width: 100%; background: var(--card); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14.5px; }
th { background: var(--soft); font-family: var(--ui); font-weight: 500; font-size: 14px; color: #2c3445; position: sticky; top: 0; z-index: 1; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fff4e6; }
tfoot td, tr.tot td { font-weight: 600; background: var(--soft); }
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; max-height: calc(100vh - 220px); }
.desc { max-width: 440px; color: #344054; }
.muted { color: var(--muted); }
.chip { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 13px; white-space: nowrap; font-family: var(--ui); }
.ok { background: var(--ok-bg); color: var(--green); }
.warn { background: var(--warn-bg); color: var(--orange-d); }
.bad { background: var(--bad-bg); color: var(--red); }
.info { background: #e6ebf5; color: var(--navy-2); }

form.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
label { display: block; font-family: var(--ui); font-size: 14.5px; color: #2c3445; margin-bottom: 4px; letter-spacing: .01em; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #c3c9d3; border-radius: 8px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(247,147,30,.45); border-color: var(--orange); }
input[type=checkbox] { width: 18px; height: 18px; vertical-align: -3px; accent-color: var(--navy); }
textarea { min-height: 64px; }

/* ---------- botones */
.btn { display: inline-block; font-family: var(--ui); font-size: 15.5px; padding: 9px 18px; border-radius: 8px; border: 1px solid var(--navy);
  background: var(--navy); color: #fff; cursor: pointer; transition: transform .12s, box-shadow .12s, background .12s; }
.btn:hover { background: var(--navy-3); text-decoration: none; color: #fff; transform: translateY(-2px); box-shadow: 0 6px 14px rgba(31,42,68,.25); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn.sec { background: #fff; color: var(--navy); }
.btn.sec:hover { background: #fff4e6; border-color: var(--orange); color: var(--navy); }
.btn.acc { background: var(--orange); border-color: var(--orange); color: var(--navy); }
.btn.acc:hover { background: #ffa53d; }
.btn.sm { padding: 6px 12px; font-size: 14px; }
.btn.danger { background: #fff; color: var(--red); border-color: #e4a2a2; }
.btn.danger:hover { background: var(--bad-bg); color: var(--red); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; }
.form-grid .w2 { grid-column: span 2; }
.help { font-size: 13px; color: var(--muted); margin-top: 4px; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- ventanas emergentes */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: none; z-index: 50; }
.modal { position: fixed; top: 3vh; left: 50%; transform: translateX(-50%); width: min(1200px, 96vw); max-height: 94vh; overflow: auto;
  background: #fff; border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.3); z-index: 51; display: none; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: start; position: sticky; top: 0; background: #fff; z-index: 2;
  border-top: 5px solid var(--orange); border-radius: 12px 12px 0 0; }
.modal header h3 { margin: 0; color: var(--navy); font-family: var(--titulo); font-size: 24px; }
.modal .body { padding: 16px 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; position: sticky; bottom: 0; background: #fff; }
.totbox { font-variant-numeric: tabular-nums; text-align: right; font-size: 15.5px; }
.totbox b { font-size: 19px; }
.sug td { font-size: 14px; }
.score { font-size: 12px; color: var(--muted); }
.err { color: var(--red); margin: 6px 0; }
.aviso { background: #fff6e8; border: 1px solid #f6c27a; border-radius: 10px; padding: 12px 16px; margin: 10px 0; }
.aviso.verde { background: #eef7f0; border-color: #9fd0ab; }

/* ---------- tarjetas de categorías (centros de costo) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.tile { background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--navy); border-radius: 12px; padding: 16px 18px; cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s; position: relative; }
.tile:hover { transform: translateY(-4px) scale(1.02); box-shadow: 0 12px 28px rgba(31,42,68,.18); border-left-color: var(--orange); }
.tile .cod { font-family: var(--titulo); font-size: 15px; color: #fff; background: var(--navy); border-radius: 6px; padding: 1px 8px; display: inline-block; }
.tile:hover .cod { background: var(--orange); color: var(--navy); }
.tile .nom { font-family: var(--titulo); font-size: 22px; color: var(--navy); margin: 8px 0 2px; line-height: 1.1; }
.tile .cnt { color: var(--muted); font-size: 14px; }
.tile .nums { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin-top: 12px; font-size: 13.5px; }
.tile .nums span { color: var(--muted); }
.tile .nums b { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.tile .ir { position: absolute; right: 14px; top: 14px; color: var(--gray); font-size: 20px; }
.tile:hover .ir { color: var(--orange); }
.neg { color: var(--red); }
.migas { font-family: var(--ui); font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.migas a { cursor: pointer; }

/* ---------- acceso */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1f2a44 0%, #2b3a5c 60%, #1f2a44 100%); }
.login .caja { background: #fff; border-radius: 14px; padding: 34px 38px 30px; width: min(440px, 92vw); box-shadow: 0 30px 70px rgba(0,0,0,.35); border-top: 6px solid var(--orange); }
.login .caja img { width: 100%; margin-bottom: 18px; }
.login .caja h1 { font-size: 26px; }

@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } nav.side { position: static; height: auto; } .g4, .g3 { grid-template-columns: 1fr 1fr; } }

/* ---------- selector con botón al lado, ayudas de importe, ventana de búsqueda y arrastre */
.selbtn { display: flex; gap: 6px; align-items: center; }
.selbtn select, .selbtn input { flex: 1; min-width: 0; }
.selbtn .btn { flex: none; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.picker { display: none; position: fixed; top: 3vh; right: 1vw; width: 47vw; max-height: 94vh; overflow: auto; background: #fff; z-index: 55;
  border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.picker header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: start; position: sticky; top: 0; background: #fff; z-index: 2;
  border-top: 5px solid var(--navy); border-radius: 12px 12px 0 0; }
.picker header h3 { margin: 0; color: var(--navy); font-family: var(--titulo); font-size: 22px; }
.picker .body { padding: 14px 18px; }
.picker .tiles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
body.picking #modal { left: 1vw; transform: none; width: 51vw; }
#m_editor.soltar, #cccard.soltar { outline: 3px dashed var(--orange); outline-offset: 6px; border-radius: 8px; background: #fffaf2; }
#pk_t tr[draggable=true] { cursor: grab; }
#pk_t tr.ya td { color: var(--muted); background: #f7f8fa; }
th[data-o] { cursor: pointer; user-select: none; }
th[data-o]:hover { color: var(--orange-d); }
th.ord { color: var(--orange-d); text-decoration: underline; }
.migas a { color: var(--navy-2); text-decoration: underline; }

/* barra de totales (documento): total, pagado, por pagar; centros de costo: asignado y por asignar */
.totbar { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 18px; }
.totbar > div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; min-width: 170px; }
.totbar span { display: block; font-family: var(--ui); font-size: 13.5px; color: var(--muted); }
.totbar b { font-family: var(--titulo); font-size: 24px; color: var(--navy); font-variant-numeric: tabular-nums; }
.totbar .ok { border-color: #9fd0ab; background: #eef7f0; } .totbar .ok b { color: var(--green); }
.totbar .pend { border-color: #f6c27a; background: #fff6e8; } .totbar .pend b { color: var(--orange-d); }
.totbar .neg { border-color: #e4a2a2; background: var(--bad-bg); } .totbar .neg b { color: var(--red); }
.totbar.chica { margin: 0; flex-wrap: nowrap; } .totbar.chica > div { padding: 7px 12px; min-width: 0; flex: 1; } .totbar.chica b { font-size: 20px; }

/* ventana lateral de centros de costo en documentos: el formulario se recorre a la izquierda */
body.ccpanel main { margin-right: 47vw; }
body.ccpanel main .grid.g2 { grid-template-columns: 1fr; }
#ccpan_t tr[draggable=true], #pk_t tr[draggable=true] { cursor: grab; }
#ccpan_t tr[draggable=true]:active, #pk_t tr[draggable=true]:active { cursor: grabbing; }
#ccpan_t tr.ya td { color: var(--muted); background: #f7f8fa; }

/* barra fija con Guardar y cerrar / Cancelar (documentos) */
.barra-accion { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(243,244,246,.97); backdrop-filter: blur(4px); margin: -26px -32px 14px; padding: 14px 32px 12px;
  border-bottom: 1px solid var(--line); box-shadow: 0 6px 14px rgba(31,42,68,.06); }
.barra-accion h1 { margin: 0; }
.barra-accion .btn { font-size: 16px; padding: 10px 22px; }
.dosc { align-items: start; }
.dosc > .col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.dosc > .col > .card { margin-bottom: 0; }

/* ventanas que se mueven tomándolas del encabezado; las de búsqueda también cambian de tamaño desde la esquina */
.modal > header, .picker > header { cursor: move; }
.modal > header::before, .picker > header::before { content: "⠿"; color: var(--gray-soft); font-size: 18px; margin-right: -4px; align-self: center; }
.picker { resize: both; min-width: 360px; min-height: 240px; }
body.moviendo, body.moviendo * { user-select: none !important; cursor: move !important; }
#pk_t tr[draggable=true] td, #ccpan_t tr[draggable=true] td { user-select: none; }
/* mientras se arrastra: se resalta dónde soltar */
body.arrastrando #cccard, body.arrastrando #m_editor { outline: 3px dashed var(--orange); outline-offset: 6px; border-radius: 10px; background: #fffaf2; }
body.arrastrando #cccard h2::before { content: "Suelta aquí ⤵  "; color: var(--orange-d); }
