:root {
  --primary: #005eb8;
  --primary-dark: #003d7a;
  --primary-mid: #004f9e;
  --primary-light: #1a78cc;
  --primary-soft: #e6f0fa;
  --accent: #0078c8;
  --bg: #e8edf3;
  --surface: #ffffff;
  --text: #1a2736;
  --muted: #64748b;
  --border: #d5dee8;
  --danger: #e11d48;
  --success: #059669;
  --warning: #d97706;
  --shadow: 0 6px 18px rgba(0, 61, 122, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --header-h: 58px;
  --pdf-bar: #323639;
  --pdf-bg: #525659;
  /* Banner: azul navy → azul medio (más oscuro, como Allnexo) */
  --blue-grad: linear-gradient(90deg, #003366 0%, #004a8f 45%, #0066c5 100%);
  --blue-grad-deep: linear-gradient(90deg, #003366 0%, #004a8f 45%, #0066c5 100%);
  /* Cada th: vertical, claro arriba → navy abajo */
  --th-grad: linear-gradient(180deg, #2b7fd0 0%, #1560b0 45%, #0a4a8f 100%);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Login (estilo modal Allnexo) ---------- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background:
    radial-gradient(circle at 12% 20%, rgba(26, 163, 232, .22), transparent 40%),
    radial-gradient(circle at 88% 80%, rgba(11, 116, 222, .18), transparent 42%),
    linear-gradient(160deg, #dce8f6 0%, #e9eef5 45%, #f3f7fb 100%);
}
.login-brand { display: none; }
.login-panel {
  width: 100%;
  display: grid;
  place-items: center;
}
.login-card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 22px 50px rgba(6, 60, 120, .18);
  border: 1px solid rgba(255,255,255,.7);
}
.login-card-head {
  background: var(--blue-grad-deep);
  color: #fff;
  padding: 28px 28px 24px;
  position: relative;
  overflow: hidden;
}
.login-card-head::before,
.login-card-head::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
}
.login-card-head::before { width: 160px; height: 160px; right: -40px; top: -50px; }
.login-card-head::after { width: 100px; height: 100px; left: -20px; bottom: -40px; }
.login-card-head .mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: rgba(255,255,255,.2); display: grid; place-items: center;
  font-weight: 800; margin-bottom: 12px; position: relative; z-index: 1;
}
.login-card-head h2 {
  margin: 0; font-size: 1.45rem; position: relative; z-index: 1;
}
.login-card-head .sub {
  margin: 6px 0 0; opacity: .92; font-size: .88rem;
  letter-spacing: .04em; text-transform: uppercase; font-weight: 600;
  position: relative; z-index: 1;
}
.login-card-body { padding: 26px 28px 28px; }
.login-card .hint {
  text-align: center; color: var(--muted); font-size: .8rem; margin-top: 14px;
}

/* ---------- Full-width top menu ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.top-header {
  position: sticky; top: 0; z-index: 80;
  width: 100%;
  background: var(--blue-grad-deep);
  color: #fff;
  box-shadow: 0 4px 18px rgba(0, 41, 82, 0.35);
  overflow: visible;
}

.top-header-inner {
  width: 100%;
  min-height: var(--header-h);
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: visible;
}

.brand-link {
  display: flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none; font-weight: 800; white-space: nowrap;
}
.brand-link:hover { color: #fff; text-decoration: none; }
.brand-link .mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,.2); display: grid; place-items: center; font-size: .8rem;
}
.brand-link small {
  display: block; font-weight: 500; opacity: .85; font-size: .68rem; line-height: 1.1;
}

.top-nav {
  display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0;
  overflow: visible;
  flex-wrap: wrap;
}
.top-nav a {
  color: rgba(255,255,255,.92); text-decoration: none;
  padding: 8px 12px; border-radius: 999px; font-size: .86rem; font-weight: 650;
  white-space: nowrap;
}
.top-nav a:hover, .top-nav a.active {
  background: rgba(255,255,255,.18); color: #fff; text-decoration: none;
}

.nav-dropdown {
  position: relative;
  flex-shrink: 0;
}
.nav-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 0;
  color: rgba(255,255,255,.92);
  padding: 8px 12px;
  border-radius: 999px;
  font: inherit;
  font-size: .86rem;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.nav-dropdown-btn:hover,
.nav-dropdown.open .nav-dropdown-btn {
  background: rgba(255,255,255,.18);
  color: #fff;
}
.nav-dropdown-caret {
  font-size: .65rem;
  opacity: .85;
}
.nav-dropdown-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  width: 200px;
  min-width: 200px;
  box-sizing: border-box;
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 40, 80, .22);
  border: 1px solid var(--border);
  padding: 8px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-dropdown-panel[hidden] { display: none !important; }
.nav-dropdown-label {
  display: block;
  padding: 8px 12px 4px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.nav-dropdown-label:not(:first-child) {
  margin-top: 6px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.nav-dropdown-panel a {
  color: var(--text) !important;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: .86rem;
  font-weight: 650;
  text-decoration: none;
}
.nav-dropdown-panel a:hover,
.nav-dropdown-panel a.active {
  background: var(--primary-soft) !important;
  color: var(--primary-dark) !important;
}

.user-menu {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}
.user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.28);
  color: #fff;
  border-radius: 999px;
  padding: 5px 12px 5px 14px;
  cursor: pointer;
  font: inherit;
  max-width: 220px;
}
.user-menu-btn:hover,
.user-menu.open .user-menu-btn {
  background: rgba(255,255,255,.2);
}
.user-menu-text {
  text-align: left;
  min-width: 0;
  line-height: 1.15;
}
.user-menu-text strong {
  display: block;
  font-size: .86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-menu-text small {
  display: block;
  font-size: .72rem;
  opacity: .85;
  font-weight: 600;
}
.user-menu-caret {
  font-size: .7rem;
  opacity: .85;
  flex-shrink: 0;
}
.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 210px;
  background: #fff;
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(0, 40, 80, .22);
  border: 1px solid var(--border);
  padding: 12px;
  z-index: 50;
}
.user-menu-panel[hidden] { display: none !important; }
.user-menu-role {
  padding: 6px 8px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.user-menu-role span {
  display: block;
  font-size: .72rem;
  color: var(--muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.user-menu-role strong {
  display: block;
  font-size: .92rem;
  color: var(--primary-dark);
}
.user-menu .btn-logout {
  display: block;
  width: 100%;
  text-align: center;
  color: #fff !important;
  background: var(--danger);
  border: 0;
  padding: 9px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: .82rem;
  text-decoration: none !important;
}
.user-menu .btn-logout:hover {
  filter: brightness(1.05);
  background: #be123c;
}

.nav-toggle {
  display: none; background: rgba(255,255,255,.14); border: 0; color: #fff;
  width: 38px; height: 38px; border-radius: 10px; font-size: 1.15rem; cursor: pointer;
}

.main {
  flex: 1;
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px 18px 48px;
}

/* ---------- Page banner (estilo Allnexo) ---------- */
.page-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 16px 18px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--blue-grad-deep);
  color: #fff;
  box-shadow: 0 8px 20px rgba(0, 41, 82, .28);
}
.page-banner-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.page-banner-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: rgba(255,255,255,.18);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.page-banner-text h1 {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 800;
  letter-spacing: .01em;
}
.page-banner-text p {
  margin: 3px 0 0;
  font-size: .86rem;
  opacity: .92;
}
.page-banner-actions .btn-primary {
  background: #fff;
  color: var(--primary-dark) !important;
  box-shadow: none;
}
.page-banner-actions .btn-primary:hover {
  color: var(--primary-dark) !important;
  filter: none;
  background: #f0f7ff;
}
.page-banner-actions .btn-secondary {
  background: rgba(255,255,255,.16);
  color: #fff !important;
  border-color: rgba(255,255,255,.35);
}
.page-banner-actions .btn-secondary:hover {
  background: rgba(255,255,255,.24);
  color: #fff !important;
}

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 12px; margin-bottom: 14px; width: 100%;
}
.page-head h1 { margin: 0; font-size: 1.45rem; color: var(--primary-dark); }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Dropdown Acciones (filas CRUD) */
.acciones-dd {
  position: relative;
  display: inline-block;
}
.acciones-dd-btn {
  white-space: nowrap;
}
.acciones-dd-caret {
  font-size: .65rem;
  margin-left: 2px;
  opacity: .85;
}
.acciones-dd-panel {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 40, 80, .2);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.acciones-dd-panel[hidden] { display: none !important; }
body > .acciones-dd-panel {
  z-index: 4000;
}
.acciones-dd-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: .84rem;
  font-weight: 650;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none !important;
  box-sizing: border-box;
}
.acciones-dd-item:hover {
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.acciones-dd-item.is-danger {
  color: var(--danger);
}
.acciones-dd-item.is-danger:hover {
  background: #ffe4e6;
  color: #be123c;
}
td .acciones-dd { vertical-align: middle; }

.permisos-grupo {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px 12px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}
.permisos-grupo-title {
  grid-column: 1 / -1;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 2px;
}
.permiso-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: .88rem;
  margin: 0;
  cursor: pointer;
}
.permiso-item input { width: auto; margin: 0; }

