:root {
  --bg: #f6f7fb; --card: #fff; --text: #1b2232; --muted: #7a8296; --line: #e8eaf1;
  --accent: #041f5a; --accent-soft: #e8eefb;
  --ok: #17a05d;   --ok-soft: #e3f6ec;
  --warn: #0d05eb; --warn-soft: #d6c094;
  --bad: #e0413a;  --bad-soft: #fde7e6;
  --violet: #7b5cf0; --violet-soft: #efebfe;
  --gray-soft: #eef0f5;
  --accent-ink: #fff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .04), 0 4px 16px rgba(20, 30, 60, .06);
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
h2 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 10px; }
a { color: var(--accent); }

/* ---------- Barra superior ---------- */
header { background: rgba(255,255,255,.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  padding: 10px 24px; display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
header h1 { font-size: 17px; margin: 0; flex: 1; line-height: 0; }
header .logo { height: 38px; width: auto; }
header #who { margin-right: 8px; font-size: 13px; }
@media (max-width: 700px) { header #who { display: none; } }

main { max-width: 1200px; margin: 0 auto; padding: 28px 16px 60px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, monospace; font-size: 11px; word-break: break-all; }
.error { color: var(--bad); }
.view { animation: fadeUp .25s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Botones ---------- */
button, .btn { font: inherit; font-weight: 550; border: 1px solid transparent; background: var(--gray-soft); color: var(--text);
  padding: 8px 16px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease, filter .15s ease; }
button:hover, .btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(20,30,60,.10); }
button:active, .btn:active { transform: translateY(0); box-shadow: none; }
button:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }
button.primary, .btn.primary { background: var(--accent); color: #fff; }
button.success, .btn.success { background: var(--ok); color: #fff; }
button.warn, .btn.warn { background: var(--warn); color: #fff; }
button.danger, .btn.danger { background: var(--bad-soft); color: var(--bad); }
button.danger:hover { background: var(--bad); color: #fff; }
button.violet, .btn.violet { background: var(--violet-soft); color: var(--violet); }
button.ghost, .btn.ghost { background: transparent; color: var(--muted); }
button.ghost:hover, .btn.ghost:hover { background: var(--gray-soft); color: var(--text); box-shadow: none; }
button.soft, .btn.soft { background: var(--accent-soft); color: var(--accent); }
button.sm, .btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 8px; }
button.icon { padding: 6px 9px; }

/* ---------- Formularios ---------- */
input, select { font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; width: 100%; background: #fff;
  transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
label input { margin-top: 4px; }

/* ---------- Estados ---------- */
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: var(--gray-soft); color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.Completed, .badge.Signed { background: var(--ok-soft); color: var(--ok); }
.badge.Sent, .badge.Viewed, .badge.Notified { background: var(--warn-soft); color: var(--warn); }
.badge.Declined, .badge.Canceled { background: var(--bad-soft); color: var(--bad); }
.badge.Draft { background: var(--violet-soft); color: var(--violet); }

/* ---------- Tarjetas de resumen ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { border-radius: var(--radius); padding: 16px 18px; cursor: pointer; border: 2px solid transparent; transition: transform .15s, box-shadow .15s, border-color .15s;
  display: flex; flex-direction: column; gap: 2px; text-align: left; font: inherit; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat.on { border-color: currentColor; }
.stat .n { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: 13px; font-weight: 600; opacity: .85; }
.stat.all { background: var(--accent-soft); color: var(--accent); }
.stat.Sent { background: var(--blue-soft); color: var(--blue); }
.stat.Completed { background: var(--ok-soft); color: var(--ok); }
.stat.Draft { background: var(--violet-soft); color: var(--violet); }
.stat.Declined { background: var(--bad-soft); color: var(--bad); }

/* ---------- Subir PDF ---------- */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); background: var(--card); padding: 22px; display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap; margin-bottom: 18px; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .ico { width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 22px; flex: none; }
.drop .txt { flex: 1; min-width: 180px; }
.drop .txt b { display: block; font-size: 15px; }
.drop input[name=title] { flex: 1; min-width: 180px; }

/* ---------- Lista de documentos ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; position: relative; }
.toolbar .search input { padding-left: 36px; }
.toolbar .search::before { content: "🔍"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: .5; }
.docs { display: flex; flex-direction: column; gap: 8px; }
.doc { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; display: grid;
  grid-template-columns: 40px 1fr auto auto; gap: 14px; align-items: center; cursor: pointer; transition: transform .12s, box-shadow .15s, border-color .15s; }
.doc:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: transparent; }
.doc .ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; background: var(--gray-soft); }
.doc .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc .s { font-size: 12px; color: var(--muted); }
.doc .prog { width: 110px; }
.doc .bar { height: 6px; border-radius: 3px; background: var(--gray-soft); overflow: hidden; margin-top: 4px; }
.doc .bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .4s; }
@media (max-width: 640px) { .doc { grid-template-columns: 40px 1fr; } .doc .prog, .doc .badge { grid-column: 2; } }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- Tablas ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex: none; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .editor { grid-template-columns: 1fr; } }
.side { position: sticky; top: 74px; max-height: calc(100vh - 90px); overflow: auto; }
.signer { border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 12px; padding: 10px; margin-bottom: 10px; cursor: pointer; transition: background .15s, box-shadow .15s; }
.signer:hover { box-shadow: var(--shadow); }
.signer.active { background: color-mix(in srgb, var(--c) 7%, #fff); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 35%, transparent); }
.signer input { margin-bottom: 6px; }
.tabs { background: var(--gray-soft); padding: 4px; border-radius: 12px; display: flex; gap: 4px; }
.tabs button { flex: 1; background: transparent; justify-content: center; }
.tabs button:hover { box-shadow: none; transform: none; background: rgba(255,255,255,.6); }
.tabs button.on { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(20,30,60,.12); }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.steps li { counter-increment: s; display: flex; gap: 8px; margin-bottom: 6px; }
.steps li::before { content: counter(s); width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 11px; display: grid; place-items: center; flex: none; }

.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page { position: relative; max-width: 100%; border-radius: 6px; box-shadow: 0 2px 14px rgba(20,30,60,.12); background: #fff; overflow: hidden; }
.page canvas { display: block; width: 100%; height: auto; }
.page.placing { cursor: crosshair; }
.field { position: absolute; border: 2px dashed var(--c, var(--accent)); border-radius: 6px; background: color-mix(in srgb, var(--c, var(--accent)) 14%, transparent);
  font-size: 11px; font-weight: 600; color: color-mix(in srgb, var(--c, var(--accent)) 80%, #000); padding: 2px 6px; overflow: hidden; cursor: move; user-select: none; touch-action: none;
  transition: box-shadow .15s; animation: pop .18s ease; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
.field:hover { box-shadow: 0 2px 10px rgba(20,30,60,.2); }
.field .x { position: absolute; top: 1px; right: 4px; cursor: pointer; font-weight: bold; opacity: .6; }
.field .x:hover { opacity: 1; color: var(--bad); }
.field.mine { cursor: pointer; border-style: solid; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 40%, transparent); } 50% { box-shadow: 0 0 0 6px transparent; } }

/* ---------- Bitácora ---------- */
.timeline { position: relative; padding-left: 18px; max-height: 320px; overflow: auto; font-size: 12px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.timeline .ev { position: relative; padding: 0 0 12px; }
.timeline .ev::before { content: ""; position: absolute; left: -17px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; }

/* ---------- Ventanas y avisos ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,20,35,.45); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; animation: fadeUp .2s ease; }
.modal .card { width: 560px; max-width: 100%; }
.pad { border: 2px dashed var(--line); border-radius: 12px; width: 100%; height: 180px; touch-action: none; background: #fff; }

#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 20; }
.toast { background: var(--text); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  display: flex; gap: 10px; align-items: center; animation: fadeUp .2s ease; max-width: 360px; }
.toast.ok { background: var(--ok); } .toast.bad { background: var(--bad); }

/* ---------- Login ---------- */
.login { max-width: 380px; margin: 8vh auto; text-align: center; }
.login form { text-align: left; }
.login button { width: 100%; justify-content: center; padding: 11px; }
