*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --border: rgba(0,0,0,0.1);
  --border-strong: rgba(0,0,0,0.2);
  --text: #1a1a1a;
  --text-muted: #666;
  --text-hint: #999;
  --accent: #1a1a1a;
  --info-bg: #e6f1fb;
  --info-text: #0c447c;
  --warn-bg: #faeeda;
  --warn-text: #854f0b;
  --success-bg: #eaf3de;
  --success-text: #3b6d11;
  --danger-bg: #fcebeb;
  --danger-text: #a32d2d;
  --radius: 10px;
  --radius-sm: 6px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }

/* NAV */
.navbar { background: var(--surface); border-bottom: 0.5px solid var(--border); padding: 0 1.5rem; height: 52px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.nav-logo { font-weight: 500; font-size: 15px; }
.nav-links { display: flex; gap: 1.5rem; }
.nav-links a { font-size: 14px; color: var(--text-muted); text-decoration: none; }
.nav-links a.active { color: var(--text); font-weight: 500; }
.nav-links a:hover { color: var(--text); }

/* CONTAINER */
.container { max-width: 720px; margin: 0 auto; padding: 2rem 1.25rem; }

/* PERIOD BAR */
.period-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 1.5rem; }
.period-bar label { font-size: 13px; color: var(--text-muted); }
.period-bar select, .period-bar input { padding: 6px 10px; border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); font-size: 14px; color: var(--text); }

/* CARDS */
.cards-grid { display: grid; gap: 12px; margin-bottom: 1.5rem; }
.card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.card-title { font-size: 15px; font-weight: 500; }
.badge { font-size: 11px; padding: 3px 10px; border-radius: 20px; }
.badge-info { background: var(--info-bg); color: var(--info-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-success { background: var(--success-bg); color: var(--success-text); }

/* INPUT GROUP */
.input-group { display: flex; align-items: center; gap: 8px; margin-bottom: 0.75rem; }
.input-group input { flex: 1; padding: 8px 12px; border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 16px; font-weight: 500; background: var(--surface); color: var(--text); }
.prefix, .suffix { font-size: 13px; color: var(--text-muted); }

/* RECIBO ROW */
.recibo-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.recibo-status { font-size: 12px; color: var(--text-hint); flex: 1; min-width: 80px; }
.recibo-status.ok { color: var(--success-text); }

/* BUTTONS */
button, .btn-sm { cursor: pointer; font-size: 12px; padding: 5px 12px; border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); transition: background 0.12s; }
button:hover, .btn-sm:hover { background: var(--bg); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #333; }
.btn-calcular { width: 100%; padding: 12px; font-size: 15px; font-weight: 500; border: 0.5px solid var(--border-strong); border-radius: var(--radius); background: var(--accent); color: #fff; cursor: pointer; transition: background 0.12s; }
.btn-calcular:hover { background: #333; }
.btn-danger { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-text); }

/* RESULTADOS */
.section-title { font-size: 15px; font-weight: 500; margin: 1.5rem 0 0.75rem; }
.deptos-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.depto-card { background: var(--bg); border-radius: var(--radius-sm); padding: 0.75rem 1rem; }
.depto-name { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.depto-total { font-size: 22px; font-weight: 500; margin-bottom: 6px; }
.depto-breakdown { font-size: 11px; color: var(--text-hint); margin-bottom: 8px; }
.depto-breakdown div { display: flex; justify-content: space-between; margin-top: 2px; }
.wa-btn { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 4px 10px; border: 0.5px solid var(--border-strong); border-radius: 20px; background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; transition: background 0.12s; }
.wa-btn:hover { background: var(--bg); }
.wa-btn.sent { background: var(--success-bg); color: var(--success-text); border-color: var(--success-text); }
.wa-icon { width: 14px; height: 14px; }
.tu-parte { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-sm); margin-top: 12px; }
.tu-parte span { font-size: 13px; color: var(--text-muted); }
.tu-parte strong { font-size: 16px; font-weight: 500; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; width: 90%; max-width: 480px; }
.modal-wide { max-width: 600px; }
.modal-box h3 { font-size: 16px; font-weight: 500; margin-bottom: 1.25rem; }
.config-section { margin-bottom: 1.25rem; }
.config-label { font-size: 12px; color: var(--text-muted); margin-bottom: 0.5rem; }
.config-grid { display: grid; grid-template-columns: 80px 1fr; gap: 8px; align-items: center; }
.config-grid label { font-size: 13px; color: var(--text-muted); }
.config-grid input, .config-section input { padding: 6px 10px; border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; background: var(--surface); color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 1.25rem; }

/* HISTÓRICO */
.page-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 1.5rem; }
.page-title { font-size: 20px; font-weight: 500; }
.muted { font-size: 13px; color: var(--text-muted); }
.historico-item { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; transition: background 0.12s; }
.historico-item:hover { background: #fafaf8; }
.historico-periodo { font-size: 15px; font-weight: 500; }
.historico-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.historico-right { display: flex; align-items: center; gap: 10px; }
.historico-total { font-size: 15px; font-weight: 500; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; }
.pill-ok { background: var(--success-bg); color: var(--success-text); }
.pill-pending { background: var(--warn-bg); color: var(--warn-text); }

/* DETALLE */
.detalle-periodo { font-size: 18px; font-weight: 500; margin-bottom: 1rem; }
.detalle-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-bottom: 1rem; }
.detalle-card { background: var(--bg); border-radius: var(--radius-sm); padding: 0.75rem; }
.detalle-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.detalle-val { font-size: 18px; font-weight: 500; }
.recibos-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 1rem; }
.enviados-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* TOAST */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 10px 20px; border-radius: var(--radius-sm); font-size: 14px; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 300; }
.toast.show { opacity: 1; }

