:root {
  --ink: #14213d;
  --ink-2: #3b4559;
  --muted: #6b7385;
  --line: #e4e7ee;
  --bg: #f5f6f9;
  --card: #ffffff;
  --gold: #b08d57;
  --gold-soft: #f6efe3;
  --blue: #2f6fed;
  --ok: #0f8a5f;
  --ok-soft: #e5f5ee;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --info: #2f6fed;
  --info-soft: #e8effd;
  --danger: #c2311f;
  --danger-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 8px 24px rgba(20, 33, 61, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: .2px; margin: 0 0 .4em; }
h1 { font-size: 28px; } h2 { font-size: 20px; } h3 { font-size: 16px; font-family: var(--sans); }
.muted { color: var(--muted); } .small { font-size: 13px; } .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }
.hidden { display: none !important; }

/* Barra superior */
.topbar { background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 40; }
.topbar .in { max-width: 1200px; margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 24px; }
.brand { font-family: var(--serif); font-size: 19px; color: #fff; letter-spacing: .5px; display: flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand .seal { width: 36px; height: 36px; flex: none; display: block; }
.brand small { color: #c9b48f; font-family: var(--sans); font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #d6dbe6; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.nav a:hover, .nav a.on { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.who { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #c3c9d6; }
.who form { margin: 0; }
.who button { background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.who-link { color: #c3c9d6; }
.who-link:hover { color: #fff; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; }
.role-tag { background: rgba(176,141,87,.25); color: #e8d5b3; border-radius: 99px; padding: 2px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 28px 20px 60px; }
.wrap.narrow { max-width: 760px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .bd { padding: 22px; }
.card + .card { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 900px) { .grid.two, .grid.side { grid-template-columns: 1fr; } .nav { display: none; } .who .email { display: none; } }

/* Botones y formularios */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 10px 16px; border-radius: 10px; font: 600 14px var(--sans); cursor: pointer; transition: .15s; text-decoration: none !important; }
.btn:hover { border-color: #c9cfdb; background: #fafbfc; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #1f2f55; }
.btn.gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn.gold:hover { background: #9c7a47; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.big { padding: 14px 22px; font-size: 15px; border-radius: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 6px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; padding: 11px 12px; border: 1px solid #d5dae4; border-radius: 10px; font: 15px var(--sans); color: var(--ink); background: #fff; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(47,111,237,.25); border-color: var(--blue); }
.field { margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: 13px; color: var(--ink-2); }
.check input { margin-top: 3px; width: 18px; height: 18px; flex: none; }

/* Avisos */
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.alert.ok { background: var(--ok-soft); color: #0b6247; }
.alert.err { background: var(--danger-soft); color: #9a2617; }
.alert.info { background: var(--info-soft); color: #1d4fb8; }

/* Estados */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.enviado { background: var(--warn-soft); color: var(--warn); }
.chip.recibido { background: var(--info-soft); color: var(--info); }
.chip.en_revision { background: #f1eafd; color: #7c3aed; }
.chip.completado { background: var(--ok-soft); color: var(--ok); }
.chip.cancelado { background: #eef0f4; color: var(--muted); }

/* Tablas */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); }
table.list td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover td { background: #fafbfd; }
.table-wrap { overflow-x: auto; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { padding: 7px 12px; border-radius: 99px; background: #fff; border: 1px solid var(--line); color: var(--ink-2); font-size: 13px; }
.tabs a.on { background: var(--ink); color: #fff; border-color: var(--ink); text-decoration: none; }
.tabs a span { opacity: .7; margin-left: 4px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }

/* Línea de tiempo (trazabilidad) */
.steps { display: flex; gap: 0; margin: 4px 0 6px; }
.steps .st { flex: 1; text-align: center; position: relative; font-size: 12px; color: var(--muted); }
.steps .st::before { content: ""; position: absolute; top: 13px; left: -50%; width: 100%; height: 2px; background: var(--line); z-index: 0; }
.steps .st:first-child::before { display: none; }
.steps .dot { width: 28px; height: 28px; border-radius: 50%; background: #fff; border: 2px solid var(--line); display: grid; place-items: center; margin: 0 auto 6px; position: relative; z-index: 1; font-size: 13px; font-weight: 700; }
.steps .st.done { color: var(--ink); } .steps .st.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.steps .st.done::before, .steps .st.now::before { background: var(--ok); }
.steps .st.now { color: var(--ink); font-weight: 600; } .steps .st.now .dot { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 0 4px var(--gold-soft); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.timeline li::after { content: ""; position: absolute; left: 7.5px; top: 16px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline time { display: block; color: var(--muted); font-size: 12px; }

/* Visor PDF */
.viewer { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 22px 0; background: #e9ebf0; border-radius: var(--radius); min-height: 300px;
  user-select: none; -webkit-user-select: none; }
.viewer .loading { padding: 60px; color: var(--muted); }
.pg { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(20,33,61,.15); max-width: calc(100% - 24px); }
.pg canvas { display: block; width: 100%; height: auto; }
.pg .wm { position: absolute; inset: 0; pointer-events: none; overflow: hidden; display: flex; flex-wrap: wrap; align-content: space-around; justify-content: space-around; opacity: .07;
  font-size: 14px; font-weight: 700; color: var(--ink); }
.pg .wm span { display: inline-block; transform: rotate(-24deg); margin: 30px 20px; white-space: nowrap; }
.pg .num { position: absolute; bottom: -20px; right: 0; font-size: 11px; color: var(--muted); }
.box { position: absolute; border: 2px dashed var(--c, var(--blue)); background: color-mix(in srgb, var(--c, var(--blue)) 10%, transparent); border-radius: 6px;
  display: flex; align-items: center; justify-content: center; text-align: center; font-size: 12px; font-weight: 600; color: var(--c, var(--blue)); padding: 2px; overflow: hidden; }
.box.edit { cursor: move; }
.box .x { position: absolute; top: -1px; right: -1px; width: 20px; height: 20px; border: 0; border-radius: 0 4px 0 6px; background: var(--c); color: #fff; cursor: pointer; font-size: 13px; line-height: 1; }
.box .rs { position: absolute; right: -1px; bottom: -1px; width: 14px; height: 14px; background: var(--c); cursor: nwse-resize; border-radius: 4px 0 4px 0; }
.box.sign { cursor: pointer; border-style: solid; animation: pulse 1.8s infinite; background: rgba(176,141,87,.12); border-color: var(--gold); color: #8a6a3b; }
.box.sign:hover { background: rgba(176,141,87,.22); }
.box.sign.focus { box-shadow: 0 0 0 4px rgba(176,141,87,.35); }
.box.signed { animation: none; border: 1px solid var(--gold); background: #fbf8f2; color: var(--ink); cursor: default; flex-direction: column; align-items: flex-start; justify-content: center;
  text-align: left; padding: 4px 8px; font-weight: 400; line-height: 1.25; }
.box.signed b { color: var(--gold); font-size: .9em; } .box.signed strong { font-size: 1em; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(176,141,87,.45); } 50% { box-shadow: 0 0 0 7px rgba(176,141,87,0); } }

/* Barra fija de firma (cliente) */
.signbar { position: sticky; bottom: 0; z-index: 30; background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgba(20,33,61,.08); }
.signbar .in { max-width: 1200px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.signbar .progress { flex: 1; min-width: 180px; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--gold); width: 0; transition: width .3s; }

/* Ventana de e.firma */
.modal { position: fixed; inset: 0; background: rgba(20,33,61,.55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal .dlg { background: #fff; border-radius: 16px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.modal .hd { padding: 20px 22px 0; display: flex; justify-content: space-between; align-items: flex-start; }
.modal .hd button { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal .bd { padding: 16px 22px 22px; }
.drop { border: 1.5px dashed #c9cfdb; border-radius: 12px; padding: 14px; display: flex; align-items: center; gap: 12px; cursor: pointer; transition: .15s; margin-bottom: 12px; }
.drop:hover, .drop.over { border-color: var(--gold); background: var(--gold-soft); }
.drop.ready { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }
.drop .ic { width: 38px; height: 38px; border-radius: 10px; background: var(--gold-soft); color: var(--gold); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.drop.ready .ic { background: var(--ok); color: #fff; }
.drop b { display: block; font-size: 14px; } .drop span { font-size: 12px; color: var(--muted); }
.drop input { display: none; }
.pw { position: relative; } .pw button { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.certinfo { background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.lock { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 12px; }

/* Login */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .art { position: relative; color: #fff; padding: 72px 80px 64px; display: flex; flex-direction: column; justify-content: space-between; gap: 48px;
  background: linear-gradient(rgba(18,30,54,.95), rgba(18,30,54,.95)), url(/static/img/audamex-sello.png) right -160px bottom -160px / 600px no-repeat, #121e36; }
/* Marco doble, como el de un certificado */
.auth .art::before, .auth .art::after { content: ""; position: absolute; pointer-events: none; }
.auth .art::before { inset: 24px; border: 1px solid rgba(176,141,87,.38); }
.auth .art::after { inset: 30px; border: 1px solid rgba(176,141,87,.14); }
.art-top { display: flex; align-items: center; justify-content: center; gap: 20px; }
.art-seal { width: 84px; height: 84px; display: block; }
.art-main { max-width: 640px; }
.auth .art .firm { font-family: var(--serif); font-weight: 400; font-size: clamp(40px, 4.1vw, 60px); line-height: 1.06; letter-spacing: -.3px; color: #f3eee4; margin: 0; }
.auth .art .firm span { font-style: italic; font-size: .6em; letter-spacing: 1px; color: #c9a86a; }
.art-main .rule { width: 88px; height: 4px; border-top: 1px solid var(--gold); border-bottom: 1px solid var(--gold); margin: 34px 0 30px; }
.art-main .lead { color: #b8bfcd; font-size: 16px; line-height: 1.7; max-width: 440px; margin: 0; }
.art-foot { margin: 0; font-size: 11px; letter-spacing: 1.6px; text-transform: uppercase; color: #8790a3; }
.auth .form { display: grid; place-items: center; padding: 32px 20px; background: #faf8f4; }
.auth .form h2 { font-size: 26px; font-weight: 500; }
.form-seal { display: none; width: 64px; height: 64px; margin-bottom: 12px; }
.form-firm { display: none; margin: 0 0 28px; font-family: var(--serif); font-size: 15px; letter-spacing: .3px; color: var(--ink-2); }
.auth .form .in { width: 100%; max-width: 380px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 22px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.ms-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 11px; border: 1px solid #c9cfdb; border-radius: 10px; background: #fff; color: #333; font: 600 14px var(--sans); }
.ms-btn:hover { background: #f8f8f8; text-decoration: none; }
.ms-logo { display: grid; grid-template-columns: 9px 9px; gap: 2px; } .ms-logo i { width: 9px; height: 9px; display: block; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth .art { display: none; } .form-seal, .form-firm { display: block; } }

/* Colocación de campos (nuevo documento) */
.signer-list { display: flex; flex-direction: column; gap: 8px; }
.signer { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.signer.active { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 20%, transparent); }
.signer .sw { width: 14px; height: 14px; border-radius: 4px; background: var(--c); flex: none; }
.signer .info { flex: 1; min-width: 0; } .signer .info b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signer input { padding: 6px 8px; font-size: 12px; margin-top: 4px; }
.signer .cnt { font-size: 12px; color: var(--muted); white-space: nowrap; }
.placing .pg { cursor: crosshair; }
.step-n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--gold); color: #fff; font-size: 13px; font-weight: 700; margin-right: 6px; }
.dropzone { border: 2px dashed #c9cfdb; border-radius: 12px; padding: 30px; text-align: center; cursor: pointer; color: var(--muted); }
.dropzone:hover, .dropzone.over { border-color: var(--gold); background: var(--gold-soft); }
.sticky { position: sticky; top: 80px; }
