:root {
  --azul: #0f4c81;
  --azul-claro: #e8f0f8;
  --verde: #1b8a5a;
  --rojo: #c0392b;
  --gris: #6b7280;
  --gris-claro: #f3f4f6;
  --borde: #e2e6ea;
  --texto: #1f2937;
  --sombra: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--texto);
  background: #f7f8fa;
  line-height: 1.5;
}

.app-header {
  background: var(--azul);
  color: #fff;
  padding: 24px 16px;
  text-align: center;
}
.app-header h1 { margin: 0; font-size: 1.6rem; }
.subtitle { margin: 4px 0 0; opacity: 0.85; font-size: 0.95rem; }

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.card {
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--sombra);
}
.card h2 { margin: 0 0 14px; font-size: 1.1rem; color: var(--azul); }

/* Campos */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.82rem; font-weight: 600; color: var(--gris); }
.field input {
  padding: 10px 12px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  font-size: 1rem;
  width: 100%;
}
.field input:focus { outline: 2px solid var(--azul); border-color: var(--azul); }

.field-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.field-monto input { max-width: 260px; font-weight: 700; }

.factura-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}
.field-grow { min-width: 0; }
.factura-form .btn { align-self: end; height: 42px; }

/* Botones */
.btn {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--azul); color: #fff; }
.btn-guardar { background: var(--verde); color: #fff; }
.btn-ghost { background: transparent; color: var(--rojo); border: 1px solid var(--rojo); }

.actions { align-items: center; flex-wrap: wrap; }
.guardado-estado {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--verde);
  opacity: 0;
  transition: opacity 0.2s;
}
.guardado-estado.visible { opacity: 1; }
.guardado-estado.error { color: var(--rojo); }
.nota-guardado {
  font-size: 0.85rem;
  color: var(--gris);
  margin: 10px 2px 0;
}
.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--rojo);
  font-size: 1.1rem;
  padding: 4px 6px;
}
.btn-icon.btn-editar { color: var(--azul); }
.acciones-fila { white-space: nowrap; }
tr.editando { background: var(--azul-claro); }

/* Tabla */
.table-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.badge {
  background: var(--azul-claro);
  color: var(--azul);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--borde); }
th { font-size: 0.8rem; color: var(--gris); text-transform: uppercase; letter-spacing: 0.03em; }
.text-right { text-align: right; }
td.text-right { font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--gris); padding: 24px; font-style: italic; }

/* Resumen */
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--borde);
  font-size: 1rem;
}
.summary-row.total {
  font-size: 1.3rem;
  font-weight: 800;
  border-bottom: none;
  color: var(--verde);
  padding-top: 14px;
}
.summary-row.total.negativo { color: var(--rojo); }
.alerta { color: var(--rojo); font-weight: 600; margin: 10px 0 0; }
.hidden { display: none; }

/* Acciones */
.actions { display: flex; gap: 12px; margin-top: 8px; }

/* Encabezado y firma (solo impresión) */
.print-header { display: none; }
.print-datos { display: flex; flex-wrap: wrap; gap: 8px 32px; margin-bottom: 12px; font-size: 0.95rem; }
.print-footer { display: none; }
.firma { margin-top: 50px; }
.firma-linea { display: block; width: 260px; border-top: 1px solid #333; margin-bottom: 6px; }

/* Responsive */
@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
  .factura-form { grid-template-columns: 1fr; }
  .factura-form .btn { width: 100%; }
}

/* Impresión */
@media print {
  body { background: #fff; }
  .app-header { background: #fff; color: #000; border-bottom: 2px solid #000; }
  .no-print, .no-print-controls, .btn-icon, .actions { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .print-footer { display: block; }
  .print-header { display: block; }
  table { font-size: 0.82rem; }
  th, td { padding: 6px 8px; }
  th:last-child, td:last-child { display: none; }
}
