/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --radius: 12px;
  --navbar-color: #d97706;
  --sidebar-w: 340px;
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Login ──────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #e0e7ff 0%, #f1f5f9 100%);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.auth-logo { width: 140px; height: auto; margin-bottom: 8px; display: block; margin-left: auto; margin-right: auto; }
.brand { font-size: 2rem; font-weight: 700; letter-spacing: -0.5px; color: var(--navbar-color); }
.subtitle { color: var(--muted); font-size: 0.95rem; margin-bottom: 8px; }

.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #3c3c3c;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 20px; font-size: 0.95rem; font-weight: 500;
  cursor: pointer; transition: box-shadow 0.2s, background 0.2s;
  width: 100%; box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.btn-google:hover { background: #f8fafc; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.btn-google img { width: 20px; height: 20px; }

.error { color: var(--danger); font-size: 0.85rem; }
.hidden { display: none !important; }

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px;
  background: var(--navbar-color); color: #fff;
  position: sticky; top: 0; z-index: 100;
  transition: background 0.3s;
  flex-shrink: 0;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar .brand { font-size: 1.15rem; font-weight: 700; color: #fff; }
.nav-periodo {
  font-size: 0.82rem; font-weight: 500; color: rgba(255,255,255,0.8);
  border-left: 1px solid rgba(255,255,255,0.3); padding-left: 12px;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }

.company-select {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; border-radius: 8px; padding: 5px 10px;
  font-size: 0.88rem; cursor: pointer; outline: none;
}
.company-select option { color: var(--text); background: #fff; }

.user-info { display: flex; align-items: center; gap: 10px; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: none;
  object-fit: cover; border: 2px solid rgba(255,255,255,0.5);
}

.btn-logout {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; border-radius: 8px; padding: 5px 12px;
  font-size: 0.82rem; cursor: pointer; transition: background 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.25); }

/* ── Layout principal ───────────────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  gap: 0;
  overflow: hidden;
  height: calc(100vh - 56px);
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

/* ── Consejo ─────────────────────────────────────────────────── */
.consejo-card {
  margin-top: 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.consejo-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.consejo-texto {
  font-size: 0.78rem;
  color: #92400e;
  line-height: 1.5;
  margin: 0;
  transition: opacity 0.4s ease;
}

/* ── Content (tabla) ─────────────────────────────────────────── */
.content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.card.full-height {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card h2 { font-size: 1rem; font-weight: 600; color: var(--text); }

.btn-cancelar-edicion {
  background: none; border: none; color: var(--danger);
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
  padding: 0; margin-bottom: 10px; text-align: left;
}
.btn-cancelar-edicion:hover { text-decoration: underline; }

/* ── Form ───────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group label { font-size: 0.78rem; font-weight: 500; color: var(--muted); }

/* ── Typeahead ──────────────────────────────────────────────── */
.typeahead-wrap { position: relative; }

.typeahead-input {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: 0.9rem; color: var(--text);
  background: var(--surface); outline: none;
  transition: border-color 0.2s; width: 100%;
}
.typeahead-input:focus { border-color: var(--navbar-color); }
.typeahead-input.selected { border-color: var(--navbar-color); background: #fafafa; }

.typeahead-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  list-style: none; z-index: 200; max-height: 200px; overflow-y: auto;
}

.typeahead-list li {
  padding: 9px 12px; cursor: pointer; font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
  transition: background 0.15s;
}
.typeahead-list li:last-child { border-bottom: none; }
.typeahead-list li:hover { background: var(--bg); }
.typeahead-list li .rfc { font-size: 0.75rem; color: var(--muted); }
.typeahead-list li .highlight { font-weight: 600; color: var(--navbar-color); }

.cliente-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-right: 6px; flex-shrink: 0;
  vertical-align: middle;
}
.typeahead-empty { padding: 10px 12px; color: var(--muted); font-size: 0.85rem; text-align: center; }

/* ── Upload areas ───────────────────────────────────────────── */
.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }

.upload-area {
  border: 2px dashed var(--border); border-radius: 8px;
  padding: 14px 8px; text-align: center; cursor: pointer;
  transition: border-color 0.2s, background 0.2s; position: relative;
}
.upload-area:hover { border-color: var(--navbar-color); background: #fafafa; }
.upload-area.has-file { border-color: #16a34a; background: #f0fdf4; }
.upload-area.has-file .upload-icon { color: #16a34a; }

.upload-area input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}

.upload-icon { font-size: 1.4rem; margin-bottom: 4px; }
.upload-area p { font-size: 0.78rem; color: var(--muted); }
.upload-area .file-name { font-size: 0.7rem; color: #16a34a; font-weight: 500; margin-top: 2px; word-break: break-all; }

/* ── Totales ────────────────────────────────────────────────── */
.totales {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-bottom: 14px;
}

.totales.con-retencion { grid-template-columns: 1fr 1fr; }

.total-item {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.total-item span { display: block; font-size: 0.72rem; color: var(--muted); margin-bottom: 2px; }
.total-item strong { font-size: 0.92rem; color: var(--text); }
.total-item.total-highlight { border-color: var(--navbar-color); }
.total-item.total-highlight strong { color: var(--navbar-color); font-size: 1rem; }

/* ── Button ─────────────────────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 10px; background: var(--navbar-color);
  color: #fff; border: none; border-radius: 8px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Flujo de pagos ──────────────────────────────────────────── */
.flujo-panel {
  flex-shrink: 0;
  margin-bottom: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 14px;
  overflow: hidden;
}

.flujo-toggle {
  background: none; border: none; cursor: pointer;
  font-size: 0.75rem; font-weight: 600; color: var(--muted);
  padding: 4px 0; width: 100%; text-align: left;
}
.flujo-toggle:hover { color: var(--text); }

.flujo-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 165px;
}

/* ── Resumen cards ───────────────────────────────────────────── */
.resumen-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.resumen-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
}

.resumen-card span {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.resumen-card strong {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.resumen-card.resumen-cobrado {
  border-color: #16a34a;
  background: #f0fdf4;
}

.resumen-card.resumen-cobrado strong {
  color: #15803d;
}

/* ── Count cards ─────────────────────────────────────────────── */
.resumen-counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.count-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.count-card span {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.count-card strong {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.count-card.count-pagadas   { border-color: #16a34a; }
.count-card.count-pagadas strong { color: #15803d; }
.count-card.count-pendientes { border-color: #f59e0b; }
.count-card.count-pendientes strong { color: #b45309; }

/* ── Toggle mes ──────────────────────────────────────────────── */
.mes-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.mes-btn {
  padding: 5px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  border: none;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mes-btn:first-child { border-right: 1px solid var(--border); }
.mes-btn.active { background: var(--navbar-color); color: #fff; }
.mes-btn:not(.active):hover { background: #f1f5f9; }

/* ── Input mes ───────────────────────────────────────────────── */
.input-mes {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
  color: var(--text);
  background: var(--surface);
}
.input-mes:focus { border-color: var(--navbar-color); }

/* ── Tabla header ───────────────────────────────────────────── */
.tabla-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; flex-shrink: 0; gap: 12px;
}

.tabla-header-right { display: flex; align-items: center; gap: 12px; }

.leyenda-estatus { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.leyenda-comp-row { font-size: 0.75rem; color: #7c3aed; background: #faf5ff; border: 1px solid #ddd6fe; border-radius: 4px; padding: 2px 7px; white-space: nowrap; }

.input-buscar {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; font-size: 0.88rem; outline: none;
  width: 180px; transition: border-color 0.2s;
}
.input-buscar:focus { border-color: var(--navbar-color); }

/* ── Tabla ───────────────────────────────────────────────────── */
.tabla-wrap { overflow: auto; flex: 1; }

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

.tabla th {
  text-align: left; padding: 9px 12px; color: var(--muted);
  font-weight: 600; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.04em; border-bottom: 2px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface); z-index: 1;
}

.tabla td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tabla tbody tr:last-child td { border-bottom: none; }
.tabla tbody tr:hover td { background: #fafafa; }
.tabla tbody tr.row-pendiente-comp td { background: #faf5ff; border-bottom-color: #e9d5ff; }
.tabla tbody tr.row-pendiente-comp:hover td { background: #f3e8ff; }
.tabla tbody tr.row-pagada td { background: #f0fdf4; }
.tabla tbody tr.row-pagada td:first-child { border-left: 3px solid #16a34a; }
.tabla tbody tr.row-pagada:hover td { background: #dcfce7; }
.tabla td.num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.tabla td.rfc-col { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.tabla-empty { text-align: center; color: var(--muted); padding: 32px !important; }

/* ── Badge compartido ────────────────────────────────────────── */
.badge-compartido {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 0.68rem;
  font-weight: 600;
  background: #ede9fe;
  color: #6d28d9;
  border-radius: 4px;
  vertical-align: middle;
  white-space: nowrap;
}

/* ── Badge estatus ───────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600; color: #fff; white-space: nowrap;
}

/* ── Botones acción ──────────────────────────────────────────── */
.acciones { display: flex; gap: 5px; flex-wrap: wrap; }
.col-archivos-acciones { display: flex; flex-direction: column; gap: 4px; }
.col-archivos-acciones > div { display: flex; gap: 5px; flex-wrap: wrap; }
.sep-archivos { border: none; border-top: 1px solid var(--border); margin: 2px 0; }

.btn-accion {
  padding: 3px 9px; border-radius: 6px; border: none;
  font-size: 0.72rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.2s; white-space: nowrap;
}
.btn-accion:hover:not(:disabled) { opacity: 0.75; }
.btn-accion:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-accion.enviar       { background: #dbeafe; color: #1d4ed8; }
.btn-accion.reenviar     { background: #e0e7ff; color: #4338ca; }
.btn-accion.recordatorio { background: #fef9c3; color: #a16207; }
.btn-accion.pagada       { background: #dcfce7; color: #15803d; }
.btn-accion.complemento   { background: #ede9fe; color: #6d28d9; }
.btn-accion.reenviar-comp { background: #f3e8ff; color: #7c3aed; }
.btn-accion.subir-pago   { background: #dcfce7; color: #15803d; }
.btn-accion.agradecer    { background: #f0fdf4; color: #15803d; }
.btn-accion.ver-pdf      { background: #fee2e2; color: #b91c1c; }
.btn-accion.ver-xml      { background: #e0f2fe; color: #0369a1; }
.btn-accion.ver-pago     { background: #dcfce7; color: #15803d; }
.btn-accion.ver-comp-pdf { background: #ede9fe; color: #6d28d9; }
.btn-accion.ver-comp-xml { background: #ede9fe; color: #6d28d9; }
.btn-accion.eliminar     { background: #fee2e2; color: #dc2626; }
.btn-accion.wa-btn       { background: #dcfce7; color: #15803d; }

.wa-wrap { position: relative; display: inline-block; }
.wa-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 100;
  min-width: 170px;
  overflow: hidden;
}
.wa-dropdown.open { display: block; }
.wa-dropdown button {
  display: block;
  width: 100%;
  padding: 9px 14px;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.82rem;
  color: #1e293b;
  white-space: nowrap;
}
.wa-dropdown button:hover { background: #f1fdf4; color: #15803d; }
.btn-accion.editar       { background: #f1f5f9; color: #475569; }
.col-ops { width: 1px; white-space: nowrap; padding: 6px 6px !important; vertical-align: middle; display: table-cell; }

/* ── SweetAlert tabla ────────────────────────────────────────── */
.swal-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; text-align: left; }
.swal-table td { padding: 7px 10px; border-bottom: 1px solid #e2e8f0; }
.swal-table td:first-child { color: #64748b; font-weight: 500; width: 45%; }
.swal-table tr.sep td { padding-top: 14px; border-top: 2px solid #e2e8f0; }
.swal-table tr.total-row td { font-weight: 700; font-size: 1rem; border-bottom: none; }

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #0f172a; color: #fff; padding: 10px 18px;
  border-radius: 10px; font-size: 0.88rem;
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s; z-index: 999;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

/* ── Topnav ──────────────────────────────────────────────────── */
.topnav { display: flex; gap: 2px; margin-left: 16px; }
.topnav-link {
  color: rgba(255,255,255,.72); text-decoration: none;
  padding: 6px 13px; border-radius: 7px; font-size: 0.84rem;
  font-weight: 500; transition: background .15s, color .15s;
}
.topnav-link:hover { color: #fff; background: rgba(255,255,255,.18); }
.topnav-link.active { color: #fff; background: rgba(255,255,255,.22); }

/* ── ODC – áreas de archivo ──────────────────────────────────── */
.odc-file-area {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1.5px dashed var(--border);
  border-radius: 8px; cursor: pointer; transition: border-color .2s, background .2s;
  font-size: 0.85rem; color: var(--muted); user-select: none;
}
.odc-file-area:hover { border-color: var(--navbar-color); color: var(--text); }
.odc-file-area.has-file { border-color: #22c55e; background: #f0fdf4; color: #15803d; border-style: solid; }
.odc-file-area .odc-file-icon { font-size: 1.25rem; flex-shrink: 0; }
.odc-file-area .odc-file-name { font-size: 0.8rem; word-break: break-all; }
.odc-file-area input[type=file] { display: none; }

/* ── ODC selector en formulario de factura ───────────────────── */
.odc-selector { margin-top: 0; }
.odc-selector select {
  width: 100%; padding: 7px 10px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 0.88rem; color: var(--text);
  background: #fff; cursor: pointer; outline: none;
}
.odc-selector select:focus { border-color: var(--navbar-color); }

/* ── Selección de grupo ──────────────────────────────────────── */
.grupo-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; background: #1e293b; color: #fff;
  border-radius: 10px; margin-bottom: 10px; flex-wrap: wrap;
}
.grupo-bar.hidden { display: none; }
#grupo-count { font-size: 0.82rem; font-weight: 600; white-space: nowrap; padding-right: 4px; }
.grupo-btns { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.grupo-btns button {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.25);
  color: #fff; border-radius: 7px; padding: 5px 10px;
  font-size: 0.78rem; cursor: pointer; transition: background .15s; white-space: nowrap;
}
.grupo-btns button:hover:not(:disabled) { background: rgba(255,255,255,.28); }
.grupo-btns button:disabled { opacity: .35; cursor: not-allowed; }
.gbtn-limpiar {
  background: transparent; border: none; color: rgba(255,255,255,.6);
  cursor: pointer; font-size: 0.78rem; padding: 4px 8px; border-radius: 6px; margin-left: auto;
}
.gbtn-limpiar:hover { color: #fff; background: rgba(255,255,255,.1); }
.col-check { width: 32px; text-align: center !important; padding: 4px 6px !important; }
.col-check input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--navbar-color, #2563eb); }
tr.seleccionada td { background: #eff6ff !important; }
.modal { display: flex; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.5); justify-content: center; align-items: center; } .modal.hidden { display: none; } .modal-content { background-color: #fefefe; padding: 20px; border: 1px solid #888; width: 90%; max-width: 500px; border-radius: 8px; position: relative; } .close-modal { color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer; } .close-modal:hover, .close-modal:focus { color: black; text-decoration: none; cursor: pointer; }

/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .4s; border-radius: 20px; }
.switch .slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
.switch input:checked + .slider { background-color: var(--navbar-color, #2563eb); }
.switch input:checked + .slider:before { transform: translateX(16px); }