/* ---------- Filters ---------- */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  align-items: end;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  width: 100%;
}
.filters.compact {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.filters label {
  margin-bottom: 5px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #475569;
  font-weight: 700;
}

/* ---------- UI atoms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 999px; padding: 9px 16px;
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none !important;
  line-height: 1.2;
}
.btn:hover { text-decoration: none !important; filter: brightness(1.04); }
.btn-primary {
  background: var(--primary);
  color: #fff !important;
  box-shadow: 0 6px 14px rgba(0, 61, 122, .22);
}
.btn-primary:hover,
.btn-primary:focus {
  color: #fff !important;
  background: var(--primary-dark);
}
.btn-secondary {
  background: #fff;
  color: var(--primary-dark) !important;
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  color: var(--primary-dark) !important;
  background: var(--primary-soft);
}
.btn-danger {
  background: #fff;
  color: var(--danger) !important;
  border: 1px solid #fecdd3;
}
.btn-danger:hover { color: var(--danger) !important; background: #fff1f2; }
.btn-ghost { background: transparent; color: var(--primary) !important; border: 1px solid transparent; }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 999px; }

a.btn-primary,
a.btn-secondary,
a.btn-danger,
a.btn-ghost {
  color: inherit;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0;
  width: 100%;
  overflow: hidden;
  margin-bottom: 14px;
}
.card > h2,
.card > strong,
.card > .card-title {
  display: block;
  margin: 0;
  padding: 13px 16px;
  font-size: .95rem;
  color: #fff;
  background: var(--blue-grad-deep);
  font-weight: 700;
}
.card-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--blue-grad-deep);
  color: #fff;
}
.card-toolbar h2 {
  margin: 0;
  font-size: 1.05rem;
  color: #fff;
}
.card-toolbar .btn-primary {
  background: #fff;
  color: var(--primary-dark) !important;
  box-shadow: none;
}
.card-toolbar .btn-secondary {
  background: rgba(255,255,255,.18);
  color: #fff !important;
  border-color: rgba(255,255,255,.35);
}
.card .table-wrap { margin: 0; }
.card > .empty { padding: 36px 16px; }
.card > .form-grid,
.card > form,
.card > .check-grid,
.card > .mini-preview,
.card > .card-pad {
  padding: 16px;
}
.card .form-grid { padding: 16px; }
.card .mini-preview { margin: 0 16px 16px; border-radius: var(--radius-sm); }

.grid-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px;
}
.stat {
  padding: 16px 18px; border-radius: var(--radius); background: #fff;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
}
.stat .label {
  color: var(--muted); font-size: .72rem; margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
}
.stat .value { font-size: 1.65rem; font-weight: 800; color: var(--primary-dark); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; position: relative; }
.form-grid.is-sri-loading { pointer-events: none; }
.form-sri-loader {
  position: absolute;
  inset: 0;
  z-index: 12;
  background: rgba(255, 255, 255, .78);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}
.form-sri-loader[hidden] { display: none !important; }
.form-sri-loader-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 22px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(0, 40, 80, .12);
  text-align: center;
}
.form-sri-loader-box strong { font-size: .95rem; color: var(--primary-dark); }
.form-sri-loader-box span:last-child { color: var(--muted); font-size: .82rem; }
.form-sri-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #d5dee8;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: sriSpin .75s linear infinite;
}
@keyframes sriSpin {
  to { transform: rotate(360deg); }
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }

label {
  display: block; font-size: .72rem; font-weight: 700; margin-bottom: 5px;
  color: #475569; text-transform: uppercase; letter-spacing: .04em;
}
input, select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11,116,222,.14);
}
input[readonly] {
  background: #f1f5f9;
  color: var(--text);
  cursor: default;
}
input[data-valor-minimo][readonly] {
  pointer-events: none;
  background: #e2e8f0;
  color: #64748b;
}
.input-with-addon {
  display: flex;
  align-items: stretch;
}
.input-with-addon input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  flex: 1;
  min-width: 0;
}
.field-addon {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  min-width: 118px;
  background: #eef6ff;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-weight: 700;
  font-size: .78rem;
  color: var(--primary-dark);
  white-space: nowrap;
}
.field-addon.is-empty {
  color: var(--muted);
  background: #f1f5f9;
  font-weight: 600;
}
.field-addon.is-error {
  color: #b91c1c;
  background: #fef2f2;
}
.field-addon.is-warn {
  color: #9a3412;
  background: #fff7ed;
}
.field-hint {
  margin: 6px 0 0;
  font-size: .75rem;
  color: var(--muted);
}
.field-with-btn {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.field-with-btn select,
.field-with-btn .search-select { flex: 1; min-width: 0; }
.search-select {
  position: relative;
  min-width: 0;
}
.search-select-native {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  margin: 0;
}
.search-select-input {
  width: 100%;
}
.search-select-list {
  overflow: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 14px 32px rgba(15, 30, 50, .18);
}
.search-select-option {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: #fff;
  padding: 9px 12px;
  font: inherit;
  cursor: pointer;
  color: var(--text);
}
.search-select-option:hover,
.search-select-option.is-active {
  background: #eef6ff;
  color: var(--primary-dark);
}
.search-select-empty {
  padding: 10px 12px;
  color: var(--muted);
  font-size: .85rem;
}
.field-plus {
  min-width: 42px;
  padding: 0 12px;
  font-size: 1.25rem;
  line-height: 1;
  font-weight: 700;
}
input[type="range"] {
  width: 100%;
  padding: 8px 0;
  accent-color: var(--primary);
}
.descuento-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: .8rem;
  color: var(--muted);
  margin-top: 4px;
}
.compra-financiacion {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
}
.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
.check-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
.cuotas-resumen {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: .88rem;
}
.cuotas-resumen strong:first-child {
  display: block;
  margin-bottom: 8px;
}
.cuotas-resumen p {
  margin: 4px 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
textarea { min-height: 100px; resize: vertical; }

.table-wrap { overflow: auto; width: 100%; max-width: 100%; }
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
}
table.data.table-fit {
  table-layout: auto;
}
table.data .td-plan-name {
  min-width: 140px;
  max-width: 240px;
  white-space: normal;
  word-break: break-word;
}
table.data .td-muted {
  color: #475467;
  white-space: normal;
  max-width: 180px;
}
table.data .td-stack {
  white-space: normal;
  line-height: 1.35;
  min-width: 180px;
}
table.data .td-stack small {
  display: block;
  color: var(--muted);
  font-size: .75rem;
  margin-top: 2px;
}
table.data thead tr.table-filters th {
  background: #f1f5f9;
  vertical-align: middle;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
table.data thead tr.table-filters input,
table.data thead tr.table-filters select {
  width: 100%;
  min-width: 72px;
  max-width: 100%;
  margin: 0;
  padding: 5px 7px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  font: inherit;
  font-size: .78rem;
  font-weight: 500;
  color: #0f172a;
  box-sizing: border-box;
}
table.data thead tr.table-filters input:focus,
table.data thead tr.table-filters select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 102, 197, .15);
}
table.data th.col-acciones,
table.data td.col-acciones {
  position: sticky;
  right: 0;
  z-index: 3;
  white-space: nowrap;
  width: 1%;
  box-shadow: -10px 0 12px -10px rgba(0, 40, 80, .28);
}
table.data thead th.col-acciones {
  z-index: 4;
}
table.data tbody td.col-acciones {
  background: #fff;
}
table.data tbody tr:nth-child(even) td.col-acciones {
  background: #f7fafc;
}
table.data tbody tr:hover td.col-acciones {
  background: #eef5fc;
}
table.data th,
table.data td {
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: .875rem;
}
/* Encabezado Allnexo: degradé VERTICAL en CADA columna */
table.data thead th {
  color: #fff !important;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 700;
  white-space: nowrap;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, .28);
  /* Claro arriba → azul más oscuro abajo (igual en cada th) */
  background: var(--th-grad) !important;
  background-color: #0a4a8f;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22);
  position: sticky;
  top: 0;
  z-index: 2;
}
table.data thead th:last-child {
  border-right: 0;
}
table.data tbody td {
  border-bottom: 1px solid #e6edf5;
  color: #1e293b;
  background: #fff;
}
table.data tbody tr:nth-child(even) td {
  background: #f7fafc;
}
table.data tbody tr:hover td {
  background: #eef5fc;
}
table.data tbody td a:not(.btn) {
  font-weight: 700;
  color: #005eb8;
}
table.data tbody td a:not(.btn):hover {
  color: #003d7a;
}
table.data tbody td a.btn-primary {
  color: #fff !important;
}
table.data tbody td a.btn-secondary {
  color: var(--primary-dark) !important;
}
table.data tbody td a.btn-danger {
  color: var(--danger) !important;
}

