:root {
  --blue: #155e9f;
  --blue-dark: #0f3f64;
  --blue-soft: #e8f2fb;
  --green: #15803d;
  --red: #b42318;
  --orange: #b45309;
  --text: #17212f;
  --muted: #637083;
  --bg: #f5f7fb;
  --card: #fff;
  --surface: #f9fbfd;
  --border: #d8e2ee;
  --border-strong: #c2d1e2;
  --shadow: 0 10px 28px rgba(23, 33, 47, .08);
  --shadow-soft: 0 4px 14px rgba(23, 33, 47, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(21, 94, 159, .10), transparent 34rem),
    linear-gradient(180deg, #f8fbff 0, var(--bg) 18rem);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
h2 { margin: 24px 0 14px; font-size: 25px; letter-spacing: 0; }
h3 { margin: 22px 0 12px; font-size: 18px; letter-spacing: 0; }

.top {
  background:
    linear-gradient(135deg, rgba(255,255,255,.08), transparent 34%),
    linear-gradient(120deg, #155e9f, #0f3f64);
  color: #fff;
  padding: 12px clamp(18px, 5vw, 50px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 8px 22px rgba(15, 63, 100, .14);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-logo {
  display: inline-flex;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  object-fit: contain;
  background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.24);
  padding: 5px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.14);
}
.top h1 { margin: 0 0 1px; font-size: clamp(21px, 2.6vw, 28px); font-weight: 800; line-height: 1.08; }
.top p { margin: 0; color: #d9eafe; font-size: 13px; }

.nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px clamp(14px, 5vw, 50px);
  background: rgba(249, 251, 253, .94);
  position: sticky;
  top: 0;
  z-index: 4;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.nav a,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--blue);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s ease, border-color .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.nav a:hover,
.btn:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-soft);
}
.nav a.active,
.btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(21, 94, 159, .18);
}
.nav-icon {
  width: 19px;
  height: 19px;
  font-size: 19px;
  line-height: 1;
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 20;
  opacity: .9;
  flex: 0 0 auto;
}
.nav a.active .nav-icon {
  font-variation-settings: 'FILL' 1, 'wght' 600, 'GRAD' 0, 'opsz' 20;
  opacity: 1;
}
.btn.primary:hover { background: #0f528e; }
.btn.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.btn.ghost {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.35);
  color: #fff;
}
.btn.small {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 12px;
  margin: 2px;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px clamp(14px, 4vw, 32px) 46px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.cards {
  display: grid;
  gap: 14px;
}
.card,
.empty {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card:hover {
  border-color: var(--border-strong);
}
.metric span,
.metric small {
  display: block;
  color: var(--muted);
}
.metric strong {
  display: block;
  margin: 10px 0;
  font-size: 28px;
  line-height: 1.1;
  color: var(--blue);
}
.metric.good strong { color: var(--green); }
.metric.warn strong { color: var(--orange); }
.metric.bad strong { color: var(--red); }

.split-title,
.print-actions,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.actions { justify-content: flex-start; margin: 14px 0; }
.settings-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 0 0 16px;
}
.settings-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #f8fbff);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.settings-link:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  box-shadow: 0 12px 24px rgba(23, 33, 47, .09);
}
.settings-link .nav-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 22px;
}
.settings-link strong,
.settings-link small {
  display: block;
}
.settings-link strong {
  font-size: 15px;
  color: var(--blue-dark);
}
.settings-link small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
.row-card,
.profile {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}
.row-card {
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.row-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 34px rgba(23, 33, 47, .10);
}
.row-card p,
.profile p {
  margin: 8px 0 0;
  color: var(--muted);
}
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  background: var(--blue-soft);
  color: var(--blue);
}
.pill.good { background: #eaf7ee; color: var(--green); }
.pill.warn { background: #fff3e0; color: var(--orange); }
.pill.bad { background: #ffeceb; color: var(--red); }

.filters,
.form {
  display: grid;
  gap: 13px;
  margin-bottom: 18px;
}
.filters {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  align-items: end;
  background: rgba(255,255,255,.68);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}
input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
}
input:focus,
select:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(21, 94, 159, .13);
}
.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}
.userbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 5px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 13px;
  background: rgba(255,255,255,.09);
}
.userbar span {
  color: #e7f0ff;
  font-weight: 700;
}
.user-chip {
  display: grid;
  gap: 0;
  padding-left: 8px;
}
.user-chip strong,
.user-chip small {
  line-height: 1.15;
}
.user-chip strong {
  color: #fff;
  font-size: 13px;
}
.user-chip small {
  color: #cfe2f7;
  font-size: 11px;
  font-weight: 600;
}
.check {
  display: flex;
  align-items: center;
  gap: 10px;
}
.check input {
  width: auto;
  min-height: auto;
}
.permissions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.permissions fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin: 0;
  background: var(--surface);
}
.permissions legend {
  color: var(--blue);
  font-weight: 800;
  padding: 0 6px;
}

