/* ============================================================
   PARISH LEDGER — Church Operations Manager
   Single stylesheet for the whole app
   ============================================================ */

:root {
  /* Palette - warm ledger aesthetic */
  --bg: #f5efe4;
  --bg-paper: #faf6ec;
  --ink: #1c1c1a;
  --ink-soft: #4a4a44;
  --ink-mute: #8a857a;
  --line: #d9cfb8;
  --line-soft: #eae1c8;

  --pine: #2d4a3e;
  --pine-deep: #1e3328;
  --pine-soft: #6f8a7e;

  --burgundy: #8b2c2c;
  --burgundy-soft: #c87575;
  --gold: #b78a2c;
  --gold-soft: #e9c976;

  --green-tint: #e6efe8;
  --red-tint: #f6e6e3;
  --gold-tint: #f6ecd0;
  --blue-tint: #e3eaf1;

  /* Type */
  --font-display: 'Fraunces', 'Georgia', serif;
  --font-body: 'Outfit', system-ui, sans-serif;

  /* Sizing */
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Subtle paper texture using layered gradients */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 10%, rgba(183, 138, 44, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(45, 74, 62, 0.05) 0%, transparent 40%);
  z-index: 0;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--pine-deep);
  color: #e9e2cf;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  border-right: 1px solid rgba(0,0,0,0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 22px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.brand-mark {
  width: 38px; height: 38px;
  background: var(--gold);
  color: var(--pine-deep);
  font-size: 22px;
  display: grid; place-items: center;
  border-radius: 8px;
  font-weight: 700;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand-sub {
  font-size: 11px;
  color: var(--gold-soft);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 20px;
}

.nav-group { margin-bottom: 16px; }
.nav-group-title {
  font-size: 10.5px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: rgba(233, 226, 207, 0.4);
  padding: 8px 12px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(233, 226, 207, 0.82);
  text-decoration: none;
  font-size: 14px;
  margin: 1px 0;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.nav-link.active {
  background: var(--pine);
  color: #fff;
  border-left: 3px solid var(--gold);
  padding-left: 9px; /* keep text aligned despite the 3px border */
}

.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  color: var(--gold-soft);
  font-size: 14px;
}
.nav-link.active .nav-icon { color: var(--gold); }

.sidebar-footer {
  padding: 14px 18px 18px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 34px; height: 34px;
  background: var(--gold);
  color: var(--pine-deep);
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700;
}
.user-name { font-size: 13px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--gold-soft); }

/* ---------- Main / Topbar ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg-paper);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 10;
}
.menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 36px; height: 36px;
  font-size: 18px;
  cursor: pointer;
  color: var(--ink-soft);
}
.crumbs {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  color: var(--ink);
}
.topbar-right { margin-left: auto; }
.date-pill {
  background: #fff;
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- Frame (loaded pages) ---------- */
.frame {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
  animation: fadeIn 0.25s ease;
}

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

.loading {
  padding: 60px 0;
  text-align: center;
  color: var(--ink-mute);
  font-style: italic;
}

/* ============================================================
   PAGE COMPONENTS
   ============================================================ */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.page-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 500;
  margin: 0 0 4px;
  letter-spacing: -0.2px;
}
.page-desc { color: var(--ink-mute); font-size: 13.5px; margin: 0; }

/* Stat cards (dashboard) */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  background: var(--pine);
}
.stat-card.income::before { background: var(--pine); }
.stat-card.expense::before { background: var(--burgundy); }
.stat-card.balance::before { background: var(--gold); }
.stat-card.neutral::before { background: var(--ink-soft); }

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--ink-mute);
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.stat-sub { font-size: 12px; color: var(--ink-mute); margin-top: 4px; }

/* Cards / panels */
.card {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 22px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}
.card-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}
.card-sub { font-size: 12px; color: var(--ink-mute); }

/* Two-column layout for form + table */
.grid-2 {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 22px;
  align-items: start;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
}
@media (max-width: 1000px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Forms ---------- */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.form-grid .full { grid-column: 1 / -1; }

label {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 500;
  letter-spacing: 0.2px;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--pine);
}
textarea { resize: vertical; min-height: 70px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--pine);
  color: #fff;
}
.btn-primary:hover { background: var(--pine-deep); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.btn-ghost:hover { background: var(--line-soft); }

.btn-danger {
  background: transparent;
  border: 1px solid transparent;
  color: var(--burgundy);
  padding: 4px 8px;
  font-size: 12px;
}
.btn-danger:hover { background: var(--red-tint); }

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

/* ---------- Table ---------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: #fff;
}
table.data th, table.data td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
}
table.data th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--ink-mute);
  font-weight: 600;
  background: var(--bg-paper);
}
table.data tbody tr:hover { background: var(--bg); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data td.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-weight: 500;
}

.empty-row td {
  text-align: center;
  color: var(--ink-mute);
  font-style: italic;
  padding: 30px !important;
}

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
}
.badge-green { background: var(--green-tint); color: var(--pine-deep); }
.badge-red { background: var(--red-tint); color: var(--burgundy); }
.badge-gold { background: var(--gold-tint); color: #6e5413; }
.badge-blue { background: var(--blue-tint); color: #2b4a6b; }
.badge-mute { background: var(--line-soft); color: var(--ink-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--pine); }
.toast.error { background: var(--burgundy); }

/* ---------- Chart grid (Highcharts) ---------- */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}
.chart-wide { grid-column: 1 / -1; }

