:root {
  --gold: #f4a227;
  --gold-d: #d4881e;
  --gold-l: #ffd97a;
  --dark: #1a1a2e;
  --darker: #0f0f1e;
  --surf: #ffffff;
  --bg: #f5f5f7;
  --bg-2: #eef0f3;
  --text: #1a1a2e;
  --text-2: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-2: #d1d5db;
  --green: #10b981;
  --green-bg: rgba(16,185,129,.1);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,.1);
  --yellow: #f59e0b;
  --yellow-bg: rgba(245,158,11,.12);
  --blue: #3b82f6;
  --blue-d: #2563eb;
  --blue-bg: rgba(59,130,246,.12);
  --purple: #8b5cf6;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.12);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* Topbar */
.topbar {
  background: var(--dark);
  color: #fff;
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-icon { font-size: 1.8rem; }
.logo h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1.2;
}
.tagline {
  font-size: .7rem;
  color: rgba(255,255,255,.5);
  letter-spacing: .02em;
}
.conn-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 8px currentColor;
  flex-shrink: 0;
}
.conn-dot.ok { background: var(--green); color: var(--green); }
.conn-dot.err { background: var(--red); color: var(--red); }

/* Nav */
.nav {
  background: var(--surf);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 62px;
  z-index: 90;
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 8px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-inner::-webkit-scrollbar { display: none; }
.nav-btn {
  background: transparent;
  border: none;
  padding: 14px 18px;
  font-size: .92rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.nav-btn:hover:not(:disabled) { color: var(--text); }
.nav-btn.active {
  color: var(--gold-d);
  border-bottom-color: var(--gold);
  font-weight: 600;
}
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }

/* Main */
.main { padding: 24px 0 60px; }
.section { display: none; }
.section.active { display: block; }

/* Card */
.card {
  background: var(--surf);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-header { margin-bottom: 20px; }
.card h2 { font-size: 1.15rem; color: var(--dark); margin-bottom: 6px; }
.card p { color: var(--text-2); }
.muted { color: var(--muted) !important; font-size: .9rem; }

/* Lists */
.checklist { list-style: none; padding-left: 0; }
.checklist li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}
.checklist li:last-child { border-bottom: none; }
.checklist li.done { color: var(--green); font-weight: 500; }
.checklist li.active { color: var(--gold-d); font-weight: 600; }

/* Form */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-2);
}
.lbl-required::after { content: ' *'; color: var(--red); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 12px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(244,162,39,.15);
}
.form-group .hint { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.form-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
}
.form-divider::before,
.form-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Buttons */
.btn {
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s, transform .05s, box-shadow .15s;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--gold); color: var(--dark); }
.btn-primary:hover { background: var(--gold-d); }
.btn-primary:disabled {
  background: var(--border-2);
  color: var(--muted);
  cursor: not-allowed;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border-2);
}
.btn-ghost:hover { background: var(--bg-2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }

/* Meta info */
.meta-info {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: .8rem;
  color: var(--muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--dark);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: transform .25s, opacity .25s;
  z-index: 1000;
  max-width: 90vw;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

/* Card header con botón */
.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* Filters */
.filters {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-2);
  padding: 4px;
  border-radius: 8px;
  flex-wrap: wrap;
}
.filter-tab {
  background: transparent;
  border: none;
  padding: 6px 14px;
  font-size: .85rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  transition: all .15s;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active {
  background: var(--surf);
  color: var(--gold-d);
  box-shadow: var(--shadow);
}
.search-wrap { flex: 1; max-width: 300px; min-width: 200px; }
.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
}
.search-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(244,162,39,.15);
}

