:root {
  --azul: #1f4e79;
  --azul-osc: #14345a;
  --bg: #f3f5f8;
  --card: #ffffff;
  --texto: #22303f;
  --muted: #6b7a8c;
  --borde: #dde4ec;
  --ok: #1e7d46;
  --ok-bg: #e3f4ea;
  --err: #b3261e;
  --err-bg: #fdecea;
  --proc: #8a5a00;
  --proc-bg: #fff4d6;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--texto);
  font-size: 15px;
}

/* ── Barra superior ── */
.topbar {
  background: var(--azul);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 54px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.topbar .brand { font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.topbar .cliente-switch {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px;
  padding: 4px 10px;
}
.topbar .cliente-switch label { font-size: 12.5px; font-weight: 600; color: #e3eefb; white-space: nowrap; }
.topbar .cliente-switch select {
  border: none; border-radius: 5px; padding: 4px 6px;
  font-size: 13px; font-weight: 600; color: #1d3557;
  background: #fff; max-width: 240px;
}
.topbar nav { display: flex; gap: 4px; align-items: center; }
.topbar nav a {
  color: #cfe0f2;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
}
.topbar nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.topbar nav a.act { background: rgba(255,255,255,.22); color: #fff; font-weight: 600; }
.topbar nav a.logout { color: #ffd6d1; }

.container { max-width: 1200px; margin: 0 auto; padding: 22px 20px 60px; }
h1 { font-size: 22px; margin: 4px 0 16px; color: var(--azul); }
.h1-cliente { color: var(--muted); font-weight: 600; font-size: 17px; }
h2 { font-size: 17px; margin: 22px 0 10px; color: var(--azul); }
h3 { font-size: 15px; margin: 14px 0 8px; }
hr { border: none; border-top: 1px solid var(--borde); margin: 14px 0; }

/* ── Cards / grid ── */
.card {
  background: var(--card);
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(16,34,56,.06);
}
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
  margin-bottom: 10px;
}
.stat-card .stat-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stat-card.activo { border: 2px solid var(--azul); }
.stat-nombre { font-weight: 600; }
.stat-rfc { color: var(--muted); font-size: 13px; margin: 3px 0 10px; }
.stat-num { font-size: 30px; font-weight: 700; color: var(--azul); }
.stat-num small { font-size: 13px; color: var(--muted); font-weight: 400; }
.stat-acciones { margin-top: 10px; display: flex; gap: 6px; }
.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ── Tablas ── */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  background: #eef2f7;
  color: var(--azul);
  padding: 8px 10px;
  border-bottom: 2px solid var(--borde);
  white-space: nowrap;
}
.table td { padding: 8px 10px; border-bottom: 1px solid var(--borde); vertical-align: top; }
.table tr:hover td { background: #f7fafc; }
.table.kv th { background: transparent; border: none; color: var(--muted); font-weight: 600; width: 140px; }
.moneda, .nowrap { white-space: nowrap; }
.actions { white-space: nowrap; }
.actions form { display: inline; }
code {
  background: #eef1f5;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12.5px;
  color: var(--azul-osc);
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: #e9edf2;
  color: #44566a;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.proc { background: var(--proc-bg); color: var(--proc); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ing { background: #e2f0e6; color: var(--ok); }
.badge.pag { background: #e4ecfa; color: #29589c; }
.badge.fisica { background: #e4ecfa; color: #29589c; }
.badge.moral { background: #efe4fa; color: #6b2f9c; }

/* ── Botones ── */
.btn {
  display: inline-block;
  border: 1px solid var(--borde);
  background: #fff;
  color: var(--texto);
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #f0f4f9; }
.btn.primary { background: var(--azul); border-color: var(--azul); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--azul-osc); }
.btn.small { padding: 4px 9px; font-size: 12.5px; border-radius: 6px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: #f0c4c0; }
.btn.danger:hover { background: var(--err-bg); }

/* ── Formularios ── */
.form label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: 13.5px; color: #33475c; }
.form input[type=text], .form input[type=password], .form input[type=date],
.form input[type=number], .form input[type=email], .form input[type=datetime-local],
.form select, .form textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--borde);
  border-radius: 7px;
  font-size: 14px;
  background: #fff;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: 2px solid #9db8d8;
  border-color: var(--azul);
}
.form input[type=file] { margin-top: 4px; font-size: 13px; }
.form-actions { margin-top: 18px; display: flex; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters select, .filters input[type=text] {
  padding: 8px 10px;
  border: 1px solid var(--borde);
  border-radius: 7px;
  font-size: 13.5px;
  background: #fff;
}

/* Formulario compacto de descarga (una sola fila) */
.desc-form { align-items: flex-end; }
.f-field { display: flex; flex-direction: column; }
.f-field select, .f-field input[type=date] {
  padding: 8px 10px;
  border: 1px solid var(--borde);
  border-radius: 7px;
  font-size: 13.5px;
  background: #fff;
}
.f-field select:focus, .f-field input[type=date]:focus {
  outline: 2px solid #9db8d8;
  border-color: var(--azul);
}
.f-field select { min-width: 260px; }
.f-field input[type=date] { min-width: 150px; }
.f-label { font-size: 11.5px; font-weight: 600; color: #33475c; margin-bottom: 3px; }
.desc-btn { align-self: flex-end; padding: 8px 14px; }

/* ── Flashes ── */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #bcddca; }
.flash.err { background: var(--err-bg); color: var(--err); border: 1px solid #f0c4c0; }
.flash.proc { background: var(--proc-bg); color: var(--proc); border: 1px solid #ecd9a0; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.page-head { display: flex; justify-content: space-between; align-items: center; }

.btn-cancel {
  background: #fdecea; color: #c0392b; border: 1px solid #f5c6c2;
  border-radius: 6px; padding: 3px 9px; font-size: 12px; cursor: pointer;
}
.btn-cancel:hover { background: #fadbd8; }
.btn-cancel:disabled { opacity: .5; cursor: default; }

/* Fila de totales al final del listado */
tr.totales { background: #eef4fb; border-top: 2px solid var(--azul); }
tr.totales td { padding: 9px 10px; font-size: 13.5px; }

/* Estatus Vigente/Cancelado (círculos V/C) */
.est-cir {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 13px; font-weight: 800; color: #fff;
}
.est-cir.v { background: #2e9e5b; }
.est-cir.c { background: #d64545; }

/* Moneda (círculo con banderita) */
.mon-cir {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: #f0f4fa; border: 1px solid var(--borde);
  font-size: 15px; cursor: default;
}
.center { text-align: center; }

/* Folio como enlace al detalle */
.folio-link { color: var(--azul); font-weight: 600; text-decoration: underline dotted; cursor: pointer; }
.folio-link:hover { color: #163a63; }

/* Paginación (pestañitas) */
.paginacion { display: flex; align-items: center; gap: 6px; margin: 10px 0 4px; flex-wrap: wrap; }
.pag-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 9px;
  border: 1px solid var(--borde); border-radius: 7px;
  background: var(--card); color: var(--azul);
  font-size: 13.5px; font-weight: 600; text-decoration: none;
}
.pag-btn:hover { border-color: var(--azul); }
.pag-btn.act { background: var(--azul); border-color: var(--azul); color: #fff; }
.dots { color: var(--muted); padding: 0 2px; }

/* ── Conceptos dinámicos (formulario de factura) ── */
.concepto-row {
  background: #f8fafc;
  border: 1px dashed var(--borde);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
}
.concepto-grid {
  display: grid;
  grid-template-columns: 1.5fr .6fr .8fr .6fr 1.8fr auto auto;
  gap: 6px;
  align-items: center;
}
.concepto-grid input, .concepto-grid select { width: 100%; min-width: 0; }
/* Modo factura global: el renglón es UN ticket → folio, importe, descuento y total */
.concepto-grid.global { grid-template-columns: 1.4fr .9fr .6fr auto auto; }
.row-total { font-weight: 700; color: var(--azul); white-space: nowrap; text-align: right; font-size: 13px; }
@media (max-width: 900px) {
  .concepto-grid, .concepto-grid.global { grid-template-columns: 1fr 1fr; }
  .concepto-grid .row-total { text-align: left; }
}

/* ── «Últimos datos del cliente» y captura por TOTAL (formulario de factura) ── */
.ultimos-cli { margin-top: 6px; }
.chk-linea {
  display: flex; align-items: flex-start; gap: 6px; font-weight: 500 !important;
  font-size: 12.5px !important; color: var(--muted) !important; margin: 4px 0 2px !important;
  cursor: pointer;
}
.chk-linea input { margin-top: 2px; }
.ok-txt { color: var(--ok); }
.err-txt { color: var(--err); }

.captura-total {
  display: grid; grid-template-columns: 1fr minmax(260px, 380px); gap: 16px;
  align-items: start; margin-top: 14px; padding: 12px 14px;
  background: #f8fafc; border: 1px dashed var(--borde); border-radius: 8px;
}
.ct-fila { display: flex; gap: 8px; align-items: center; }
.ct-fila input { flex: 1 1 140px; min-width: 110px; }
.ct-fila .btn { white-space: nowrap; }
.resumen-mini { font-size: 13px; }
.resumen-mini td { padding: 4px 8px; }
.resumen-mini tr.dest td { font-size: 14px; }
@media (max-width: 900px) {
  .captura-total { grid-template-columns: 1fr; }
}

/* ── Details/summary (cancelación) ── */
details { margin: 8px 0; }
summary.btn { list-style: none; cursor: pointer; }
summary.btn::-webkit-details-marker { display: none; }

/* ── Login ── */
.login-wrap { display: flex; justify-content: center; padding-top: 10vh; }
.login-card { max-width: 380px; width: 100%; text-align: center; }
.login-card h1 { margin-bottom: 2px; }
.login-card .form { text-align: left; }
.login-card .btn { width: 100%; margin-top: 14px; }

/* ── Modal ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(10, 20, 32, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 16px; overflow-y: auto; z-index: 50;
}
.modal-box { max-width: 860px; width: 100%; }
.modal-box h2 { margin-top: 4px; }

/* ── Chips de tipo (contadores) ── */
.chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip-sep { width: 1px; height: 22px; background: var(--borde); margin: 0 6px; }
.chip {
  display: inline-block; padding: 5px 14px; border-radius: 999px;
  border: 1px solid var(--borde); background: #fff; color: var(--azul);
  font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.chip:hover { border-color: var(--azul); background: #f0f7ff; }
.chip.active { background: var(--azul); border-color: var(--azul); color: #fff; }

/* ── Tabla de totales (estilo Siigo) ── */
.totales { width: 100%; border-collapse: collapse; font-size: 14px; }
.totales th {
  text-align: right; padding: 8px 14px; background: var(--encabezado);
  border-bottom: 2px solid var(--borde); color: var(--muted);
  font-weight: 700; font-size: 12px; text-transform: uppercase;
}
.totales th.left { text-align: left; }
.totales td { padding: 8px 14px; border-bottom: 1px solid var(--borde); }
.totales td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totales td.left { text-align: left; }
.totales tr.dest td { background: #fdf6e3; color: #7a5c00; }
.totales tr:hover td { background: #f7fafc; }

/* ── Clientes desde la constancia (CIF) ── */
.wrap-x { overflow-x: auto; }
.tabla-cif td { vertical-align: middle; }
.tabla-cif .inp {
  width: 100%; min-width: 88px; padding: 5px 7px; font-size: 13px;
  border: 1px solid var(--borde); border-radius: 6px; background: #fff;
  font-family: inherit; color: inherit;
}
.tabla-cif .inp:focus { outline: 2px solid #9db8d8; border-color: var(--azul); }
.tabla-cif .celda-cliente { min-width: 280px; }
.tabla-cif .inp.rfc { font-weight: 700; text-transform: uppercase; margin-bottom: 4px; letter-spacing: .3px; }
.tabla-cif .cp { max-width: 8ch; }
.tabla-cif .email { min-width: 160px; }
.tabla-cif .resultado { min-width: 180px; }
.tabla-cif .aviso { color: #a36a00; }
.tabla-cif tr.no-inc td { opacity: .5; }
