:root {
  --mf-blue: #1B3A6B;
  --mf-blue-light: #3B6EA5;
  --mf-blue-wash: #E8EEF6;
  --mf-red: #C8102E;
  --mf-red-wash: #FBEAEC;
  --mf-green: #1F7A4D;
  --mf-green-wash: #E6F3EC;
  --mf-amber: #8A5A00;
  --mf-amber-wash: #FFF4DB;
  --mf-bg: #F5F6F8;
  --mf-surface: #FFFFFF;
  --mf-text: #1A1D23;
  --mf-text-muted: #6B7280;
  --mf-border: #E2E5EA;
  --radio: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--mf-bg); color: var(--mf-text);
  font: 400 16px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { font-family: 'Poppins', 'Inter', system-ui, sans-serif; font-weight: 600; line-height: 1.2; margin: 0; }
a { color: var(--mf-blue-light); }
:focus-visible { outline: 3px solid var(--mf-blue-light); outline-offset: 2px; }

/* Cabecera */
.barra {
  background: var(--mf-blue); color: #fff;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 14px;
}
.barra-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.marca { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.marca small { font-family: 'Inter', sans-serif; font-weight: 400; font-size: 14px; opacity: .8; margin-left: 8px; }
.barra a { color: #fff; text-decoration: none; font-size: 14px; opacity: .9; }
.barra a:hover { opacity: 1; text-decoration: underline; }
.barra nav { display: flex; gap: 18px; }

/* ---------- Formulario del cliente ---------- */
.carga { max-width: 520px; margin: 0 auto; padding: 28px 18px 48px; }
.carga h1 { font-size: 26px; color: var(--mf-blue); margin-bottom: 6px; }
.carga .bajada { color: var(--mf-text-muted); margin: 0 0 24px; }
.campo { margin-bottom: 18px; }
.campo label { display: block; font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.campo .ayuda { font-weight: 400; color: var(--mf-text-muted); font-size: 13px; }
input[type=text], input[type=tel], input[type=date], input[type=password], select, textarea {
  width: 100%; font: inherit; color: inherit; background: var(--mf-surface);
  border: 1.5px solid var(--mf-border); border-radius: var(--radio); padding: 12px 14px;
}
input:focus, select:focus, textarea:focus { border-color: var(--mf-blue-light); outline: none; box-shadow: 0 0 0 3px var(--mf-blue-wash); }
.monto-wrap { position: relative; }
.monto-wrap span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--mf-text-muted); font-weight: 600; }
.monto-wrap input { padding-left: 32px; font-family: 'Poppins', sans-serif; font-size: 20px; font-weight: 600; }

/* El talón: zona para adjuntar el comprobante */
.talon {
  position: relative; display: block; cursor: pointer; text-align: center;
  background: var(--mf-surface); border-radius: var(--radio);
  padding: 26px 18px 22px; border: 1.5px solid var(--mf-border);
  background-image: radial-gradient(circle at 10px 0, var(--mf-bg) 6px, transparent 6.5px);
  background-size: 20px 12px; background-repeat: repeat-x; background-position: top left;
}
.talon::after {
  content: ""; position: absolute; left: 16px; right: 16px; top: 18px;
  border-top: 1.5px dashed var(--mf-border);
}
.talon:hover, .talon.arrastrando { border-color: var(--mf-blue-light); }
.campo .talon { font-weight: 400; }
.talon input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.talon .ico { width: 40px; height: 40px; margin: 8px auto 8px; color: var(--mf-blue); }
.talon strong { display: block; font-family: 'Poppins', sans-serif; color: var(--mf-blue); font-size: 16px; }
.talon .tipos { color: var(--mf-text-muted); font-size: 13px; }
.talon .elegido { margin-top: 10px; font-size: 14px; color: var(--mf-text); word-break: break-all; }
.talon img.previa { max-width: 100%; max-height: 220px; border-radius: 6px; margin: 12px auto 0; display: none; }

.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 16px 'Inter', sans-serif; border: 0; border-radius: var(--radio);
  background: var(--mf-blue); color: #fff; padding: 14px 22px; cursor: pointer; text-decoration: none;
}
.boton:hover { background: #15305A; }
.boton[disabled] { opacity: .6; cursor: wait; }
.boton.ancho { width: 100%; font-size: 17px; padding: 16px; }
.boton.sec { background: var(--mf-surface); color: var(--mf-blue); border: 1.5px solid var(--mf-border); }
.boton.sec:hover { border-color: var(--mf-blue-light); }
.boton.chico { padding: 7px 12px; font-size: 14px; }
.boton.ok { background: var(--mf-green); }
.boton.ok:hover { background: #18613D; }

.aviso { border-radius: var(--radio); padding: 14px 16px; margin-bottom: 20px; font-size: 15px; }
.aviso.error { background: var(--mf-red-wash); color: #8E0B20; }
.aviso.bien { background: var(--mf-green-wash); color: #15553A; }
.hp { position: absolute; left: -9999px; }
.privacidad { font-size: 13px; color: var(--mf-text-muted); margin-top: 16px; }

.gracias { text-align: center; padding-top: 32px; }
.gracias .check { width: 64px; height: 64px; border-radius: 50%; background: var(--mf-green-wash); color: var(--mf-green); display: grid; place-items: center; margin: 0 auto 18px; }
.gracias .ref { display: inline-block; margin: 18px 0 26px; padding: 10px 18px; border: 1.5px dashed var(--mf-border); border-radius: var(--radio); background: var(--mf-surface); }
.gracias .ref b { font-family: 'Poppins', sans-serif; font-size: 20px; color: var(--mf-blue); }

/* ---------- Panel ---------- */
.panel { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; }
.controles { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.controles h1 { font-size: 22px; color: var(--mf-blue); margin-right: auto; }
.controles form { display: flex; gap: 8px; align-items: center; }
.controles input[type=date] { width: auto; padding: 8px 10px; }
.vistas { display: flex; gap: 4px; background: var(--mf-surface); border: 1px solid var(--mf-border); border-radius: var(--radio); padding: 3px; }
.vistas a { padding: 6px 12px; border-radius: 7px; text-decoration: none; color: var(--mf-text-muted); font-size: 14px; font-weight: 500; }
.vistas a.activa { background: var(--mf-blue); color: #fff; }

.totales { display: flex; flex-wrap: wrap; gap: 10px 28px; background: var(--mf-surface); border: 1px solid var(--mf-border); border-radius: var(--radio); padding: 14px 18px; margin-bottom: 18px; }
.totales div { font-size: 13px; color: var(--mf-text-muted); }
.totales b { display: block; font-family: 'Poppins', sans-serif; font-size: 20px; color: var(--mf-blue); }
.totales .atencion b { color: var(--mf-red); }

.tabla-wrap { overflow-x: auto; background: var(--mf-surface); border: 1px solid var(--mf-border); border-radius: var(--radio); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--mf-text-muted); font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--mf-border); white-space: nowrap; background: #FAFBFC; }
td { padding: 12px; border-bottom: 1px solid var(--mf-border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cliente { font-weight: 600; }
.sub { color: var(--mf-text-muted); font-size: 13px; }
.leido { font-size: 13px; line-height: 1.45; }
.leido .monto { font-weight: 600; font-size: 14px; }
.alertas { margin: 0; padding: 0; list-style: none; }
.alertas li { background: var(--mf-red-wash); color: #8E0B20; border-radius: 6px; padding: 3px 8px; font-size: 12.5px; margin-bottom: 4px; }
.sin-alertas { color: var(--mf-green); font-size: 13px; }
.estado { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.estado.pendiente { background: var(--mf-amber-wash); color: var(--mf-amber); }
.estado.conciliado { background: var(--mf-green-wash); color: var(--mf-green); }
.estado.observado { background: var(--mf-red-wash); color: var(--mf-red); }
.accion-rapida { display: flex; gap: 6px; margin-top: 8px; }
.accion-rapida input { width: 110px; padding: 6px 8px; font-size: 13px; }
.vacio { text-align: center; padding: 48px 20px; color: var(--mf-text-muted); }

/* Detalle */
.detalle { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; }
@media (max-width: 860px) { .detalle { grid-template-columns: 1fr; } }
.caja { background: var(--mf-surface); border: 1px solid var(--mf-border); border-radius: var(--radio); padding: 18px; }
.caja h2 { font-size: 16px; color: var(--mf-blue); margin-bottom: 12px; }
.visor img { max-width: 100%; border-radius: 6px; display: block; }
.visor iframe { width: 100%; height: 640px; border: 0; }
dl.datos { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 8px; font-size: 14px; }
dl.datos dt { color: var(--mf-text-muted); }
dl.datos dd { margin: 0; word-break: break-word; }
.login { max-width: 360px; margin: 64px auto; }

/* ---------- Portal del cliente: identidad del logo de Mi Farma ---------- */
body.portal {
  --mf-magenta: #E5007E;
  --mf-magenta-dark: #C2006B;
  --mf-magenta-wash: #FCE6F2;
  --mf-purple: #86368D;
  --mf-cyan: #07B0D7;
  font-family: 'Lato', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: #F7F5F9;
}
.portal h1, .portal h2, .portal h3,
.portal .talon strong, .portal .gracias .ref b, .portal .monto-wrap input {
  font-family: 'Lato', system-ui, sans-serif;
}
.portal .barra {
  background: #fff; color: var(--mf-purple);
  border-bottom: 4px solid var(--mf-magenta);
  box-shadow: 0 3px 0 var(--mf-cyan);
  padding-bottom: 10px; margin-bottom: 3px;
}
.portal .barra-in { justify-content: center; }
.portal .logo { display: block; height: 52px; width: auto; }
.portal .carga h1 { color: var(--mf-purple); font-weight: 900; font-size: 28px; letter-spacing: -.01em; }
.portal .carga .bajada { color: #5F5A66; }
.portal .campo label { font-weight: 700; color: #2A2230; }
.portal .campo .ayuda { color: #7A7382; }
.portal .campo .talon { font-weight: 400; color: var(--mf-text); }
.portal input:focus, .portal select:focus, .portal textarea:focus {
  border-color: var(--mf-magenta); box-shadow: 0 0 0 3px var(--mf-magenta-wash);
}
.portal :focus-visible { outline-color: var(--mf-magenta); }
.portal .monto-wrap input { font-weight: 900; color: var(--mf-purple); }
.portal .talon .ico, .portal .talon strong { color: var(--mf-magenta); }
.portal .talon strong { font-weight: 900; }
.portal .talon:hover, .portal .talon.arrastrando { border-color: var(--mf-magenta); }
.portal .talon::after { border-top-color: #E6D7E8; }
.portal .boton { background: var(--mf-magenta); font-family: 'Lato', sans-serif; font-weight: 700; }
.portal .boton:hover { background: var(--mf-magenta-dark); }
.portal .boton.sec { background: #fff; color: var(--mf-purple); border-color: #E6D7E8; }
.portal .boton.sec:hover { border-color: var(--mf-purple); }
.portal .gracias h1 { color: var(--mf-purple); }
.portal .gracias .check { background: var(--mf-magenta-wash); color: var(--mf-magenta); }
.portal .gracias .ref { border-color: #E6D7E8; }
.portal .gracias .ref b { color: var(--mf-magenta); font-weight: 900; }

/* ---------- App-Cobranzas: cartera, saldos, facturas ---------- */
.cartera-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.cliente-card { background: var(--mf-surface); border: 1px solid var(--mf-border); border-radius: var(--radio); padding: 16px; text-decoration: none; color: inherit; display: block; }
.cliente-card:hover { border-color: var(--mf-blue-light); }
.cliente-card h3 { font-size: 15px; color: var(--mf-text); margin-bottom: 6px; }
.cliente-card .saldo { font-family: 'Poppins', sans-serif; font-size: 20px; font-weight: 600; color: var(--mf-blue); }
.cliente-card .saldo.vencido { color: var(--mf-red); }
.cliente-card .sub { margin-top: 4px; }

.badge-vencido { display: inline-block; background: var(--mf-red-wash); color: var(--mf-red); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; }

.facturas-wrap { background: var(--mf-surface); border: 1px solid var(--mf-border); border-radius: var(--radio); overflow-x: auto; margin-bottom: 20px; }
.facturas-wrap table { width: 100%; min-width: 560px; }
.facturas-wrap td.chk { width: 34px; text-align: center; }
.facturas-wrap input[type=number].monto-fact { width: 130px; padding: 6px 8px; font-size: 14px; }
.fila-vencida td { background: var(--mf-red-wash); }

.resumen-imputacion { display: flex; justify-content: space-between; align-items: center; background: var(--mf-blue-wash); border-radius: var(--radio); padding: 12px 16px; margin: 16px 0; font-size: 14px; }
.resumen-imputacion b { font-family: 'Poppins', sans-serif; font-size: 17px; color: var(--mf-blue); }

/* Nav de acciones en la plantilla "portal" (volver, salir) */
.acciones-portal { max-width: 520px; margin: 8px auto 0; padding: 0 18px; text-align: right; font-size: 13px; }
.acciones-portal a { color: var(--mf-purple); text-decoration: none; margin-left: 14px; }
.acciones-portal a:hover { text-decoration: underline; }

.portal .carga { max-width: 560px; }
.carga.ancho, .portal .carga.ancho { max-width: 980px; }
.portal .facturas-wrap { border-color: #E6D7E8; }
.portal .facturas-wrap thead th { background: var(--mf-magenta-wash); color: var(--mf-purple); }
.portal .facturas-wrap input[type=checkbox] { accent-color: var(--mf-magenta); }
.portal .facturas-wrap input.monto-fact:focus { border-color: var(--mf-magenta); box-shadow: 0 0 0 3px var(--mf-magenta-wash); }

.portal .cliente-card { border-color: #E6D7E8; }
.portal .cliente-card:hover { border-color: var(--mf-magenta); }
.portal .cliente-card .saldo { color: var(--mf-purple); }
.portal .cliente-card .saldo.vencido { color: var(--mf-magenta); }
.portal .totales { border-color: #E6D7E8; }
.portal .totales b { color: var(--mf-purple); }
.portal .totales .atencion b { color: var(--mf-magenta); }

/* ---------- Tablas en pantallas de celular: cada fila pasa a tarjeta ---------- */
@media (max-width: 640px) {
  .facturas-wrap table, .tabla-wrap table { display: block; width: 100%; min-width: 0; }
  .facturas-wrap thead, .tabla-wrap thead { display: none; }
  .facturas-wrap tbody, .tabla-wrap tbody,
  .facturas-wrap tr, .tabla-wrap tr,
  .facturas-wrap td, .tabla-wrap td { display: block; width: 100%; }
  .facturas-wrap tr, .tabla-wrap tr {
    padding: 10px 12px; border-bottom: 1px solid var(--mf-border);
  }
  .facturas-wrap td, .tabla-wrap td {
    padding: 5px 0; border: 0; white-space: normal; text-align: left;
  }
  .facturas-wrap td.num, .tabla-wrap td.num { text-align: left; }
  .facturas-wrap td::before, .tabla-wrap td::before {
    content: attr(data-label); display: block; font-weight: 600; color: var(--mf-text-muted); font-size: 12px; margin-bottom: 2px;
  }
  .facturas-wrap td[data-label=""]::before, .tabla-wrap td[data-label=""]::before { content: none; margin: 0; }
  .facturas-wrap td.chk { display: flex; align-items: center; gap: 10px; }
  .facturas-wrap td.chk::before { content: none; }
  .facturas-wrap td.chk label { font-weight: 600; }
  .facturas-wrap .monto-fact { width: 100%; max-width: 160px; }
}

.paginacion { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.boton.deshabilitado { opacity: .4; pointer-events: none; }

/* ---------- Filtro desplegable detrás de un ícono ---------- */
.filtro-dropdown { position: relative; }
.filtro-boton { display: inline-flex; align-items: center; gap: 7px; }
.filtro-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20;
  background: var(--mf-surface); border: 1px solid var(--mf-border); border-radius: var(--radio);
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; min-width: 160px;
}
.filtro-panel[hidden] { display: none; }
.filtro-panel:not([hidden]) { display: flex; flex-direction: column; }
.filtro-panel a { padding: 9px 12px; border-radius: 7px; text-decoration: none; color: var(--mf-text); font-size: 14px; }
.filtro-panel a:hover { background: var(--mf-bg); }
.filtro-panel a.activa { background: var(--mf-blue); color: #fff; font-weight: 600; }
.portal .filtro-panel a.activa { background: var(--mf-magenta); }

/* ---------- Encabezados de columna ordenables ---------- */
th .col-orden { color: inherit; text-decoration: none; white-space: nowrap; cursor: pointer; }
th .col-orden:hover { text-decoration: underline; }
th .col-orden.activa { color: var(--mf-blue); }
.portal th .col-orden.activa { color: var(--mf-magenta); }
.flecha-orden { font-size: 11px; }
.flecha-orden.tenue { color: var(--mf-text-muted); opacity: .55; }

/* ---------- Factura sin monto disponible para imputar ---------- */
.facturas-wrap input.chk-factura:disabled { opacity: .35; cursor: not-allowed; }
.facturas-wrap tr:has(.chk-factura:disabled) { opacity: .5; }
