/* 
 * Bank Nkhonde Premium Design System
 * Enterprise-grade ROSCA Banking App - 2026 Standards
 * Glassmorphism + Minimalist Editorial Design
 */

/* ============================================
   PREMIUM FONT STACK
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@300;400;500;600;700;800&display=swap');
@import url('mobile-modals.css');
@import url('unified-mobile-nav.css');

/* Global overflow fixes for mobile - prevent border-radius from hiding content */
@media (max-width: 768px) {
  .content-section,
  .content-card,
  .rules-container,
  .info-card,
  .member-card,
  .interest-rates-display,
  .content-section-body,
  .content-card-body {
    overflow: visible !important;
  }
}

/* ============================================
   DESIGN TOKENS - PREMIUM COLOR PALETTE
   ============================================ */
:root {
  /* Primary Brand Colors - Deep Navy & Warm Gold */
  --bn-primary: #0A1628;
  --bn-primary-dark: #060D17;
  --bn-primary-light: #1A2B47;
  --bn-accent: #C9A227;
  --bn-accent-dark: #A68B1F;
  --bn-accent-light: #E4C853;
  --bn-accent-subtle: rgba(201, 162, 39, 0.08);
  
  /* Sophisticated Neutrals */
  --bn-dark: #0A1628;
  --bn-dark-secondary: #1A2B47;
  --bn-gray-900: #1E293B;
  --bn-gray-800: #334155;
  --bn-gray-700: #475569;
  --bn-gray: #64748B;
  --bn-gray-400: #94A3B8;
  --bn-gray-light: #CBD5E1;
  --bn-gray-lighter: #E2E8F0;
  --bn-gray-100: #F1F5F9;
  --bn-gray-50: #F8FAFC;
  --bn-gray-200: #E2E8F0;
  --bn-gray-300: #CBD5E1;
  --bn-gray-500: #64748B;
  --bn-gray-600: #475569;
  --bn-white: #FFFFFF;
  --bn-off-white: #FAFBFC;
  
  /* Semantic Colors - Muted & Professional */
  --bn-success: #059669;
  --bn-success-light: rgba(5, 150, 105, 0.12);
  --bn-success-dark: #047857;
  --bn-warning: #D97706;
  --bn-warning-light: rgba(217, 119, 6, 0.12);
  --bn-warning-dark: #92400E;
  --bn-danger: #DC2626;
  --bn-danger-light: rgba(220, 38, 38, 0.12);
  --bn-danger-dark: #B91C1C;
  --bn-info: #2563EB;
  --bn-info-light: rgba(37, 99, 235, 0.12);
  
  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-bg-dark: rgba(10, 22, 40, 0.85);
  --glass-border: rgba(255, 255, 255, 0.18);
  --glass-border-dark: rgba(255, 255, 255, 0.08);
  --glass-blur: 20px;
  
  /* Background Gradients */
  --bn-gradient-primary: linear-gradient(135deg, #0A1628 0%, #1A2B47 100%);
  --bn-gradient-accent: linear-gradient(135deg, #C9A227 0%, #E4C853 100%);
  --bn-gradient-subtle: linear-gradient(180deg, #F8FAFC 0%, #EEF2F7 100%);
  --bn-gradient-mesh: radial-gradient(ellipse at 30% 20%, rgba(201, 162, 39, 0.05) 0%, transparent 50%),
                      radial-gradient(ellipse at 80% 80%, rgba(10, 22, 40, 0.03) 0%, transparent 50%);
  
  /* Premium Shadows */
  --bn-shadow-xs: 0 1px 2px rgba(10, 22, 40, 0.04);
  --bn-shadow-sm: 0 2px 4px rgba(10, 22, 40, 0.06), 0 1px 2px rgba(10, 22, 40, 0.04);
  --bn-shadow-md: 0 4px 8px rgba(10, 22, 40, 0.08), 0 2px 4px rgba(10, 22, 40, 0.04);
  --bn-shadow-lg: 0 12px 24px rgba(10, 22, 40, 0.10), 0 4px 8px rgba(10, 22, 40, 0.06);
  --bn-shadow-xl: 0 24px 48px rgba(10, 22, 40, 0.12), 0 8px 16px rgba(10, 22, 40, 0.08);
  --bn-shadow-glow: 0 0 40px rgba(201, 162, 39, 0.15);
  --bn-shadow-inset: inset 0 2px 4px rgba(10, 22, 40, 0.06);
  
  /* Border Radius - Generous Curves */
  --bn-radius-sm: 8px;
  --bn-radius-md: 12px;
  --bn-radius-lg: 16px;
  --bn-radius-xl: 20px;
  --bn-radius-2xl: 24px;
  --bn-radius-3xl: 32px;
  --bn-radius-full: 9999px;
  
  /* Spacing Scale - 4px base */
  --bn-space-1: 4px;
  --bn-space-2: 8px;
  --bn-space-3: 12px;
  --bn-space-4: 16px;
  --bn-space-5: 20px;
  --bn-space-6: 24px;
  --bn-space-8: 32px;
  --bn-space-10: 40px;
  --bn-space-12: 48px;
  --bn-space-16: 64px;
  --bn-space-20: 80px;
  --bn-space-24: 96px;
  
  /* Legacy spacing aliases */
  --bn-space-xs: 4px;
  --bn-space-sm: 8px;
  --bn-space-md: 16px;
  --bn-space-lg: 24px;
  --bn-space-xl: 32px;
  --bn-space-2xl: 48px;
  --bn-space-3xl: 64px;
  --bn-space-4xl: 96px;
  
  /* Typography */
  --bn-font-sans: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bn-font-mono: 'SF Mono', 'Roboto Mono', monospace;
  
  /* Font Sizes */
  --bn-text-xs: 0.75rem;
  --bn-text-sm: 0.875rem;
  --bn-text-base: 1rem;
  --bn-text-lg: 1.125rem;
  --bn-text-xl: 1.25rem;
  --bn-text-2xl: 1.5rem;
  --bn-text-3xl: 1.875rem;
  --bn-text-4xl: 2.25rem;
  --bn-text-5xl: 3rem;
  --bn-text-6xl: 3.75rem;
  --bn-text-7xl: 4.5rem;
  
  /* Line Heights */
  --bn-leading-none: 1;
  --bn-leading-tight: 1.1;
  --bn-leading-snug: 1.25;
  --bn-leading-normal: 1.5;
  --bn-leading-relaxed: 1.625;
  
  /* Letter Spacing */
  --bn-tracking-tight: -0.025em;
  --bn-tracking-normal: 0;
  --bn-tracking-wide: 0.025em;
  --bn-tracking-wider: 0.05em;
  --bn-tracking-widest: 0.1em;
  
  /* Transitions */
  --bn-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --bn-ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --bn-transition-fast: 150ms var(--bn-ease-out);
  --bn-transition-base: 250ms var(--bn-ease-out);
  --bn-transition-slow: 400ms var(--bn-ease-out);
  --bn-transition-slower: 600ms var(--bn-ease-out);
  
  /* Z-Index Scale */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-popover: 600;
  --z-tooltip: 700;
  --z-toast: 800;
}

/* ============================================
    CSS RESET & BASE STYLES
    ============================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* The HTML [hidden] attribute must win over any class-based display rule
   (e.g. .btn { display: inline-flex }) — otherwise buttons toggled via
   element.hidden = true in JS stay visible. */
[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--bn-font-sans);
  font-size: var(--bn-text-base);
  font-weight: 400;
  color: var(--bn-dark);
  background: var(--bn-off-white);
  line-height: var(--bn-leading-normal);
  overflow-x: hidden;
  min-height: 100vh;
}

/* ============================================
   TYPOGRAPHY SYSTEM
   ============================================ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--bn-font-sans);
  font-weight: 700;
  line-height: var(--bn-leading-tight);
  color: var(--bn-dark);
  letter-spacing: var(--bn-tracking-tight);
}

h1 {
  font-size: clamp(2.25rem, 5vw, 3.75rem);
  font-weight: 800;
}

h2 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
}

h3 {
  font-size: clamp(1.375rem, 3vw, 1.875rem);
}

h4 {
  font-size: clamp(1.125rem, 2vw, 1.5rem);
}

h5 {
  font-size: var(--bn-text-lg);
}

h6 {
  font-size: var(--bn-text-base);
  font-weight: 600;
}

p {
  margin-bottom: var(--bn-space-4);
  color: var(--bn-gray-700);
  line-height: var(--bn-leading-relaxed);
}

.text-display {
  font-size: clamp(3rem, 8vw, 5rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}

.text-mono {
  font-family: var(--bn-font-mono);
  font-size: 0.9em;
}

.text-accent {
  color: var(--bn-accent);
}

.text-muted {
  color: var(--bn-gray);
}

/* Emphasised figure inside a read-only info line (e.g. "Outstanding: MWK …") */
.text-emphasis {
  font-weight: 700;
  font-size: var(--bn-text-base);
  color: var(--bn-danger);
}

.text-white {
  color: var(--bn-white);
}

/* Number emphasis for financial data */
.number-display {
  font-family: var(--bn-font-sans);
  font-weight: 700;
  font-feature-settings: 'tnum' 1;
  letter-spacing: -0.02em;
}

.currency {
  font-size: 0.65em;
  font-weight: 500;
  opacity: 0.7;
  margin-right: 0.15em;
}

/* ============================================
   GLASSMORPHISM CARDS
   ============================================ */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--bn-radius-xl);
  padding: var(--bn-space-6);
  transition: all var(--bn-transition-base);
}

