:root {
  --ink: #201a16;
  --muted: #756d66;
  --line: #eadfd5;
  --line-strong: #dcc8b8;
  --brand: #c65f1b;
  --brand-dark: #984111;
  --brand-soft: #fff2e9;
  --income: #23964a;
  --income-soft: #e9f8ee;
  --expense: #c93434;
  --expense-soft: #fdeaea;
  --warning: #c77a16;
  --surface: #fbf7ef;
  --surface-2: #f4eee5;
  --card: #fffdf9;
  --shadow: 0 14px 34px rgba(72, 45, 24, .08);
  --shadow-sm: 0 8px 20px rgba(72, 45, 24, .06);
  --radius: 8px;
  --bottom-nav-height: 72px;
}

* {
  min-width: 0;
}

html {
  background: var(--surface);
}

body {
  background: var(--surface);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

a {
  color: var(--brand);
}

.auth-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -10%, rgba(255, 244, 215, .85), transparent 32%),
    linear-gradient(180deg, #fff8ed 0%, #f4e6d5 100%);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(430px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: var(--shadow);
}

.auth-panel::before,
.brand-mark {
  content: "MF";
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.app-layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #251b15;
  color: #fff8ef;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 8px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 12px;
}

.sidebar-brand .brand-mark {
  width: 42px;
  height: 42px;
  margin: 0;
  border-radius: 11px;
  font-size: .95rem;
  box-shadow: 0 10px 22px rgba(198, 95, 27, .24);
}

.sidebar-title {
  font-weight: 800;
  line-height: 1.1;
}

.sidebar-subtitle {
  color: rgba(255, 248, 239, .68);
  font-size: .78rem;
}

.sidebar nav {
  display: grid;
  gap: 4px;
}

.sidebar a {
  color: rgba(255, 248, 239, .78);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 650;
}

.sidebar a::before {
  content: attr(data-icon);
  display: inline-grid;
  place-items: center;
  width: 22px;
  color: rgba(255, 248, 239, .72);
  font-size: .95rem;
}

.sidebar a.active,
.sidebar a:hover {
  background: rgba(255, 255, 255, .12);
  color: #fff;
}

.sidebar a.active {
  box-shadow: inset 3px 0 0 var(--brand);
}

