@font-face { font-family: 'Carlito'; src: url('../assets/fonts/Carlito-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Carlito'; src: url('../assets/fonts/Carlito-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }

:root {
  --red: #d90b14;
  --red-d: #b0070f;
  --ink: #1f1f1f;
  --ink-2: #4a4a4a;
  --muted: #767676;
  --line: #d9d9d6;
  --line-2: #ececea;
  --bg: #f4f4f2;
  --card: #ffffff;
  --ok: #1e7d43;
  --ok-bg: #e5f3ea;
  --warn: #9a5b00;
  --warn-bg: #fdf1dc;
  --info: #1d4f91;
  --info-bg: #e6eef9;
  --off: #6b6b6b;
  --off-bg: #ececec;
  --ink-firma: #1b3a8a;
  --r: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
main { max-width: 1180px; margin: 0 auto; padding: 22px 20px 80px; outline: none; }
h1 { font-size: 1.55rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
a { color: var(--info); }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; word-break: break-all; }
[hidden] { display: none !important; }

/* Barra superior */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 56px; background: var(--ink); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand img { filter: brightness(0) invert(1); }
.brand-txt b { font-weight: 700; }
.brand-txt span { color: #bdbdbd; font-weight: 400; margin-left: 2px; }
.topnav { margin-left: auto; display: flex; gap: 4px; overflow-x: auto; }
.topnav a { color: #d6d6d6; text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-size: .95rem; }
.topnav a:hover { background: #2f2f2f; color: #fff; }
.topnav a.on { background: #3a3a3a; color: #fff; box-shadow: inset 0 -2px 0 var(--red); }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #bdbdb8; background: #fafaf9; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-d); border-color: var(--red-d); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--red-d); }
.btn.danger:hover { background: #fdecec; border-color: #f0b9bb; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { min-height: 34px; padding: 0 11px; font-size: .9rem; }
.btn.lg { min-height: 56px; padding: 0 26px; font-size: 1.1rem; border-radius: 10px; }
.btn.xl { min-height: 68px; padding: 0 32px; font-size: 1.25rem; border-radius: 12px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btns.end { justify-content: flex-end; }

/* Tarjetas y estructura */
.card { background: var(--card); border: 1px solid var(--line-2); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 14px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid2, .split { grid-template-columns: 1fr; } }

/* Formularios */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
input[type=text], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--info); outline-offset: 1px; border-color: var(--info); }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.warn-txt { color: var(--warn); font-size: .82rem; margin-top: 4px; }

.checklist { border: 1px solid var(--line); border-radius: 8px; max-height: 300px; overflow: auto; background: #fff; }
.checklist label { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.checklist label:last-child { border-bottom: 0; }
.checklist label:hover { background: #fafaf9; }
.checklist input { width: 18px; height: 18px; accent-color: var(--red); }
.checklist .sub { color: var(--muted); font-size: .85rem; margin-left: auto; }

.conceptos .item { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.conceptos .num { width: 26px; text-align: right; color: var(--muted); font-weight: 600; font-size: .9rem; }
.conceptos input { flex: 1; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .94rem; }
table.t th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.t td { padding: 11px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #fafaf9; }
table.t tr.inactivo td { color: var(--muted); }

/* Chips de estado */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.pendiente { color: var(--info); background: var(--info-bg); }
.chip.parcial { color: var(--warn); background: var(--warn-bg); }
.chip.firmado, .chip.subido { color: var(--ok); background: var(--ok-bg); }
.chip.anulado, .chip.off { color: var(--off); background: var(--off-bg); }
.chip.error { color: var(--red-d); background: #fdecec; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; }
.filters .seg { display: inline-flex; background: #e8e8e5; border-radius: 9px; padding: 3px; }
.filters .seg button { border: 0; background: transparent; padding: 7px 13px; border-radius: 7px; font: inherit; font-size: .92rem; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.filters .seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.filters input[type=search] { max-width: 260px; margin-left: auto; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 1.1rem; margin-bottom: 4px; }

/* Inicio */
.home { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 30px; }
.tile { display: flex; flex-direction: column; gap: 10px; padding: 30px; min-height: 220px; border-radius: 16px; text-decoration: none; color: var(--ink); background: #fff; border: 1px solid var(--line-2); box-shadow: var(--shadow); }
.tile:hover { border-color: var(--line); }
.tile .ic { width: 54px; height: 54px; border-radius: 12px; display: grid; place-items: center; background: var(--ink); color: #fff; }
.tile.main .ic { background: var(--red); }
.tile b { font-size: 1.45rem; }
.tile span { color: var(--muted); }
@media (max-width: 700px) { .home { grid-template-columns: 1fr; } }

/* Lista de firma (tablet) */
.sign-list { display: grid; gap: 12px; }
.sign-item { display: flex; align-items: center; gap: 18px; padding: 20px 22px; border-radius: 14px; background: #fff; border: 1px solid var(--line-2); box-shadow: var(--shadow); text-decoration: none; color: var(--ink); min-height: 92px; }
.sign-item:active { transform: scale(.995); }
.sign-item .who { font-size: 1.25rem; font-weight: 700; }
.sign-item .what { color: var(--ink-2); }
.sign-item .when { margin-left: auto; text-align: right; color: var(--muted); font-size: .95rem; }
.sign-item .go { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--red); color: #fff; flex: none; }

/* Vista de documento en tablet */
.sign-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.sign-side { position: sticky; top: 76px; display: grid; gap: 12px; }
@media (max-width: 1000px) { .sign-layout { grid-template-columns: 1fr; } .sign-side { position: static; } }
.firmante { background: #fff; border: 1px solid var(--line-2); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.firmante .n { font-weight: 700; font-size: 1.1rem; }
.firmante .d { color: var(--muted); font-size: .9rem; margin-bottom: 10px; }
.firmante img { display: block; max-width: 100%; height: 70px; object-fit: contain; margin: 0 auto 6px; }
.firmante.hecho { border-color: #bfe0cb; background: #f6fbf8; }
.firmante .ok { color: var(--ok); font-weight: 600; font-size: .92rem; }

/* Documento renderizado en HTML (vista previa) */
.docv { font-family: 'Carlito', Calibri, var(--font); background: #fff; color: #222; border: 1px solid var(--line); border-radius: 6px; padding: 28px 30px; box-shadow: var(--shadow); font-size: 15px; }
.docv table { width: 100%; border-collapse: collapse; }
.docv table.cont { margin-top: -1px; }
.docv td { border: 1px solid #555; padding: 6px 8px; vertical-align: middle; }
.docv .hd td { padding: 10px 12px; }
.docv .hd img.i { height: 48px; vertical-align: middle; }
.docv .hd img.t { height: 36px; vertical-align: middle; margin-left: 10px; }
.docv .tit { text-align: center; font-weight: 700; font-size: 1.15em; background: #f0f0f0; padding: 9px; text-transform: uppercase; }
.docv .sec { text-align: center; font-weight: 700; background: #f0f0f0; text-transform: uppercase; }
.docv .lab { font-weight: 700; white-space: nowrap; width: 1%; }
.docv .nro { width: 32px; text-align: center; font-weight: 700; }
.docv .up { text-transform: uppercase; }
.docv .legal { margin-top: 18px; line-height: 1.45; }
.docv .legal p { margin: 0 0 4px; }
.docv .legal .li { display: flex; gap: 8px; }
.docv .legal .li.n2 { padding-left: 34px; }
.docv .legal .li.n1 { padding-left: 14px; }
.docv .legal .sp { height: 8px; }
.docv .firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.docv .fbox { border: 1px solid #555; min-height: 130px; padding: 8px 10px; display: flex; flex-direction: column; }
.docv .fbox .l { color: #6b6b6b; font-weight: 700; font-size: .85em; }
.docv .fbox .img { flex: 1; display: grid; place-items: center; min-height: 64px; }
.docv .fbox .img img { max-height: 70px; max-width: 90%; }
.docv .fbox .img .pend { color: #999; font-size: .9em; }
.docv .fbox .nm { border-top: 1px solid #999; text-align: center; padding-top: 4px; font-weight: 700; font-size: .9em; text-transform: uppercase; }
.docv .fbox .dn { text-align: center; color: #6b6b6b; font-size: .82em; }
.docv .fbox.emp .img img { max-height: 92px; }
@media (max-width: 600px) { .docv { padding: 16px; font-size: 14px; } .docv .firmas { grid-template-columns: 1fr; } }

/* Modal */
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(20,20,20,.55); display: grid; place-items: center; padding: 20px; animation: fade .12s ease-out; }
.modal { background: #fff; border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin-bottom: 8px; }
.modal .btns { margin-top: 18px; }
@keyframes fade { from { opacity: 0; } }

/* Pantalla de firma */
.pad-screen { position: fixed; inset: 0; z-index: 60; background: #f4f4f2; display: flex; flex-direction: column; padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); gap: 12px; }
.pad-head { display: flex; align-items: center; gap: 16px; }
.pad-head .who { font-size: 1.4rem; font-weight: 700; }
.pad-head .dni { color: var(--muted); }
.pad-head .btn { margin-left: auto; }
.pad-wrap { position: relative; flex: 1; min-height: 200px; background: #fff; border: 2px dashed #c8c8c4; border-radius: 14px; overflow: hidden; touch-action: none; }
.pad-wrap.activo { border-style: solid; border-color: #9ab0d6; }
.pad-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.pad-guide { position: absolute; left: 6%; right: 6%; bottom: 26%; border-bottom: 2px solid #d4d4d0; pointer-events: none; }
.pad-guide::before { content: '✕'; position: absolute; left: -4px; bottom: 4px; color: #b5b5b0; font-size: 22px; }
.pad-ph { position: absolute; inset: 0; display: grid; place-items: center; color: #b5b5b0; font-size: 1.6rem; pointer-events: none; }
.pad-foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.pad-foot .acepto { display: flex; gap: 12px; align-items: center; font-size: 1.08rem; flex: 1; min-width: 300px; cursor: pointer; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.pad-foot .acepto input { width: 26px; height: 26px; accent-color: var(--red); flex: none; }

/* Superposición de proceso */
.busy { position: fixed; inset: 0; z-index: 70; background: rgba(255,255,255,.92); display: grid; place-items: center; text-align: center; padding: 20px; }
.busy .box { max-width: 460px; }
.busy .big { font-size: 1.5rem; font-weight: 700; margin: 14px 0 6px; }
.spinner { width: 46px; height: 46px; border: 4px solid #e2e2df; border-top-color: var(--red); border-radius: 50%; margin: 0 auto; animation: spin .8s linear infinite; }
.check { width: 72px; height: 72px; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; opacity: 0; transition: .2s; z-index: 90; max-width: calc(100vw - 40px); pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--red-d); }

/* PIN */
.pin-box { max-width: 380px; margin: 40px auto; text-align: center; }
.pin-box input { text-align: center; font-size: 1.6rem; letter-spacing: .4em; min-height: 58px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .93rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--line-2); display: flex; gap: 10px; }
.timeline li span:first-child { color: var(--muted); min-width: 140px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; margin-bottom: 8px; font-size: .95rem; }
.back:hover { color: var(--ink); }

/* Tablet en modo firma: más grande */
body.modo-firma main { max-width: 1280px; }
body.modo-firma .docv { font-size: 16px; }