.glass-card:hover {
  border-color: rgba(201, 162, 39, 0.2);
  box-shadow: var(--bn-shadow-lg);
}

.glass-card-dark {
  background: var(--glass-bg-dark);
  border-color: var(--glass-border-dark);
  color: var(--bn-white);
}

/* Standard Card */
.card {
  background: var(--bn-white);
  border-radius: var(--bn-radius-xl);
  padding: var(--bn-space-6);
  box-shadow: var(--bn-shadow-sm);
  border: 1px solid var(--bn-gray-lighter);
  transition: all var(--bn-transition-base);
}

.card:hover {
  box-shadow: var(--bn-shadow-md);
  transform: translateY(-2px);
}

.card-header {
  margin-bottom: var(--bn-space-5);
  padding-bottom: var(--bn-space-4);
  border-bottom: 1px solid var(--bn-gray-lighter);
}

.card-title {
  font-size: var(--bn-text-xl);
  font-weight: 700;
  margin-bottom: var(--bn-space-1);
}

.card-subtitle {
  font-size: var(--bn-text-sm);
  color: var(--bn-gray);
}

.card-body {
  flex: 1;
}

.card-footer {
  margin-top: var(--bn-space-5);
  padding-top: var(--bn-space-4);
  border-top: 1px solid var(--bn-gray-lighter);
}

/* Stat Card */
.stat-card {
  background: var(--bn-white);
  border-radius: var(--bn-radius-xl);
  padding: var(--bn-space-5);
  border: 1px solid var(--bn-gray-lighter);
  transition: all var(--bn-transition-base);
}

.stat-card:hover {
  border-color: var(--bn-accent);
  box-shadow: var(--bn-shadow-glow);
}

.stat-label {
  font-size: var(--bn-text-xs);
  font-weight: 600;
  color: var(--bn-gray);
  text-transform: uppercase;
  letter-spacing: var(--bn-tracking-wider);
  margin-bottom: var(--bn-space-2);
}

.stat-value {
  font-size: var(--bn-text-3xl);
  font-weight: 800;
  color: var(--bn-dark);
  line-height: var(--bn-leading-none);
  font-feature-settings: 'tnum' 1;
}

.stat-value.success { color: var(--bn-success); }
.stat-value.warning { color: var(--bn-warning); }
.stat-value.danger { color: var(--bn-danger); }
.stat-value.info { color: var(--bn-info); }

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: var(--bn-space-1);
  font-size: var(--bn-text-sm);
  font-weight: 600;
  margin-top: var(--bn-space-2);
}

.stat-change.positive { color: var(--bn-success); }
.stat-change.negative { color: var(--bn-danger); }

/* ============================================
   BUTTON SYSTEM
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--bn-space-2);
  padding: var(--bn-space-3) var(--bn-space-5);
  font-family: var(--bn-font-sans);
  font-size: var(--bn-text-sm);
  font-weight: 600;
  text-decoration: none;
  border: none;
  border-radius: var(--bn-radius-lg);
  cursor: pointer;
  transition: all var(--bn-transition-base);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--bn-gradient-primary);
  color: var(--bn-white);
  box-shadow: var(--bn-shadow-md);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--bn-shadow-lg);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-accent {
  background: var(--bn-gradient-accent);
  color: var(--bn-dark);
  box-shadow: var(--bn-shadow-md);
}

.btn-accent:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--bn-shadow-glow);
}

.btn-secondary {
  background: var(--bn-white);
  color: var(--bn-dark);
  border: 1px solid var(--bn-gray-lighter);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bn-gray-100);
  border-color: var(--bn-gray-light);
}

.btn-ghost {
  background: transparent;
  color: var(--bn-gray-700);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bn-gray-100);
  color: var(--bn-dark);
}

.btn-danger {
  background: var(--bn-danger);
  color: var(--bn-white);
}

.btn-danger:hover:not(:disabled) {
  background: #B91C1C;
}

.btn-success {
  background: var(--bn-success);
  color: var(--bn-white);
}

.btn-success:hover:not(:disabled) {
  background: #047857;
}

/* Button Sizes */
.btn-xs {
  padding: var(--bn-space-1) var(--bn-space-2);
  font-size: var(--bn-text-xs);
  border-radius: var(--bn-radius-sm);
}

.btn-sm {
  padding: var(--bn-space-2) var(--bn-space-4);
  font-size: var(--bn-text-sm);
}

.btn-lg {
  padding: var(--bn-space-4) var(--bn-space-8);
  font-size: var(--bn-text-base);
}

.btn-xl {
  padding: var(--bn-space-5) var(--bn-space-10);
  font-size: var(--bn-text-lg);
  border-radius: var(--bn-radius-xl);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--bn-radius-md);
}

.btn-icon.btn-sm {
  width: 44px;
  height: 44px;
}

.btn-icon.btn-lg {
  width: 48px;
  height: 48px;
}

/* ============================================
   FORM SYSTEM
   ============================================ */
.form-group {
  margin-bottom: var(--bn-space-5);
}

.form-label {
  display: block;
  font-size: var(--bn-text-sm);
  font-weight: 600;
  color: var(--bn-dark);
  margin-bottom: var(--bn-space-2);
}

.form-label-required::after {
  content: ' *';
  color: var(--bn-danger);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--bn-space-3) var(--bn-space-4);
  font-family: var(--bn-font-sans);
  font-size: var(--bn-text-base);
  color: var(--bn-dark);
  background: var(--bn-white);
  border: 1px solid var(--bn-gray-lighter);
  border-radius: var(--bn-radius-lg);
  transition: all var(--bn-transition-fast);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--bn-accent);
  box-shadow: 0 0 0 3px var(--bn-accent-subtle);
}

.form-input::placeholder {
  color: var(--bn-gray-400);
}

.form-input-lg {
  padding: var(--bn-space-4) var(--bn-space-5);
  font-size: var(--bn-text-lg);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 48px;
}

.form-error-message {
  font-size: var(--bn-text-sm);
  color: var(--bn-danger);
  margin-top: var(--bn-space-2);
  display: flex;
  align-items: center;
  gap: var(--bn-space-1);
}