.sidebar-footer {
  flex: 0 0 auto;
  text-align: center;
  color: rgba(255, 248, 239, .56);
  font-size: .75rem;
  line-height: 1.4;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.content {
  padding: 22px;
}

.topbar,
.panel,
.metric {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.topbar {
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar h1 {
  font-weight: 800;
  letter-spacing: 0;
}

.panel {
  overflow: hidden;
}

.metric {
  padding: 17px;
  min-height: 116px;
  position: relative;
}

.metric span {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 750;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  font-size: clamp(1.35rem, 2.4vw, 1.9rem);
  margin-top: 8px;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.metric.metric-income {
  border-color: rgba(35, 150, 74, .22);
  background: linear-gradient(180deg, #fffdf9, var(--income-soft));
}

.metric.metric-expense {
  border-color: rgba(201, 52, 52, .2);
  background: linear-gradient(180deg, #fffdf9, var(--expense-soft));
}

.metric.metric-brand {
  border-color: rgba(198, 95, 27, .2);
  background: linear-gradient(180deg, #fffdf9, var(--brand-soft));
}

.btn {
  border-radius: var(--radius);
  font-weight: 750;
  min-height: 40px;
}

.btn-sm {
  min-height: 34px;
}

.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark);
  --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-dark);
  --bs-btn-active-border-color: var(--brand-dark);
}

.btn-success {
  --bs-btn-bg: var(--income);
  --bs-btn-border-color: var(--income);
}

.btn-danger {
  --bs-btn-bg: var(--expense);
  --bs-btn-border-color: var(--expense);
}

.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: rgba(198, 95, 27, .42);
  --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-border-color: var(--brand);
}

.form-label {
  color: var(--muted);
  font-weight: 750;
}

.form-control,
.form-select {
  border-color: var(--line);
  border-radius: var(--radius);
  min-height: 44px;
  background-color: #fff;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 .22rem rgba(198, 95, 27, .16);
}

.nav-tabs {
  border: 0;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.nav-tabs .nav-link {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-2);
  font-weight: 750;
  white-space: nowrap;
}

.nav-tabs .nav-link.active {
  color: var(--brand-dark);
  border-color: rgba(198, 95, 27, .28);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.table {
  margin-bottom: 0;
  color: var(--ink);
}

.table thead th {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
  border-bottom-color: var(--line);
  background: #fffaf3;
}

.table tbody td {
  border-color: var(--line);
  vertical-align: middle;
}

.table-hover tbody tr:hover {
  background-color: #fff7ed;
}

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

.filter-row .form-control,
.filter-row .form-select {
  max-width: 260px;
}

.donation-scroll {
  max-height: 620px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.donation-scroll tbody tr {
  height: 58px;
}

.action-cell,
td:last-child {
  white-space: nowrap;
}

.mobile-menu-toggle,
.mobile-bottom-nav {
  display: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.required::after {
  content: " *";
  color: var(--expense);
}

.amount-positive,
.text-success {
  color: var(--income) !important;
}

.amount-negative,
.text-danger {
  color: var(--expense) !important;
}

.status-badge,
.badge-soft {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: .78rem;
  font-weight: 800;
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.module-mobile-list {
  display: none;
}

.volunteer-card-list {
  display: none;
}

.transaction-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.transaction-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.transaction-card.income .transaction-icon {
  background: var(--income-soft);
  color: var(--income);
}

.transaction-card.expense .transaction-icon {
  background: var(--expense-soft);
  color: var(--expense);
}

.transaction-card.neutral .transaction-icon {
  background: var(--brand-soft);
  color: var(--brand);
}

.transaction-title {
  font-weight: 800;
  font-size: 1rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.transaction-meta {
  color: var(--muted);
  font-size: .88rem;
  margin-top: 3px;
}

.transaction-amount {
  font-weight: 900;
  font-size: 1.05rem;
  text-align: right;
  white-space: nowrap;
}

.transaction-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.sticky-action {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(251, 247, 239, 0), var(--surface) 24%);
  padding: 18px 0 0;
  margin-top: 16px;
}

.receipt-page {
  background: var(--surface);
  padding: 24px;
}

.template-receipt {
  max-width: 1127px;
  margin: auto;
}

.composed-receipt {
  display: block;
  width: 100%;
  height: auto;
}

.receipt-canvas {
  aspect-ratio: 1127/1162;
  background: #fff;
  padding: 12px;
}

.receipt-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.live-receipt-preview {
  max-width: 900px;
  margin-inline: auto;
}

@page {
  margin: 0;
  size: auto;
}

@media print {
  .receipt-page {
    padding: 0;
    background: #fff;
  }
  .template-receipt {
    max-width: none;
  }
  .receipt-actions {
    display: none;
  }
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    width: min(82vw, 300px);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-main {
    overflow-y: auto;
  }

  .mobile-menu-toggle {
    display: inline-flex;
  }

  .content {
    padding: 14px 14px calc(var(--bottom-nav-height) + 18px);
  }

  .topbar {
    align-items: flex-start;
    box-shadow: none;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    margin: -14px -14px 16px;
    border-radius: 0;
    background: rgba(255, 253, 249, .96);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .filter-row,
  .table-actions,
  .receipt-actions {
    width: 100%;
  }

  .filter-row .form-control,
  .filter-row .form-select,
  .filter-row .btn,
  .table-actions .btn {
    max-width: none;
    flex: 1 1 150px;
  }

  .table {
    min-width: 760px;
  }

  .table-responsive {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
  }

  .donation-scroll {
    max-height: 640px;
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 44px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: auto;
  }

  .modal-dialog {
    margin: 8px;
  }

  .modal-content {
    border-radius: var(--radius);
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top-color: var(--line);
    gap: 8px;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    height: var(--bottom-nav-height);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 7px 8px max(7px, env(safe-area-inset-bottom));
    background: rgba(255, 253, 249, .98);
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 28px rgba(72, 45, 24, .08);
  }

  .mobile-bottom-nav a,
  .mobile-bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 0;
    background: transparent;
    color: var(--muted);
    text-decoration: none;
    font-size: .72rem;
    font-weight: 750;
    border-radius: var(--radius);
  }

  .mobile-bottom-nav .active {
    color: var(--brand);
    background: var(--brand-soft);
  }

  .mobile-bottom-nav .nav-icon {
    font-size: 1.16rem;
    line-height: 1;
  }
}

@media (max-width: 576px) {
  .auth-shell {
    padding: 16px;
  }

  .auth-panel {
    padding: 24px;
  }

  .content,
  .volunteer-content {
    padding: 12px 12px calc(var(--bottom-nav-height) + 16px);
  }

  .panel {
    border-radius: var(--radius);
  }

  .modal-footer .btn {
    flex: 1 1 140px;
  }

  .modal-footer .form-check {
    width: 100%;
    margin-bottom: 4px;
  }

  .donation-scroll {
    max-height: none;
  }

  .module-table {
    display: none;
  }

  .module-mobile-list {
    display: grid;
    gap: 10px;
  }

  .volunteer-table {
    display: none;
  }

  .volunteer-card-list {
    display: grid;
    gap: 10px;
  }

  .module-result-bar {
    margin-top: 12px;
  }

  .transaction-card {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .transaction-amount {
    grid-column: 2;
    text-align: left;
  }

  .receipt-page {
    padding: 8px;
  }

  .receipt-actions .btn {
    width: 100%;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar > div {
    min-width: 0;
  }
}