/* LOADING / EMPTY */
.loading-msg, .empty-msg { text-align: center; padding: 3rem; color: var(--text-muted); font-size: 14px; }

/* ─── ESTADO DE CUENTA ───────────────────────────────────────────── */
.ec-resumen-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 1.5rem; }
.ec-resumen-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; cursor: pointer; transition: background 0.12s; }
.ec-resumen-card:hover { background: #fafaf8; }
.ec-resumen-deuda { border-color: #e8b4b4; }
.ec-resumen-ok { border-color: #b4d9b4; }
.ec-resumen-nombre { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.ec-resumen-monto { font-size: 24px; font-weight: 500; margin-bottom: 4px; }
.monto-deuda { color: var(--danger-text); }
.monto-ok { color: var(--success-text); }
.ec-resumen-sub { font-size: 12px; color: var(--text-hint); }

.ec-tabs { display: flex; gap: 6px; margin-bottom: 1.25rem; }
.ec-tab { padding: 7px 18px; font-size: 14px; border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text-muted); cursor: pointer; transition: all 0.12s; }
.ec-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.ec-tab:hover:not(.active) { background: var(--bg); color: var(--text); }

.ec-saldo-header { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.25rem; display: flex; justify-content: space-between; align-items: center; }
.ec-saldo-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.ec-saldo-monto { font-size: 28px; font-weight: 500; }
.ec-saldo-meta { font-size: 13px; color: var(--text-muted); text-align: right; }
.text-deuda { color: var(--danger-text); font-weight: 500; }
.text-ok { color: var(--success-text); font-weight: 500; }

.ec-tabla { width: 100%; border-collapse: collapse; background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
.ec-tabla thead { background: var(--bg); }
.ec-tabla th { padding: 10px 14px; text-align: left; font-size: 12px; color: var(--text-muted); font-weight: 500; border-bottom: 0.5px solid var(--border); }
.ec-tabla td { padding: 10px 14px; border-bottom: 0.5px solid var(--border); vertical-align: middle; }
.ec-tabla tr:last-child td { border-bottom: none; }
.row-pagado td { opacity: 0.55; }
.row-pendiente td { }
.text-hint { color: var(--text-hint); font-size: 12px; }

/* Modal descarga fallida */
.modal-error-icon { font-size: 32px; margin-bottom: 0.5rem; }
.modal-error-msg { font-size: 13px; color: var(--text-muted); margin-bottom: 1rem; }
.modal-error-tip-box { background: var(--bg); border-radius: var(--radius-sm); padding: 0.75rem 1rem; margin-bottom: 1rem; }
.modal-error-tip { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* Botón Saphir */
.btn-saphir { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; margin-top: 1rem; padding: 14px; font-size: 15px; font-weight: 500; border: none; border-radius: var(--radius); background: #25D366; color: #fff; cursor: pointer; transition: background 0.15s; }
.btn-saphir:hover { background: #1da851; }
