/* ───────────────────────────────────────────────────────────
   Funeraria Corazón de Cristo — sistema de contratos
   Diseño sobrio cálido. Tokens + base.
   ─────────────────────────────────────────────────────────── */

:root {
  /* Tipografía */
  --font-display: "Spectral", "Newsreader", Georgia, serif;
  --font-sans: "Geist", "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;

  /* Paleta — sobrio cálido (default) */
  --bg: #f4f0e9;
  --surface: #fbf8f2;
  --surface-elev: #ffffff;
  --paper: #fffdf8;
  --ink: #1a1814;
  --ink-soft: #3d3830;
  --ink-muted: #6b6457;
  --ink-faint: #9a9387;
  --line: #e3ddd0;
  --line-strong: #cdc5b3;
  --line-soft: #ece6d8;

  /* Acento — vino sobrio */
  --accent: #5a1f2e;
  --accent-hover: #6e2839;
  --accent-soft: #f3e6e6;
  --accent-ink: #ffffff;

  /* Destructivo */
  --danger: #b91c1c;
  --danger-hover: #991b1b;

  /* Color de trazo de firma */
  --signature-color: #1a3a72;

  /* Estados */
  --status-firmado-bg: #e6efe7;
  --status-firmado-fg: #2d5a3a;
  --status-firmado-dot: #4a8159;
  --status-pendiente-bg: #f5ebd6;
  --status-pendiente-fg: #7a5a14;
  --status-pendiente-dot: #b8893a;
  --status-borrador-bg: #ece6d8;
  --status-borrador-fg: #5c574e;
  --status-borrador-dot: #8c8675;
  --status-vencido-bg: #f1dcd6;
  --status-vencido-fg: #7a2a1f;
  --status-vencido-dot: #a4392a;

  /* Espaciado base */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 14px;

  /* Density */
  --row-h: 48px;
  --field-h: 38px;
}

[data-density="compact"] {
  --row-h: 40px;
  --field-h: 34px;
}
[data-density="comfy"] {
  --row-h: 56px;
  --field-h: 42px;
}

/* Paleta alterna: pizarra sobria (mas frío, corporativo) */
[data-palette="pizarra"] {
  --bg: #f1f3f6;
  --surface: #f8f9fb;
  --surface-elev: #ffffff;
  --paper: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --ink-muted: #64748b;
  --ink-faint: #94a3b8;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --line-soft: #eef1f6;
  --accent: #1e293b;
  --accent-hover: #334155;
  --accent-soft: #e2e8f0;
  --accent-ink: #ffffff;
}

/* Paleta alterna: bosque (sage profundo, más natural) */
[data-palette="bosque"] {
  --bg: #f1efe8;
  --surface: #f7f5ee;
  --surface-elev: #ffffff;
  --paper: #fcfaf3;
  --ink: #1c2018;
  --ink-soft: #3d4337;
  --ink-muted: #6b7064;
  --line: #ddddd0;
  --line-strong: #c5c5b4;
  --line-soft: #ebe9dc;
  --accent: #2f4a3a;
  --accent-hover: #3a5b47;
  --accent-soft: #e2ebde;
}

/* Paleta alterna: tinta (alto contraste, monocromo) */
[data-palette="tinta"] {
  --bg: #ededea;
  --surface: #f5f5f2;
  --surface-elev: #ffffff;
  --paper: #ffffff;
  --ink: #0b0b0a;
  --ink-soft: #2b2b29;
  --ink-muted: #5c5c58;
  --line: #d8d8d3;
  --line-strong: #b8b8b3;
  --line-soft: #e8e8e3;
  --accent: #0b0b0a;
  --accent-hover: #2b2b29;
  --accent-soft: #e8e8e3;
  --accent-ink: #ffffff;
}

/* ─── Base ─── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; color: inherit; }
a { text-decoration: none; }

::selection { background: var(--accent-soft); color: var(--accent); }

/* ─── App shell ─── */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

