:root {
  --bg: #f3f6fa;
  --surface: #fff;
  --ink: #172235;
  --muted: #69788d;
  --line: #dce4ed;
  --blue: #1677e8;
  --blue-dark: #0c5dbb;
  --green: #169c59;
  --red: #c33c3c;
  --shadow: 0 12px 34px rgba(23, 34, 53, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a { color: var(--blue-dark); }
button, input, textarea, select { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 68px;
  padding: .7rem max(1rem, calc((100vw - 1180px) / 2));
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -.03em;
}

.brand span span { color: var(--blue); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: #fff;
  background: var(--blue);
  border-radius: 10px;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: .4rem;
}

.topbar nav > a:not(.btn), .nav-button {
  padding: .5rem .7rem;
  border: 0;
  color: var(--muted);
  background: transparent;
  text-decoration: none;
  font-weight: 650;
  cursor: pointer;
}

.topbar nav > a.active { color: var(--blue-dark); }
.topbar nav form { margin: 0; }

.shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.2rem 0 4rem;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1, .login-card h1, .error-card h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  letter-spacing: -.045em;
  line-height: 1.1;
}

.page-header p { margin: .35rem 0 0; }
.eyebrow { margin: 0 0 .35rem; color: var(--blue-dark); font-size: .76rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.muted { color: var(--muted); }
code {
  display: inline-block;
  margin: 0 .15rem .25rem 0;
  padding: .1rem .35rem;
  color: var(--blue-dark);
  background: #eaf3ff;
  border-radius: 5px;
  font-size: .82rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: .58rem .9rem;
  border: 1px solid transparent;
  border-radius: 9px;
  text-decoration: none;
  font-weight: 750;
  cursor: pointer;
}

.btn-primary { color: #fff; background: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { color: var(--ink); background: #fff; border-color: var(--line); }
.btn-whatsapp { color: #fff; background: var(--green); }
.btn-danger { color: var(--red); background: #fff; border-color: #efcaca; }
.btn-small { min-height: 36px; padding: .4rem .7rem; }

.alert {
  margin-bottom: 1rem;
  padding: .75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
}
.alert-success { color: #146c43; border-color: #badbcc; background: #dff4e9; }
.alert-danger { color: #842029; border-color: #f5c2c7; background: #f8d7da; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .85rem;
  margin-bottom: 2rem;
}

.stats article {
  padding: 1.15rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 6px 20px rgba(23, 34, 53, .035);
}

.stats strong { display: block; font-size: 1.7rem; letter-spacing: -.04em; }
.stats span { color: var(--muted); font-size: .9rem; }

.panel-section { margin-top: 2rem; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.section-heading h2, .form-card h2 { margin: 0; font-size: 1.2rem; letter-spacing: -.025em; }
.section-heading span { color: var(--muted); font-size: .9rem; }

.client-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .85rem;
}

.client-card {
  padding: 1.05rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 6px 20px rgba(23, 34, 53, .035);
}

.client-card-alert { border-color: #efbbbb; }
.client-card-top { display: flex; justify-content: space-between; gap: .6rem; }
.client-name { color: var(--ink); font-size: 1.08rem; font-weight: 800; text-decoration: none; }
.client-card-top p { margin: .2rem 0 0; color: var(--muted); font-size: .88rem; }
.day { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.amount { margin: 1rem 0 .55rem; font-size: 1.7rem; font-weight: 850; letter-spacing: -.04em; }
.meta { min-height: 30px; }

.status {
  display: inline-flex;
  align-items: center;
  padding: .25rem .5rem;
  color: var(--muted);
  background: #eef2f6;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 750;
}
.status-danger { color: #982f2f; background: #fce7e7; }
.status-ok { color: #146c43; background: #def3e8; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-top: .9rem; }
.actions form { margin: 0; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 6px 20px rgba(23, 34, 53, .035);
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: .85rem 1rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); background: #f8fafc; font-size: .76rem; letter-spacing: .05em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
td a { color: var(--ink); font-weight: 750; }
.row-muted { opacity: .55; }
.empty { padding: 1.4rem; color: var(--muted); text-align: center; }

.form-card, .error-card {
  padding: clamp(1.1rem, 3vw, 1.6rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: .35rem; color: var(--ink); font-size: .9rem; font-weight: 750; }
label small { color: var(--muted); font-weight: 450; }

input, textarea, select {
  width: 100%;
  padding: .68rem .75rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd9e4;
  border-radius: 8px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(22, 119, 232, .12); }
.check { display: flex; align-items: center; gap: .55rem; }
.check input { width: 18px; height: 18px; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 1.2rem; }

.detail-grid { display: grid; grid-template-columns: .9fr 1.1fr; gap: 1rem; }
.details { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.details div { padding: .75rem; background: #f7f9fc; border-radius: 9px; }
.details dt { color: var(--muted); font-size: .78rem; }
.details dd { margin: .2rem 0 0; font-weight: 800; }
.inline-form { display: flex; align-items: end; gap: .6rem; padding: 1rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.inline-form input { width: 120px; }
.notes { margin: 1rem 0; }
.notes p { margin: .3rem 0 0; color: var(--muted); }
.message-preview { margin: 1rem 0; padding: 1rem; color: #1d5639; background: #e4f6ec; border-radius: 10px; }
.receipt-banner {
  margin-bottom: 1.25rem;
  border-color: rgba(22, 156, 89, .35);
  background:
    radial-gradient(500px 160px at 100% 0%, rgba(22, 156, 89, .12), transparent 60%),
    #fff;
}
.receipt-preview {
  margin: .85rem 0 1rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #e8eef5;
  height: 420px;
}
.receipt-preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.payments-table {
  margin-top: .6rem;
}

.actions-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .4rem;
  white-space: nowrap;
}

.actions-cell form {
  margin: 0;
}
.history { display: grid; gap: .55rem; }
.history div { display: flex; justify-content: space-between; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.history span { color: var(--muted); }

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 1rem;
  background: radial-gradient(circle at 80% 10%, #dbeeff, transparent 35%), var(--bg);
}
.login-card { width: min(430px, 100%); padding: 2rem; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.brand-login { margin-bottom: 1.8rem; }
.login-card .muted { margin: .5rem 0 1.3rem; }
.stack { display: grid; gap: 1rem; }
.error-card { margin-top: 3rem; text-align: center; }
.error-card .btn { margin-top: 1rem; }

@media (max-width: 850px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .client-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  .topbar nav { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 580px) {
  .topbar { position: static; flex-direction: column; align-items: stretch; }
  .topbar nav { justify-content: flex-start; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .stats, .client-grid, .form-grid, .details { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .shell { width: min(100% - 1rem, 1180px); padding-top: 1rem; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form input { width: 100%; }
}
