:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-faint: #9aa1ac;
  --accent: #2f5cff;
  --accent-hover: #244ae0;
  --accent-soft: #eaefff;
  --success: #16794c;
  --success-soft: #e6f4ec;
  --warn: #9a6b00;
  --warn-soft: #fbf1d9;
  --danger: #c0392b;
  --danger-soft: #fbeae8;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ─── Layout ─────────────────────────────────────────────── */
.app-nav {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-nav .brand {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
}
.app-nav .brand .dot {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #6a8bff);
  display: inline-block;
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
  font-size: 13px;
}
.nav-links {
  display: flex;
  gap: 4px;
  margin-left: 12px;
}
.nav-link {
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.nav-link:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}
.container-wide {
  max-width: 1120px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-head h1 {
  font-size: 22px;
}
.page-head .sub {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 13px;
}

/* ─── Cards / surfaces ───────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad {
  padding: 20px;
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-weight: 500;
  font-size: 13.5px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  text-decoration: none;
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  text-decoration: none;
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  text-decoration: none;
}
.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border-strong);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  text-decoration: none;
}
.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

/* ─── Forms ──────────────────────────────────────────────── */
.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.row {
  display: flex;
  gap: 14px;
}
.row > * {
  flex: 1;
}

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: capitalize;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-draft {
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-sent {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge-signed {
  background: var(--success-soft);
  color: var(--success);
}
.badge-rejected,
.badge-error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ─── Table / list ───────────────────────────────────────── */
.list {
  width: 100%;
  border-collapse: collapse;
}
.list th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.list td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.list tr:last-child td {
  border-bottom: none;
}
.list tbody tr {
  transition: background 0.1s;
}
.list tbody tr:hover {
  background: var(--surface-2);
}
.list .title-cell {
  font-weight: 500;
  color: var(--text);
}
.list .muted {
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Empty state ────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-muted);
}
.empty h3 {
  color: var(--text);
  margin-bottom: 6px;
}

/* ─── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f0c9c3;
}
.alert-success {
  background: var(--success-soft);
  color: var(--success);
  border-color: #bfe3cd;
}
.alert-info {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: #cdd9ff;
}

/* ─── Auth page ──────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
}
.auth-card .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 4px;
}
.auth-card .dot {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #6a8bff);
}

/* ─── Editor ─────────────────────────────────────────────── */
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--surface-2);
}
.tb-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tb-btn:hover {
  background: var(--surface);
  border-color: var(--border);
}
.tb-btn.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}
.tb-sep {
  width: 1px;
  background: var(--border-strong);
  margin: 4px 4px;
}
.editor-surface {
  border: 1px solid var(--border-strong);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--surface);
  padding: 28px 32px;
  min-height: 480px;
}
.editor-surface .ProseMirror {
  outline: none;
  min-height: 440px;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}
.editor-surface .ProseMirror:focus {
  outline: none;
}
.editor-surface .ProseMirror h1 {
  font-size: 22px;
  margin: 18px 0 8px;
}
.editor-surface .ProseMirror h2 {
  font-size: 18px;
  margin: 16px 0 6px;
}
.editor-surface .ProseMirror h3 {
  font-size: 15px;
  margin: 14px 0 6px;
}
.editor-surface .ProseMirror p {
  margin: 0 0 10px;
}
.editor-surface .ProseMirror ul,
.editor-surface .ProseMirror ol {
  padding-left: 24px;
  margin: 0 0 10px;
}
.editor-surface .ProseMirror blockquote {
  border-left: 3px solid var(--border-strong);
  padding-left: 14px;
  color: var(--text-muted);
  margin: 0 0 10px;
}
.editor-surface .ProseMirror table {
  border-collapse: collapse;
  margin: 10px 0;
  width: 100%;
  table-layout: fixed;
}
.editor-surface .ProseMirror td,
.editor-surface .ProseMirror th {
  border: 1px solid var(--border-strong);
  padding: 6px 8px;
  vertical-align: top;
}
.editor-surface .ProseMirror th { background: var(--bg); }
.editor-surface .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--text-faint);
  pointer-events: none;
  height: 0;
}

/* ─── Utilities ──────────────────────────────────────────── */
.stack > * + * {
  margin-top: 16px;
}
.flex {
  display: flex;
}
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.gap-8 {
  gap: 8px;
}
.gap-12 {
  gap: 12px;
}
.mt-0 {
  margin-top: 0;
}
.muted {
  color: var(--text-muted);
}
.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.definition-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px 16px;
  font-size: 13.5px;
}
.definition-list dt {
  color: var(--text-muted);
}
.definition-list dd {
  margin: 0;
  color: var(--text);
}

/* ─── Signature placer (pdf.js) ──────────────────────────── */
.placer-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.placer-page {
  position: relative;
  box-shadow: var(--shadow);
  background: #fff;
  cursor: crosshair;
  flex: none;
}
.placer-page canvas {
  display: block;
}
.sig-box {
  position: absolute;
  border: 2px dashed;
  border-radius: 4px;
  cursor: move;
  box-sizing: border-box;
}
.sig-box.active {
  border-style: solid;
}
.sig-box-label {
  position: absolute;
  top: -20px;
  left: -2px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sig-box-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid;
  border-radius: 50%;
  cursor: nwse-resize;
}

/* ─── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
}
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ─── Signer rows ────────────────────────────────────────── */
.signer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: var(--surface);
}
.signer-row.selectable {
  cursor: pointer;
}
.signer-row.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.signer-color {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: none;
}
.signer-order {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex: none;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--text-muted);
}
.var-token {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  padding: 1px 6px;
  border-radius: 4px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}
.tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 8px;
  margin-bottom: 20px;
}
.tab {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ─── Añadidos de la versión PHP ──────────────────────────── */

/* Detalle del contrato: panel lateral fijo + documento con el resto. */
.detalle-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
@media (max-width: 900px) {
  .detalle-grid {
    grid-template-columns: 1fr;
  }
}

/* Vista previa del documento. El contenido es HTML del contrato, así que
   las tablas anchas se desplazan DENTRO del panel y no empujan la página. */
.doc-preview {
  max-height: 70vh;
  overflow: auto;
  font-size: 14px;
  line-height: 1.7;
}
.doc-preview p {
  margin: 0 0 10px;
  text-align: justify;
}
.doc-preview h1 { font-size: 19px; margin: 16px 0 8px; }
.doc-preview h2 { font-size: 17px; margin: 14px 0 7px; }
.doc-preview h3 { font-size: 15px; margin: 12px 0 6px; }
.doc-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
}
.doc-preview td,
.doc-preview th {
  padding: 4px 8px;
  vertical-align: top;
}
/* Recuadros de firma: la vista previa usa la MISMA transformación que el PDF
   (App\Lib\Pdf::prepareBody), así que lo que se ve aquí es lo que se imprime. */
.doc-preview table.sign-box {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin: 10px 0;
}
.doc-preview table.sign-box td {
  height: 72px;
  vertical-align: bottom;
  padding: 6px 8px;
}
.doc-preview table.sign-box-loose { width: 240px; }
.doc-preview .sign-marker {
  font-size: 11px;
  color: var(--text-faint);
}
