:root {
  --ink: #1c2b29;
  --muted: #63736f;
  --line: #d9e2df;
  --surface: #ffffff;
  --background: #f3f7f5;
  --primary: #176b5b;
  --primary-dark: #0d4c40;
  --income: #e8f5ee;
  --income-ink: #17633e;
  --expense: #fdf0eb;
  --expense-ink: #9a4630;
  --danger: #ad3429;
  --success: #166534;
}

html {
  font-size: 15px;
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(23, 107, 91, .08), transparent 30rem),
    var(--background);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-container {
  width: min(1520px, calc(100% - 32px));
  margin-inline: auto;
}

.app-nav {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
}

.nav-content {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 750;
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: white;
  background: var(--primary);
  font-family: Georgia, serif;
  font-size: 1.25rem;
}

.nav-label {
  color: var(--muted);
  font-size: .84rem;
  letter-spacing: .03em;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav-user {
  color: var(--ink);
  font-size: .86rem;
  font-weight: 650;
}

.nav-link-button {
  border: 0;
  padding: 0;
  color: var(--primary-dark);
  background: none;
  font-size: .86rem;
  font-weight: 700;
  text-decoration: none;
}

.nav-link-button:hover {
  color: var(--primary);
}

.login-shell {
  width: min(460px, 100%);
  margin: 24px auto 48px;
}

.login-shell h1 {
  margin: 6px 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.4rem;
  font-weight: 500;
}

.login-shell > p {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 22px;
}

.login-form input {
  height: 44px;
  padding: 0 12px;
}

.primary-btn {
  height: 44px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--primary);
  font-weight: 700;
}

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

.login-hint,
.login-resend {
  margin-top: 16px;
  color: var(--muted);
  font-size: .9rem;
}

.link-btn {
  border: 0;
  padding: 0;
  color: var(--primary-dark);
  background: none;
  font-weight: 700;
}

.login-alert {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.login-alert-error {
  border-color: #f0c7c2;
  color: var(--danger);
  background: #fff6f4;
}

main {
  padding: 42px 0 24px;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.eyebrow {
  color: var(--primary);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.page-heading h1 {
  margin: 5px 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.2rem, 4vw, 3.6rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.035em;
}

.page-heading p,
.section-title p {
  margin: 0;
  color: var(--muted);
}

.connection-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .8);
  color: var(--muted);
  font-size: .8rem;
}

.month-navigation {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -10px 0 24px;
}

.month-navigation strong {
  margin-left: 4px;
  font-size: .92rem;
}

.month-nav-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--primary-dark);
  background: var(--surface);
  font-size: 1.2rem;
  font-weight: 800;
  text-decoration: none;
}

.month-nav-button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.month-picker label {
  display: flex;
  align-items: center;
  gap: 9px;
}

.month-picker label span {
  margin: 0;
}

.month-picker input {
  width: auto;
  height: 40px;
  padding: 0 10px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22a06b;
  box-shadow: 0 0 0 4px rgba(34, 160, 107, .12);
}

.panel {
  margin-bottom: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 32px rgba(31, 53, 48, .055);
}

.reorder-upload {
  padding: 24px;
}

.reorder-upload label {
  display: block;
  max-width: 620px;
}

.reorder-upload input[type="file"] {
  min-height: 48px;
  padding: 10px 12px;
}

.reorder-upload p {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: .84rem;
}

.reorder-empty-preview {
  min-height: 220px;
  background: #f5f7f6;
}

.reorder-empty-preview iframe {
  visibility: hidden;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.section-title > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 750;
}

.step-number {
  color: var(--primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .75rem;
  font-weight: 800;
}

.header-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 18px;
  padding: 24px;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: #41514e;
  font-size: .78rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid #cfd9d6;
  border-radius: 8px;
  color: var(--ink);
  background: white;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.header-grid input {
  height: 42px;
  padding: 0 12px;
}

.summary-grid {
  grid-template-columns: 1.2fr 1.4fr;
}

.sample-note {
  margin-bottom: 18px;
  padding: 11px 14px;
  border: 1px solid #e0d2a8;
  border-radius: 10px;
  color: #6b551d;
  background: #fbf5e4;
  font-size: .82rem;
}

.document-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .86);
}

.document-tab {
  min-height: 42px;
  padding: 0 20px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: .86rem;
  font-weight: 750;
  cursor: pointer;
}

.document-tab:hover {
  color: var(--primary-dark);
  background: #eef5f2;
}

.document-tab.active {
  color: white;
  background: var(--primary);
}

.document-panel[hidden] {
  display: none;
}

.report-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label span small {
  display: block;
  margin-top: 2px;
  color: #83908d;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .66rem;
  font-weight: 500;
}

.checkbox-field {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid #cfd9d6;
  border-radius: 8px;
  background: #fafcfb;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.checkbox-field span {
  margin: 0;
}

.table-subtitle {
  margin: 0 0 10px;
  color: #41514e;
  font-size: .82rem;
  font-weight: 750;
}

.report-group {
  margin: 0 24px 24px;
  padding: 16px 16px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8faf9;
}

.report-category {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}

.report-category-title {
  margin: 0 0 12px;
  color: var(--primary-dark);
  font-size: .88rem;
  font-weight: 750;
}

.compact-grid {
  padding: 0 0 14px;
}

.betel-table-wrap {
  padding: 0 24px 24px;
}

.betel-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.betel-table th,
.betel-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px;
}