.chart-card {
  padding: 18px 18px 14px;
}
.chart-box {
  width: 100%;
  height: 320px;
  min-width: 0; /* allow shrink inside grid */
}
.chart-box.tall { height: 360px; }
.chart-box.short { height: 240px; }

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  font-size: 13px;
  align-items: flex-end;
}
.summary-strip .si {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.summary-strip .si-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--ink-mute);
}
.summary-strip .si-value {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.summary-strip .si-value.income { color: var(--pine); }
.summary-strip .si-value.expense { color: var(--burgundy); }
.summary-strip .si-value.balance { color: var(--gold); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-grid; place-items: center; }
  .frame { padding: 18px; }
  .topbar { padding: 0 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}

@media (max-width: 640px) {
  .chart-box { height: 260px; }
  .chart-box.tall { height: 300px; }
  .page-title { font-size: 22px; }
  .crumbs { font-size: 16px; }
  .date-pill { display: none; }
  .frame { padding: 14px; }
  .card { padding: 16px; }
  .chart-card { padding: 14px; }
  .summary-strip { gap: 14px; }
  .summary-strip .si-value { font-size: 16px; }
  .stat-value { font-size: 22px; }
  table.data th, table.data td { padding: 9px 10px; font-size: 12.5px; }
}

@media (max-width: 420px) {
  .chart-box { height: 240px; }
  .stats { grid-template-columns: 1fr; }
}

/* Tiny utilities */
.muted { color: var(--ink-mute); }
.small { font-size: 12px; }
.right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.nowrap { white-space: nowrap; }

/* HIDE SCROLLBARS */
* {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
*::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

/* ============================================================
   SELECT2
   ============================================================ */
.select2-container--default .select2-selection--single {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font-family: var(--font-body);
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 36px;
  padding-left: 11px;
  color: var(--ink);
  font-size: 14px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 36px;
  right: 4px;
}
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
  border-color: var(--pine);
}
.select2-container .select2-dropdown {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-paper);
  font-family: var(--font-body);
}
.select2-container .select2-search--dropdown .select2-search__field {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 7px 10px;
}
.select2-container .select2-search--dropdown .select2-search__field:focus {
  outline: none;
  border-color: var(--pine);
}
.select2-container--default .select2-results__option {
  font-size: 14px;
  padding: 8px 12px;
  color: var(--ink);
}
.select2-container--default .select2-results__option--highlighted[aria-selected] {
  background: var(--pine);
  color: #fff;
}
.select2-container--default .select2-results__option[aria-selected=true] {
  background: var(--green-tint);
  color: var(--pine-deep);
}

/* ============================================================
   FLATPICKR
   ============================================================ */
.flatpickr-calendar {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
}
.flatpickr-months .flatpickr-month {
  background: var(--pine);
  color: #fff;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  height: 42px;
}
.flatpickr-current-month {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  padding-top: 8px;
}
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  color: #fff;
  font-weight: 500;
}
.flatpickr-current-month .flatpickr-monthDropdown-months {
  background: transparent;
}
.flatpickr-current-month .flatpickr-monthDropdown-months .flatpickr-monthDropdown-month {
  background: var(--pine-deep);
  color: #fff;
}

/* ============================================================
   DATATABLES OVERRIDES
   ============================================================ */
.dataTables_wrapper .dataTables_filter input {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  outline: none;
}
.dataTables_wrapper .dataTables_filter input:focus {
  border-color: var(--pine);
}
.dt-buttons .dt-button {
  background: transparent !important;
  border: 1px solid var(--line) !important;
  color: var(--ink-soft) !important;
  border-radius: var(--radius-sm) !important;
  padding: 4px 10px !important;
}
.dt-buttons .dt-button:hover {
  background: var(--line-soft) !important;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 28, 26, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.98);
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1001;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes modalIn {
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-title {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
  color: var(--ink);
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 18px;
  color: var(--ink-mute);
  cursor: pointer;
  padding: 4px;
}
.modal-close:hover {
  color: var(--burgundy);
}
.modal-body {
  padding: 22px;
}
