/* Piezas reutilizables: botones, tablas, modales, formularios, pastillas. */



#app { min-height: 100vh; }



input, select, textarea {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.6rem 0.75rem; font-size: 0.9rem; font-family: inherit;
  outline: none; transition: border-color 0.15s;
}


input:focus, select:focus, textarea:focus { border-color: var(--purple); }


label { display: block; font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.35rem; font-weight: 500; }


/* Label que envuelve un checkbox: necesita flex para alinear la casilla
   con su texto. Se define aquí (y no en línea) porque el "display:block"
   de la regla de arriba le gana a un style inline en algunos casos y
   rompe el acomodo. */
label.check-inline {
  display: flex; align-items: center; gap: 0.5rem; font-weight: normal;
  color: var(--text); white-space: normal;
}


label.check-inline input[type="checkbox"] { flex: 0 0 auto; margin: 0; width: auto; }


.field { margin-bottom: 1rem; }



.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: none; border-radius: 8px; padding: 0.6rem 1.1rem; font-weight: 600; font-size: 0.85rem;
  cursor: pointer; transition: opacity 0.15s, transform 0.1s;
}


.btn:active { transform: scale(0.98); }


.btn-primary { background: var(--gradient); color: white; }


.btn-primary:hover { opacity: 0.9; }


.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }


.btn-secondary:hover { background: var(--bg-hover); }


.btn-full { width: 100%; }


.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; }

.btn-peligro { background: rgba(239,68,68,0.12); color: #f87171; border: 1px solid rgba(239,68,68,0.4); }
.btn-peligro:hover { background: rgba(239,68,68,0.22); }


.btn:disabled { opacity: 0.5; cursor: not-allowed; }



.error-box { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.4); color: #fca5a5;
  border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.82rem; margin-bottom: 1rem; }



/* ---------- Cards / tables ---------- */
.card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; }


.card + .card { margin-top: 1rem; }


.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }


.card-head h2 { font-size: 0.95rem; font-weight: 700; margin: 0; }



.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.9rem; }


.pick-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem;
  cursor: pointer; text-align: left; color: var(--text); transition: border-color 0.15s, transform 0.1s;
}


.pick-card:hover { border-color: var(--purple); transform: translateY(-1px); }


.pick-card .t { font-weight: 700; font-size: 0.92rem; }


.pick-card .s { font-size: 0.76rem; color: var(--text-muted); margin-top: 0.2rem; }



table.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }


table.data-table th {
  text-align: left; padding: 0.6rem 0.75rem; color: var(--text-muted); font-weight: 600;
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border);
}


table.data-table td { padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border); }


table.data-table tr:hover td { background: var(--bg-hover); cursor: pointer; }


table.data-table tr:last-child td { border-bottom: none; }



.pivot-table { overflow-x: auto; }


.pivot-table table { border-collapse: collapse; font-size: 0.82rem; min-width: 100%; }


.pivot-table th, .pivot-table td { border: 1px solid var(--border); padding: 0.55rem 0.8rem; text-align: center; white-space: nowrap; }


.pivot-table th { background: var(--bg-card); color: var(--text-muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; }


.pivot-table td.proyecto-cell { text-align: left; font-weight: 600; background: var(--bg-card); position: sticky; left: 0; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }


.pivot-table td.count-cell.has-value { color: white; font-weight: 700; background: rgba(124,58,237,0.18); }


.pivot-table td.count-cell { color: var(--text-muted); }



.pill { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 9999px; font-size: 0.72rem; font-weight: 700; }


.pill-green { background: rgba(34,197,94,0.15); color: #4ade80; }


.pill-red { background: rgba(239,68,68,0.15); color: #f87171; }


.pill-gray { background: rgba(151,151,184,0.15); color: var(--text-muted); }



.empty-state { color: var(--text-muted); font-size: 0.85rem; padding: 1.5rem 0; text-align: center; }



.search-row { display: flex; gap: 0.6rem; margin-bottom: 1rem; }


.search-row input { flex: 1; }



/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5,5,15,0.7); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}


.modal-box {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 1.5rem;
}


.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: -1.5rem; z-index: 5;
  margin: -1.5rem -1.5rem 1.1rem -1.5rem;
  padding: 1.5rem 1.5rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}


