﻿:root {
  --bg: #eef4f1;
  --surface: #ffffff;
  --surface-soft: #f4f8f6;
  --ink: #1b2723;
  --muted: #5d6d67;
  --brand: #1f6f52;
  --brand-soft: #daf0e6;
  --accent: #ba5d2a;
  --ok: #1f8b4c;
  --warn: #c18a05;
  --line: #d8e4de;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(21, 45, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 20%, #dfeee7 0%, transparent 35%),
    radial-gradient(circle at 85% 10%, #f4e3d8 0%, transparent 30%),
    var(--bg);
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: linear-gradient(160deg, #10352a 0%, #1f6f52 100%);
  color: #ecf7f2;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.4rem;
}

.brand-mark {
  height: 44px;
  width: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand-title {
  font-family: "DM Serif Display", serif;
  font-size: 1.15rem;
}

.brand-subtitle {
  font-size: 0.78rem;
  opacity: 0.86;
}

.menu {
  display: grid;
  gap: 0.45rem;
}

.menu-item {
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #e5f3ed;
  text-align: left;
  padding: 0.72rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.menu-item:hover,
.menu-item.active {
  background: rgba(255, 255, 255, 0.14);
}

.sidebar-foot {
  margin-top: auto;
  font-size: 0.85rem;
  opacity: 0.9;
}

.main-area {
  padding: 1.2rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.topbar-left {
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

#viewTitle {
  font-size: 1.6rem;
  font-family: "DM Serif Display", serif;
}

#viewSubtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.topbar-right {
  display: flex;
  gap: 0.7rem;
  align-items: center;
}

.icon-btn,
.primary-btn {
  border: 0;
  border-radius: 12px;
  padding: 0.62rem 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.icon-btn {
  background: var(--surface-soft);
}

.primary-btn {
  background: var(--brand);
  color: #fff;
}

.search-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.3rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
}

.search-wrap input,
.toolbar input,
.toolbar select,
.settings-grid input,
.settings-grid select {
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  color: inherit;
}

.content-view {
  display: none;
  animation: fade 0.24s ease;
}

.content-view.active {
  display: block;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem;
}

.kpi p {
  color: var(--muted);
  font-size: 0.85rem;
}

.kpi h3 {
  margin-top: 0.35rem;
  font-size: 1.45rem;
}

.two-col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.8rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-top: 0.8rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.panel-head h2 {
  font-size: 1.02rem;
}

.badge {
  font-size: 0.72rem;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  font-weight: 700;
}

.badge.warning {
  color: #8c5c00;
  background: #fff6de;
  border-color: #ffe1a0;
}

.badge.success {
  color: #0e6c39;
  background: #dbf4e5;
  border-color: #9ad8b4;
}

#dataSourceBadge[data-source="api"] {
  color: #0e6c39;
  background: #dbf4e5;
  border-color: #9ad8b4;
}

#dataSourceBadge[data-source="mixed"] {
  color: #8c5c00;
  background: #fff6de;
  border-color: #ffe1a0;
}

.sparkline {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  align-items: end;
  gap: 0.25rem;
  height: 170px;
}

.sparkline div {
  border-radius: 7px 7px 0 0;
  background: linear-gradient(180deg, #2f9b73, #1f6f52);
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.55rem;
}

.list li,
.cards article {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  padding: 0.72rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.65rem;
}

.toolbar {
  display: flex;
  gap: 0.55rem;
  margin-bottom: 0.75rem;
}

.crud-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.crud-form input,
.crud-form select {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 0.5rem 0.6rem;
  font: inherit;
}

.crud-form .primary-btn,
.crud-form .icon-btn {
  align-self: stretch;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
}

.action-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 0.3rem 0.45rem;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.action-btn.delete {
  color: #9a2f2f;
  border-color: #e7b7b7;
  background: #fff5f5;
}

.toolbar input,
.toolbar select {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 0.5rem 0.6rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.55rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

th {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 0.8rem;
}

.fund-row {
  margin-bottom: 0.8rem;
}

.fund-row .meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.24rem;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #dcebe4;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #2c916a, #57b888);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  gap: 0.8rem;
}

.settings-grid label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.settings-grid input,
.settings-grid select {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 0.5rem 0.6rem;
}

.api-field {
  grid-column: 1 / -1;
}

.settings-actions {
  display: flex;
  gap: 0.5rem;
  align-items: end;
}

.muted-note {
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 0.85rem;
}

#menuToggle {
  display: none;
}

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

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    z-index: 20;
    width: 260px;
    transition: left 0.24s ease;
  }

  .sidebar.show {
    left: 0;
  }

  .main-area {
    padding: 1rem;
  }

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

  .topbar-right {
    width: 100%;
    flex-wrap: wrap;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .two-col,
  .split-grid,
  .settings-grid,
  .crud-form {
    grid-template-columns: 1fr;
  }

  .settings-actions {
    flex-wrap: wrap;
  }

  #menuToggle {
    display: inline-block;
  }
}

