/* Paneles web de Saldar: mismos tokens que la app (docs/12 §7). */
:root {
  --primary: #1652f0;
  --primary-pressed: #123fae;
  --primary-tint: #e8eefe;
  --ink: #0f1419;
  --ink2: #5e6670;
  --ink3: #687079;
  --canvas: #f2f3f5;
  --surface: #ffffff;
  --surface2: #f7f8f9;
  --divider: #e3e6ea;
  --positive: #0b8a5b;
  --positive-tint: #e4f5ec;
  --positive-ink: #0b6b47;
  --pending: #c08a00;
  --pending-tint: #fdf3df;
  --pending-ink: #7a5400;
  --partial: #b4521a;
  --partial-tint: #fcede3;
  --partial-ink: #8f3f10;
  --overdue: #c8352b;
  --overdue-tint: #fbeae8;
  --overdue-ink: #a32a21;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 20, 25, 0.04), 0 6px 18px rgba(15, 20, 25, 0.06);
}

* {
  box-sizing: border-box;
}

/* Las clases con display (.tabs, .btn, .tip) no deben pisar al atributo hidden. */
[hidden] {
  display: none !important;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  font-family:
    Inter,
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand img {
  width: 30px;
  height: 30px;
  border-radius: 9px;
}

.brand small {
  font-weight: 600;
  color: var(--ink3);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar .spacer {
  flex: 1;
}

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tabs button {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  color: var(--ink2);
  cursor: pointer;
}

.tabs button[aria-current='page'] {
  background: var(--ink);
  color: #fff;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: grid;
  /* minmax(0, …): una tabla ancha se desplaza dentro de su tarjeta, no estira la página. */
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card h2,
.card h3 {
  margin: 0 0 6px;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.muted {
  color: var(--ink2);
}

.small {
  font-size: 13px;
}

.overline {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink3);
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
}

.stat {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

.stat.hero {
  background: var(--ink);
  color: #fff;
}

.stat.hero .overline {
  color: rgba(255, 255, 255, 0.7);
}

.stat .amount {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-top: 4px;
}

a.stat {
  color: inherit;
  display: block;
}

a.stat:hover {
  outline: 2px solid var(--primary-tint);
}

.stat.hero .amount {
  font-size: 40px;
}

.stat .amount .cur {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink3);
  margin-left: 4px;
}

.stat.hero .amount .cur {
  color: rgba(255, 255, 255, 0.7);
}

.stat .note {
  margin-top: 4px;
  font-size: 13px;
  color: var(--ink2);
}

.stat.hero .note {
  color: rgba(255, 255, 255, 0.8);
}

.bar {
  display: flex;
  gap: 3px;
  height: 6px;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 14px;
}

.bar span {
  display: block;
  height: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--divider);
  vertical-align: top;
}

th {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink3);
}

td.num,
th.num {
  text-align: right;
  white-space: nowrap;
}

tr.link {
  cursor: pointer;
}

tr.link:hover {
  background: var(--surface2);
}

.table-wrap {
  overflow-x: auto;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--surface2);
  color: var(--ink2);
  white-space: nowrap;
}

.badge.overdue {
  background: var(--overdue-tint);
  color: var(--overdue-ink);
}

.badge.pending {
  background: var(--pending-tint);
  color: var(--pending-ink);
}

.badge.partial {
  background: var(--partial-tint);
  color: var(--partial-ink);
}

.badge.paid,
.badge.clear,
.badge.pro,
.badge.team,
.badge.enterprise,
.badge.active {
  background: var(--positive-tint);
  color: var(--positive-ink);
}

.badge.free {
  background: var(--primary-tint);
  color: var(--primary-pressed);
}

.badge.cancelled,
.badge.voided,
.badge.expired {
  background: var(--surface2);
  color: var(--ink3);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 14px;
  border: 0;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}

.btn:hover {
  background: var(--primary-pressed);
}

.btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--divider);
}

.btn.secondary:hover {
  background: var(--surface2);
}

.btn.danger {
  background: var(--overdue-tint);
  color: var(--overdue-ink);
}

.btn.solid-danger {
  background: var(--overdue);
  color: #fff;
}

.btn.solid-danger:hover {
  background: var(--overdue-ink);
}

.btn.small {
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.field {
  display: grid;
  gap: 4px;
}

.field label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink3);
}

.field label.plain {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink2);
}

.field input,
.field select,
.field textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  min-width: 0;
}

