/* ============================================================================
   Facturas SAT · Portal FEL — Tema claro, elegante y formal
   ============================================================================ */
:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --border: #e6e9f2;
  --border-soft: #eef1f7;
  --text: #16233b;
  --muted: #667085;
  --navy: #0f2b4c;
  --navy-2: #1e3a8a;
  --accent: #1d4ed8;
  --accent-dark: #1e40af;
  --accent-soft: #eef4ff;
  --green: #15803d;
  --red: #c0392b;
  --amber: #b45309;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px -4px rgba(16, 24, 40, 0.12), 0 2px 6px -2px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 24px 64px -12px rgba(15, 23, 42, 0.28), 0 8px 24px -8px rgba(15, 23, 42, 0.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1140px; margin: 0 auto; padding: 0 24px; }

/* ------------------------------ Encabezado ------------------------------ */
.topbar {
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #fff;
  padding: 16px 0;
  box-shadow: var(--shadow-md);
  margin-bottom: 26px;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; font-weight: 800; color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15);
}
.brand-text h1 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: 0.01em; line-height: 1.1; }
.brand-text .subtitle { color: rgba(255, 255, 255, 0.72); font-size: 12.5px; }
.sesion-top {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
}

main { padding-bottom: 70px; }

/* ------------------------------ Tarjetas ------------------------------ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
  margin-bottom: 22px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 700; color: var(--text); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.grid label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.form-actions { display: flex; align-items: flex-end; }

/* ------------------------------ Inputs ------------------------------ */
input, select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--font);
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.14);
}
input::placeholder { color: #a3adc2; }

/* ------------------------------ Botones ------------------------------ */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.06s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  box-shadow: 0 4px 12px -4px rgba(29, 78, 216, 0.55);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 6px 16px -4px rgba(29, 78, 216, 0.65); filter: brightness(1.04); }
.btn-secondary { background: var(--accent-soft); color: var(--accent-dark); }
.btn-secondary:hover:not(:disabled) { background: #e2eafd; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); }

.hint { font-size: 12.5px; color: var(--muted); margin: 12px 0 0; }
.muted { color: var(--muted); }

.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 12.5px;
  font-weight: 700;
  vertical-align: middle;
}

/* ------------------------------ Progreso ------------------------------ */
.progress-track {
  height: 8px;
  background: var(--border-soft);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #3b82f6);
  border-radius: 999px;
  transition: width 0.2s;
}
.progress span { font-size: 12.5px; }

/* ------------------------------ Tablas ------------------------------ */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.table-wrap table { border-collapse: separate; border-spacing: 0; }
table { width: 100%; font-size: 13.5px; }
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  background: #f2f4f9;
  color: #41516b;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 14px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: #fafbfd; }
tbody tr:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.col-check { width: 30px; }

.estado-vigente { color: var(--green); font-weight: 700; }
.estado-anulada { color: var(--red); font-weight: 700; }
.estado-rechazada { color: var(--red); font-weight: 700; }
.estado-desconocido { color: var(--amber); font-weight: 700; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 2px 4px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--accent-dark); }
.link-btn:disabled { opacity: 0.5; cursor: wait; }

/* ------------------------------ Toast ------------------------------ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 13px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  max-width: 90vw;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
.hidden { display: none !important; }

/* ------------------------------ Login ------------------------------ */
.login-card { max-width: 460px; margin: 60px auto; }
.login-card h2 { font-size: 22px; font-weight: 800; color: var(--navy); }
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login-form .btn { align-self: stretch; margin-top: 6px; padding: 12px; font-size: 15px; }

/* ------------------------------ Resumen / acciones ------------------------------ */
.resumen { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.resumen .mini {
  flex: 1 1 150px;
  background: linear-gradient(180deg, #fafbfd, #f5f6fa);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
}
.resumen .mini .k { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.resumen .mini .v { font-size: 19px; font-weight: 800; color: var(--text); margin-top: 3px; }
.acciones { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }

/* ------------------------------ Análisis ------------------------------ */
.an-head { margin: 6px 0 18px; }
.an-head h2 { font-size: 22px; font-weight: 800; color: var(--navy); margin: 0; }
.an-head .muted { margin: 2px 0 0; font-size: 13px; }
.an-select { min-width: 320px; }
.an-selector { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.an-search { min-width: 220px; }
.chart-wrap { position: relative; height: 320px; margin: 12px 0 18px; }
#an-prod-nombre { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
table.compact { font-size: 13px; }
table.compact td, table.compact th { padding: 8px 12px; }

/* ------------------------------ Modal (carga) ------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 34, 0.52);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
}
.modal {
  position: relative;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 26px 30px;
  width: min(440px, 92vw);
  animation: modal-in 0.18s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal h3 { margin: 0 0 14px; font-size: 17px; font-weight: 700; color: var(--text); }
.modal .progress-track { margin: 8px 0 14px; }
.modal .muted { font-size: 13px; margin: 0; }
.modal-acciones { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.modal-acciones .btn { width: 100%; padding: 11px; font-size: 14px; }
.modal-lg { width: min(780px, 94vw); max-height: 88vh; overflow: auto; }
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px; height: 32px;
  border: none;
  border-radius: 9px;
  background: #f2f4f9;
  color: #41516b;
  font-size: 15px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  z-index: 2;
}
.modal-close:hover { background: #e4e8f1; }

/* ------------------------------ Modal de factura (estilo factura) ------------------------------ */
.factura { font-size: 13.5px; color: var(--text); }
.factura-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border-soft);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.factura-emisor { display: flex; gap: 12px; align-items: center; }
.factura-marca {
  width: 48px; height: 48px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--navy));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800;
  box-shadow: var(--shadow-sm);
}
.factura-empresa { font-weight: 800; font-size: 15px; color: var(--text); }
.factura-nit { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.factura-titulo { text-align: right; }
.factura-doc { font-size: 20px; font-weight: 800; color: var(--navy); text-transform: uppercase; letter-spacing: 0.04em; }
.factura-num { font-size: 15px; font-weight: 700; color: var(--text); margin-top: 2px; }
.factura-uuid { font-size: 11px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.factura-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 26px;
  font-size: 12.5px;
  background: #fafbfd;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
}
.factura-meta span { color: var(--muted); }
.factura-items { width: 100%; border-collapse: collapse; }
.factura-items thead th { background: var(--accent-soft); color: var(--accent-dark); }
.factura-totales {
  margin-top: 16px;
  margin-left: auto;
  width: min(340px, 100%);
  border-top: 2px solid var(--border-soft);
  padding-top: 12px;
}
.factura-total-fila {
  display: flex; justify-content: space-between;
  padding: 5px 0; font-size: 13.5px; color: var(--muted);
}
.factura-total-fila.total {
  font-size: 17px; font-weight: 800; color: var(--navy);
  border-top: 1px solid var(--border);
  margin-top: 8px; padding-top: 10px;
}

/* ------------------------------ Paginación ------------------------------ */
.paginacion {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 0 8px;
}
.paginacion .btn { font-size: 13px; padding: 7px 14px; }
.paginacion .btn:disabled { opacity: 0.4; }
#pag-info { font-size: 13px; color: var(--muted); }

/* ------------------------------ Scrollbars (elegante) ------------------------------ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c9d2e0; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #aab6c9; background-clip: padding-box; }