/* Dashboard feedback uses the existing palette and panel layout. */
.dashboard-toolbar {
  gap: 0.75rem;
  flex-wrap: wrap;
}

.dashboard-panel-status:not([hidden]),
.dashboard-retry:not([hidden]) {
  margin-bottom: 0.65rem;
}

.dashboard-panel-status[data-state="error"] {
  color: var(--accent);
}

#dashboardRefreshBtn:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* Shared interaction states extend the existing ChurchFlow palette. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  top: -5rem;
  left: 1rem;
  z-index: 100;
  background: var(--surface);
  color: var(--brand);
  padding: 0.8rem;
  border-radius: 8px;
}
.skip-link:focus { top: 1rem; }
body :is(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 3px;
}
.search-wrap:focus-within { box-shadow: 0 0 0 2px var(--brand); }
button:disabled { cursor: not-allowed; opacity: 0.65; }
.is-loading::before,
.dashboard-panel-status[data-state="loading"]::before {
  content: "";
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-right: 0.5em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.1em;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.form-feedback, .collection-status, .result-count {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.6rem 0;
  overflow-wrap: anywhere;
}
.form-feedback[data-state="error"], #loginError { color: #9a2f2f; }
.form-feedback[data-state="success"] { color: var(--brand); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: #9a2f2f; box-shadow: 0 0 0 1px #9a2f2f; }
.empty-state, .empty-row td { padding: 1.1rem; color: var(--muted); text-align: center; }
.toast-region {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  width: min(390px, calc(100vw - 2rem));
  max-height: 50vh;
  overflow-y: auto;
  display: grid;
  gap: 0.6rem;
  pointer-events: none;
}
.toast {
  display: flex;
  gap: 0.8rem;
  align-items: start;
  padding: 0.85rem 1rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 12px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}
.toast p { flex: 1; }
.toast-error { border-left-color: #9a2f2f; }
.toast-warning { border-left-color: var(--warn); }
.toast-dismiss { border: 0; background: transparent; color: var(--muted); padding: 0 0.4rem; font-size: 1.4rem; cursor: pointer; }
.app-shell { grid-template-columns: 280px minmax(0, 1fr); }
.main-area, .panel, .two-col > *, .split-grid > * { min-width: 0; }
.crud-form :is(input, select), .settings-grid :is(input, select), .search-wrap input { min-width: 0; max-width: 100%; }
.panel-head { gap: 0.6rem; }
.panel :is(p, strong, td), .kpi h3 { overflow-wrap: anywhere; }
.toolbar { flex-wrap: wrap; align-items: center; }
.toolbar input { flex: 1; min-width: 160px; }
.table-wrap { max-height: 28rem; max-width: 100%; overflow: auto; scrollbar-gutter: stable; }
.table-wrap table { min-width: 580px; }
.table-wrap th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.table-wrap tbody tr:hover, .table-wrap tbody tr:focus-within { background: var(--surface-soft); }
.table-wrap td:last-child { white-space: nowrap; }
.table-sort { border: 0; background: transparent; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; padding: 0.3rem 0; cursor: pointer; text-align: left; }
th[aria-sort="ascending"] .table-sort::after { content: " ↑"; }
th[aria-sort="descending"] .table-sort::after { content: " ↓"; }
#donationTable :is(th, td):nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 1180px) and (min-width: 981px) {
  .topbar { flex-wrap: wrap; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crud-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { overflow-y: auto; }
  .action-btn, .icon-btn, .primary-btn, .menu-item, .toast-dismiss { min-height: 44px; }
  .search-wrap { max-width: 100%; }
  .toolbar { align-items: stretch; }
  .toolbar input { width: 100%; }
  .cards { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
.login-card {
  width: min(420px, calc(100% - 2rem));
  margin: clamp(2rem, 10vh, 6rem) auto;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-card h1 { font-family: "DM Serif Display", serif; margin: 0 0 1.2rem; }
#loginForm { display: grid; gap: 0.8rem; }
#loginForm input { width: 100%; min-width: 0; padding: 0.7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); font: inherit; }
@media (max-width: 980px) {
  .crud-form :is(input:not([type=checkbox]), select), .toolbar :is(input, select), #loginForm input { min-height: 44px; }
}
body { min-height: 100vh; }
.table-sort::after { content: " ↕"; color: var(--muted); }
.table-scroll-hint { display: none; }
.donation-table-section { min-width: 0; }
@media (max-width: 980px) {
  .table-scroll-hint { display: block; font-size: 0.8rem; color: var(--muted); margin: 0.5rem 0; }
}