/* ─── Sidebar ─── */
.sb {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.sb-brand-mark {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  font-style: italic;
  letter-spacing: -.02em;
}
.sb-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.sb-brand-text b { font-family: var(--font-display); font-weight: 500; font-size: 14.5px; letter-spacing: -.005em; }
.sb-brand-text span { font-size: 10.5px; color: var(--ink-muted); letter-spacing: .04em; text-transform: uppercase; }

.sb-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); padding: 0 8px 4px; font-weight: 500; }
.sb-nav { display: flex; flex-direction: column; gap: 1px; }
.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-md);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13.5px;
  border: 0; background: transparent; text-align: left;
  width: 100%;
}
.sb-item:hover { background: var(--line-soft); color: var(--ink); }
.sb-item.is-active {
  background: var(--surface-elev);
  color: var(--ink);
  font-weight: 500;
  box-shadow: 0 0 0 1px var(--line) inset, 0 1px 0 rgba(0,0,0,.02);
}
.sb-item-icon { width: 16px; height: 16px; opacity: .75; flex-shrink: 0; }
.sb-item.is-active .sb-item-icon { opacity: 1; color: var(--accent); }
.sb-item-count { margin-left: auto; font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

.sb-footer {
  margin-top: auto;
  padding: 10px 6px 0;
  border-top: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px;
}
.sb-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--line-strong); color: var(--ink-soft);
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 500;
}
.sb-user-name { font-size: 13px; font-weight: 500; line-height: 1.1; }
.sb-user-role { font-size: 11px; color: var(--ink-muted); }

/* ─── Main ─── */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex; align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-family: var(--font-display); font-size: 22px; font-weight: 500; letter-spacing: -.01em; }
.topbar-meta { display: contents; }
.show-mobile { display: none !important; }
.topbar-crumb { color: var(--ink-muted); font-size: 13px; }
.topbar-crumb a { color: var(--ink-muted); text-decoration: none; }
.topbar-crumb a:hover { color: var(--ink); }
.topbar-spacer { flex: 1; }
.topbar-sep { width: 1px; height: 22px; background: var(--line); flex-shrink: 0; }
.content {
  padding: 28px;
  flex: 1;
  min-width: 0;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0 14px; height: 36px;
  border-radius: var(--r-md);
  font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  white-space: nowrap;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled,
.btn-secondary:disabled,
.btn[disabled] { opacity: 0.4 !important; cursor: not-allowed !important; pointer-events: none !important; }
.btn-secondary {
  background: var(--surface-elev);
  border-color: var(--line);
  color: var(--ink);
}
.btn-secondary:hover { border-color: var(--line-strong); background: var(--surface); }
.btn-ghost { color: var(--ink-soft); }
.btn-ghost:hover { background: var(--line-soft); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 14px; }
.btn-icon { width: 36px; padding: 0; justify-content: center; }
.btn-icon.btn-sm { width: 30px; }

/* ─── Badges (estado) ─── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 7px;
  border-radius: 100px;
  font-size: 11.5px; font-weight: 500;
  line-height: 1.4;
}
.badge::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  opacity: .8;
}
.badge-firmado { background: var(--status-firmado-bg); color: var(--status-firmado-fg); }
.badge-pendiente { background: var(--status-pendiente-bg); color: var(--status-pendiente-fg); }
.badge-borrador { background: var(--status-borrador-bg); color: var(--status-borrador-fg); }
.badge-vencido { background: var(--status-vencido-bg); color: var(--status-vencido-fg); }

/* ─── Inputs ─── */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 11.5px; font-weight: 500; color: var(--ink-muted); letter-spacing: .02em; }
.field-label-req::after { content: " *"; color: var(--accent); }
.field-hint { font-size: 11px; color: var(--ink-faint); }
.input, .select, .textarea {
  height: var(--field-h);
  border: 1px solid var(--line);
  background: var(--surface-elev);
  border-radius: var(--r-md);
  padding: 0 11px;
  font-size: 13.5px;
  color: var(--ink);
  outline: none;
  font-family: inherit;
  width: 100%;
  min-width: 0;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--ink-soft); box-shadow: 0 0 0 3px rgba(0,0,0,.03); }