.badge {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 999px; font-size: .72rem; font-weight: 700;
}
.badge-ok { background: #d1fae5; color: #047857; }
.badge-warn { background: #fef3c7; color: #b45309; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-mute { background: #e8eef5; color: #475467; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-stack { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.gestion-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.gestion-inline select {
  min-width: 120px;
  max-width: 160px;
  font-size: .82rem;
  padding: 4px 8px;
}
.gestion-inline .btn {
  padding: 4px 10px;
  font-size: .78rem;
  min-height: 0;
}

.alert {
  padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-weight: 600;
}
.alert-error { background: #ffe4e6; color: #be123c; }
.alert-success { background: #d1fae5; color: #047857; }
.alert-info { background: #dbeafe; color: #1d4ed8; }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }

.check-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px;
}
.check-grid label {
  display: flex; gap: 8px; align-items: center; font-weight: 500; margin: 0;
  text-transform: none; letter-spacing: 0; font-size: .88rem; color: var(--text);
}
.check-grid input { width: auto; }

/* ---------- Modals (estilo selector Allnexo) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 30, 50, .52);
  z-index: 100; display: none; align-items: flex-start; justify-content: center;
  padding: 28px 12px; overflow: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(920px, 100%);
  background: #fff; border-radius: 18px;
  box-shadow: 0 28px 60px rgba(0,0,0,.28);
  overflow: hidden;
  animation: modalIn .2s ease;
}
.modal.sm { width: min(520px, 100%); }
.modal.lg { width: min(1100px, 100%); }
.modal.xl {
  width: min(1280px, 100%);
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
}
.modal.xl .modal-body {
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 18px 20px;
  background: var(--blue-grad-deep);
  color: #fff;
  position: relative;
  overflow: hidden;
}
.modal-header::before {
  content: "";
  position: absolute; width: 140px; height: 140px; border-radius: 50%;
  background: rgba(255,255,255,.1); right: -30px; top: -50px;
}
.modal-header h2 {
  margin: 0; font-size: 1.15rem; color: #fff; position: relative; z-index: 1;
}
.modal-close {
  border: 0; background: rgba(255,255,255,.2); width: 34px; height: 34px;
  border-radius: 10px; cursor: pointer; font-size: 1.1rem; color: #fff;
  position: relative; z-index: 1;
}
.modal-close:hover { background: rgba(255,255,255,.3); }
.modal-body { padding: 18px 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border); background: #f7fafc;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* Bootstrap 4: evitar que oculte modales propios (.modal-backdrop > .modal) */
.modal-backdrop > .modal {
  display: block;
  position: static;
  height: auto;
  overflow: visible;
  z-index: auto;
}
.modal-backdrop > .modal.xl {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: auto;
  max-height: calc(100vh - 36px);
}
body.modal-open { overflow: hidden; }
.modal-backdrop.nested {
  z-index: 140;
  background: rgba(15, 30, 50, .62);
}
.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 1;
}
.btn-on-header {
  background: rgba(255,255,255,.18);
  color: #fff !important;
  border: 1px solid rgba(255,255,255,.35);
  font-size: .82rem;
  padding: 7px 14px;
}
.btn-on-header:hover {
  background: rgba(255,255,255,.3);
  color: #fff !important;
  filter: none;
}

.plantilla-copy-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--primary-soft);
  border: 1px dashed #9bb8d9;
  border-radius: 10px;
}
.plantilla-copy-bar span {
  color: var(--muted);
  font-size: .84rem;
}
.plantilla-copy-intro {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.45;
}
.plantilla-copy-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(60vh, 480px);
  overflow: auto;
}
.plantilla-copy-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.plantilla-copy-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.plantilla-copy-item-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
.plantilla-copy-item-main strong {
  font-size: .95rem;
}
.plantilla-copy-item-action {
  flex-shrink: 0;
  color: var(--primary);
  font-weight: 700;
  font-size: .82rem;
}