.modal-head h2 { font-size: 1.02rem; font-weight: 700; margin: 0; }


.modal-close { color: var(--text-muted); cursor: pointer; font-size: 1.3rem; line-height: 1; background: none; border: none; }


.modal-close:hover { color: var(--text); }


.modal-actions {
  display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem;
  position: sticky; bottom: -1.5rem; z-index: 5;
  padding: 1rem 1.5rem 1.5rem; margin-left: -1.5rem; margin-right: -1.5rem; margin-bottom: -1.5rem;
  background: var(--bg-panel); border-top: 1px solid var(--border);
}


.panel-campos {
  border-left: 3px solid transparent; padding-left: 0.85rem; margin-left: -0.85rem;
  border-radius: 6px; transition: border-color 0.15s, background 0.15s;
}


.panel-campos.solo-lectura input,
.panel-campos.solo-lectura select,
.panel-campos.solo-lectura textarea {
  background: transparent; border-color: transparent; color: var(--text);
  cursor: default; padding-left: 0;
}


.panel-campos.solo-lectura input::placeholder { color: transparent; }


.panel-campos.solo-lectura .combo-multi,
.panel-campos.solo-lectura .toggle-switch,
.panel-campos.solo-lectura input[type=file] {
  pointer-events: none; opacity: 0.7;
}


.panel-campos.modo-edicion {
  border-left-color: var(--purple);
  background: rgba(139, 92, 246, 0.05);
  padding-top: 0.6rem; padding-bottom: 0.2rem; padding-right: 0.4rem;
}


.panel-campos.modo-edicion input,
.panel-campos.modo-edicion select,
.panel-campos.modo-edicion textarea { cursor: text; }



.tabs { display: flex; gap: 0.3rem; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; }


.tab-btn { background: none; border: none; color: var(--text-muted); padding: 0.55rem 0.9rem; font-weight: 600;
  font-size: 0.85rem; cursor: pointer; border-bottom: 2px solid transparent; }


.tab-btn.active { color: white; border-color: var(--purple); }



.detail-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 0.9rem; font-size: 0.85rem; margin-bottom: 1rem; }


.detail-box div { margin-bottom: 0.25rem; }


.detail-box .k { color: var(--text-muted); }



.toggle-switch { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; }


.toggle-track { width: 34px; height: 18px; border-radius: 999px; background: var(--border); position: relative; transition: background 0.15s; }


.toggle-track.on { background: var(--gradient); }


.toggle-thumb { width: 14px; height: 14px; border-radius: 50%; background: white; position: absolute; top: 2px; left: 2px; transition: left 0.15s; }


.toggle-track.on .toggle-thumb { left: 18px; }



/* --------------------------------------------------------------
   Notificaciones tipo "toast" (confirmación de guardado/errores)
-------------------------------------------------------------- */
#toast-container {
  position: fixed; top: 1rem; right: 1rem; z-index: 500;
  display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none;
}


.toast {
  background: var(--bg-card); border: 1px solid var(--border); border-left: 4px solid var(--purple);
  border-radius: 8px; padding: 0.7rem 1rem; font-size: 0.85rem; color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45); min-width: 220px; max-width: 360px;
  display: flex; align-items: center; gap: 0.5rem; opacity: 1; transition: opacity 0.25s, transform 0.25s;
}