.input::placeholder { color: var(--ink-faint); }
.textarea { height: auto; padding: 9px 11px; min-height: 76px; resize: vertical; line-height: 1.45; }
.select { appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'><path d='M2.5 4.5l3.5 3.5 3.5-3.5' stroke='%236b6457' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ─── Card / sections ─── */
.card {
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card-hd {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-hd h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -.005em;
}
.card-hd-actions { display: flex; gap: 6px; }
.card-bd { padding: 18px; }
.card-bd-tight { padding: 0; }

/* ─── Tables ─── */
.tbl-wrap { background: var(--surface-elev); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-muted);
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl tbody td {
  padding: 0 14px;
  height: var(--row-h);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--surface); cursor: default; }
.tbl tbody tr.is-active { background: var(--accent-soft); }
.tbl th.num, .tbl td.num { text-align: center; font-variant-numeric: tabular-nums; }
.tbl-folio { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-soft); }
.tbl-name { font-weight: 500; color: var(--ink); }
.tbl-sub { font-size: 12px; color: var(--ink-muted); margin-top: 1px; }
.tbl-stack { display: flex; flex-direction: column; gap: 1px; line-height: 1.3; }

/* ─── Filter bar ─── */
.filterbar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filterbar-search {
  position: relative; flex: 1; min-width: 240px; max-width: 420px;
}
.filterbar-search input {
  width: 100%; height: 36px;
  border: 1px solid var(--line);
  background: var(--surface-elev);
  border-radius: var(--r-md);
  padding: 0 12px 0 34px;
  font-size: 13px;
  outline: none; color: var(--ink);
}
.filterbar-search input:focus { border-color: var(--ink-soft); }
.filterbar-search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 11px; height: 30px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-elev);
  font-size: 12.5px;
  color: var(--ink-soft);
}
.chip:hover { border-color: var(--line-strong); }
.chip.is-active { border-color: var(--ink-soft); color: var(--ink); background: var(--surface); }
.chip-x { color: var(--ink-faint); margin-left: 2px; }
.chip-x:hover { color: var(--ink); }

/* ─── Page header (lista) ─── */
.page-hd {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 22px;
  gap: 18px;
}
.page-hd-title {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -.015em;
  margin: 0 0 4px;
  color: var(--ink);
}
.page-hd-sub { color: var(--ink-muted); font-size: 13.5px; }
.page-hd-actions { display: flex; gap: 8px; }

/* ─── Stat cards ─── */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat {
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px 16px;
}
.stat-label { font-size: 11.5px; color: var(--ink-muted); letter-spacing: .03em; text-transform: uppercase; font-weight: 500; }
.stat-value { font-family: var(--font-display); font-size: 28px; font-weight: 500; letter-spacing: -.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-delta { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; }
.stat-delta b { color: var(--status-firmado-fg); font-weight: 500; }

/* ─── Detail layout ─── */
/* Preview page */
.preview-body {
  padding: 32px 24px;
  display: flex;
  justify-content: center;
  background: var(--bg);
  min-height: calc(100vh - 60px);
  overflow-x: auto;
}
.preview-body .paper {
  max-width: 760px;
  width: 100%;
}
@media print {
  .sidebar, .preview-topbar { display: none !important; }
  .preview-body { padding: 0; min-height: unset; }
  .main { margin-left: 0 !important; }
}

.detail {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 0;
  min-height: calc(100vh - 60px);
}
.detail-pdf {
  background: var(--bg);
  padding: 28px;
  display: flex; justify-content: center;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}
.detail-pdf-inner {
  max-width: 640px; width: 100%;
}
.detail-side {
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 24px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}
.detail-side h4 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-muted);
  margin: 22px 0 10px;
}
.detail-side h4:first-child { margin-top: 0; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--ink-muted); }
.kv dd { margin: 0; color: var(--ink); }
.kv dd.num { font-variant-numeric: tabular-nums; }