/* Clientes */
.clientes-list { display: flex; flex-direction: column; gap: 8px; }
.cliente-item {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: border-color .15s;
}
.cliente-item:hover { border-color: var(--gold); }
.cliente-item.inactivo { opacity: .55; border-style: dashed; }
.cliente-main { flex: 1; min-width: 0; }
.cliente-nombre {
  font-weight: 600;
  color: var(--text);
  font-size: .98rem;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.cliente-tipo-badge {
  font-size: .65rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.cliente-tipo-badge.privado { background: rgba(59,130,246,.12); color: var(--blue); }
.cliente-tipo-badge.estatal { background: rgba(245,158,11,.15); color: #b45309; }
.cliente-tipo-badge.inactivo { background: rgba(107,114,128,.15); color: var(--muted); }
.cliente-meta { font-size: .8rem; color: var(--muted); }
.cliente-actions { display: flex; gap: 4px; flex-shrink: 0; }

.btn-icon {
  background: transparent;
  border: 1px solid transparent;
  width: 32px; height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: all .15s;
}
.btn-icon:hover {
  background: var(--bg-2);
  border-color: var(--border-2);
  color: var(--text);
}
.btn-icon.danger:hover { background: var(--red-bg); color: var(--red); border-color: rgba(239,68,68,.3); }
.btn-icon.success:hover { background: var(--green-bg); color: var(--green); }
.btn-icon.blue:hover { background: var(--blue-bg); color: var(--blue-d); }

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

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surf);
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  margin: 20px 0;
  animation: slideUp .25s ease-out;
}
.modal-lg { max-width: 800px; }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.15rem; color: var(--dark); }
.modal-close {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  color: var(--muted);
  cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg-2); color: var(--text); }
.modal-body { padding: 24px; }

/* Radio group */
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-option {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  transition: all .15s;
  min-width: 180px;
}
.radio-option:has(input:checked) {
  border-color: var(--gold);
  background: rgba(244,162,39,.08);
  color: var(--gold-d);
}
.radio-option input { cursor: pointer; }

/* Facturas list */
.facturas-list { display: flex; flex-direction: column; gap: 8px; }
.factura-item {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 14px;
  align-items: center;
  transition: border-color .15s;
}
.factura-item:hover { border-color: var(--gold); }
.factura-item.prefactura:hover { border-color: var(--blue); }
.factura-numero {
  font-weight: 700;
  color: var(--dark);
  font-family: monospace;
  font-size: 1rem;
}
.factura-info { min-width: 0; }
.factura-cliente {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.factura-meta { font-size: .78rem; color: var(--muted); }
.factura-fecha { font-size: .85rem; color: var(--text-2); white-space: nowrap; }
.factura-total {
  font-weight: 700;
  color: var(--dark);
  font-size: 1.05rem;
  white-space: nowrap;
}
.factura-estado {
  font-size: .68rem;
  padding: 3px 10px;
  border-radius: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.factura-estado.emitido { background: rgba(59,130,246,.15); color: var(--blue); }
.factura-estado.pagado { background: rgba(16,185,129,.15); color: var(--green); }
.factura-estado.anulado { background: rgba(239,68,68,.12); color: var(--red); text-decoration: line-through; }
.factura-estado.borrador { background: rgba(107,114,128,.15); color: var(--muted); }
.factura-estado.enviada { background: rgba(59,130,246,.15); color: var(--blue); }
.factura-estado.aceptada { background: rgba(16,185,129,.15); color: var(--green); }
.factura-estado.rechazada { background: rgba(239,68,68,.12); color: var(--red); }
.factura-estado.vencida { background: rgba(245,158,11,.15); color: #b45309; }
.factura-estado.convertida { background: rgba(139,92,246,.15); color: var(--purple); }
.factura-actions { display: flex; gap: 2px; }

/* Items section */
.items-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin: 8px 0;
  background: var(--bg);
}
.items-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.items-header h3 { font-size: .95rem; color: var(--text-2); }
.items-list { display: flex; flex-direction: column; gap: 6px; }
.item-row {
  display: grid;
  grid-template-columns: 1fr 80px 110px 100px 32px;
  gap: 6px;
  align-items: center;
  background: var(--surf);
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.item-row input {
  padding: 6px 8px;
  border: 1px solid var(--border-2);
  border-radius: 4px;
  font-size: .85rem;
  font-family: inherit;
  width: 100%;
}
.item-row input:focus { outline: none; border-color: var(--gold); }
.item-row input[readonly] {
  background: var(--bg-2);
  color: var(--text-2);
  font-weight: 600;
}
.item-row input.numero { text-align: right; }
.item-remove {
  background: transparent;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 1.1rem;
  border-radius: 4px;
  width: 32px;
  height: 32px;
}
.item-remove:hover { background: var(--red-bg); }
.items-empty {
  text-align: center;
  color: var(--muted);
  padding: 16px;
  font-size: .85rem;
  font-style: italic;
}

/* Totals box */
.totals-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  margin: 8px 0;
}
.totals-pref { background: var(--blue-bg); border-color: rgba(59,130,246,.2); }
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: .92rem;
  color: var(--text-2);
}
.total-row.total-grand {
  border-top: 2px solid var(--border-2);
  padding-top: 10px;
  margin-top: 6px;
  font-size: 1.1rem;
  color: var(--dark);
  font-weight: 700;
}
.total-row.total-grand-pref { border-top-color: var(--blue-d); }
.total-row strong { font-family: monospace; font-size: 1.02em; }

/* Ver factura */
.factura-view { font-family: -apple-system, sans-serif; }
.factura-view h3 { color: var(--dark); margin-bottom: 8px; }
.factura-view .fv-section { margin-bottom: 18px; }
.factura-view .fv-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.factura-view .fv-value { color: var(--text); font-weight: 500; }
.factura-view .fv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; }
.factura-view table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.factura-view th { background: var(--bg-2); padding: 8px; text-align: left; font-size: .78rem; text-transform: uppercase; color: var(--muted); }
.factura-view td { padding: 8px; border-bottom: 1px solid var(--border); font-size: .9rem; }
.factura-view td.num { text-align: right; font-family: monospace; }