.field input:focus,
.field select:focus,
.search:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: transparent;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}

.row > * {
  flex: 1 1 160px;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chips button {
  border: 1px solid var(--divider);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink2);
  cursor: pointer;
}

.chips button[aria-pressed='true'] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.notice {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.notice.ok {
  background: var(--positive-tint);
  color: var(--positive-ink);
}

.notice.error {
  background: var(--overdue-tint);
  color: var(--overdue-ink);
}

.notice.info {
  background: var(--primary-tint);
  color: var(--primary-pressed);
}

.center {
  max-width: 460px;
  margin: 48px auto;
  text-align: center;
  display: grid;
  gap: 14px;
  justify-items: center;
}

.center h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.03em;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary-tint);
  color: var(--primary-pressed);
  font-weight: 800;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--ink2);
}

.search {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--divider);
  border-radius: 14px;
  background: var(--surface);
}

footer.note {
  color: var(--ink3);
  font-size: 12px;
  text-align: center;
  padding: 12px;
}

/* ---------- Composición ---------- */

.grid-2 {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
}

.context {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.context h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.context .spacer {
  flex: 1;
}

.card .sub {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ink2);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.danger-zone {
  border: 1px solid var(--overdue-tint);
}

dl.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
}

dl.facts dt {
  color: var(--ink2);
}

dl.facts dd {
  margin: 0;
  font-weight: 600;
}

code {
  font-size: 12px;
  color: var(--ink2);
}

/* ---------- Gráficos (shared/charts.js) ---------- */

.chart {
  position: relative;
}

.cols {
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding-top: 22px;
  border-bottom: 1px solid var(--divider);
}

.col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: default;
  font: inherit;
}

.col:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-radius: 4px;
}

.col .fill {
  position: relative;
  display: block;
  width: 100%;
  max-width: 24px;
  border-radius: 4px 4px 0 0;
  background: var(--primary);
}

.col:hover .fill,
.col:focus-visible .fill {
  background: var(--primary-pressed);
}

.cap {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.cap.start {
  left: 0;
  transform: none;
}

.cap.end {
  left: auto;
  right: 0;
  transform: none;
}

.axis {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink3);
}

.axis span {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  justify-content: center;
  white-space: nowrap;
}

.axis span.start {
  justify-content: flex-start;
}

.axis span.end {
  justify-content: flex-end;
}

.tip {
  position: absolute;
  top: 0;
  z-index: 2;
  display: grid;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.tip strong {
  font-size: 14px;
}

.tip span {
  color: rgba(255, 255, 255, 0.75);
}

details.data {
  margin-top: 10px;
  font-size: 13px;
}

details.data summary {
  cursor: pointer;
  color: var(--ink2);
  font-weight: 600;
}

.bars {
  display: grid;
  gap: 4px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(96px, 34%) 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: left;
}

button.bar-row {
  cursor: pointer;
}

button.bar-row:hover {
  background: var(--surface2);
}

.bar-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.bar-label small {
  display: block;
  font-weight: 500;
  color: var(--ink2);
  font-size: 12px;
}

.bar-track {
  display: block;
  min-width: 0;
}

.bar-fill {
  display: block;
  height: 14px;
  border-radius: 0 4px 4px 0;
  background: var(--primary);
}

.bar-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Diálogo (shared/ui.js) ---------- */

.dialog {
  width: min(440px, calc(100% - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 20px;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(15, 20, 25, 0.3);
}

.dialog::backdrop {
  background: rgba(15, 20, 25, 0.45);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.dialog form {
  display: grid;
  gap: 12px;
}

.dialog-body {
  display: grid;
  gap: 10px;
  color: var(--ink2);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- Impresión (estado de cuenta) ---------- */

.print-only {
  display: none;
}

@media print {
  body {
    background: #fff;
    font-size: 12px;
  }

  .topbar,
  footer.note,
  .no-print,
  details.data {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  .wrap {
    padding: 0;
    max-width: none;
  }

  .card {
    box-shadow: none;
    padding: 0;
    break-inside: avoid;
  }

  .table-wrap {
    overflow: visible;
  }

  tr.link {
    cursor: auto;
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 16px;
  }

  .tabs {
    order: 5;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .tabs button {
    flex: none;
    padding: 8px 10px;
  }

  .who-name {
    display: none;
  }

  .stat .amount {
    font-size: 22px;
  }

  .stat.hero .amount {
    font-size: 32px;
  }
}