.form-success-message {
  font-size: var(--bn-text-sm);
  color: var(--bn-success);
  margin-top: var(--bn-space-2);
}

/* Input with icon */
.input-group {
  position: relative;
}

.input-icon {
  position: absolute;
  left: var(--bn-space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--bn-gray);
  pointer-events: none;
  transition: color var(--bn-transition-fast);
}

.input-group .form-input {
  padding-left: var(--bn-space-12);
}

.input-group:focus-within .input-icon {
  color: var(--bn-accent);
}

/* ============================================
   BADGE SYSTEM
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--bn-space-1);
  padding: var(--bn-space-1) var(--bn-space-3);
  font-size: var(--bn-text-xs);
  font-weight: 600;
  border-radius: var(--bn-radius-full);
  text-transform: uppercase;
  letter-spacing: var(--bn-tracking-wide);
}

.badge-primary {
  background: var(--bn-accent-subtle);
  color: var(--bn-accent-dark);
}

.badge-success {
  background: var(--bn-success-light);
  color: var(--bn-success-dark);
}

.badge-warning {
  background: var(--bn-warning-light);
  color: var(--bn-warning-dark);
}

.badge-danger {
  background: var(--bn-danger-light);
  color: var(--bn-danger-dark);
}

.badge-info {
  background: var(--bn-info-light);
  color: var(--bn-info);
}

.badge-neutral {
  background: var(--bn-gray-100);
  color: var(--bn-gray-700);
}

/* Dot indicator */
.badge-dot {
  display: inline-flex;
  align-items: center;
  gap: var(--bn-space-2);
  font-size: var(--bn-text-sm);
  font-weight: 500;
  color: var(--bn-gray-700);
}

.badge-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bn-gray);
}

.badge-dot.success::before { background: var(--bn-success); }
.badge-dot.warning::before { background: var(--bn-warning); }
.badge-dot.danger::before { background: var(--bn-danger); }
.badge-dot.info::before { background: var(--bn-info); }

/* Pulse animation for live indicators */
.badge-pulse::before {
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

/* ============================================
   ALERT SYSTEM
   ============================================ */
.alert {
  padding: var(--bn-space-4) var(--bn-space-5);
  border-radius: var(--bn-radius-lg);
  margin-bottom: var(--bn-space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--bn-space-3);
  border-left: 4px solid;
}

.alert-success {
  background: var(--bn-success-light);
  border-color: var(--bn-success);
  color: #065F46;
}

.alert-warning {
  background: var(--bn-warning-light);
  border-color: var(--bn-warning);
  color: #92400E;
}

.alert-danger {
  background: var(--bn-danger-light);
  border-color: var(--bn-danger);
  color: #991B1B;
}

.alert-info {
  background: var(--bn-info-light);
  border-color: var(--bn-info);
  color: #1E40AF;
}

/* ============================================
   TABLE SYSTEM
   ============================================ */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--bn-radius-lg);
  border: 1px solid var(--bn-gray-lighter);
  background: var(--bn-white);
}

.table,
.data-table table,
table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bn-white);
}

.table th,
.data-table table th,
table.data-table th {
  padding: var(--bn-space-3) var(--bn-space-4);
  text-align: left;
  font-size: var(--bn-text-xs);
  font-weight: 700;
  color: var(--bn-gray);
  text-transform: uppercase;
  letter-spacing: var(--bn-tracking-wider);
  background: var(--bn-gray-100);
  border-bottom: 2px solid var(--bn-gray-lighter);
  white-space: nowrap;
}

.table td,
.data-table table td,
table.data-table td {
  padding: var(--bn-space-3) var(--bn-space-4);
  border-bottom: 1px solid var(--bn-gray-lighter);
  color: var(--bn-dark);
  font-size: var(--bn-text-sm);
  vertical-align: middle;
}

.table tbody tr,
.data-table table tbody tr,
table.data-table tbody tr {
  transition: background var(--bn-transition-fast);
}

.table tbody tr:hover,
.data-table table tbody tr:hover,
table.data-table tbody tr:hover {
  background: var(--bn-gray-50, #f9fafb);
}

.table tbody tr:nth-child(even),
.data-table table tbody tr:nth-child(even),
table.data-table tbody tr:nth-child(even) {
  background: var(--bn-gray-50, #f9fafb);
}

.table tbody tr:nth-child(even):hover,
.data-table table tbody tr:nth-child(even):hover,
table.data-table tbody tr:nth-child(even):hover {
  background: var(--bn-gray-100);
}

.table tbody tr:last-child td,
.data-table table tbody tr:last-child td,
table.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Table cell utility classes.
   Scoped to BOTH .table and .data-table — these utilities were .table-only,
   so adding cell-right to a <table class="data-table"> (manage_payments_sql.js's
   "All Payment Details" — a table deliberately NOT using .table-responsive, so
   it never collapses into mobile cards and stays one real row per member on
   any device) silently did nothing: the class landed on the element, but no
   selector in the sheet ever matched it. Money columns rendered flush left
   with the class present and correct, which is what made this look like a
   caching problem rather than the real cause — a selector that only ever
   covered one of the app's two table base classes. */
.table .cell-right, .data-table .cell-right   { text-align: right; }
.table .cell-center, .data-table .cell-center { text-align: center; }
.table .cell-bold, .data-table .cell-bold     { font-weight: 600; }
.table .cell-muted, .data-table .cell-muted   { color: var(--bn-gray); }
.table .cell-nowrap, .data-table .cell-nowrap { white-space: nowrap; }
.table .cell-name, .data-table .cell-name     { font-weight: 600; color: var(--bn-dark); }
.table .cell-success, .data-table .cell-success { color: var(--bn-success); font-weight: 600; }
.table .cell-danger, .data-table .cell-danger   { color: var(--bn-danger); font-weight: 600; }
.table .cell-warning, .data-table .cell-warning { color: var(--bn-warning-dark); font-weight: 600; }

/* Totals footer row */
.table tfoot td,
.table tr.table-totals td {
  font-weight: 700;
  background: var(--bn-primary);
  color: var(--bn-white);
  padding: var(--bn-space-3) var(--bn-space-4);
  border-bottom: none;
  font-size: var(--bn-text-sm);
}

.table tfoot tr:first-child td,
.table tr.table-totals td {
  border-top: 2px solid var(--bn-primary-dark, var(--bn-primary));
}

/* Alternate totals style (gray) */
.table tfoot.totals-gray td,
.table tr.table-totals-gray td {
  background: var(--bn-gray-100);
  color: var(--bn-dark);
  font-weight: 700;
}

/* ============================================
   RESPONSIVE TABLES — card layout on mobile
   ============================================ */
@media (max-width: 768px) {
  .table-container {
    border: none;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }

  .table-responsive thead,
  .table-responsive th {
    display: none;
  }

  .table-responsive,
  .table-responsive tbody,
  .table-responsive tr,
  .table-responsive td {
    display: block;
    width: 100%;
  }

  .table-responsive tbody tr {
    background: var(--bn-white);
    border: 1px solid var(--bn-gray-lighter);
    border-radius: var(--bn-radius-md);
    margin-bottom: var(--bn-space-3);
    padding: var(--bn-space-3) var(--bn-space-4);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }

  .table-responsive tbody tr:nth-child(even) {
    background: var(--bn-white);
  }

  .table-responsive tbody tr:hover {
    background: var(--bn-gray-50, #f9fafb);
  }

  .table-responsive td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: var(--bn-space-1) 0;
    border-bottom: 1px solid var(--bn-gray-100);
    font-size: var(--bn-text-sm);
    text-align: right;
    white-space: normal;
    word-break: break-word;
    gap: var(--bn-space-2);
  }

  .table-responsive td:last-child {
    border-bottom: none;
  }

  /* Hide empty colspan cells on mobile (e.g. tfoot spacers) */
  .table-responsive td[data-label=""],
  .table-responsive td:empty {
    display: none;
  }

  .table-responsive tbody td[colspan] {
    display: block;
    width: 100%;
    text-align: center;
    padding: var(--bn-space-4) var(--bn-space-2);
    border-bottom: none;
    color: var(--bn-gray);
  }

  .table-responsive tbody td[colspan]::before {
    content: none;
    display: none;
  }

  .table-responsive tbody tr {
    box-sizing: border-box;
    max-width: 100%;
    margin-inline: auto;
  }

  /* Show the column label from data-label attr.
     min-width was 80px with max-width 35% — on a 390px phone that reserved a
     wide fixed gutter and squeezed the VALUE into what was left, so a
     description like "Monthly contribution (December 2026)" wrapped to two or
     three lines. Measured on user_analytics: a 12-row statement rendered
     2,574px tall, ~215px per row, on a page 6,169px long.
     Letting the label shrink to its content and capping it at 40% gives the
     value the room it actually needs. */
  .table-responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--bn-gray);
    font-size: var(--bn-text-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    flex-shrink: 0;
    max-width: 40%;
    /* A column NAME is short by definition; letting it wrap cost a whole extra
       line per cell ("RUNNING BALANCE" broke across two). The value beside it
       still wraps freely. */
    white-space: nowrap;
  }

  /* Reset alignment helpers on mobile */
  .table-responsive .cell-right,
  .table-responsive .cell-center {
    text-align: right;
  }

  /* Ensure cell-nowrap does NOT apply on mobile */
  .table-responsive .cell-nowrap {
    white-space: normal;
  }

  /* Totals card on mobile */
  .table-responsive tfoot tr,
  .table-responsive tr.table-totals {
    background: var(--bn-primary) !important;
    border-color: var(--bn-primary);
    color: var(--bn-white);
    border-radius: var(--bn-radius-md);
  }

  .table-responsive tfoot td,
  .table-responsive tr.table-totals td {
    color: var(--bn-white);
    border-bottom-color: rgba(255,255,255,0.15);
    padding: 6px 0;
  }

  .table-responsive tfoot td::before,
  .table-responsive tr.table-totals td::before {
    color: rgba(255,255,255,0.7);
  }

  .table-responsive .cell-success,
  .table-responsive .cell-danger {
    font-weight: 700;
  }
}

/* Keep scroll approach for tables that are NOT .table-responsive */
@media (max-width: 768px) {
  .table-container:has(.table:not(.table-responsive)) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--bn-gray-lighter);
    border-radius: var(--bn-radius-md);
    background: var(--bn-white);
  }

  .table:not(.table-responsive) th,
  .table:not(.table-responsive) td {
    padding: var(--bn-space-2) var(--bn-space-3);
    font-size: var(--bn-text-xs);
  }
}

