:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #17282b;
  --muted: #5d6f72;
  --line: #dde4e3;
  --brand: #0f5c63;
  --brand-soft: #e3f0f0;
  --ok: #1f7a4d;
  --ok-soft: #e2f3ea;
  --warn: #9a6200;
  --warn-soft: #fbefd6;
  --bad: #a8322b;
  --bad-soft: #f9e3e1;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 76px;
}

h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
a { color: var(--brand); }

/* Encabezado y navegación */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { display: block; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { color: #cfe5e6; }
.logo {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: #fff; color: var(--brand); font-weight: 800;
}
.rol { font-size: .75rem; color: #cfe5e6; display: flex; flex-direction: column; }
.rol select { margin-top: 2px; border: 0; border-radius: 8px; padding: 5px 6px; font: inherit; font-size: .85rem; }

#nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
}
#nav a {
  flex: 1; text-align: center; padding: 14px 4px;
  color: var(--muted); text-decoration: none; font-size: .82rem; font-weight: 600;
}
#nav a.on { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }

main { max-width: 980px; margin: 0 auto; padding: 16px; }

/* Bloques */
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat span { display: block; font-size: .78rem; color: var(--muted); }
.stat b { display: block; font-size: 1.3rem; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat small { font-size: .76rem; }

.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.bar.warn i { background: var(--warn); }

.alert { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; font-size: .92rem; }
.alert.warn { background: var(--warn-soft); color: #5e3c00; }
.alert.bad { background: var(--bad-soft); color: #6d1f1a; }
.alert.info { background: var(--brand-soft); color: #0b4347; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.gris { background: #e9eded; color: var(--muted); }
.badge.info { background: var(--brand-soft); color: var(--brand); }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .main { min-width: 0; }
.list .main b { display: block; }
.list .main small { display: block; }
.list .side { text-align: right; flex: none; }
.row-link { cursor: pointer; }
.row-link:hover { background: #fafcfb; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.amount.in { color: var(--ok); }
.amount.out { color: var(--bad); }
.tachado { text-decoration: line-through; color: var(--muted); }

.months { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 10px 0; }
.months div { text-align: center; padding: 7px 2px; border-radius: 8px; font-size: .78rem; font-weight: 700; background: #e9eded; color: var(--muted); }
.months .paid { background: var(--ok-soft); color: var(--ok); }
.months .due { background: var(--warn-soft); color: var(--warn); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
td, th { padding: 7px 4px; border-top: 1px solid var(--line); text-align: left; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; }

/* Controles */
.btns { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
button, .btn {
  font: inherit; font-weight: 600; font-size: .9rem;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 9px 13px; cursor: pointer; text-decoration: none; display: inline-block;
}
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.small { padding: 5px 9px; font-size: .8rem; }
button.danger { color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chips button { border-radius: 99px; padding: 5px 12px; font-size: .8rem; }
.chips button.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

input, select, textarea {
  font: inherit; width: 100%; padding: 9px 10px;
  border: 1px solid #c6d1d0; border-radius: 10px; background: #fff; color: var(--ink);
}
label.f { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
label.f > input, label.f > select, label.f > textarea { margin-top: 4px; font-weight: 400; color: var(--ink); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: .85rem; padding: 9px 11px; border-radius: 10px; background: var(--brand-soft); color: #0b4347; margin-bottom: 10px; }
.error { font-size: .88rem; padding: 9px 11px; border-radius: 10px; background: var(--bad-soft); color: #6d1f1a; margin-bottom: 10px; }
.error:empty { display: none; }

dialog { border: 0; border-radius: 16px; padding: 18px; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; }
dialog::backdrop { background: rgba(10, 30, 32, .5); }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
dialog img { max-width: 100%; border-radius: 10px; }

#toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: #17282b; color: #fff; padding: 10px 16px; border-radius: 99px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 90vw; text-align: center;
}
#toast.on { opacity: 1; }

body.ro [data-w] { display: none !important; }
body:not(.asesora) [data-asesora] { display: none !important; }

/* Recibo y talones */
.recibo { border: 1px dashed #8a9a9c; border-radius: 10px; padding: 14px; font-size: .92rem; }
.recibo h3 { margin: 0 0 2px; font-size: 1rem; }
.recibo .tot { font-size: 1.15rem; font-weight: 800; margin-top: 8px; }
#print { display: none; }

@media (min-width: 860px) {
  body { padding-bottom: 0; padding-left: 190px; }
  #nav { top: 56px; right: auto; width: 190px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding-top: 10px; }
  #nav a { flex: none; text-align: left; padding: 12px 18px; font-size: .95rem; }
  #nav a.on { box-shadow: inset 3px 0 0 var(--brand); background: var(--brand-soft); }
  .top { left: 0; margin-left: -190px; }
  #toast { bottom: 24px; }
}

@media print {
  body { padding: 0; background: #fff; }
  body > *:not(#print) { display: none !important; }
  #print { display: block; }
  .talon { border: 1px dashed #000; padding: 10px 12px; margin: 0 0 8px; font-size: 11pt; break-inside: avoid; }
  .talon h3 { margin: 0 0 4px; font-size: 11pt; }
  .talon p { margin: 0 0 4px; white-space: pre-line; }
  .recibo { border: 1px solid #000; }
}