/* ─── PDF paper preview ─── */
.paper {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 44px 52px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03), 0 12px 32px -16px rgba(0,0,0,.08);
  font-family: var(--font-serif, "Spectral"), Georgia, serif;
  font-size: 11px;
  color: #1a1814;
  line-height: 1.5;
  margin-bottom: 28px;
}
.paper-hd { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1.5px solid #1a1814; padding-bottom: 10px; margin-bottom: 14px; gap: 16px; }
.paper-hd-left { display: flex; gap: 12px; align-items: flex-start; flex: 1; min-width: 0; }
.paper-hd-mark { width: 38px; height: 38px; border-radius: 50%; background: #1a1814; color: #fffdf8; display: grid; place-items: center; font-family: var(--font-display); font-style: italic; font-size: 18px; font-weight: 500; flex-shrink: 0; }
.paper-hd-title { font-family: var(--font-display); font-size: 13px; font-weight: 500; line-height: 1.4; display: flex; flex-direction: column; }
.paper-hd-title b { font-size: 14px; }
.paper-hd-contact { font-size: 10px; color: #6b6457; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.paper-hd-address { font-size: 10px; color: #6b6457; letter-spacing: .04em; text-transform: uppercase; margin-top: 2px; }
.paper-hd-right { text-align: right; flex-shrink: 0; padding-top: 6px; }
.paper-hd-right .folio { font-family: var(--font-display); font-size: 13px; font-weight: 600; letter-spacing: -.005em; white-space: nowrap; }
.paper-hd-right .folio span { font-size: 10px; font-weight: 400; color: #6b6457; letter-spacing: .04em; text-transform: uppercase; display: block; margin-top: 1px; }
.paper-doc-title { font-family: var(--font-display); font-size: 17px; font-weight: 500; text-align: center; margin: 8px 0 18px; letter-spacing: .01em; }
.paper-sec-title { font-family: var(--font-display); font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; margin: 14px 0 6px; border-bottom: .5px solid #cdc5b3; padding-bottom: 3px; }
.paper-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 14px; font-size: 10.5px; }
.paper-grid-2 { grid-template-columns: repeat(2, 1fr); }
.paper-field { display: flex; gap: 4px; align-items: baseline; min-width: 0; }
.paper-field-label { color: #6b6457; font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em; flex-shrink: 0; }
.paper-field-value { color: #1a1814; border-bottom: .5px dotted #cdc5b3; flex: 1; min-width: 0; padding-bottom: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.paper-check { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; padding: 2px 0; }
.paper-check-box { width: 10px; height: 10px; border: .8px solid #1a1814; display: inline-block; position: relative; flex-shrink: 0; }
.paper-check-box.is-on::after { content: "✓"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -52%); font-size: 9px; line-height: 1; }
.paper-checks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 12px; margin-top: 4px; }
.paper-totals { margin-top: 12px; display: grid; grid-template-columns: 1fr 220px; gap: 18px; align-items: flex-start; }
.paper-totals-tbl { width: 100%; font-size: 10.5px; border-top: .8px solid #1a1814; border-bottom: .8px solid #1a1814; }
.paper-totals-tbl div { display: flex; justify-content: space-between; padding: 4px 6px; border-bottom: .5px dotted #cdc5b3; }
.paper-totals-tbl div:last-child { border-bottom: 0; font-weight: 600; }
.paper-totals-tbl div.strong { background: #f4ece6; font-weight: 600; }
.paper-totals-tbl div.strong span:last-child { font-variant-numeric: tabular-nums; }
.paper-signs { margin-top: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.paper-sign { text-align: center; }
.paper-sign-box { height: 70px; border-bottom: 1px solid #1a1814; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; }
.paper-sign-box svg { width: 100%; max-width: 180px; }
.paper-sign-label { font-size: 9.5px; color: #6b6457; margin-top: 4px; text-transform: uppercase; letter-spacing: .06em; }
.paper-sign-name { font-size: 10.5px; margin-top: 2px; }
.paper-fine { font-size: 9.5px; color: #6b6457; line-height: 1.45; margin-top: 14px; text-align: justify; }

/* ─── Form (nuevo contrato) ─── */
.form-shell { max-width: 940px; margin: 0 auto; }
.form-stepper { display: flex; gap: 0; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.form-step {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 18px;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  color: var(--ink-muted);
  cursor: default;
}
.form-step-n {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line-strong);
  display: grid; place-items: center;
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.form-step.is-done .form-step-n { background: var(--status-firmado-dot); border-color: var(--status-firmado-dot); color: white; }
.form-step.is-active { color: var(--ink); }
.form-step.is-active { border-bottom-color: var(--accent); }
.form-step.is-active .form-step-n { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.form-sec {
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  margin-bottom: 16px;
}
.form-sec-hd { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft); }
.form-sec-hd h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500; font-size: 17px;
  letter-spacing: -.005em;
}
.form-sec-hd-num {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--accent);
  font-size: 14px;
}
.form-sec-hd-sub { color: var(--ink-muted); font-size: 12.5px; margin-left: auto; }
.form-fields { display: flex; flex-direction: column; gap: 14px; }
.form-checks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 14px; }
.form-check {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 13px;
  cursor: default;
  user-select: none;
}
.form-check:hover { border-color: var(--line-strong); }
.form-check.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.form-check-box {
  width: 16px; height: 16px; border-radius: 3px;
  border: 1.4px solid var(--line-strong);
  display: grid; place-items: center;
  flex-shrink: 0;
  background: var(--surface-elev);
}
.form-check.is-on .form-check-box {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.form-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

/* ─── Misc ─── */
.divider { height: 1px; background: var(--line-soft); margin: 14px 0; }
.muted { color: var(--ink-muted); }
.file-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-elev); text-decoration: none; color: var(--ink); font-size: 13px; }
.file-link:hover { border-color: var(--line-strong); }
.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: var(--r-lg); font-size: 13px; z-index: 1000; max-width: 90vw; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.25); white-space: pre-wrap; word-break: break-all; }
.alert-ok { background: var(--status-firmado-bg); color: var(--status-firmado-fg); border-radius: var(--r-md); padding: 10px 14px; font-size: 13px; }
.field-label-note { font-size: 10px; color: var(--ink-faint); font-weight: 400; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.amount { font-variant-numeric: tabular-nums; }

/* ─── Activity / timeline ─── */
.activity { display: flex; flex-direction: column; gap: 0; position: relative; }
.activity-item { display: flex; gap: 12px; padding: 6px 0; position: relative; }
.activity-item::before {
  content: ""; position: absolute; left: 7px; top: 18px; bottom: -6px;
  width: 1px; background: var(--line);
}
.activity-item:last-child::before { display: none; }
.activity-dot {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  flex-shrink: 0;
  margin-top: 4px;
  position: relative;
  z-index: 1;
}
.activity-dot.is-accent { border-color: var(--accent); background: var(--accent); }
.activity-dot.is-ok { border-color: var(--status-firmado-dot); background: var(--status-firmado-dot); }
.activity-body { font-size: 12.5px; padding-bottom: 6px; }
.activity-body b { font-weight: 500; }
.activity-time { font-size: 11px; color: var(--ink-muted); margin-top: 1px; }

/* ─── Signature canvas placeholder ─── */
.status-banner {
  padding: 10px 24px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.status-banner-pendiente {
  background: var(--status-pendiente-bg);
  color: var(--status-pendiente-fg);
}

.sig-canvas {
  height: 180px;
  background: var(--paper);
  border: 1.4px dashed var(--line-strong);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
.sig-canvas svg { width: 100%; height: 100%; }
.sig-canvas-line { position: absolute; left: 24px; right: 24px; bottom: 38px; height: 1px; background: var(--line-strong); }
.sig-canvas-label { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); white-space: nowrap; }

/* ─── Public signing page ─── */
.pubpage {
  min-height: 100%;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.pubpage-hd {
  padding: 20px 22px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.pubpage-hd-mark {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-family: var(--font-display); font-style: italic; font-size: 18px;
}
.pubpage-hd-text b { display: block; font-family: var(--font-display); font-size: 14.5px; line-height: 1.1; }
.pubpage-hd-text span { font-size: 11px; color: var(--ink-muted); letter-spacing: .04em; text-transform: uppercase; }
.pubpage-bd { padding: 20px 22px 24px; flex: 1; }
.pubpage-title { font-family: var(--font-display); font-size: 22px; font-weight: 500; letter-spacing: -.005em; line-height: 1.2; margin: 0 0 4px; }
.pubpage-sub { color: var(--ink-muted); font-size: 13.5px; margin-bottom: 18px; }
.pubpage-summary {
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.pubpage-summary .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.pubpage-summary .row + .row { border-top: 1px solid var(--line-soft); }
.pubpage-summary .row dt { color: var(--ink-muted); }
.pubpage-summary .row dd { margin: 0; color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.pubpage-pdf-btn {
  width: 100%;
  height: 44px;
  border-radius: var(--r-md);
  background: var(--surface-elev);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-bottom: 18px;
}
.pubpage-sigblock {
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 18px;
}
.pubpage-sigblock h5 { margin: 0 0 4px; font-family: var(--font-display); font-size: 14.5px; font-weight: 500; }
.pubpage-sigblock p { margin: 0 0 12px; font-size: 12.5px; color: var(--ink-muted); }
.pubpage-fine { font-size: 13px; color: var(--ink-muted); line-height: 1.5; margin-bottom: 16px; }
.pubpage-cta {
  width: 100%; height: 52px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--r-md);
  border: 0;
  font-size: 14.5px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
}
.pubpage-cta.is-disabled { background: var(--line-strong); color: var(--ink-muted); cursor: not-allowed; }

/* Empty state */
.empty { padding: 42px 20px; text-align: center; color: var(--ink-muted); font-size: 13px; }

/* Pagination */
.pagi { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--surface); font-size: 12.5px; color: var(--ink-muted); }
.pagi-nav { display: flex; gap: 4px; }
.pagi-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 28px; min-width: 28px; padding: 0 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-elev);
  font-size: 12px; color: var(--ink-soft);
  text-decoration: none; line-height: 1;
}
.pagi-btn.is-active { background: var(--ink); color: white; border-color: var(--ink); }
.pagi-btn:hover:not(.is-active) { border-color: var(--line-strong); }

/* ─── Mobile brand (visible only on small screens) ─── */
.mobile-brand {
  display: none;
}

/* ─── Responsive: mobile breakpoint ─── */
@media (max-width: 768px) {

  /* App shell: single column, sidebar hidden */
  .app {
    grid-template-columns: 1fr;
  }
  .sb {
    display: none;
  }

  /* Show mobile brand bar */
  .mobile-brand {
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -.005em;
    color: var(--ink);
    position: sticky;
    top: 0;
    z-index: 10;
  }

  /* Topbar adjustments */
  .topbar {
    padding: 0 12px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    height: auto;
    min-height: 52px;
  }
  .topbar-crumb {
    font-size: 12px;
  }
  .topbar-meta {
    display: none;
  }
  .hide-mobile { display: none; }
  .show-mobile { display: inline-flex; }

  /* Content padding */
  .content,
  .form-shell {
    padding: 16px 14px;
  }

  /* Field grids: single column */
  .field-row,
  .field-row-3,
  .field-row-4 {
    grid-template-columns: 1fr;
  }

  /* Override field-row span-2 on mobile so they don't overflow */
  .field-row [style*="grid-column:span 2"],
  .field-row [style*="grid-column: span 2"] {
    grid-column: span 1;
  }

  /* Stats: 2x2 grid */
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  /* Form checks: 2 columns */
  .form-checks {
    grid-template-columns: 1fr;
  }

  /* Date/time inputs: prevent native picker from overflowing */
  .field { overflow: hidden; min-width: 0; }
  .input, .select, .textarea { box-sizing: border-box; max-width: 100%; }

  /* Preview page: sin padding lateral para maximizar ancho */
  .preview-body {
    padding: 16px 0;
    align-items: flex-start;
  }

  /* Detail layout: stacked, PDF panel hidden */
  .detail {
    display: flex;
    flex-direction: column;
    gap: 16px;
    grid-template-columns: unset;
    min-height: unset;
  }
  .detail-pdf {
    display: none;
  }
  .detail-side {
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: none;
    overflow-y: visible;
  }

  /* Table: horizontal scroll */
  .tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Signature canvas: taller on mobile for easier signing */
  .sig-canvas {
    min-height: 200px;
  }

  /* Touch targets: 44px minimum (WCAG 2.5.5) */
  .btn { height: 44px; padding: 0 18px; }
  .btn-sm { height: 44px; padding: 0 14px; font-size: 13px; }
  .btn-icon { width: 44px; padding: 0; }
  .btn-icon.btn-sm { width: 44px; height: 44px; }
  .chip { height: 44px; padding: 0 16px; }
  .pagi-btn { height: 44px; min-width: 44px; }
  .topbar { min-height: 60px; height: auto; padding: 8px 12px; gap: 6px; }

  /* iOS: prevent auto-zoom on input focus (requires font-size >= 16px) */
  .input, .select, .textarea {
    font-size: 16px;
    height: 48px;
  }


  /* Paper contract: scrollable on mobile */
  .paper {
    padding: 24px 20px;
    min-width: 520px;
  }
  .paper-hd-contact {
    white-space: normal;
  }
  .paper-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .paper-checks {
    grid-template-columns: repeat(2, 1fr);
  }
  .paper-totals {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .paper-signs {
    gap: 16px;
  }
}

/* ── Transiciones interactivas ───────────────────────────────────────────── */
.btn, .sb-item, .chip, .form-check, .pagi-btn {
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

/* ── Puntos de carga ─────────────────────────────────────────────────────── */
@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.3; }
  40% { transform: translateY(-4px); opacity: 1; }
}
.ldots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  vertical-align: middle;
  margin-left: 3px;
}
.ldots span {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: dotBounce 1.2s ease-in-out infinite;
}
.ldots span:nth-child(2) { animation-delay: 0.2s; }
.ldots span:nth-child(3) { animation-delay: 0.4s; }

/* ── Toast de advertencia ────────────────────────────────────────────────── */
.toast-warn {
  background: var(--accent);
  color: #fff;
}

/* ── Errores de formulario ───────────────────────────────────────────────── */
.form-error-banner {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: var(--r-md);
  color: #991b1b;
  font-size: 13px;
  padding: 12px 16px;
  margin-bottom: 20px;
}
.field-error {
  font-size: 11.5px;
  color: var(--danger, #b91c1c);
  margin-top: 3px;
}
.field-error ul { list-style: none; margin: 0; padding: 0; }

/* ── Tabla — fila completa clickeable ─────────────────────────────────────── */
.tbl-row-link-row,
.tbl-row-link-row td { cursor: pointer; }
.tbl-row-link { color: inherit; }

/* ── Hamburger / sidebar drawer mobile ───────────────────────────────────── */
.sb-close { display: none; }
.sb-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.25);
  z-index: 149;
  cursor: pointer;
}
.sb-overlay.sb-open { display: block; }

@media (max-width: 768px) {
  .sb.sb-open {
    display: flex !important;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 150;
    width: 232px;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
  }
  .sb-close {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    background: none;
    border: none;
    padding: 4px;
    color: var(--ink-muted);
    cursor: pointer;
    border-radius: var(--r-sm);
  }
  .sb-close:hover { background: var(--line-soft); color: var(--ink); }
  .mobile-brand { gap: 10px; }
}