.betel-table th:first-child,
.betel-table td:first-child {
  border-left: 1px solid var(--line);
}

.betel-table thead th {
  border-top: 1px solid var(--line);
  background: #f8faf9;
  font-size: .72rem;
  font-weight: 750;
  text-align: left;
}

.betel-table .row-number {
  width: 42px;
  text-align: center;
  color: #82908d;
  background: #f8faf9;
}

.betel-table td input {
  height: 38px;
  padding: 0 10px;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, .12);
}

.table-shell {
  max-height: 620px;
  overflow: auto;
}

.ledger-table {
  width: 100%;
  min-width: 1130px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.ledger-table th,
.ledger-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.ledger-table th:last-child,
.ledger-table td:last-child {
  border-right: 0;
}

.ledger-table thead {
  position: sticky;
  top: 0;
  z-index: 3;
}

.ledger-table th {
  padding: 9px 8px;
  color: #4c5c58;
  background: #f8faf9;
  font-size: .72rem;
  font-weight: 750;
  text-align: center;
}

.ledger-table .group-head th {
  border-bottom-color: #cbd6d3;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.ledger-table .donation-group {
  color: #1d4d3c;
  background: #e8f5ee;
}

.ledger-table .bank-group {
  color: #1a4a5c;
  background: #e8f1f6;
}

.ledger-table .other-group {
  color: #4a3d1d;
  background: #f6f1e4;
}

.ledger-table .income-col {
  color: var(--income-ink);
  background: var(--income);
}

.ledger-table .expense-col {
  color: var(--expense-ink);
  background: var(--expense);
}

.ledger-table .row-number {
  width: 42px;
  text-align: center;
}

.ledger-table .day-column {
  width: 58px;
}

.ledger-table .description-column {
  width: 260px;
}

.ledger-table .symbol-column {
  width: 60px;
}

.ledger-table tbody .row-number {
  color: #82908d;
  background: #f8faf9;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .72rem;
}

.ledger-table td {
  height: 39px;
  padding: 4px;
  background: white;
}

.ledger-table tbody tr:hover td {
  background: #fbfdfc;
}

.ledger-table td input {
  height: 30px;
  padding: 0 7px;
  border-color: transparent;
  border-radius: 5px;
  font-size: .78rem;
}

.ledger-table td input:hover {
  border-color: #d7e0de;
}

.ledger-table td input:focus {
  border-color: var(--primary);
}

.action-bar {
  position: sticky;
  bottom: 14px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 22px;
  padding: 13px 16px;
  border: 1px solid rgba(207, 219, 215, .95);
  border-radius: 13px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 10px 38px rgba(27, 49, 44, .13);
  backdrop-filter: blur(14px);
}

.action-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--ink);
  font-size: .84rem;
  font-weight: 650;
  user-select: none;
}

.toggle-control {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  align-items: center;
}

.toggle-control input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 42px;
  height: 24px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.toggle-track {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #cfd9d6;
  box-shadow: inset 0 0 0 1px rgba(31, 53, 48, .08);
  transition: background .15s ease;
}

.toggle-track::after {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  margin: 3px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(27, 49, 44, .22);
  transition: transform .15s ease;
}

.toggle-control input:checked ~ .toggle-track {
  background: var(--primary);
}

.toggle-control input:checked ~ .toggle-track::after {
  transform: translateX(18px);
}

.toggle-control input:focus-visible ~ .toggle-track {
  box-shadow: 0 0 0 3px rgba(23, 107, 91, .22);
}

.action-buttons {
  display: flex;
  gap: 9px;
  margin-left: auto;
}

.btn-generate,
.btn-download {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: 8px;
  font-size: .84rem;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}

.btn-generate {
  border: 1px solid var(--primary);
  color: white;
  background: var(--primary);
}

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

.btn-generate:disabled {
  cursor: wait;
  opacity: .75;
}

.btn-download {
  border: 1px solid #bdcbc7;
  color: var(--primary-dark);
  background: white;
}

.btn-download.disabled {
  pointer-events: none;
  color: #97a39f;
  background: #f3f5f4;
}

.button-loader {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.loading .button-label {
  display: none;
}

.loading .button-loader {
  display: block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.form-message {
  min-height: 20px;
  color: var(--muted);
  font-size: .82rem;
}

.form-message.error {
  color: var(--danger);
}

.form-message.success {
  color: var(--success);
}

.pdf-frame {
  height: min(78vh, 960px);
  min-height: 580px;
  padding: 10px;
  background: #e8eeec;
}

.pdf-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 8px;
  background: white;
}

.app-footer {
  padding: 22px 0 32px;
  color: #7b8986;
  font-size: .78rem;
  text-align: center;
}

@media (max-width: 900px) {
  .header-grid,
  .summary-grid,
  .report-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 600px) {
  .app-container {
    width: min(100% - 20px, 1520px);
  }

  main {
    padding-top: 26px;
  }

  .header-grid,
  .summary-grid,
  .report-grid {
    grid-template-columns: 1fr;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .action-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .action-meta {
    width: 100%;
  }

  .action-buttons,
  .btn-generate,
  .btn-download {
    width: 100%;
  }

  .pdf-frame {
    min-height: 460px;
  }

  .nav-label {
    display: none;
  }

  .document-tabs {
    overflow-x: auto;
  }

  .document-tab {
    flex: 1 0 auto;
  }
}
