/* ===== FONTS ===== */

@font-face {
  font-family: 'Granary';
  src: url('lib/granary-light.woff2') format('woff2'),
       url('lib/granary-light.woff') format('woff');
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: 'Quicksand';
  src: url('lib/Quicksand-VariableFont.ttf') format('truetype');
  font-weight: 100 900;
  font-display: swap;
}

/* ===== RESET & BASE ===== */

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Granary', 'Quicksand', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: #161A1D;
  background: #f0f0f0;
  margin: 0;
}

h1, h2, h3 { font-weight: 700; }

/* ===== HEADER ===== */

header {
  background: #161A1D;
  color: white;
  padding: 11px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo { height: 36px; width: auto; flex-shrink: 0; filter: brightness(0) invert(1); }
.header-text { display: flex; flex-direction: column; gap: 1px; flex: 1; }

header h1 {
  margin: 0;
  font-size: 16px;
  color: white;
  letter-spacing: 0.2px;
}

.file-info { font-size: 11px; opacity: 0.55; font-weight: 400; }

/* DWD "powered by" badge */
.powered-by {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.dwd-badge {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px 5px 5px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 9999px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}
.dwd-badge:hover { background: rgba(255,255,255,0.16); }

.dwd-logo-circle {
  width: 30px;
  height: 30px;
  background: #F6DA08;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.dwd-logo-circle img { width: 30px; height: 30px; object-fit: cover; border-radius: 50%; }

.dwd-badge-text {
  font-size: 10px;
  color: rgba(255,255,255,0.75);
  line-height: 1.4;
  font-weight: 400;
}

.dwd-badge-text strong {
  display: block;
  font-size: 11px;
  color: white;
  font-weight: 700;
  letter-spacing: 0.1px;
}

/* ===== SETUP PANEL ===== */

#setup-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 58px);
  padding: 40px 20px;
}

.setup-card {
  background: white;
  border-radius: 20px;
  padding: 48px 52px;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}

.setup-card h2 { margin: 0 0 12px; font-size: 22px; color: #161A1D; }
.setup-card p  { color: #7F7A77; line-height: 1.7; margin: 0 0 28px; font-size: 13px; }
.setup-card code { background: #f5f5f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.btn-pick {
  display: inline-block;
  padding: 13px 32px;
  background: #469EDE;
  color: white;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-pick:hover { background: #003de0; }

.settings-file-row {
  margin-top: 16px;
  font-size: 12px;
  color: #7F7A77;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.settings-file-row input[type="file"] {
  font-size: 12px;
  color: #7F7A77;
}

.setup-error {
  margin-top: 18px;
  color: #c0392b;
  font-size: 13px;
  background: #fff0f0;
  border: 1px solid #ffb3b3;
  border-radius: 10px;
  padding: 10px 14px;
}

.privacy-note {
  margin-top: 20px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #f0f7f0;
  border: 1px solid #b8ddb8;
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  font-size: 12px;
  color: #3a6b3a;
  line-height: 1.5;
}

.privacy-note .privacy-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }

/* ===== HELP PAGE ===== */

.help-page { max-width: 720px; }

.help-section {
  background: white;
  border-radius: 14px;
  padding: 22px 26px;
  margin-bottom: 16px;
}

.help-section h3 { margin: 0 0 12px; font-size: 15px; }
.help-section h4 { margin: 16px 0 6px; font-size: 13px; color: #161A1D; }

.help-section p, .help-section li {
  font-size: 13px;
  color: #32373C;
  line-height: 1.7;
  margin: 0 0 6px;
}

.help-section ul, .help-section ol {
  margin: 4px 0 10px;
  padding-left: 20px;
}

.help-badge {
  display: inline-block;
  background: #edf5fc;
  color: #469EDE;
  border: 1px solid #c0d0ff;
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* ===== APP LAYOUT ===== */

.app-layout {
  display: flex;
  height: calc(100vh - 58px);
}

.sidebar {
  width: 210px;
  min-width: 210px;
  background: white;
  border-right: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.page-area {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  background: #f5f5f5;
}

/* ===== SIDEBAR NAV ===== */

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 10px 10px 0;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #7F7A77;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  user-select: none;
}

.nav-item:hover { background: #f5f5f5; color: #161A1D; }

.nav-item.active {
  background: #edf5fc;
  color: #469EDE;
}

.nav-icon { font-size: 14px; width: 16px; text-align: center; }

/* ===== SIDEBAR FILTERS ===== */

#filters-charts, #filters-donors {
  padding: 12px 12px 0;
  flex: 1;
}

hr { border: none; border-top: 1px solid #eee; margin: 10px 0; }

.filter-section { margin-bottom: 10px; }

.filter-section h4 {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: #7F7A77;
  letter-spacing: 0.8px;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 260px;
  overflow-y: auto;
}

/* Two-level category filter */
.filter-cat-group { margin-bottom: 4px; }

.filter-cat-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
}

.filter-cat-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: #161A1D;
  cursor: pointer;
  line-height: 1.3;
  margin: 0;
}

.cat-count {
  font-size: 10px;
  color: #aaa;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.cat-expand-btn {
  font-size: 9px;
  color: #bbb;
  cursor: pointer;
  padding: 2px 4px;
  flex-shrink: 0;
  transition: color 0.1s;
  user-select: none;
}

.cat-expand-btn:hover { color: #469EDE; }

.cat-accounts {
  padding-left: 16px;
  padding-bottom: 3px;
}

.account-sub-label { font-size: 11px; padding: 1px 0; color: #555; }
.account-sub-label:hover { color: #469EDE; }

/* Year group filter — accordion */
.year-group { margin-bottom: 6px; }

.year-header {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
  cursor: pointer;
  padding: 3px 2px;
  border-radius: 5px;
  user-select: none;
}

.year-header:hover { background: #f5f5f5; }

.year-chevron {
  font-size: 8px;
  color: #aaa;
  width: 10px;
  text-align: center;
  flex-shrink: 0;
  transition: color 0.1s;
}

.year-header:hover .year-chevron { color: #469EDE; }

.year-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: #7F7A77;
  letter-spacing: 0.5px;
  flex: 1;
}

.year-sel-count {
  font-size: 10px;
  color: #bbb;
  font-variant-numeric: tabular-nums;
  margin-right: 2px;
}

.year-months { padding-left: 4px; }

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 0;
  line-height: 1.4;
  color: #32373C;
}

.checkbox-label:hover { color: #469EDE; }
.checkbox-label input { margin-top: 2px; flex-shrink: 0; accent-color: #469EDE; }

.radio-label {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 12px;
  padding: 3px 0;
  color: #32373C;
}

.radio-label:hover { color: #469EDE; }
input[type="radio"] { accent-color: #469EDE; }

.btn-row { display: flex; gap: 5px; margin-top: 7px; }

.btn-sm {
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  padding: 4px 10px;
  border: 1px solid #ddd;
  border-radius: 9999px;
  background: white;
  cursor: pointer;
  color: #32373C;
  transition: background 0.12s;
}

.btn-sm:hover { background: #edf5fc; border-color: #469EDE; color: #469EDE; }

/* ===== TOGGLE SWITCH ===== */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #32373C;
  margin-bottom: 4px;
}

.toggle-switch { position: relative; display: inline-block; width: 32px; height: 18px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 18px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-track::before {
  content: '';
  position: absolute;
  width: 12px; height: 12px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-track { background: #469EDE; }
.toggle-switch input:checked + .toggle-track::before { transform: translateX(14px); }

/* ===== REFRESH BUTTON ===== */

.btn-refresh {
  margin: 10px 12px 12px;
  padding: 8px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  background: #161A1D;
  color: white;
  border: none;
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-refresh:hover { background: #32373C; }

/* ===== PAGES ===== */

.page section { margin-bottom: 24px; }

.page section h3 {
  margin: 0 0 3px;
  font-size: 15px;
  color: #161A1D;
}

.chart-note { margin: 0 0 10px; font-size: 11px; color: #999; }

/* ===== CHARTS ===== */

.chart-grid { display: grid; gap: 12px; }

.chart-panel-div {
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 14px;
  padding: 6px;
  min-height: 220px;
}

.chart-no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #ccc;
  font-size: 13px;
  text-align: center;
}

#line-chart, #forecast-chart {
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 14px;
}

.no-data { color: #ccc; font-style: italic; padding: 30px; text-align: center; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  font-size: 12px;
}

.legend-item { display: flex; align-items: center; gap: 5px; color: #32373C; }
.legend-swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }

/* Forecast summary */
.forecast-summary {
  margin-top: 14px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.forecast-stat {
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 12px 18px;
  min-width: 160px;
}

.forecast-stat-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #7F7A77;
  margin-bottom: 4px;
}

.forecast-stat-value {
  font-size: 20px;
  font-weight: 700;
  color: #161A1D;
}

.forecast-stat-value.positive { color: #478425; }
.forecast-stat-value.negative { color: #EA3369; }

/* Forecast dotted legend item */
.legend-dashed { border-top: 2px dashed #469EDE; width: 20px; height: 0; display: inline-block; vertical-align: middle; }

/* ===== DRAG AND DROP GROUPS ===== */

.dnd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  align-items: start;
}

.dnd-group {
  background: white;
  border: 2px solid #e5e5e5;
  border-radius: 12px;
  padding: 0;
  min-height: 70px;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
}

.dnd-group.drag-over {
  border-color: #469EDE;
  background: #edf5fc;
}

.dnd-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 8px 10px;
  background: #f7f7f7;
  border-bottom: 1px solid #eeeeee;
}

.dnd-group-name {
  font-weight: 700;
  font-size: 13px;
  color: #161A1D;
  cursor: text;
  padding: 2px 4px;
  border-radius: 5px;
  border: 1px solid transparent;
  flex: 1;
  min-width: 0;
  outline: none;
}

.dnd-group-name:hover { border-color: #ddd; background: white; }
.dnd-group-name:focus { border-color: #469EDE; background: white; }

.dnd-accounts {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 32px;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px 6px;
}

.dnd-account {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 5px 6px;
  font-size: 12px;
  cursor: grab;
  user-select: none;
  transition: background 0.1s, border-color 0.1s;
}

.dnd-account:hover { background: #eef2ff; border-color: #c0d0ff; }
.dnd-account.dragging { opacity: 0.3; }

.dnd-drag-handle {
  color: #ccc;
  font-size: 14px;
  flex-shrink: 0;
  line-height: 1;
  cursor: grab;
}

.dnd-account-name {
  flex: 1;
  min-width: 0;
  color: #161A1D;
  word-break: break-word;
  line-height: 1.35;
}

.sub-rename-btn {
  font-size: 12px;
  opacity: 0;
  cursor: pointer;
  color: #7F7A77;
  transition: opacity 0.1s;
  flex-shrink: 0;
  padding: 1px 3px;
}

.dnd-account:hover .sub-rename-btn { opacity: 1; }

.sub-rename-input {
  flex: 1;
  font-size: 12px;
  font-family: inherit;
  border: none;
  background: white;
  outline: 2px solid #469EDE;
  border-radius: 4px;
  padding: 2px 5px;
  color: #161A1D;
}

.dnd-empty-hint {
  font-size: 11px;
  color: #ccc;
  font-style: italic;
  padding: 6px 4px;
}

.dnd-new-group {
  border: 2px dashed #ddd;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #bbb;
  font-size: 12px;
  text-align: center;
  min-height: 70px;
  gap: 4px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.dnd-new-group:hover { border-color: #469EDE; color: #469EDE; }
.dnd-new-group.drag-over { border-color: #469EDE; background: #edf5fc; color: #469EDE; }

.dnd-new-group-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

/* ===== TITHE TABLE ===== */

.tithe-table { border-collapse: collapse; font-size: 13px; min-width: 400px; }

.tithe-table th {
  background: #161A1D;
  color: white;
  padding: 9px 14px;
  text-align: left;
  font-weight: 700;
  font-family: 'Granary', sans-serif;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

.tithe-table th:first-child { border-radius: 10px 0 0 0; }
.tithe-table th:last-child  { border-radius: 0 10px 0 0; }

.tithe-table td { padding: 7px 14px; border-bottom: 1px solid #f0f0f0; }
.tithe-table tbody tr:nth-child(even) td { background: #fafafa; }
.tithe-table tbody tr:hover td { background: #edf5fc; }
.tithe-table td.zero { color: #ccc; }
.tithe-table td.num, .tithe-table th.num { text-align: right; }
.tithe-table tfoot td { border-top: 2px solid #e5e5e5; background: #f5f5f5; font-weight: 600; }

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

/* Expandable rows */
.payee-row { cursor: pointer; }
.payee-row:hover td { background: #eef2ff !important; }

.expand-icon {
  display: inline-block;
  width: 12px;
  font-size: 9px;
  color: #aaa;
  margin-right: 4px;
  vertical-align: middle;
}

.detail-row > td { padding: 0; border-bottom: 2px solid #e8eeff; }

.detail-inner {
  padding: 6px 14px 10px 28px;
  background: #f8faff;
  border-left: 3px solid #469EDE;
}

.detail-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.detail-table th { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #7F7A77; background: none; padding: 4px 8px 6px; border-bottom: 1px solid #e5e5e5; text-align: left; border-radius: 0; }
.detail-table th.num { text-align: right; }
.detail-table td { padding: 5px 8px; border-bottom: 1px solid #f0f0f0; color: #32373C; }
.detail-date { white-space: nowrap; color: #7F7A77; width: 110px; }
.detail-amt { text-align: right; white-space: nowrap; font-weight: 600; color: #161A1D; }
.credit-amt { color: #478425; }
.debit-amt  { color: #EA3369; }
.debit-cell { color: #EA3369; }

/* ===== SETTINGS PAGE ===== */

.settings-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-bottom: 24px;
}

.settings-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: #7F7A77;
  letter-spacing: 0.6px;
  margin: 0 0 10px;
}

.no-groups { font-size: 12px; color: #ccc; font-style: italic; margin: 4px 0 10px; }

.group-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
}

.group-item-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.group-item-name { font-size: 13px; font-weight: 600; color: #161A1D; }
.group-item-patterns { font-size: 11px; color: #7F7A77; }

.btn-remove {
  background: none; border: none; cursor: pointer;
  color: #ccc; font-size: 13px; padding: 2px 4px; flex-shrink: 0;
}
.btn-remove:hover { color: #c0392b; }

.add-group-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}

.input-sm {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  color: #161A1D;
  outline: none;
}

.input-sm:focus { border-color: #469EDE; }
.input-sm::placeholder { color: #bbb; }

.input-hint { margin: 0; font-size: 11px; color: #aaa; }
.input-hint code { background: #f5f5f5; padding: 1px 4px; border-radius: 3px; }

.btn-add {
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 8px 16px; align-self: flex-start;
  background: #469EDE; color: white;
  border: none; border-radius: 9999px; cursor: pointer;
  transition: background 0.15s;
}
.btn-add:hover { background: #003de0; }

/* Auto-groups preview */
.auto-group-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f5f5f5;
  font-size: 12px;
}

.auto-group-name { font-weight: 600; color: #161A1D; min-width: 100px; flex-shrink: 0; }
.auto-group-members { color: #7F7A77; }

.settings-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid #eee;
}

.btn-action {
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 20px;
  background: #161A1D; color: white;
  border: none; border-radius: 9999px; cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  display: inline-block;
}
.btn-action:hover { background: #32373C; }

.btn-action-outline {
  background: white;
  color: #161A1D;
  border: 2px solid #161A1D;
}
.btn-action-outline:hover { background: #f5f5f5; }

/* Account categories selector in Settings */
.acct-cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.acct-cat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 2px solid #e5e5e5;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #161A1D;
  transition: border-color 0.12s, background 0.12s;
  user-select: none;
}

.acct-cat-item:hover { border-color: #469EDE; background: #edf5fc; }
.acct-cat-item.selected { border-color: #469EDE; background: #edf5fc; color: #469EDE; }
.acct-cat-check {
  width: 16px; height: 16px;
  border: 2px solid #aaa;
  border-radius: 3px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1;
  transition: border-color 0.12s, background 0.12s;
}
.acct-cat-item.selected .acct-cat-check {
  border-color: #469EDE; background: #469EDE; color: #fff;
}

/* Comparison charts grid */
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.comparison-chart-wrap h4 {
  font-size: 13px;
  font-weight: 600;
  color: #161A1D;
  margin: 0 0 4px 0;
}
.comparison-chart-div { height: 220px; }
