:root {
  color-scheme: light;
  --ink: #17273d;
  --muted: #52647a;
  --navy: #112948;
  --navy-deep: #0b2039;
  --accent: #24528a;
  --accent-hover: #1b4272;
  --surface: #fff;
  --canvas: #f3f6fa;
  --line: #d9e2ec;
  --line-strong: #c2cfdd;
  --pale: #edf3f9;
  --success: #23604b;
  --success-bg: #e9f4ee;
  --warning: #765016;
  --warning-bg: #fff4de;
  --danger: #9a3333;
  --danger-bg: #fdf0ef;
  --focus: #296bb6;
  --shadow: 0 2px 5px #11294808, 0 10px 28px #11294807;
  --radius: 12px;
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
h1, h2, p { margin: 0; }
h1, h2, .stat-value { font-family: "Manrope", system-ui, sans-serif; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
a { color: var(--accent); }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .91em; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.session-view { display: grid; min-height: 100vh; place-items: center; color: var(--muted); }
.brand, .brand-copy, .account { display: flex; align-items: center; }
.brand { gap: 13px; min-width: 0; }
.brand-copy { flex-direction: column; align-items: flex-start; gap: 2px; }
.brand-copy strong { font-size: 1rem; font-weight: 700; }
.brand-copy > span { color: inherit; font-size: .85rem; }
.brand-mark {
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
  padding: 4px;
  color: var(--navy);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: .8rem;
}

.login-view {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  min-height: 100vh;
}
.login-intro {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 56px;
  padding: clamp(28px, 6vw, 86px);
  overflow: hidden;
  color: var(--navy);
  background: linear-gradient(143deg, #fafcff 15%, var(--pale) 68%, #e3edf8);
}
.login-intro::before,
.login-intro::after {
  content: "";
  position: absolute;
  z-index: -1;
  aspect-ratio: 1;
  border: 1px solid #c9dbed;
  border-radius: 50%;
  pointer-events: none;
}
.login-intro::before { right: -11rem; bottom: -20rem; width: 43rem; }
.login-intro::after { right: -9rem; bottom: -16rem; width: 34rem; }
.login-brand .brand-mark { border-radius: 13px; }
.login-brand .brand-copy strong { font-size: 1.1rem; }
.login-brand .brand-copy > span, .login-intro-content p { color: var(--muted); }
.login-intro-content { padding-bottom: clamp(14px, 9vh, 100px); }
.login-intro-content::before { content: ""; display: block; width: 42px; height: 3px; margin-bottom: 23px; background: var(--accent); }
.login-intro-content h1 {
  font-size: clamp(2.35rem, 4.6vw, 4.7rem);
  font-weight: 800;
  line-height: 1.06;
  letter-spacing: -.055em;
}
.login-intro-content p { margin-top: 16px; font-size: clamp(1rem, 1.45vw, 1.17rem); }
.login-panel { display: grid; align-items: center; justify-items: center; padding: 38px; background: var(--surface); }
.login-form-wrap { width: 100%; max-width: 370px; }
.login-form-wrap h2 { font-size: 2.25rem; font-weight: 800; letter-spacing: -.04em; }
.login-form-wrap > p { color: var(--muted); }
#loginForm { display: grid; gap: 8px; margin-top: 28px; }
#loginForm label { font-size: .94rem; font-weight: 700; }
#loginForm .control { min-height: 46px; margin-bottom: 9px; }
#loginForm .button { min-height: 46px; margin-top: 4px; }
.access-note { margin-top: 22px; font-size: .88rem; }

.button, .chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  min-height: 36px;
  white-space: nowrap;
  font-weight: 700;
  text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s;
}
.primary { background: var(--accent); color: var(--surface); }
.primary:not(:disabled):hover { background: var(--accent-hover); }
.secondary, .refresh { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.secondary:not(:disabled):hover, .refresh:not(:disabled):hover, .chip:hover { background: var(--pale); border-color: var(--line-strong); }
.text-button { background: transparent; color: var(--accent); }
.text-button:hover { background: var(--pale); }
.control {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
}
.control::placeholder { color: var(--muted); opacity: 1; }
.control:focus-visible { border-color: var(--focus); }
select.control { padding-right: 19px; }
.error-message, .warning { padding: 9px 12px; border-radius: 7px; font-size: .9rem; }
.error-message { color: var(--danger); background: var(--danger-bg); }
.warning { color: var(--warning); background: var(--warning-bg); }

.masthead { border-bottom: 1px solid var(--line); background: #fbfdff; color: var(--navy); }
.masthead-inner, .dashboard { width: min(100%, 1512px); margin-inline: auto; padding-inline: clamp(16px, 3.4vw, 48px); }
.masthead-inner { display: flex; align-items: center; justify-content: space-between; gap: 13px; min-height: 75px; padding-block: 9px; }
.masthead .brand-copy > span, .user-email { color: var(--muted); }
.account { gap: 14px; }
.user-email { overflow-wrap: anywhere; font-size: .9rem; text-align: right; }
.dashboard { padding-block: clamp(23px, 3vw, 37px) 40px; }
.dashboard-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.heading-copy { display: flex; flex-direction: column; gap: 5px; }
.period-label { color: var(--muted); font-size: .94rem; font-weight: 600; }
.dashboard-heading h1 {
  font-size: clamp(1.85rem, 3vw, 2.65rem);
  font-weight: 800;
  line-height: 1.16;
  letter-spacing: -.045em;
}
.refresh span { color: var(--accent); font-size: 1.25em; line-height: 1; }

.summary { margin-bottom: 24px; }
.summary-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 10px;
}
.summary-heading h2 { font-size: 1.18rem; font-weight: 800; letter-spacing: -.025em; }
.summary-scope { color: var(--muted); font-size: .85rem; }
.stats {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(2, minmax(0, 1.2fr)) repeat(2, minmax(0, .9fr));
  gap: 12px;
}
.stat-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  min-height: 118px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.stat-label { color: var(--ink); font-size: .91rem; font-weight: 700; }
.stat-value {
  color: var(--navy);
  font-size: clamp(1.42rem, 2vw, 2.1rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.17;
  letter-spacing: -.035em;
  overflow-wrap: anywhere;
}
.stat-note { color: var(--muted); font-size: .82rem; }
.stat-collected { background: var(--pale); border-color: #cbdced; }
.stat-payment-completed .stat-value { color: var(--accent); }
.stat-payment-initiated { background: var(--warning-bg); border-color: #ecd7af; }
.stat-payment-initiated .stat-value, .stat-missing { color: var(--warning); }
.stat-follow-up .stat-value { color: var(--warning); }
.stat-action {
  min-height: 28px;
  margin: auto 0 -4px -2px;
  padding: 2px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--warning);
  font-size: .82rem;
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.stat-action:not(:disabled):hover, .stat-action[aria-pressed="true"] { color: #583a11; }

.ledger { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.ledger-head, .ledger-controls, .pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; }
.ledger-head { padding-top: 15px; }
.ledger-head h2 { font-size: 1.43rem; font-weight: 800; letter-spacing: -.035em; }
.result-count { margin-top: 2px; color: var(--muted); font-size: .88rem; min-height: 1.38em; }
.filters {
  display: grid;
  gap: 11px;
  margin-inline: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
}
.filter-top, .presets, .search-group, .sort-fields, .page-size, .page-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filter-top { justify-content: space-between; flex-wrap: wrap; }
.search-group { flex: 1 1 390px; gap: 0; }
.search-group select { flex: 0 0 12.7rem; border-radius: 7px 0 0 7px; }
.search-group input { border-left: 0; border-radius: 0 7px 7px 0; }
.search-group .control:focus-visible { border-left: 1px solid var(--focus); z-index: 1; }
.presets { flex-wrap: wrap; }
.chip { min-height: 32px; padding: 5px 9px; border-color: var(--line-strong); background: var(--surface); color: var(--accent); font-size: .87rem; }
.chip[aria-pressed="true"] { background: var(--pale); color: var(--accent-hover); border-color: #95b0cf; }
.filter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.1fr) repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 9px;
}
.filter-grid label { display: grid; gap: 4px; min-width: 0; font-size: .86rem; font-weight: 700; }
.filter-grid select, .filter-grid input { font-size: .93rem; font-weight: 400; }
.ledger-controls { min-height: 57px; padding-block: 9px; }
.sort-fields { margin-left: auto; font-size: .89rem; }
.sort-fields label { color: var(--muted); white-space: nowrap; }
.sort-fields .control, .sort-fields .button { min-height: 34px; }
.sort-fields .control { width: auto; }

.table-scroll { overflow: auto; }
.table-scroll:focus-visible { outline-offset: -2px; }
table { width: 100%; min-width: 870px; border-collapse: separate; border-spacing: 0; font-size: .94rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { width: 15%; padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
th:nth-child(2) { width: 153px; }
th { background: var(--pale); color: #3b506a; font-size: .85rem; white-space: nowrap; font-weight: 700; }
td { background: var(--surface); overflow-wrap: anywhere; }
tbody tr:nth-child(even) td { background: #fbfcfe; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td, tbody tr:focus-within td { background: var(--pale); }
td.amount, td.reference { color: var(--navy); font-weight: 700; }
td.code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .86rem; }
.created-date { white-space: nowrap; }
.created-date small { display: block; color: var(--muted); font-size: .86em; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 5px;
  background: #edf1f7;
  color: #43546b;
  font-size: .83rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.badge-good { background: var(--success-bg); color: var(--success); }
.badge-pending { background: var(--warning-bg); color: var(--warning); }
.badge-error { background: var(--danger-bg); color: var(--danger); }
.reference-button {
  display: inline-block;
  min-height: 28px;
  padding: 2px 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}
.reference-button:hover, .receipt-link:hover { color: var(--navy-deep); }
.receipt-link { text-underline-offset: 3px; }
.table-message { padding: 30px 16px; text-align: center; color: var(--muted); }
#loadError p { margin-bottom: 9px; color: var(--danger); }

.pagination { border-top: 1px solid var(--line); font-size: .9rem; color: var(--muted); }
.page-size { white-space: nowrap; }
.page-size .control { min-height: 34px; width: auto; }
.page-nav .button { min-height: 34px; }
#pageInfo { text-align: center; }

dialog {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: min(100%, 480px);
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: -14px 0 45px #11294828;
}
dialog::backdrop { background: #0b203980; }
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 21px 24px;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.detail-header h2 { font-size: 1.45rem; letter-spacing: -.035em; font-weight: 800; }
.detail-header p { color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }
.close-dialog { width: 36px; min-height: 36px; padding: 0; font-size: 1.5rem; line-height: 1; }
.detail-body { padding: 0 24px 24px; }
.detail-section { padding-block: 19px; border-bottom: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 8px; font-size: 1rem; color: var(--navy); }
.detail-section dl { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 8px 14px; margin: 0; align-items: start; }
.detail-section dt { color: var(--muted); }
.detail-section dd { margin: 0; overflow-wrap: anywhere; }
.detail-body .receipt-open { margin-top: 17px; }
.toast {
  position: fixed;
  z-index: 2;
  right: 18px;
  bottom: 18px;
  width: max-content;
  max-width: min(420px, calc(100% - 36px));
  border-radius: 8px;
  padding: 11px 16px;
  color: var(--surface);
  background: var(--navy);
  box-shadow: 0 4px 20px #11294836;
}
.toast.error { background: var(--danger); }

@media (min-width: 1000px) {
  .table-scroll { max-height: min(65vh, 700px); }
  th { position: sticky; top: 0; z-index: 1; }
}
@media (max-width: 1120px) {
  .filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .login-intro { padding: 28px; }
}
@media (max-width: 670px) {
  .login-view { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-intro { gap: 24px; }
  .login-intro-content { padding-bottom: 0; }
  .login-intro-content::before { display: none; }
  .login-intro-content h1 br { display: none; }
  .login-intro-content p { margin-top: 7px; }
  .login-panel { align-items: start; padding: 28px 22px; }
  .login-form-wrap h2 { font-size: 2rem; }
  .brand-copy strong { font-size: .93rem; }
  .brand-copy > span { font-size: .78rem; }
  .masthead .brand-mark { width: 48px; height: 48px; }
  .account { align-items: flex-end; flex-direction: column-reverse; gap: 3px; min-width: 0; max-width: 30%; }
  .account .button { min-height: 32px; padding: 4px 8px; }
  .user-email { max-width: 100%; overflow: hidden; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
  .dashboard-heading { margin-bottom: 17px; padding-bottom: 14px; }
  .summary { margin-bottom: 18px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat-card { min-height: 98px; padding: 10px 11px; }
  .stat-payments-started { grid-column: 1 / -1; }
  .stat-action { min-height: 32px; }
  .reference-button { min-height: 34px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ledger-head, .ledger-controls, .pagination { padding-inline: 12px; }
  .filters { margin-inline: 12px; }
  .ledger-controls { flex-wrap: wrap; }
  .sort-fields { flex-wrap: wrap; justify-content: flex-end; }
}
@media (max-width: 430px) {
  .dashboard-heading { align-items: flex-start; gap: 10px; }
  .dashboard-heading h1 { font-size: clamp(1.52rem, 6vw, 1.85rem); }
  .refresh { gap: 5px; padding-inline: 8px; }
  .search-group select { flex-basis: 43%; }
  .pagination { flex-wrap: wrap; }
  .page-nav { justify-content: space-between; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