.plantilla-editor-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.45;
}
.plantilla-editor {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #dce3ec;
  display: flex;
  flex-direction: column;
  min-height: 520px;
}
.plantilla-editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.plantilla-editor-tabs {
  display: flex;
  gap: 4px;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 999px;
}
.plantilla-editor-tabs button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
  color: var(--muted);
}
.plantilla-editor-tabs button.is-active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 1px 4px rgba(0, 40, 80, .1);
}
.plantilla-editor-cmds {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.plantilla-editor-cmds button {
  min-width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: .88rem;
  color: var(--text);
}
.plantilla-editor-cmds button:hover {
  background: var(--primary-soft);
  border-color: #9bb8d9;
}
.plantilla-editor-cmds select {
  min-height: 32px;
  width: auto;
  padding: 4px 8px;
  font-size: .78rem;
  border-radius: 8px;
}
.plantilla-editor-stage {
  flex: 1;
  overflow: auto;
  padding: 16px;
  min-height: 420px;
}
.plantilla-editor-preview {
  width: min(210mm, 100%);
  margin: 0 auto;
  background: #fff;
  min-height: 260mm;
  padding: 18mm 16mm 20mm;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .12);
  outline: none;
}
.plantilla-editor-preview:focus {
  box-shadow: 0 6px 22px rgba(0, 61, 122, .18), 0 0 0 2px rgba(0, 94, 184, .25);
}
.plantilla-editor-html {
  display: none;
  width: 100%;
  min-height: 480px;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 16px 18px;
  font-family: Consolas, "SFMono-Regular", ui-monospace, monospace;
  font-size: .84rem;
  line-height: 1.5;
  background: #1a2736;
  color: #e2e8f0;
  resize: vertical;
  white-space: pre-wrap;
  tab-size: 2;
}
.plantilla-editor-preview .tpl-var {
  color: #c0392b;
  font-weight: 700;
  background: #fdecea;
  padding: 0 2px;
  border-radius: 3px;
}
.plantilla-editor-html:focus {
  outline: none;
  box-shadow: none;
}
.plantilla-editor.is-html .plantilla-editor-stage { display: none; }
.plantilla-editor.is-html .plantilla-editor-html { display: block; }
.plantilla-editor.is-html { background: #1a2736; }
.plantilla-editor.is-compact {
  min-height: 360px;
}
.plantilla-editor.is-compact .plantilla-editor-stage {
  min-height: 280px;
}
.plantilla-editor.is-compact .plantilla-editor-preview {
  width: 100%;
  min-height: 240px;
  padding: 18px 22px;
}
.plantilla-editor.is-compact .plantilla-editor-html {
  min-height: 320px;
}
.plantilla-editor.has-campos {
  flex-direction: row;
  align-items: stretch;
}
.plantilla-campos {
  width: 250px;
  flex: 0 0 250px;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.plantilla-campos-head {
  font-weight: 800;
  font-size: .82rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 10px 12px 0;
}
.plantilla-campos-hint {
  margin: 4px 12px 8px;
  font-size: .72rem;
  color: var(--muted);
}
.plantilla-campos [data-campos-filter] {
  width: calc(100% - 24px);
  margin: 0 12px 8px;
  padding: 7px 10px;
}
.plantilla-campos-list {
  overflow: auto;
  padding: 0 8px 12px;
  flex: 1;
}
.plantilla-campos-grupo {
  margin-bottom: 10px;
}
.plantilla-campos-grupo > strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 6px 6px 4px;
}
.plantilla-origen {
  text-transform: none;
  letter-spacing: 0;
  font-size: .65rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 2px 7px;
}
.plantilla-origen.is-plan {
  color: #0f766e;
  background: #ccfbf1;
}
.plantilla-origen.is-contrato {
  color: #1d4ed8;
  background: #dbeafe;
}
.plantilla-campos-grupo.is-plan {
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 10px;
  padding: 4px 2px 6px;
}
.plantilla-campos-grupo.is-contrato {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 4px 2px 6px;
}
.plantilla-campo {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.plantilla-campo:hover {
  background: var(--primary-soft);
}
.plantilla-campo span {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text);
}
.plantilla-campo code {
  font-size: .68rem;
  color: #c0392b;
  background: #fdecea;
  padding: 1px 4px;
  border-radius: 4px;
}
.plantilla-editor-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Chrome-like PDF viewer ---------- */
.pdf-shell {
  width: 100%;
  min-height: calc(100vh - var(--header-h) - 36px);
  display: flex; flex-direction: column;
  background: var(--pdf-bg);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #3c4043;
}
.pdf-shell.is-editing {
  background: #fff;
  border-color: #d0d7de;
}
.pdf-editor-wrap {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: #fff;
}
.pdf-editor-wrap .plantilla-editor {
  min-height: calc(100vh - 200px);
}
.pdf-toolbar {
  background: var(--pdf-bar);
  color: #fff;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; flex-wrap: wrap;
  min-height: 48px;
}
.pdf-toolbar .title {
  font-size: .88rem; font-weight: 600; margin-right: 8px;
  max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pdf-toolbar .sep {
  width: 1px; height: 22px; background: rgba(255,255,255,.2); margin: 0 4px;
}
.pdf-toolbar button:not(.btn-print-pdf),
.pdf-toolbar a.tool {
  background: transparent; border: 0; color: #fff !important;
  width: 34px; height: 34px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; text-decoration: none !important; font-size: .95rem;
}
.pdf-toolbar button:not(.btn-print-pdf):hover,
.pdf-toolbar a.tool:hover { background: rgba(255,255,255,.12); }
.pdf-toolbar .zoom-label {
  min-width: 52px; text-align: center; font-size: .82rem; opacity: .95; color: #fff;
}
.pdf-toolbar .spacer { flex: 1; }
.pdf-meta {
  background: #edf3fa;
  border-bottom: 1px solid #d5e0ee;
  padding: 8px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  align-items: flex-end;
  font-size: .82rem;
  color: #1e3a5f;
}
.pdf-meta .meta-item span {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 2px;
}
.pdf-meta .meta-item strong { font-weight: 750; }
.pdf-meta .meta-comision-form {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pdf-meta .meta-comision-form input {
  width: 110px;
  height: 32px;
  border: 1px solid #c5d4e6;
  border-radius: 8px;
  padding: 0 8px;
  font: inherit;
  font-weight: 700;
}
.pdf-meta .meta-comision-form .btn-print-pdf {
  background: var(--primary);
  color: #fff !important;
}
.pdf-toolbar .btn-print-pdf,
.pdf-toolbar a.btn-print-pdf,
.pdf-toolbar button.btn-print-pdf {
  width: auto !important;
  height: auto !important;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #ffffff !important;
  color: #003d7a !important;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
  text-decoration: none !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.pdf-toolbar .btn-print-pdf:hover,
.pdf-toolbar a.btn-print-pdf:hover,
.pdf-toolbar button.btn-print-pdf:hover {
  background: #e8f2fb !important;
  color: #002952 !important;
  filter: none;
}
.pdf-canvas {
  flex: 1;
  overflow: auto;
  padding: 28px 16px 48px;
  display: block;
}
.pdf-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  zoom: 1;
  transform-origin: top center;
}
.pdf-source {
  position: absolute;
  left: -99999px;
  top: 0;
  width: 166mm;
  visibility: hidden;
  pointer-events: none;
}
.pdf-sheet {
  width: 210mm;
  height: 297mm;
  background: #fff;
  color: #111;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.35);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  page-break-after: always;
  break-after: page;
  box-sizing: border-box;
}
.pdf-sheet-inner {
  box-sizing: border-box;
  height: 100%;
  max-height: 297mm;
  overflow: hidden;
  --pdf-margin-top: 23mm;
  --pdf-margin-bottom: 25mm;
  --pdf-margin-left: 28mm;
  --pdf-margin-right: 16mm;
  padding: var(--pdf-margin-top) var(--pdf-margin-right) var(--pdf-margin-bottom) var(--pdf-margin-left);
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  font-size: 11pt;
  line-height: 1.15;
  color: #000;
}
.pdf-sheet--overflow .pdf-sheet-inner {
  overflow: visible;
}
.contrato-doc {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  font-size: 11pt;
  line-height: 1.15;
  color: #000;
}
.contrato-doc .contrato-titulo,
.pdf-sheet-inner .contrato-titulo,
.contrato-doc h1,
.pdf-sheet-inner h1 {
  text-align: center;
  color: #000;
  font-size: 11pt;
  font-weight: 400;
  margin: 0 0 0;
  line-height: 1.15;
}
.contrato-doc .contrato-seccion,
.pdf-sheet-inner .contrato-seccion {
  text-align: center;
  font-weight: 400;
  margin: 0;
}
.contrato-doc .plan-modulos p,
.contrato-doc .plan-modulos li,
.pdf-sheet-inner .plan-modulos p,
.pdf-sheet-inner .plan-modulos li {
  font-weight: 700;
  margin: 0;
}
.contrato-doc .plan-modulos ul,
.pdf-sheet-inner .plan-modulos ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
/* Listas con letras a) b) c) — como Word (SEGUNDA cláusula) */
.contrato-lista-letra,
.pdf-sheet-inner .contrato-lista-letra {
  list-style: none;
  padding: 0;
  margin: 0 0 8pt;
  counter-reset: contrato-letra;
}
.contrato-lista-letra > li,
.pdf-sheet-inner .contrato-lista-letra > li {
  counter-increment: contrato-letra;
  padding-left: 14.5mm;
  text-indent: -6.4mm;
  margin: 0 0 8pt;
  text-align: justify;
}
.contrato-lista-letra > li::before,
.pdf-sheet-inner .contrato-lista-letra > li::before {
  content: counter(contrato-letra, lower-alpha) ") ";
  font-weight: 400;
}
.contrato-lista-letra > li p,
.pdf-sheet-inner .contrato-lista-letra > li p {
  margin: 0 0 4pt;
  text-indent: 0;
  padding-left: 0;
}
.contrato-lista-letra > li .contrato-sangria-2,
.pdf-sheet-inner .contrato-lista-letra > li .contrato-sangria-2 {
  padding-left: 0;
}
/* Sangría secundaria (párrafos fuera de listas) */
.contrato-sangria-2,
.pdf-sheet-inner .contrato-sangria-2 {
  padding-left: 14.5mm;
  margin: 0 0 4pt;
}
/* Sangría en cláusulas NOVENA, DECIMOQUINTA, etc. */
.contrato-sangria-clausula,
.pdf-sheet-inner .contrato-sangria-clausula {
  padding-left: 2.5mm;
}
/* Módulos del plan: guión y subnivel o */
.contrato-modulos > ul,
.pdf-sheet-inner .contrato-modulos > ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.contrato-modulos > ul > li,
.pdf-sheet-inner .contrato-modulos > ul > li {
  padding-left: 19mm;
  text-indent: -6.4mm;
  margin: 0 0 4pt;
  font-weight: 700;
  text-align: justify;
}
.contrato-modulos > ul > li::before,
.pdf-sheet-inner .contrato-modulos > ul > li::before {
  content: "- ";
  font-weight: 700;
}
.contrato-modulos ul ul,
.pdf-sheet-inner .contrato-modulos ul ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.contrato-modulos ul ul li,
.pdf-sheet-inner .contrato-modulos ul ul li {
  padding-left: 31.75mm;
  text-indent: -6.4mm;
  margin: 0 0 4pt;
  font-weight: 700;
  text-align: justify;
}
.contrato-modulos ul ul li::before,
.pdf-sheet-inner .contrato-modulos ul ul li::before {
  content: "o ";
  font-weight: 700;
}
.contrato-doc .contrato-firmas,
.pdf-sheet-inner .contrato-firmas {
  width: 100%;
  margin-top: 28px;
  border: none;
  border-collapse: collapse;
}
.contrato-doc .contrato-firmas td,
.pdf-sheet-inner .contrato-firmas td {
  width: 50%;
  vertical-align: top;
  border: none;
  padding: 0;
}
.contrato-firma-espacio,
.pdf-sheet-inner .contrato-firma-espacio {
  min-height: 52px;
  margin: 8px 0 12px;
}
.pdf-sheet-inner h1 {
  text-align: center;
  color: #000;
  font-size: 11pt;
  margin-top: 0;
}
.pdf-sheet-inner h2,
.pdf-sheet-inner h3 {
  color: #003d7a;
}
.pdf-sheet-inner ul {
  padding-left: 1.2rem;
}
/* Contrato legal: párrafos justificados sin partir palabras */
.contrato-doc p,
.pdf-sheet-inner p {
  text-align: justify;
  text-justify: inter-word;
  hyphens: none;
  -webkit-hyphens: none;
  word-break: normal;
  overflow-wrap: normal;
  margin: 0 0 8pt;
}
.contrato-doc p.contrato-seccion,
.contrato-doc h1.contrato-titulo,
.pdf-sheet-inner p.contrato-seccion,
.pdf-sheet-inner h1.contrato-titulo,
.contrato-doc p.aceptacion-titulo,
.pdf-sheet-inner p.aceptacion-titulo {
  text-align: center !important;
  margin-bottom: 8pt;
}
.contrato-doc p.aceptacion-titulo,
.pdf-sheet-inner p.aceptacion-titulo {
  font-weight: 700;
  margin-top: 16pt;
  padding-top: 10pt;
  border-top: 1px solid #111;
}
.contrato-doc p.aceptacion-dato,
.pdf-sheet-inner p.aceptacion-dato {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.contrato-doc li,
.pdf-sheet-inner li {
  text-align: justify;
  hyphens: none;
  -webkit-hyphens: none;
  word-break: normal;
  overflow-wrap: normal;
}
.contrato-doc strong,
.contrato-doc b,
.pdf-sheet-inner strong,
.pdf-sheet-inner b {
  font-weight: 700;
}
.contrato-doc h1,
.contrato-doc p.contrato-seccion,
.contrato-doc .contrato-titulo,
.pdf-sheet-inner h1,
.pdf-sheet-inner p.contrato-seccion,
.pdf-sheet-inner .contrato-titulo {
  text-align: center !important;
  hyphens: none;
}
.pdf-sheet-label {
  position: absolute;
  right: 16mm;
  bottom: 10mm;
  font-size: 10px;
  color: #94a3b8;
  pointer-events: none;
  z-index: 2;
}
.pdf-page {
  width: 210mm;
  background: #fff;
  padding: 18mm 16mm;
  box-shadow: 0 4px 24px rgba(0,0,0,.35);
  line-height: 1.5;
  font-size: 11.5pt;
}

.mini-preview {
  max-height: 240px; overflow: auto; border: 1px dashed var(--border);
  border-radius: var(--radius-sm); padding: 12px; background: #fbfdff; font-size: .88rem;
}

@media (max-width: 1100px) {
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters.compact { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .nav-toggle { display: grid; place-items: center; margin-left: auto; }
  .top-header-inner { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .top-nav {
    display: none; width: 100%; flex-direction: column; align-items: stretch; order: 3;
  }
  .top-nav.open { display: flex; }
  .top-nav a { border-radius: 10px; }
  .nav-dropdown { width: 100%; }
  .nav-dropdown-btn {
    width: 100%;
    justify-content: space-between;
    border-radius: 10px;
  }
  .nav-dropdown-panel {
    position: static;
    width: 100%;
    min-width: 0;
    margin-top: 4px;
    box-shadow: none;
    border: 1px solid rgba(255,255,255,.2);
    background: rgba(0,0,0,.12);
  }
  .nav-dropdown-label {
    color: rgba(255,255,255,.7);
    border-top-color: rgba(255,255,255,.2);
  }
  .nav-dropdown-panel a {
    color: #fff !important;
  }
  .nav-dropdown-panel a:hover,
  .nav-dropdown-panel a.active {
    background: rgba(255,255,255,.18) !important;
    color: #fff !important;
  }
  .user-menu { order: 2; width: 100%; margin-left: 0; }
  .user-menu-btn { width: 100%; max-width: none; justify-content: space-between; }
  .user-menu-panel { left: 0; right: 0; min-width: 0; }
  .page-banner { flex-direction: column; align-items: flex-start; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .pdf-sheet { width: min(210mm, 100%); height: auto; min-height: 70vh; }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .top-header,
  .no-print,
  .pdf-toolbar,
  .page-head,
  .page-banner,
  .filters,
  .alert,
  .mobile-toggle,
  .nav-toggle,
  .pdf-sheet-label,
  .pdf-source,
  [data-pdf-source-keep] {
    display: none !important;
  }

  .app-shell,
  .main,
  .pdf-shell,
  .pdf-canvas,
  .pdf-pages {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    border: 0 !important;
    overflow: visible !important;
    gap: 0 !important;
    zoom: 1 !important;
    box-shadow: none !important;
  }

  .pdf-sheet {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
    page-break-after: always;
    break-after: page;
    box-sizing: border-box !important;
  }

  .pdf-sheet:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .pdf-sheet-inner {
    height: 100% !important;
    max-height: 297mm !important;
    min-height: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    padding: 23mm 16mm 25mm 28mm !important;
    font-family: Arial, "Helvetica Neue", Helvetica, sans-serif !important;
    font-size: 11pt !important;
    line-height: 1.15 !important;
    color: #000 !important;
  }

  .pdf-sheet--overflow .pdf-sheet-inner {
    overflow: visible !important;
  }

  .pdf-sheet-inner p {
    orphans: 3;
    widows: 3;
    text-align: justify !important;
    text-justify: inter-word;
    hyphens: none !important;
    -webkit-hyphens: none !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
  }

  .pdf-sheet-inner p.contrato-seccion,
  .pdf-sheet-inner .contrato-titulo,
  .pdf-sheet-inner h1,
  .pdf-sheet-inner p.aceptacion-titulo {
    text-align: center !important;
  }

  .pdf-sheet-inner p.aceptacion-dato {
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  body.firma-solo-lectura:not(.firma-forzar-descarga) .pdf-pages,
  body.firma-solo-lectura:not(.firma-forzar-descarga) .pdf-canvas {
    display: none !important;
  }

  body.firma-solo-lectura:not(.firma-forzar-descarga) .firma-print-aviso {
    display: block !important;
    padding: 24mm 20mm;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12pt;
    color: #000;
  }

  body.firma-forzar-descarga .firma-print-aviso {
    display: none !important;
  }

  /* En móvil el canvas vive fuera de pantalla: al imprimir debe volver al flujo normal */
  body.firma-publica-body .pdf-shell,
  body.firma-publica-body .pdf-canvas,
  body.firma-publica-body .pdf-canvas[data-firma-desktop-ui],
  body.firma-forzar-descarga .pdf-pages,
  body.firma-forzar-descarga .pdf-canvas,
  body.firma-prep-impresion .pdf-canvas {
    display: block !important;
    position: static !important;
    left: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    opacity: 1 !important;
    visibility: visible !important;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    pointer-events: auto !important;
    z-index: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    transform: none !important;
    zoom: 1 !important;
  }

  body.firma-publica-body .pdf-pages {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 0 !important;
  }

  .firma-movil-panel {
    display: none !important;
  }

  .pdf-sheet-inner li {
    text-align: justify !important;
    hyphens: none !important;
    -webkit-hyphens: none !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
  }

  .pdf-sheet-inner h1,
  .pdf-sheet-inner h2,
  .pdf-sheet-inner table {
    page-break-inside: avoid;
    break-inside: avoid;
  }
}

.pdf-toolbar .btn-print-pdf.btn-firma-cliente,
.pdf-toolbar button.btn-print-pdf.btn-firma-cliente {
  background: #0b8f63 !important;
  color: #fff !important;
}
.pdf-toolbar .btn-print-pdf.btn-firma-cliente:hover,
.pdf-toolbar button.btn-print-pdf.btn-firma-cliente:hover {
  background: #087a54 !important;
  color: #fff !important;
}

.firma-modal-texto {
  margin: 0 0 14px;
  line-height: 1.5;
  color: var(--text);
}
.subir-dropzone {
  border: 1.5px dashed #b6c5d6;
  border-radius: 12px;
  background: #f7fafc;
  padding: 16px;
  text-align: center;
  outline: none;
  transition: border-color .15s ease, background .15s ease;
}
.subir-dropzone:focus,
.subir-dropzone.is-drag {
  border-color: #0066c5;
  background: #eef6ff;
}
.subir-dropzone-title {
  margin: 0 0 4px;
  font-weight: 600;
  color: var(--text);
}
.subir-dropzone-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.4;
}
.subir-dropzone-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
.subir-preview {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #dbe4ef;
}
.subir-preview img {
  display: block;
  max-width: 100%;
  max-height: 180px;
  margin: 0 auto 8px;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
}
.subir-preview p {
  margin: 0 0 8px;
  font-size: .88rem;
  color: var(--text);
  word-break: break-all;
}
.firma-modal-nota {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.45;
}
.firma-link-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.firma-link-row input {
  flex: 1;
  min-width: 0;
  width: auto;
}
.firma-link-row .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.firma-mensaje {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  font-family: var(--font);
  line-height: 1.45;
  white-space: pre-wrap;
}
.firma-copy-actions {
  margin-top: 10px;
  justify-content: flex-end;
}
.firma-copy-actions .btn {
  min-width: 120px;
}

body.firma-publica-body {
  background: var(--pdf-bg);
  min-height: 100vh;
}
body.firma-publica-body .pdf-shell {
  min-height: 100vh;
  border: 0;
  border-radius: 0;
}
.firma-publica .pdf-toolbar .title {
  max-width: min(640px, 58vw);
}
.firma-print-aviso { display: none; }
.firma-vacio {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 18px;
  color: #fff;
}
.firma-vacio .mark {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--primary-dark);
  font-weight: 800;
  margin-bottom: 14px;
}
.firma-vacio h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}
.firma-vacio p {
  max-width: 460px;
  margin: 0;
  line-height: 1.5;
  color: rgba(255,255,255,.88);
}
.firma-error {
  background: #fef2f2;
  color: #991b1b;
  padding: 10px 16px;
  font-size: .9rem;
  border-top: 1px solid #fecaca;
}
.firma-pie {
  background: #fff;
  border-top: 1px solid #d5dee8;
  padding: 14px 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}
.firma-pie-main { flex: 1; min-width: 0; }
.firma-pie label.firma-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}
.firma-pie label.firma-check span {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}
.firma-pie input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex: 0 0 auto;
}
.firma-pie-nota {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.4;
}
.firma-pie .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.firma-pie .btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  filter: none;
}
.firma-pie-ok {
  background: #ecfdf5;
  border-top-color: #a7f3d0;
}
.firma-pie-ok strong { color: #065f46; }

.firma-movil-panel {
  display: none;
}

@media (max-width: 820px) {
  .firma-link-row,
  .firma-pie { flex-direction: column; align-items: stretch; }
  .firma-link-row input { width: 100%; }

  body.firma-publica-body {
    background: linear-gradient(160deg, #0b3d6e 0%, #145ea8 55%, #1d7ad4 100%);
  }
  body.firma-publica-body .pdf-shell.firma-publica {
    background: transparent;
    min-height: 100vh;
  }

  /* Panel móvil: instrucciones + descargar (no se muestra el contrato en pantalla) */
  body.firma-publica-body .firma-movil-panel {
    display: block;
    padding: 28px 16px 12px;
  }
  .firma-movil-card {
    background: #fff;
    border-radius: 16px;
    padding: 22px 18px 20px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
    text-align: center;
  }
  .firma-movil-card .mark {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary, #0066c5);
    color: #fff;
    font-weight: 800;
    margin-bottom: 12px;
  }
  .firma-movil-card h1 {
    margin: 0 0 4px;
    font-size: 1.15rem;
    color: var(--text, #1a2332);
  }
  .firma-movil-sub {
    margin: 0 0 8px;
    color: var(--muted, #64748b);
    font-size: .92rem;
  }
  .firma-movil-estado {
    margin: 0 0 14px;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--primary, #0066c5);
  }
  .firma-movil-aviso {
    text-align: left;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 16px;
  }
  .firma-movil-aviso p {
    margin: 0 0 8px;
    font-size: .9rem;
    line-height: 1.45;
    color: #334155;
  }
  .firma-movil-aviso p:last-child { margin-bottom: 0; }
  .firma-movil-descargar {
    width: 100%;
    min-height: 48px;
    font-size: 1.05rem;
  }
  .firma-movil-pasos {
    text-align: left;
    margin: 0 0 14px;
    padding: 0 0 0 1.15rem;
    color: #334155;
    font-size: .88rem;
    line-height: 1.45;
  }
  .firma-movil-pasos li { margin: 0 0 8px; }
  .firma-movil-pasos li:last-child { margin-bottom: 0; }
  .firma-movil-revisado {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    text-align: left;
    margin: 14px 0 0;
    padding: 12px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #fff;
    color: #1e293b;
    font-size: .88rem;
    line-height: 1.4;
    font-weight: 600;
  }
  .firma-movil-revisado input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex: 0 0 auto;
  }
  .firma-movil-revisado input:disabled {
    opacity: .55;
  }
  .firma-movil-hint {
    margin: 12px 0 0;
    font-size: .82rem;
    line-height: 1.4;
    color: var(--muted, #64748b);
  }
  .firma-pie-paso-movil {
    margin: 0 0 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e3a8a;
    font-size: .88rem;
    line-height: 1.4;
  }

  /* Mantener el documento fuera de vista en pantalla (la descarga lo reposiciona) */
  body.firma-publica-body [data-firma-desktop-ui].pdf-toolbar,
  body.firma-publica-body [data-firma-desktop-ui].firma-pie {
    display: none !important;
  }
  body.firma-publica-body .pdf-canvas[data-firma-desktop-ui] {
    position: fixed;
    left: 0;
    top: 0;
    width: 210mm;
    max-width: none;
    height: auto;
    max-height: 0;
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
    z-index: -1;
  }
  /* Antes de imprimir: dar medidas reales al canvas para paginar e imprimir */
  body.firma-publica-body.firma-prep-impresion .pdf-canvas[data-firma-desktop-ui] {
    max-height: none;
    opacity: 0.02;
    overflow: visible;
    z-index: 0;
  }

  /* Formulario de firma oculto en móvil hasta completar descarga + revisión */
  body.firma-publica-body .firma-pie[data-firma-aceptacion] {
    display: none !important;
  }
  body.firma-publica-body.firma-movil-listo .firma-pie[data-firma-aceptacion] {
    display: flex !important;
    margin: 0 16px 24px;
    border-radius: 14px;
    border: 0;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .12);
  }
  body.firma-publica-body.firma-movil-listo [data-firma-paso-movil] {
    display: block !important;
  }
}

@media (min-width: 821px) {
  body.firma-publica-body .firma-movil-panel {
    display: none !important;
  }
}

/* Panel de seguimiento público (contrato ya firmado) */
body.firma-seguimiento-body {
  background: linear-gradient(160deg, #0b3d6e 0%, #145ea8 55%, #1d7ad4 100%);
  min-height: 100vh;
}
.firma-seguimiento {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
}
.firma-seguimiento-card {
  width: min(560px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px 22px;
  box-shadow: 0 18px 50px rgba(8, 35, 70, .28);
  color: var(--text);
}
.firma-seguimiento-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 600;
}
.firma-seguimiento-brand .mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary, #0066c5);
  color: #fff;
  font-weight: 800;
}
.firma-seguimiento-card h1 {
  margin: 0 0 4px;
  font-size: 1.45rem;
  line-height: 1.25;
}
.firma-seguimiento-sub {
  margin: 0 0 14px;
  color: var(--muted);
}
.firma-seguimiento-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.firma-seguimiento-intro {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
  font-size: .95rem;
}
.firma-seguimiento-ok {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: .92rem;
  line-height: 1.4;
}
.firma-timeline {
  list-style: none;
  margin: 0 0 20px;
  padding: 0 0 0 4px;
}
.firma-timeline-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 12px;
  position: relative;
  padding-bottom: 16px;
}
.firma-timeline-item:last-child { padding-bottom: 0; }
.firma-timeline-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 18px;
  bottom: 0;
  width: 2px;
  background: #dbe4ef;
}
.firma-timeline-dot {
  width: 14px;
  height: 14px;
  margin-top: 3px;
  border-radius: 50%;
  background: #94a3b8;
  box-shadow: 0 0 0 3px #e8eef5;
}
.firma-timeline-item.is-done .firma-timeline-dot {
  background: #059669;
  box-shadow: 0 0 0 3px #d1fae5;
}
.firma-timeline-item.is-current .firma-timeline-dot {
  background: #0066c5;
  box-shadow: 0 0 0 3px #dbeafe;
}
.firma-timeline-item.is-danger .firma-timeline-dot {
  background: #dc2626;
  box-shadow: 0 0 0 3px #fee2e2;
}
.firma-timeline-item.is-pending .firma-timeline-dot {
  background: #cbd5e1;
  box-shadow: 0 0 0 3px #f1f5f9;
}
.firma-timeline-item strong {
  display: block;
  font-size: .98rem;
  margin-bottom: 2px;
}
.firma-timeline-fecha {
  display: block;
  margin: 0 0 4px;
  color: #0b3d6e;
  font-size: .8rem;
  font-weight: 600;
}
.firma-timeline-item p {
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.4;
}
.firma-seguimiento-acciones {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.firma-seguimiento-acciones .btn {
  flex: 1 1 auto;
  text-align: center;
  justify-content: center;
}
.firma-comprobante-box {
  margin: 8px 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  background: #f8fafc;
}
.firma-comprobante-box h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}
.firma-comprobante-box > p {
  margin: 0 0 12px;
  color: var(--muted, #64748b);
  font-size: .92rem;
  line-height: 1.4;
}
.firma-comprobante-form label {
  display: block;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #475569;
  margin-bottom: 6px;
}
.firma-comprobante-form input[type="file"] {
  display: block;
  width: 100%;
  margin-bottom: 8px;
}
.firma-comprobante-hint {
  margin: 0 0 12px !important;
  font-size: .8rem !important;
}
.firma-seguimiento-nota {
  margin: 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.4;
}
@media (max-width: 520px) {
  .firma-seguimiento-card { padding: 22px 16px 18px; }
  .firma-seguimiento-acciones { flex-direction: column; }
}