/* Vencimiento badge */
.vencimiento-badge {
  display: inline-block;
  background: var(--yellow-bg);
  color: #b45309;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: .72rem;
  font-weight: 600;
  margin-left: 4px;
}
.vencimiento-badge.vencido { background: var(--red-bg); color: var(--red); }

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  .topbar-inner { flex-wrap: wrap; }
  .logo h1 { font-size: 1rem; }
  .nav { top: 70px; }
  .form-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .btn { width: 100%; justify-content: center; }
  .filters { flex-direction: column; align-items: stretch; }
  .search-wrap { max-width: 100%; }
  .cliente-item { flex-direction: column; align-items: stretch; }
  .cliente-actions { justify-content: flex-end; }
  .factura-item { grid-template-columns: 1fr; gap: 6px; }
  .factura-actions { justify-content: flex-end; }
  .item-row { grid-template-columns: 1fr; }
  .modal-lg { max-width: 100%; }
}
/* ═══════ AUDITORÍA ═══════ */

.aud-filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.aud-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Métricas */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.metric-card {
  background: var(--surf);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  box-shadow: var(--shadow);
}
.metric-card.metric-blue { border-left-color: var(--blue); }
.metric-card.metric-green { border-left-color: var(--green); }
.metric-card.metric-yellow { border-left-color: var(--yellow); }

.metric-label {
  font-size: .78rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--dark);
  font-family: monospace;
  margin-bottom: 4px;
}

.metric-hint {
  font-size: .75rem;
  color: var(--muted);
}