.table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}
.obligations-table table {
  min-width: 760px;
}
th,
td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .02em;
  position: sticky;
  top: 0;
  z-index: 1;
}
td { color: var(--text); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfdff; }
.money-progress {
  white-space: nowrap;
  color: var(--muted);
}
.money-progress strong {
  color: var(--text);
  font-weight: 800;
}
.money-progress span {
  display: inline-block;
  margin: 0 4px;
  color: var(--muted);
}
.cell-actions {
  min-width: 220px;
}

details summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }
.pay-box {
  display: grid;
  gap: 8px;
  min-width: 240px;
  padding: 12px;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fbff;
}
.monthly-wrap table {
  table-layout: fixed;
  min-width: 820px;
  font-size: 12px;
}
.monthly-wrap {
  max-height: calc(100vh - 220px);
  overflow: auto;
}
.print-preview .monthly-wrap {
  max-height: none;
  overflow: visible;
}
.print-preview .wrap {
  max-width: 100%;
}
.print-preview .top,
.print-preview .nav {
  display: none;
}
.monthly-table th,
.monthly-table td {
  border-right: 1px solid var(--border);
  padding: 8px 6px;
  overflow-wrap: anywhere;
}
.monthly-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 1px 0 var(--border), 0 8px 16px rgba(23, 33, 47, .06);
}
.monthly-table th:last-child,
.monthly-table td:last-child {
  border-right: 0;
}
.monthly-table th:nth-child(1),
.monthly-table td:nth-child(1) { width: 36px; }
.monthly-table th:nth-child(2),
.monthly-table td:nth-child(2) { width: 132px; }
.monthly-table th:nth-child(3),
.monthly-table td:nth-child(3) { width: 72px; }
.monthly-table th:nth-child(4),
.monthly-table td:nth-child(4) { width: 72px; }
.monthly-table th:nth-child(n+5),
.monthly-table td:nth-child(n+5) { width: 43px; }
.month-cell {
  text-align: center;
  vertical-align: middle;
}
.paid-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-height: 28px;
  border-radius: 8px;
  background: #eaf7ee;
  color: var(--green);
  font-size: 15px;
  font-weight: 900;
}
.month-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  cursor: pointer;
  font-weight: 800;
}
.month-box:hover {
  border-color: var(--blue);
  background: #f5f9ff;
}
.muted-dot {
  color: var(--muted);
}
.table-link {
  color: var(--blue);
  font-weight: 800;
}
.link-button {
  display: inline;
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.link-button:hover {
  color: var(--blue-dark);
  text-decoration: underline;
}
.affiliate-pending {
  color: var(--orange);
}
.affiliate-pending::after {
  content: "Afiliacion pendiente";
  display: block;
  margin-top: 3px;
  color: var(--orange);
  font-size: 10px;
  font-weight: 800;
}
.capital-cell .month-box {
  min-width: 54px;
}
.cell-note {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}
.modal {
  border: 0;
  border-radius: 16px;
  padding: 0;
  max-width: min(520px, calc(100vw - 28px));
  box-shadow: 0 24px 80px rgba(31, 41, 51, .28);
}
.modal::backdrop {
  background: rgba(31, 41, 51, .55);
}
.modal-card {
  display: grid;
  gap: 14px;
  padding: 22px;
  background: #fff;
}
.pay-modal {
  width: min(430px, calc(100vw - 28px));
}
.info-modal {
  width: min(460px, calc(100vw - 28px));
}
.pay-modal .actions {
  margin: 4px 0 0;
}
.pay-modal .actions .btn {
  flex: 1;
}
.detail-list {
  display: grid;
  gap: 9px;
  margin: 2px 0 4px;
}
.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.detail-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.detail-list dd {
  margin: 0;
  color: var(--text);
  font-weight: 800;
  text-align: right;
}
.modal-card h3,
.modal-card p {
  margin: 0;
}
.modal-card p {
  color: var(--muted);
  line-height: 1.45;
}
.inline {
  display: flex;
  gap: 8px;
  align-items: center;
}
.inline input { min-width: 150px; }

.install {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-screen {
  background:
    linear-gradient(135deg, rgba(35, 100, 170, .10), rgba(46, 125, 50, .06)),
    var(--bg);
}
.install-card {
  width: min(520px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
}
.login-card {
  width: min(430px, 100%);
  padding: 28px;
  border-radius: 16px;
  box-shadow: 0 22px 60px rgba(31, 41, 51, .12);
}
.login-head {
  margin-bottom: 18px;
  text-align: center;
}
.login-logo {
  display: block;
  width: min(150px, 70%);
  max-height: 82px;
  object-fit: contain;
  margin: 0 auto 14px;
}
.login-head h1 {
  margin: 0;
  font-size: 26px;
}
.login-head p {
  margin: 4px 0 0;
  color: var(--muted);
}
.login-form {
  gap: 13px;
  margin-bottom: 0;
}
.login-form input {
  min-height: 44px;
  border-radius: 10px;
}
.login-form input:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(35, 100, 170, .14);
}
.login-form .btn {
  min-height: 44px;
  border-radius: 10px;
  margin-top: 2px;
}
.settings-logo {
  display: block;
  max-width: 180px;
  max-height: 90px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  background: #fff;
}
.success { color: var(--green); font-weight: 700; }
.danger { color: var(--red); font-weight: 700; }

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }
  .top {
    padding: 9px 14px;
    gap: 8px;
  }
  .brand {
    gap: 9px;
  }
  .brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    padding: 4px;
  }
  .top h1 {
    font-size: 22px;
  }
  .top p {
    font-size: 12px;
  }
  .userbar {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
    padding: 4px;
  }
  .user-chip {
    padding-left: 7px;
  }
  .user-chip strong {
    font-size: 12px;
  }
  .user-chip small {
    font-size: 10px;
  }
  .userbar .btn {
    min-height: 32px;
    padding: 5px 11px;
    font-size: 12px;
  }
  .nav {
    padding: 10px 14px;
    gap: 8px;
  }
  .nav a {
    min-height: 38px;
    padding: 8px 13px;
    font-size: 13px;
  }
  .wrap {
    padding-top: 4px;
  }
  h2 {
    font-size: 23px;
    margin-top: 20px;
  }
  h3 {
    font-size: 17px;
  }
  .card,
  .empty {
    padding: 15px;
  }
  .metric strong {
    font-size: 25px;
  }
  .filters {
    grid-template-columns: 1fr;
    padding: 11px;
  }
  .filters .btn {
    width: 100%;
  }
  th,
  td {
    padding: 10px 11px;
  }
  .row-card,
  .profile { display: block; }
  .pill { margin-top: 12px; }
  .actions .btn,
  .actions form { width: 100%; }
  .actions .btn { margin-bottom: 8px; }
  .obligations-table {
    overflow-x: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  .obligations-table table,
  .obligations-table thead,
  .obligations-table tbody,
  .obligations-table tr,
  .obligations-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }
  .obligations-table thead {
    display: none;
  }
  .obligations-table tr {
    margin-bottom: 12px;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow-soft);
  }
  .obligations-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #eef3f8;
    font-size: 13px;
    text-align: right;
  }
  .obligations-table td::before {
    content: attr(data-label);
    flex: 0 0 92px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-align: left;
    text-transform: uppercase;
  }
  .obligations-table td:first-child {
    display: block;
    padding-top: 0;
    text-align: left;
    color: var(--blue-dark);
    font-weight: 800;
    font-size: 15px;
  }
  .obligations-table td:first-child::before {
    display: none;
  }
  .obligations-table td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }
  .obligations-table .money-progress {
    justify-content: flex-end;
  }
  .obligations-table .pill {
    margin-top: 0;
  }
  .obligations-table .cell-actions {
    display: grid;
    grid-template-columns: 1fr;
    min-width: 0;
    text-align: left;
  }
  .obligations-table .cell-actions::before {
    display: none;
  }
  .obligations-table .cell-actions .btn,
  .obligations-table .cell-actions details {
    width: 100%;
  }
  .obligations-table .pay-box {
    min-width: 0;
  }
  .monthly-wrap {
    max-height: calc(100vh - 260px);
  }
}

@media print {
  body { background: #fff; }
  .top,
  .nav,
  .no-print,
  .btn,
  details { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .card,
  .table-wrap {
    box-shadow: none;
    border-color: #cfd8e3;
  }
  table { min-width: 0; font-size: 11px; }
  th, td { padding: 7px; }
}