.toast.exito { border-left-color: #22c55e; }


.toast.error { border-left-color: #ef4444; }


.toast.saliendo { opacity: 0; transform: translateX(16px); }



/* Botón de guardar en estado "guardando..." */
.btn-primary:disabled { opacity: 0.65; cursor: wait; }



/* --------------------------------------------------------------
   Facturas con estado_sat = CANCELADO: muy visibles en la tabla.
   (especificidad alta a propósito, para ganarle al hover genérico
   de table.data-table tr:hover td)
-------------------------------------------------------------- */
table.data-table tr.fila-cancelada td {
  background: rgba(239, 68, 68, 0.08);
}


table.data-table tr.fila-cancelada:hover td {
  background: rgba(239, 68, 68, 0.16);
}


.pill-alerta {
  font-weight: 800;
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.5);
}



/* --------------------------------------------------------------
   Tipo de comprobante: factura (ingreso) vs nota de crédito (egreso)
-------------------------------------------------------------- */
.pill-blue { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }


.pill-naranja { background: rgba(249, 115, 22, 0.15); color: #fb923c; font-weight: 800; }

/* Campo llenado por la IA en el pre-registro: se marca hasta que la
   persona lo toque, para que sepa qué revisar. */
.sugerido-ia {
  outline: 2px solid #a78bfa;
  outline-offset: 1px;
  background-color: rgba(167, 139, 250, 0.08);
}

/* Distintivo "Llenado con IA": destello propio en terracota */
.marca-ia {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.12rem 0.5rem; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.01em;
  color: #e8a07a; background: rgba(200, 100, 59, 0.12);
  border: 1px solid rgba(200, 100, 59, 0.35);
  white-space: nowrap; vertical-align: middle;
}
.marca-ia-compacta { padding: 0.1rem 0.25rem; margin-left: 0.3rem; }

/* De qué documento y página salió un dato (bajo el campo) */
.fuente-ia {
  display: flex; align-items: center; gap: 0.3rem;
  margin-top: 0.2rem; font-size: 0.68rem; color: #d99470; cursor: help;
}

/* ---- Registrar con IA: pantalla amplia de revisión ---------------- */
.modal-box.modal-ancho { width: min(1100px, 96vw); max-width: 96vw; }
.boton-ia { background: linear-gradient(135deg, #d9825b, #b8552f) !important; }
.ia-resumen {
  display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; margin: -0.2rem 0 0.9rem;
  font-size: 0.82rem; color: var(--text-muted);
}
.ia-leyendo {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding: 2.5rem 1rem; text-align: center;
}
.ia-leyendo-destello svg { width: 42px; height: 42px; animation: ia-latido 1.4s ease-in-out infinite; }
@keyframes ia-latido { 0%, 100% { opacity: 0.45; transform: scale(0.92); } 50% { opacity: 1; transform: scale(1.06); } }
.ia-registro { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.2rem; }
.ia-campos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 0.9rem; margin-top: 0.5rem; }
.ia-campo-ancho { grid-column: 1 / -1; }
.ia-lateral {
  border-left: 1px solid var(--border, rgba(255, 255, 255, 0.08)); padding-left: 1rem;
  font-size: 0.8rem;
}
.ia-lista { margin: 0.4rem 0 0; padding-left: 1.1rem; }
.ia-lista li { margin-bottom: 0.3rem; }
.ia-avisos li { color: #f5c26b; }
.ia-nota { margin-top: 1rem; font-size: 0.72rem; color: var(--text-muted); }
@media (max-width: 800px) {
  .ia-registro { grid-template-columns: 1fr; }
  .ia-lateral { border-left: 0; padding-left: 0; }
  .ia-campos { grid-template-columns: 1fr; }
}
.ia-no-disponible { font-size: 0.7rem; color: #f5c26b; max-width: 280px; margin-top: 0.3rem; }
.ia-notas { margin-top: 0.6rem; font-size: 0.78rem; }
.ia-notas summary { cursor: pointer; color: #e8a07a; }
.ia-notas ul { margin: 0.3rem 0 0; padding-left: 1.1rem; }
.identificador-previo { font-size: 0.78rem; color: var(--text-muted); margin: -0.2rem 0 0.8rem; }



/* ============================================================
   MODAL: FIANZAS DEL CONTRATO
   Ancho personalizado sin afectar otros modales
   ============================================================ */

.modal-box.modal-fianzas {
  width: min(1100px, calc(100vw - 32px));
  max-width: 1100px;
}

@media (max-width: 640px) {
  .modal-box.modal-fianzas {
    width: calc(100vw - 20px);
  }
}
