/* ───────── RECIBOS2 · estilos ───────── */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --border: #e6e8ef;
  --text: #121826;
  --text-2: #4b5468;
  --muted: #8a92a6;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef0ff;
  --green: #12a150;
  --green-50: #e7f7ee;
  --amber: #c27a00;
  --amber-50: #fff6e0;
  --red: #dc2f45;
  --red-50: #fdecee;
  --blue: #2563eb;
  --blue-50: #e9f0ff;
  --slate-50: #eef0f4;
  --sidebar: #0f1424;
  --sidebar-2: #1a2035;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }
.ico { flex-shrink: 0; vertical-align: middle; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }

/* ───── Layout ───── */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0;
  background: var(--sidebar);
  color: #c9cfdd;
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #6d63ff, #4f46e5);
  color: #fff; box-shadow: 0 6px 16px rgba(79, 70, 229, .45);
}
.brand-name { color: #fff; font-weight: 700; font-size: 16px; }
.brand-sub { color: #7d859b; font-size: 12px; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: #aab1c3; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--sidebar-2); color: #fff; }
.nav-link.active { background: rgba(109, 99, 255, .16); color: #fff; }
.nav-link.active .ico { color: #8f87ff; }
.sidebar-cta { margin-top: auto; padding: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 22px 32px 6px;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 24px; font-weight: 700; }
.topbar-title p { margin: 2px 0 0; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.content { padding: 18px 32px 48px; }

.mobile-only { display: none !important; }
.sidebar-backdrop { display: none; }

/* ───── Componentes ───── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card-head .sub { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 18px; }
.mt { margin-top: 18px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* KPI */
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { color: var(--text-2); font-weight: 550; font-size: 13px; }
.kpi-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; }
.kpi-value { font-size: 26px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.tone-primary { background: var(--primary-50); color: var(--primary); }
.tone-green { background: var(--green-50); color: var(--green); }
.tone-amber { background: var(--amber-50); color: var(--amber); }
.tone-red { background: var(--red-50); color: var(--red); }
.tone-blue { background: var(--blue-50); color: var(--blue); }

.progress { height: 8px; background: var(--slate-50); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #6d63ff, #4f46e5); }
.progress.green > span { background: linear-gradient(90deg, #34c77b, #12a150); }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); color: var(--text); border-color: #d6d9e3; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, .3); }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #0e8a44; border-color: #0e8a44; color: #fff; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-50); color: var(--red); border-color: #f5c2c9; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-wa { color: #128c4a; }
.btn-wa:hover { background: #e7f7ee; color: #128c4a; border-color: #bfe8d0; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; color: var(--text); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pendiente { background: var(--amber-50); color: var(--amber); }
.badge-parcial { background: var(--blue-50); color: var(--blue); }
.badge-vencido { background: var(--red-50); color: var(--red); }
.badge-pagado { background: var(--green-50); color: var(--green); }
.badge-anulado { background: var(--slate-50); color: var(--muted); }
.badge-vigente { background: var(--green-50); color: var(--green); }
.badge-finalizado { background: var(--slate-50); color: var(--text-2); }
.badge-cancelado { background: var(--red-50); color: var(--red); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--slate-50); color: var(--text-2); font-size: 12px; font-weight: 600; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: #fafbff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.cell-main { font-weight: 600; color: var(--text); }
.cell-sub { color: var(--muted); font-size: 12.5px; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty .ico { color: #c5cad6; margin-bottom: 6px; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-grid; place-items: center; flex-shrink: 0;
  background: var(--primary-50); color: var(--primary); font-weight: 700; font-size: 12.5px;
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

/* Listas en tarjetas */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: none; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Formularios */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px;
  border: 1px solid #d9dce5; border-radius: var(--radius-sm);
  background: #fff; color: var(--text); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
textarea.input { min-height: 80px; resize: vertical; }
.input-group { display: flex; align-items: stretch; }
.input-group .addon { display: grid; place-items: center; padding: 0 11px; background: var(--surface-2); border: 1px solid #d9dce5; border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm); color: var(--muted); font-weight: 600; font-size: 13px; }
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; margin: 8px 0 -2px; grid-column: 1 / -1; padding-top: 10px; border-top: 1px dashed var(--border); }
.section-title:first-child { border-top: none; padding-top: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.filters .field label { font-size: 12px; margin-bottom: 4px; }
.filters .input { padding: 7px 10px; min-width: 140px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); background: #fff; color: var(--text-2); font-weight: 600; font-size: 13px; }
.chip:hover { border-color: #cdd1dc; color: var(--text); }
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }
.chip .count { opacity: .6; margin-left: 4px; font-weight: 500; }

/* Líneas de recibo */
.lines { width: 100%; border-collapse: collapse; }
.lines td { padding: 6px 4px; }
.lines .input { padding: 8px 10px; }
.lines .col-monto { width: 160px; }
.lines .col-del { width: 44px; text-align: center; }

/* Alertas */
.alert { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 500; border: 1px solid; transition: opacity .4s; }
.alert-ok { background: var(--green-50); color: #0b6e37; border-color: #bfe8d0; }
.alert-error { background: var(--red-50); color: #b01f33; border-color: #f5c2c9; }
.alert-info { background: var(--primary-50); color: var(--primary-600); border-color: #d6d9ff; }
.alert-warn { background: var(--amber-50); color: #8a5600; border-color: #f2dca6; }
.banner { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: var(--radius); background: linear-gradient(135deg, #4f46e5, #6d63ff); color: #fff; margin-bottom: 18px; box-shadow: 0 8px 24px rgba(79, 70, 229, .25); }
.banner .grow { flex: 1; }
.banner .btn { background: #fff; color: var(--primary); border-color: #fff; }
.banner-icon { width: 40px; height: 40px; border-radius: 11px; background: rgba(255, 255, 255, .18); display: grid; place-items: center; }

/* Gráfica */
.chart { width: 100%; height: auto; display: block; }
.chart .bar-f { fill: #dcdffb; }
.chart .bar-c { fill: #4f46e5; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: #eef0f4; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Donut */
.donut-wrap { display: flex; align-items: center; gap: 22px; }
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.donut-legend div { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend b { margin-left: auto; font-variant-numeric: tabular-nums; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15, 20, 36, .45); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px; backdrop-filter: blur(2px); }
.modal.open { display: flex; }
.modal-box { background: #fff; border-radius: 16px; width: 100%; max-width: 480px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* Detalle de recibo */
.receipt { padding: 34px 38px; }
.receipt-head { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 22px; border-bottom: 2px solid var(--text); }
.receipt-head h2 { font-size: 20px; }
.receipt-num { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.receipt-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 20px 0; border-bottom: 1px solid var(--border); }
.receipt-meta .lbl { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.receipt-meta .val { font-weight: 600; margin-top: 2px; }
.receipt table { width: 100%; border-collapse: collapse; margin-top: 18px; }
.receipt th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 0; border-bottom: 1px solid var(--border); }
.receipt .right, .receipt th.right { text-align: right; }
.receipt td { padding: 11px 0; border-bottom: 1px solid var(--border); }
.receipt .totals { margin-left: auto; width: 300px; margin-top: 14px; }
.receipt .totals div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.receipt .totals .grand { font-size: 18px; font-weight: 800; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; }
.receipt-foot { margin-top: 28px; color: var(--text-2); font-size: 13px; white-space: pre-line; }
.stamp {
  display: inline-block; border: 3px solid var(--green); color: var(--green);
  padding: 4px 14px; border-radius: 8px; font-weight: 800; font-size: 18px; letter-spacing: .12em;
  transform: rotate(-6deg); margin-top: 8px;
}
.stamp.red { border-color: var(--red); color: var(--red); }
.stamp.gray { border-color: var(--muted); color: var(--muted); }

.photo-thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; border: 1px solid var(--border); }

/* ───── Responsive ───── */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 20, 36, .4); z-index: 30; }
  .mobile-only { display: grid !important; }
  .topbar { padding: 16px 16px 4px; flex-wrap: wrap; }
  .topbar-actions { width: 100%; }
  .content { padding: 14px 16px 40px; }
  .grid-3, .grid-2, .form-grid { grid-template-columns: 1fr; }
  .receipt { padding: 22px 18px; }
  .receipt-meta { grid-template-columns: 1fr 1fr; }
  .receipt .totals { width: 100%; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
}

/* ───── Impresión ───── */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 12.5px; }
  .sidebar, .topbar, .no-print, .alert { display: none !important; }
  .content { padding: 0; }
  .card { border: none; box-shadow: none; }
  .receipt { padding: 0; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* ───── Login ───── */
.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(109, 99, 255, .18), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(18, 161, 80, .10), transparent 60%),
    var(--bg);
}
.auth-wrap { width: 100%; max-width: 410px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; justify-content: center; }
.auth-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.auth-card { box-shadow: var(--shadow-lg); }
.auth-card .card-body { padding: 26px 26px 22px; }
.auth-card .form-actions { padding: 16px 26px 22px; background: #fff; border-top: none; }
.input-group .pw-toggle { border: 1px solid #d9dce5; border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--muted); }
.input-group .pw-toggle + .input, .input-group .input:has(+ .pw-toggle) { border-radius: 0; }

/* ───── Usuario en la barra lateral ───── */
.user-box { display: flex; align-items: center; gap: 10px; padding: 12px 8px 4px; margin-top: 10px; border-top: 1px solid var(--sidebar-2); }
.user-box .avatar { background: var(--sidebar-2); color: #c9cfdd; }
.user-box .u-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .u-role { color: #7d859b; font-size: 11.5px; }
.user-box .grow { flex: 1; min-width: 0; }
.user-box a, .user-box button { color: #8a92a6; background: none; border: none; cursor: pointer; padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.user-box a:hover, .user-box button:hover { background: var(--sidebar-2); color: #fff; }