/* ============================================
   CYCLE SHARE-OUT (pages/cycle_shareout.html)
   Payout column group + settle confirm gate.
   ============================================ */

/* Grouped "Payout" header (colspan 3) sits above Interest Refund /
   Penalty Share / Payout. Gold tint ties it to the accent used for the
   settle CTA elsewhere on the page, and marks it as the page's answer.
   Selector is scoped `.table th.payout-group-header` (not the bare
   class) because `.table th` already sets background/border-bottom/
   text-align at specificity (0,1,1) — a bare `.payout-group-header`
   class (0,1,0) would lose that fight silently and never render. */
.table th.payout-group-header {
  text-align: center;
  background: var(--bn-accent-subtle);
  border-bottom: 2px solid var(--bn-accent);
}

/* The three payout-group cells (both the sub-header row and the body
   cells) get the same gold tint so the whole column group reads as one
   unit, distinct from the four context columns beside it. Scoped the
   same way, and to both th/td, for the same specificity reason above —
   `.table td` sets no background today, but this keeps the rule correct
   even if that changes. The left border marks only the group's first
   column (Interest Refund) — the :not(.cell-payout + .cell-payout)
   selector matches a .cell-payout cell that is NOT itself preceded by
   another .cell-payout sibling, i.e. the first cell of the run — so the
   group gets one accent edge, not three. */
.table th.cell-payout,
.table td.cell-payout {
  background: var(--bn-accent-subtle);
}

.table th.cell-payout:not(.cell-payout + .cell-payout),
.table td.cell-payout:not(.cell-payout + .cell-payout) {
  border-left: 3px solid var(--bn-accent);
}

/* Settle confirm gate: an irreversible money action, styled to read as a
   deliberate "are you sure" surface rather than more page flow. Reuses
   the danger tokens already validated for .alert-danger — the *-light
   token is a background tint only, text stays on --bn-dark for contrast. */
.confirm-panel {
  margin-top: var(--bn-space-4);
  padding: var(--bn-space-5);
  background: var(--bn-danger-light);
  border: 1px solid var(--bn-danger);
  border-radius: var(--bn-radius-lg);
  display: flex;
  flex-direction: column;
  gap: var(--bn-space-4);
  color: var(--bn-dark);
}

.confirm-panel #confirmSummaryText {
  margin: 0;
  font-weight: 600;
}

.confirm-checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: var(--bn-space-3);
  min-height: 44px;
  padding: var(--bn-space-2) var(--bn-space-3);
  background: var(--bn-white);
  border: 1px solid var(--bn-gray-light);
  border-radius: var(--bn-radius-md);
  cursor: pointer;
}

.confirm-checkbox-row input[type="checkbox"] {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  cursor: pointer;
  accent-color: var(--bn-danger);
}

.confirm-checkbox-row span {
  font-size: var(--bn-text-sm);
  line-height: var(--bn-leading-normal);
  color: var(--bn-dark);
}

.confirm-panel-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--bn-space-3);
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  .confirm-panel-actions {
    flex-direction: column;
  }

  .confirm-panel-actions .btn {
    width: 100%;
  }
}

/* ============================================
   LOADING & SPINNER
   ============================================ */
.spinner-overlay {
  position: fixed;
  inset: 0;
  /* Light, calm backdrop that matches the page (--bn-off-white), not a dark scrim. */
  background: rgba(250, 251, 252, 0.82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--bn-space-4);
  z-index: var(--z-modal);
  opacity: 1;
  transition: opacity 0.3s ease;
}

.spinner-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner-content {
  text-align: center;
  background: var(--bn-white);
  border: 1px solid var(--bn-gray-lighter);
  border-radius: var(--bn-radius-xl);
  box-shadow: var(--bn-shadow-lg);
  padding: var(--bn-space-8) var(--bn-space-10);
  animation: bn-loader-pop 0.25s var(--bn-ease-out);
  max-width: 320px;
  width: calc(100% - var(--bn-space-8));
}

/* Plain ring: grey track, one brand-accent arc. No glow, no gradient. */
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--bn-gray-lighter);
  border-top-color: var(--bn-accent);
  border-radius: 50%;
  margin: 0 auto var(--bn-space-4);
  animation: spin 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .spinner-content { animation: none; }
}

.loading-text {
  color: var(--bn-gray-700);
  font-size: var(--bn-text-base);
  font-weight: 600;
  margin: 0;
}

.loading-group-name {
  font-family: var(--bn-font-sans);
  font-size: var(--bn-text-lg);
  font-weight: 800;
  color: var(--bn-accent-dark);
  letter-spacing: -0.02em;
  margin-bottom: var(--bn-space-2);
  line-height: 1.2;
}

.loading-subtitle {
  color: var(--bn-gray-500);
  font-size: var(--bn-text-xs);
  font-weight: 500;
}

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