.aud-double {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Desglose por tipo/estado */
.aud-breakdown {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.aud-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.aud-row-label {
  font-weight: 600;
  text-transform: capitalize;
}

.aud-row-count {
  color: var(--muted);
  font-size: .85rem;
}

.aud-row-monto {
  font-family: monospace;
  font-weight: 700;
  color: var(--dark);
  min-width: 100px;
  text-align: right;
}

/* Top clientes */
.top-cliente {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
}

.top-pos {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8rem;
}

.top-pos.pos-2 { background: #c0c0c0; }
.top-pos.pos-3 { background: #cd7f32; color: #fff; }

.top-cliente-info { min-width: 0; }
.top-cliente-nombre {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-cliente-meta {
  font-size: .78rem;
  color: var(--muted);
}

/* Huecos */
.huecos-result {
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.huecos-ok {
  background: var(--green-bg);
  color: #047857;
  border: 1px solid rgba(16,185,129,.3);
}

.huecos-warn {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239,68,68,.3);
}

.serie-block {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.serie-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.serie-name {
  font-weight: 700;
  font-family: monospace;
  font-size: 1.05rem;
}

.serie-range {
  font-size: .85rem;
  color: var(--muted);
}

.huecos-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.hueco-num {
  background: var(--red-bg);
  color: var(--red);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: monospace;
  font-size: .8rem;
  font-weight: 600;
}

/* Historial cronológico */
.historial-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.historial-row {
  display: grid;
  grid-template-columns: 90px 90px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 6px;
  font-size: .88rem;
  border: 1px solid var(--border);
}

.historial-row.tipo-prefactura { border-left: 3px solid var(--blue); }
.historial-row.tipo-factura { border-left: 3px solid var(--gold); }
.historial-row.estado-anulado { opacity: 0.6; text-decoration: line-through; }

.hist-num {
  font-family: monospace;
  font-weight: 700;
  color: var(--dark);
}

.hist-fecha {
  font-size: .8rem;
  color: var(--muted);
}

.hist-cliente {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hist-total {
  font-family: monospace;
  font-weight: 700;
  text-align: right;
}

@media (max-width: 800px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .aud-double { grid-template-columns: 1fr; }
  .historial-row { grid-template-columns: 1fr; gap: 4px; padding: 10px 12px; }
}
/* ═══════ RECIBOS ═══════ */

.factura-item.recibo:hover { border-color: var(--green); }
.factura-numero.recibo { color: var(--green) !important; }
.historial-row.tipo-recibo { border-left: 3px solid var(--green); }
/* ═══════ CONTRATOS ═══════ */

.factura-item.contrato:hover { border-color: #7c3aed; }
.factura-numero.contrato { color: #5b21b6 !important; }
.historial-row.tipo-contrato { border-left: 3px solid #7c3aed; }

.factura-estado.borrador { background: rgba(107,114,128,.15); color: var(--muted); }
.factura-estado.enviado { background: rgba(59,130,246,.15); color: var(--blue); }
.factura-estado.firmado { background: rgba(16,185,129,.15); color: var(--green); }
.factura-estado.vencido { background: rgba(245,158,11,.15); color: #b45309; }
.factura-estado.rescindido { background: rgba(239,68,68,.12); color: var(--red); }

.plantillas-list {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.plantilla-card {
  background: var(--surf);
  border: 2px solid var(--border-2);
  border-radius: 8px;
  padding: 14px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all .15s;
}
.plantilla-card:hover {
  border-color: #7c3aed;
  background: #faf5ff;
}
.plantilla-card.selected {
  border-color: #7c3aed;
  background: #f3e8ff;
  box-shadow: 0 0 0 3px rgba(124,58,237,.15);
}

.plantilla-card h4 {
  font-size: .95rem;
  margin-bottom: 4px;
  color: var(--dark);
}
.plantilla-card p {
  font-size: .78rem;
  color: var(--muted);
  margin: 0;
}

.card-mini {
  background: #faf5ff;
  border: 1px solid #ddd6fe;
  border-radius: 8px;
  padding: 14px;
  margin: 8px 0;
}

.contrato-view-content {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: 'Courier New', monospace;
  font-size: .85rem;
  white-space: pre-wrap;
  line-height: 1.5;
  max-height: 400px;
  overflow-y: auto;
}

@media (max-width: 800px) {
  .plantillas-list { grid-template-columns: 1fr; }
}