@keyframes bn-loader-pop {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Spinner inside main content. Keeps the lighter in-content backdrop, but stays
   FIXED TO THE VIEWPORT.
   It was `position: absolute`, which sizes the overlay to the whole content
   column — measured at 2196px tall on the admin dashboard. The overlay centres
   its content with flex, so "centred" meant ~1100px down the page: on screen
   only if you happened to be scrolled to the middle of the section, and
   completely out of sight at the top or bottom.
   Fixing the OVERLAY (rather than the .spinner-content inside it) is deliberate:
   .spinner-content carries a transform animation, so translate-centring would be
   overridden mid-animation, and this overlay's own `backdrop-filter` makes it a
   containing block — a `position: fixed` child would anchor to the overlay, not
   the screen, and nothing would change. */
main#mainContent .spinner-overlay,
.dashboard-content .spinner-overlay,
.content-section-body .spinner-overlay {
  position: fixed;
  inset: 0;
  border-radius: 0;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
  position: fixed;
  top: var(--bn-space-6);
  right: var(--bn-space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--bn-space-3);
  max-width: 400px;
  width: calc(100% - var(--bn-space-8));
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--bn-space-3);
  padding: var(--bn-space-4) var(--bn-space-5);
  background: var(--bn-white);
  border-radius: var(--bn-radius-lg);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--bn-gray-lighter);
  animation: toast-in 0.4s var(--bn-ease-out);
  border-left: 4px solid var(--bn-gray);
}

.toast.toast-success { border-left-color: var(--bn-success); }
.toast.toast-warning { border-left-color: var(--bn-warning); }
.toast.toast-danger { border-left-color: var(--bn-danger); }
.toast.toast-info { border-left-color: var(--bn-info); }

.toast-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: var(--bn-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.toast.toast-success .toast-icon { background: var(--bn-success-light); color: var(--bn-success); }
.toast.toast-warning .toast-icon { background: var(--bn-warning-light); color: var(--bn-warning); }
.toast.toast-danger .toast-icon { background: var(--bn-danger-light); color: var(--bn-danger); }
.toast.toast-info .toast-icon { background: var(--bn-info-light); color: var(--bn-info); }

.toast-content {
  flex: 1;
}

.toast-title {
  font-size: var(--bn-text-sm);
  font-weight: 600;
  color: var(--bn-dark);
}

.toast-message {
  font-size: var(--bn-text-sm);
  color: var(--bn-dark);
  font-weight: 500;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--bn-gray);
  cursor: pointer;
  padding: var(--bn-space-1);
  font-size: 18px;
  line-height: 1;
}

.toast-close:hover {
  color: var(--bn-dark);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.exiting {
  animation: toast-out 0.3s var(--bn-ease-out) forwards;
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

/* ============================================
   NOTIFICATION DROPDOWN (bell icon dropdown)
   ============================================ */
.notification-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 380px;
  max-width: calc(100vw - var(--bn-space-8));
  max-height: 480px;
  background: var(--bn-white);
  border-radius: var(--bn-radius-xl);
  box-shadow: 0 20px 60px rgba(10, 22, 40, 0.2);
  border: 1px solid var(--bn-gray-lighter);
  z-index: var(--z-popover);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: notif-dropdown-in 0.25s var(--bn-ease-out);
}

@keyframes notif-dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.notification-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--bn-space-4) var(--bn-space-5);
  border-bottom: 1px solid var(--bn-gray-lighter);
  flex-shrink: 0;
}

.notification-header-title {
  font-size: var(--bn-text-base);
  font-weight: 700;
  color: var(--bn-dark);
}

.notification-header-actions {
  display: flex;
  align-items: center;
  gap: var(--bn-space-2);
}

.notification-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bn-gray-100);
  border-radius: var(--bn-radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--bn-gray);
  transition: all var(--bn-transition-fast);
}

.notification-close:hover {
  background: var(--bn-gray-lighter);
  color: var(--bn-dark);
}

.notification-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.notification-item {
  display: flex;
  align-items: flex-start;
  gap: var(--bn-space-3);
  padding: var(--bn-space-4) var(--bn-space-5);
  cursor: pointer;
  transition: background var(--bn-transition-fast);
  border-bottom: 1px solid var(--bn-gray-100);
}

.notification-item:last-child {
  border-bottom: none;
}

.notification-item:hover {
  background: var(--bn-gray-50);
}

.notification-item.unread {
  background: var(--bn-accent-subtle);
}

.notification-item.unread:hover {
  background: rgba(201, 162, 39, 0.12);
}

.notification-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--bn-radius-full);
  background: var(--bn-gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.notification-item.unread .notification-icon {
  background: var(--bn-accent-subtle);
}

.notification-content {
  flex: 1;
  min-width: 0;
}

.notification-title {
  font-size: var(--bn-text-sm);
  font-weight: 600;
  color: var(--bn-dark);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notification-message {
  font-size: var(--bn-text-xs);
  color: var(--bn-gray-700);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.notification-time {
  font-size: 11px;
  color: var(--bn-gray-400);
  margin-top: var(--bn-space-1);
}

.notification-dismiss {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: var(--bn-radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--bn-gray-400);
  opacity: 0;
  transition: all var(--bn-transition-fast);
}

.notification-item:hover .notification-dismiss {
  opacity: 1;
}

.notification-dismiss:hover {
  background: var(--bn-gray-100);
  color: var(--bn-gray-700);
}

.notification-empty {
  padding: var(--bn-space-8) var(--bn-space-5);
  text-align: center;
  color: var(--bn-gray);
  font-size: var(--bn-text-sm);
}

/* Mobile: full-width bottom sheet for notification dropdown */
@media (max-width: 768px) {
  .notification-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--bn-radius-2xl) var(--bn-radius-2xl) 0 0;
    animation: notif-sheet-up 0.3s var(--bn-ease-out);
  }

  @keyframes notif-sheet-up {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* ============================================
   MESSAGES / CHAT INBOX
   ============================================ */
.messages-list {
  display: flex;
  flex-direction: column;
  gap: var(--bn-space-3);
}

.message-item {
  background: var(--bn-white);
  border-radius: var(--bn-radius-lg);
  padding: var(--bn-space-5);
  border: 1px solid var(--bn-gray-lighter);
  cursor: pointer;
  transition: all var(--bn-transition-base);
}

.message-item:hover {
  border-color: var(--bn-primary);
  box-shadow: var(--bn-shadow-md);
}

.message-item.unread {
  background: var(--bn-accent-subtle);
  border-color: var(--bn-accent);
}

.message-item:focus-visible {
  outline: 2px solid var(--bn-accent);
  outline-offset: 2px;
}

.message-item.read {
  opacity: 0.7;
}

.message-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--bn-space-3);
}

.message-title {
  font-size: var(--bn-text-base);
  font-weight: 700;
  color: var(--bn-dark);
  margin: 0 0 var(--bn-space-1);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: var(--bn-space-3);
  font-size: var(--bn-text-xs);
  color: var(--bn-gray);
}

.message-type-badge {
  padding: 2px 8px;
  border-radius: var(--bn-radius-full);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.message-type-badge.info {
  background: var(--bn-info-light);
  color: var(--bn-info);
}

.message-type-badge.success {
  background: var(--bn-success-light);
  color: var(--bn-success);
}

.message-type-badge.warning {
  background: var(--bn-warning-light);
  color: var(--bn-warning);
}

.message-type-badge.danger {
  background: var(--bn-danger-light);
  color: var(--bn-danger);
}

.message-body {
  font-size: var(--bn-text-sm);
  color: var(--bn-gray-700);
  line-height: 1.6;
  white-space: pre-wrap;
  margin-bottom: var(--bn-space-3);
}

.message-actions {
  display: flex;
  gap: var(--bn-space-2);
  padding-top: var(--bn-space-3);
  border-top: 1px solid var(--bn-gray-lighter);
  flex-wrap: wrap;
}

/* Action tabs (filter pills) */
.action-tabs {
  display: flex;
  gap: var(--bn-space-2);
  margin-bottom: var(--bn-space-6);
  padding: var(--bn-space-2);
  background: var(--bn-gray-100);
  border-radius: var(--bn-radius-full);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.action-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--bn-space-2) var(--bn-space-4);
  border: none;
  background: transparent;
  border-radius: var(--bn-radius-full);
  font-size: var(--bn-text-sm);
  font-weight: 600;
  color: var(--bn-gray);
  cursor: pointer;
  transition: all var(--bn-transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.action-tab.active {
  background: var(--bn-white);
  color: var(--bn-dark);
  box-shadow: var(--bn-shadow-sm);
}

.action-tab:focus-visible {
  outline: 2px solid var(--bn-accent);
  outline-offset: 2px;
}

/* Message modal */
.message-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 40, 0.8);
  backdrop-filter: blur(8px);
  z-index: var(--z-modal);
  padding: var(--bn-space-4);
  align-items: center;
  justify-content: center;
}

.message-modal.active {
  display: flex;
}

.message-modal-content {
  background: var(--bn-white);
  border-radius: var(--bn-radius-xl);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--bn-shadow-xl);
  animation: modal-in 0.25s var(--bn-ease-out);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.message-modal-header {
  padding: var(--bn-space-5) var(--bn-space-6);
  border-bottom: 1px solid var(--bn-gray-lighter);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bn-white);
  z-index: 1;
}

.message-modal-title {
  font-size: var(--bn-text-lg);
  font-weight: 700;
  color: var(--bn-dark);
  margin: 0;
}

.message-modal-close {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--bn-gray-100);
  border-radius: var(--bn-radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--bn-text-xl);
  color: var(--bn-gray);
  transition: all var(--bn-transition-fast);
}

.message-modal-close:hover {
  background: var(--bn-gray-lighter);
  color: var(--bn-dark);
}

.message-modal-body {
  padding: var(--bn-space-6);
}

.message-modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--bn-space-4);
  margin-bottom: var(--bn-space-4);
  padding-bottom: var(--bn-space-4);
  border-bottom: 1px solid var(--bn-gray-lighter);
  font-size: var(--bn-text-sm);
  color: var(--bn-gray);
}

.message-modal-text {
  font-size: var(--bn-text-base);
  color: var(--bn-dark);
  line-height: 1.7;
  white-space: pre-wrap;
}

/* Mobile: bottom sheet for message modal */
@media (max-width: 768px) {
  .message-modal {
    align-items: flex-end;
    padding: 0;
  }

  .message-modal-content {
    max-width: 100%;
    max-height: 85vh;
    border-radius: var(--bn-radius-2xl) var(--bn-radius-2xl) 0 0;
    animation: modal-sheet-up 0.3s var(--bn-ease-out);
  }

  @keyframes modal-sheet-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .message-modal-header {
    padding: var(--bn-space-4);
  }

  .message-modal-body {
    padding: var(--bn-space-4);
  }

  .action-tabs {
    gap: var(--bn-space-1);
    padding: var(--bn-space-1);
    border-radius: var(--bn-radius-lg);
  }

  .action-tab {
    padding: var(--bn-space-2) var(--bn-space-3);
    font-size: var(--bn-text-xs);
  }
}

/* ============================================
   BROADCAST NOTIFICATIONS PAGE
   ============================================ */
.form-hint {
  display: block;
  font-size: var(--bn-text-xs);
  color: var(--bn-gray);
  margin-top: var(--bn-space-1);
}

.recipients-row {
  display: flex;
  gap: var(--bn-space-4);
  flex-wrap: wrap;
}

.recipients-row .radio-option span {
  font-size: var(--bn-text-sm);
}

/* ============================================
   SHARED CARD-INFO POPOVER ("i" toggles)
   Rendered dynamically by scripts/card_info.js — the toggle button is
   appended to a positioned card, the panel is appended to <body>.
   ============================================ */
/* A card that carries an "i" toggle. The toggle is absolutely positioned and
   therefore out of flow, so without this the card's own content runs underneath
   it — measured at 390px on the admin dashboard, a stat value sat 19px behind
   the button. Reserving the corner keeps the toggle top-right (where it belongs)
   AND keeps the figure readable, instead of trading one for the other.
   Applied by attachCardInfo() so every card with a toggle is covered, now and
   later. 42px = the 26px button + its 10px inset + a 6px breathing gap. */
/* Space for this button is reserved by attachCardInfo() (card_info.js), applied
   inline so a card's own padding rule cannot win the cascade. Deliberately NOT
   a rule here — two sources of truth for the same spacing is how it drifts. */
.bn-info-toggle {
  position: absolute;
  /* INSIDE the card, not overhanging it.
     This was top/right: -10px, so the button sat outside its host's box — and
     every host that sets `overflow: hidden` (.hero-stat, the acct tiles, the
     stat cards) simply CLIPPED IT AWAY. The button was present, opaque and
     visible per the computed styles, but nothing was painted: the owner
     reported "I cannot see it" on manage_payments and the user dashboard, and
     measurement confirmed the toggle's box lay 9–10px above and right of its
     host's edge on all seven cards.
     Positioning it inside means no host's overflow can ever clip it again,
     whatever a future card does. */
  /* HALF OUTSIDE the card, centred on the top-right corner, so it never covers
     the card's own figures. attachCardInfo() forces the host to
     `overflow: visible` when it attaches — without that a host with
     `overflow: hidden` clips the overhang away and the button disappears, which
     is exactly what happened the last time it sat outside. */
  top: -13px;
  right: -13px;
  z-index: 3;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--bn-gray-lighter);
  background: var(--bn-white);
  color: var(--bn-gray);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  font-style: italic;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--bn-transition-fast);
  padding: 0;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* The visual dot stays 26px, but the TAP target becomes 44×44 (E3's bar) via an
   invisible expander. Inset -9px on a 26px button = 44px. Positioning the
   button at 10px keeps that whole area inside the card, so it is not clipped
   either — which is why the offset above is 10 and not smaller. */
.bn-info-toggle::before {
  content: "";
  position: absolute;
  inset: -9px;
  border-radius: 50%;
}

.bn-info-toggle:hover {
  background: var(--bn-accent-subtle);
  border-color: var(--bn-accent);
  color: var(--bn-accent-dark);
}

.bn-info-toggle:focus-visible {
  outline: 2px solid var(--bn-accent);
  outline-offset: 2px;
}

.bn-info-toggle[aria-expanded="true"] {
  background: var(--bn-accent);
  border-color: var(--bn-accent);
  color: var(--bn-white);
}

/* Hidden when display preference is off */
.bn-no-card-info .bn-info-toggle {
  display: none;
}

/* The popover panel — positioned fixed on <body> by card_info.js */
.bn-info-panel {
  position: fixed;
  z-index: 10001;
  background: var(--bn-dark);
  color: var(--bn-gray-100);
  border-radius: var(--bn-radius-lg);
  padding: var(--bn-space-4) var(--bn-space-5);
  max-width: 320px;
  min-width: 180px;
  /* Rows can now expand a second level, so the panel has to be able to grow
     without running off screen. Without this a panel with several open rows
     simply overflowed the viewport with no way to reach the bottom. */
  max-height: min(70vh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: var(--bn-shadow-xl);
  font-size: var(--bn-text-sm);
  line-height: 1.6;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.bn-info-panel.is-open {
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0);
}

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

/* --- Uniform panel body (scripts/card_info.js `infoContent`) ---------------
   Title, then one plain sentence, then the derivation rows, then an optional
   action that opens the detail behind the number. Every "i" panel across the
   app uses this structure so they read the same way.                        */
.bn-info-title {
  margin: 0 0 var(--bn-space-2);
  font-size: var(--bn-text-sm);
  font-weight: 700;
  color: var(--bn-white);
}

.bn-info-desc {
  margin: 0 0 var(--bn-space-3);
  color: var(--bn-gray-300);
  font-size: var(--bn-text-xs);
  line-height: 1.55;
}

.bn-info-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--bn-space-4);
  padding: var(--bn-space-2) 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.bn-info-row:first-of-type {
  border-top: none;
}

.bn-info-row-label {
  color: var(--bn-gray-300);
  font-size: var(--bn-text-xs);
}

.bn-info-row-value {
  font-weight: 700;
  color: var(--bn-white);
  font-size: var(--bn-text-xs);
  text-align: right;
  white-space: nowrap;
}

.bn-info-row-toggle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  color: var(--bn-gray-300);
  font-family: inherit;
  font-size: 9px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--bn-transition-fast);
  flex-shrink: 0;
  line-height: 1;
}

.bn-info-row-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--bn-white);
}

.bn-info-row-toggle:focus-visible {
  outline: 2px solid var(--bn-accent);
  outline-offset: 2px;
}

/* Chevron points down when closed, up when open, so the row's state is visible
   without reading the panel. */
.bn-info-row-toggle.is-open {
  background: rgba(255, 255, 255, 0.12);
  color: var(--bn-white);
  transform: rotate(180deg);
}

/* A row that leads somewhere reads as clickable. Rows without an onClick keep
   the default cursor — nothing should look tappable when it is not. */
.bn-info-row.is-clickable {
  cursor: pointer;
  margin: 0 calc(-1 * var(--bn-space-2));
  padding-left: var(--bn-space-2);
  padding-right: var(--bn-space-2);
  border-radius: var(--bn-radius-sm);
  transition: background var(--bn-transition-fast);
}

.bn-info-row.is-clickable:hover,
.bn-info-row.is-clickable:focus-visible {
  background: rgba(255, 255, 255, 0.08);
}

.bn-info-row.is-clickable:focus-visible {
  outline: 2px solid var(--bn-accent);
  outline-offset: 0;
}

/* The expandable second level. This had NO css rule at all — the one panel that
   used it (the admin due-payment card) hand-rolled ~6 inline styles, which is
   exactly why the capability never spread to the other panels. */
.bn-info-row-detail {
  padding: 0 0 var(--bn-space-2) var(--bn-space-3);
  border-left: 2px solid rgba(255, 255, 255, 0.12);
  margin: 0 0 var(--bn-space-1) var(--bn-space-1);
  font-size: 11px;
  color: var(--bn-gray-300);
  line-height: 1.7;
}

.bn-info-row-detail[hidden] {
  display: none;
}

/* A detail block may itself be label/value pairs rather than a sentence. */
.bn-info-row-detail-line {
  display: flex;
  justify-content: space-between;
  gap: var(--bn-space-3);
}

.bn-info-row-detail-line > span:last-child {
  color: var(--bn-gray-100);
  font-weight: 600;
  white-space: nowrap;
}

.bn-info-row-detail-empty {
  color: var(--bn-gray-400);
  font-style: italic;
}

/* --- Cloned popover markup rendered INSIDE the shared dark panel -----------
   Some cards still fill the panel by cloning their page's own
   `.hero-stat-popover-*` nodes. Those rules were written for a LIGHT in-card
   popover, so inside this dark panel `.hero-stat-popover-title` resolved to
   var(--bn-dark) on a var(--bn-dark) background — **contrast ratio 1.0, i.e.
   invisible**. The line it hid on the Borrowing Power card was "Why you cannot
   borrow right now", the one sentence a member most needs.

   These overrides win on specificity (0,2,0 vs 0,1,0), so they hold regardless
   of stylesheet order, and they cover every cloned popover — not just the one
   card where the bug was spotted.                                            */
.bn-info-panel .hero-stat-popover-title,
.bn-info-panel .hero-stat-popover-more {
  color: var(--bn-white);
}

.bn-info-panel .hero-stat-popover-row {
  color: var(--bn-gray-100);
}

.bn-info-panel .hero-stat-popover-row:not(:last-child) {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

/* The severity variants used the -dark tokens, which are equally unreadable on
   a dark panel.
   NOT --bn-danger-light / --bn-success-light: those are translucent BACKGROUND
   tints (rgba at 0.12 alpha), so using them as a text colour would have swapped
   one invisible colour for another. Literal Tailwind red-300 / green-300 —
   ~7:1 and ~11:1 on this panel's background. */
.bn-info-panel .hero-stat-popover-row.overdue span:last-child {
  color: #FCA5A5;
}

.bn-info-panel .hero-stat-popover-row.on-time span:last-child {
  color: #86EFAC;
}

.bn-info-action {
  display: block;
  width: 100%;
  margin-top: var(--bn-space-3);
  padding: var(--bn-space-2) var(--bn-space-3);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--bn-radius-md);
  background: transparent;
  color: var(--bn-accent);
  font-family: inherit;
  font-size: var(--bn-text-xs);
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  /* 44px touch target — the panel is frequently opened on a phone. */
  min-height: 44px;
}

.bn-info-action:hover,
.bn-info-action:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--bn-accent);
}

/* ============================================
   FINANCIAL TRENDS CHART (analytics.html)
   ============================================ */

/* KPI summary row */
.fin-kpis {
  display: flex;
  gap: var(--bn-space-4);
  margin-bottom: var(--bn-space-5);
  flex-wrap: wrap;
}
.fin-kpi {
  flex: 1;
  min-width: 140px;
  background: var(--bn-gray-50);
  border-radius: var(--bn-radius-md);
  padding: var(--bn-space-3) var(--bn-space-4);
  text-align: center;
}
.fin-kpi-label {
  display: block;
  font-size: var(--bn-text-xs);
  font-weight: 600;
  color: var(--bn-gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--bn-space-1);
}
.fin-kpi-value {
  display: block;
  font-size: var(--bn-text-lg);
  font-weight: 800;
  color: var(--bn-dark);
  font-variant-numeric: tabular-nums;
}
.fin-kpi-value.pos { color: var(--bn-success); }
.fin-kpi-value.neg { color: var(--bn-danger); }

/* Legend */
.fin-legend {
  display: flex;
  gap: var(--bn-space-5);
  margin-bottom: var(--bn-space-4);
  padding: 0 var(--bn-space-1);
}
.fin-legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--bn-space-2);
  font-size: var(--bn-text-sm);
  font-weight: 500;
  color: var(--bn-gray-700);
}
.fin-legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.fin-legend-dot.collected { background: var(--bn-accent); }
.fin-legend-dot.disbursed { background: var(--bn-danger); }

/* Plot container */
.fin-plot {
  display: flex;
  gap: 0;
  position: relative;
  min-height: 240px;
}

/* Y-axis labels */
.fin-yaxis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 60px;
  flex-shrink: 0;
  padding-right: var(--bn-space-2);
  padding-bottom: 24px;
}
.fin-yaxis span {
  font-size: 10px;
  font-weight: 600;
  color: var(--bn-gray-500);
  text-align: right;
  line-height: 1;
}

/* Scrollable plot area */
.fin-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}
.fin-plot-area {
  position: relative;
  min-width: 100%;
}

/* Gridlines */
.fin-gridline {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--bn-gray-100);
  pointer-events: none;
}

/* Bars row */
.fin-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  padding-top: 4px;
}
.fin-month {
  flex: 1;
  min-width: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.fin-month-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  width: 100%;
  justify-content: center;
}
.fin-bar {
  width: 10px;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 0.4s ease;
}
.fin-bar.collected {
  background: linear-gradient(180deg, var(--bn-accent) 0%, var(--bn-accent-hover, #2563eb) 100%);
}
.fin-bar.disbursed {
  background: linear-gradient(180deg, var(--bn-danger) 0%, #dc2626 100%);
}
.fin-month-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--bn-gray-500);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Responsive */
@media (max-width: 768px) {
  .fin-kpis { gap: var(--bn-space-3); }
  .fin-kpi { min-width: 100px; padding: var(--bn-space-2) var(--bn-space-3); }
  .fin-kpi-value { font-size: var(--bn-text-base); }
  .fin-yaxis { width: 48px; }
  .fin-yaxis span { font-size: 9px; }
  .fin-bar { width: 8px; }
  .fin-month { min-width: 22px; }
  .fin-month-label { font-size: 9px; }
}
@media (max-width: 480px) {
  .fin-kpi { min-width: 80px; }
  .fin-kpi-value { font-size: var(--bn-text-sm); }
  .fin-yaxis { width: 40px; }
  .fin-bar { width: 6px; }
  .fin-month { min-width: 18px; }
  .fin-month-label { font-size: 8px; }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .toast-container {
    top: var(--bn-space-4);
    right: var(--bn-space-4);
    max-width: calc(100% - var(--bn-space-8));
  }

  .toast {
    padding: var(--bn-space-3) var(--bn-space-4);
  }

  .bn-info-panel {
    max-width: calc(100vw - var(--bn-space-8));
  }
}

/* ============================================
   QUICK AMOUNT PRESETS (scripts/ui.js renderQuickAmounts)
   Shown above the amount field on every record-a-payment form so someone picks
   an OUTCOME ("pay it off") instead of working out a figure to type.
   ============================================ */
.quick-amount-label {
  margin: 0 0 var(--bn-space-2);
  font-size: var(--bn-text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--bn-tracking-wide);
  color: var(--bn-gray);
}

.quick-amount-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--bn-space-2);
  margin-bottom: var(--bn-space-3);
}

.quick-amount-btn {
  flex: 1 1 140px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--bn-space-2) var(--bn-space-3);
  /* 44px minimum touch target — these are tapped on a phone in the field. */
  min-height: 44px;
  border: 1px solid var(--bn-gray-lighter);
  border-radius: var(--bn-radius-md);
  background: var(--bn-white);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--bn-transition-fast), background var(--bn-transition-fast);
}

.quick-amount-btn:hover,
.quick-amount-btn:focus-visible {
  border-color: var(--bn-accent);
  background: var(--bn-accent-subtle);
}

.quick-amount-btn.is-selected {
  border-color: var(--bn-accent);
  background: var(--bn-accent-subtle);
  box-shadow: inset 0 0 0 1px var(--bn-accent);
}

.quick-amount-btn-label {
  font-size: var(--bn-text-xs);
  font-weight: 700;
  color: var(--bn-dark);
}

.quick-amount-btn-amount {
  font-size: var(--bn-text-xs);
  color: var(--bn-gray);
  white-space: nowrap;
}

.quick-amount-btn-custom .quick-amount-btn-amount {
  font-style: italic;
}

@media (max-width: 480px) {
  .quick-amount-btn {
    flex: 1 1 100%;
  }
}

/* Due date on a preset chip, and the "what comes after" instalment list. */
.quick-amount-btn-due {
  font-size: 0.6875rem;
  color: var(--bn-gray);
}

.quick-amount-btn.is-selected .quick-amount-btn-due {
  color: var(--bn-gray-700);
}

/* "0.01 loan + 237,000.00 penalty" under a combined preset, so the headline
   figure is never mistaken for the instalment alone. */
.quick-amount-btn-split {
  font-size: 0.6875rem;
  color: var(--bn-gray);
  line-height: 1.3;
}

.quick-amount-btn.is-selected .quick-amount-btn-split {
  color: var(--bn-gray-700);
}

.upcoming-instalments {
  list-style: none;
  margin: 0 0 var(--bn-space-3);
  padding: 0;
  border: 1px solid var(--bn-gray-lighter);
  border-radius: var(--bn-radius-md);
  overflow: hidden;
}

.upcoming-instalment {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--bn-space-4);
  padding: var(--bn-space-2) var(--bn-space-3);
  font-size: var(--bn-text-xs);
  color: var(--bn-gray-700);
  border-top: 1px solid var(--bn-gray-lighter);
}

.upcoming-instalment:first-child {
  border-top: none;
}

.upcoming-instalment.is-overdue {
  color: var(--bn-danger);
  background: var(--bn-danger-light);
  font-weight: 600;
}

.upcoming-instalment-amount {
  font-weight: 700;
  white-space: nowrap;
}

/* Ordering prompt under the contribution presets (seed money settles first). */
.quick-amount-note {
  margin: 0 0 var(--bn-space-3);
  padding: var(--bn-space-2) var(--bn-space-3);
  border-left: 3px solid var(--bn-warning);
  background: var(--bn-warning-light);
  border-radius: var(--bn-radius-sm);
  font-size: var(--bn-text-xs);
  line-height: 1.5;
  color: var(--bn-gray-800);
}

/* Accounting drill-down (analytics.html): FLOW cards open a period breakdown. */
.breakdown-card.is-drillable {
  cursor: pointer;
  transition: border-color var(--bn-transition-fast), box-shadow var(--bn-transition-fast);
}

.breakdown-card.is-drillable:hover,
.breakdown-card.is-drillable:focus-visible {
  border-color: var(--bn-accent);
  box-shadow: var(--bn-shadow-md);
}

.breakdown-card.is-drillable:focus-visible {
  outline: 2px solid var(--bn-accent);
  outline-offset: 2px;
}

.drill-controls {
  display: flex;
  gap: var(--bn-space-4);
  flex-wrap: wrap;
  margin-bottom: var(--bn-space-4);
}

.drill-controls .form-group {
  flex: 1 1 160px;
  margin-bottom: 0;
}

.drill-total {
  margin: 0 0 var(--bn-space-4);
  padding-bottom: var(--bn-space-3);
  border-bottom: 1px solid var(--bn-gray-lighter);
  font-size: var(--bn-text-lg);
  font-weight: 700;
  color: var(--bn-dark);
}

/* J2 Slice 3 — penalty shown WITH the sum behind it, in the member's arrears
   modal. The amount leads; the derivation is secondary text under it. */
.penalty-amount {
  font-weight: 700;
  color: var(--bn-danger);
}

.penalty-why {
  margin-top: 2px;
  font-size: var(--bn-text-xs);
  line-height: 1.4;
  color: var(--bn-gray-600);
  font-weight: 400;
}

/* The parts-and-total block that makes the modal agree with the Arrears tile
   it opens from. */
.arrears-reconcile {
  margin-top: var(--bn-space-4);
  padding: var(--bn-space-3);
  border: 1px solid var(--bn-gray-lighter);
  border-radius: var(--bn-radius-md);
  background: var(--bn-gray-50);
}

.arrears-reconcile-row {
  display: flex;
  justify-content: space-between;
  gap: var(--bn-space-4);
  font-size: var(--bn-text-sm);
  color: var(--bn-gray-700);
  padding: var(--bn-space-1) 0;
}

.arrears-reconcile-row:last-child {
  margin-top: var(--bn-space-1);
  padding-top: var(--bn-space-2);
  border-top: 1px solid var(--bn-gray-lighter);
  font-weight: 700;
  color: var(--bn-dark);
}

/* Reconciliation note: the year's one-time money that belongs to no month
   (seed money). Reads as an annotation on the total, not as another figure
   competing with it — so it is quieter than .drill-total and tucked directly
   beneath it. */
.drill-total:has(+ .drill-unmonthed) {
  margin-bottom: var(--bn-space-2);
}

.drill-unmonthed {
  margin: 0 0 var(--bn-space-4);
  padding: var(--bn-space-2) var(--bn-space-3);
  border-left: 3px solid var(--bn-accent);
  border-radius: var(--bn-radius-sm);
  background: var(--bn-gray-50);
  font-size: var(--bn-text-xs);
  line-height: 1.5;
  color: var(--bn-gray-700);
}
