/**
 * Main Stylesheet
 * Church Management System
 */

/* Import Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@400;500;600;700&display=swap');

/* CSS Variables for Theming */
:root {
  --primary-color: #1E40AF;
  --secondary-color: #7C3AED;
  --accent-color: #F59E0B;
  --success-color: #10B981;
  --warning-color: #F97316;
  --danger-color: #EF4444;
  --info-color: #3B82F6;
  --background-color: #F9FAFB;
  --text-color: #1F2937;
  --text-muted: #6B7280;
  --border-color: #E5E7EB;
  --card-background: #FFFFFF;
  --sidebar-bg: #1F2937;
  --sidebar-text: #F9FAFB;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"],
.dark-mode {
  --primary-color: #3B82F6;
  --secondary-color: #8B5CF6;
  --accent-color: #FBBF24;
  --background-color: #111827;
  --text-color: #F9FAFB;
  --text-muted: #9CA3AF;
  --border-color: #374151;
  --card-background: #1F2937;
  --sidebar-bg: #0F172A;
  --sidebar-text: #F9FAFB;
}

/* Dark mode form label visibility */
[data-theme="dark"] .form-label,
.dark-mode .form-label {
  color: #F9FAFB;
}

/* Ensure form labels in modals are visible in dark mode */
[data-theme="dark"] .modal-content .form-label,
.dark-mode .modal-content .form-label {
  color: #F9FAFB;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-color);
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--secondary-color);
}

/* Utility Classes */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
  width: 100%;
}

/* Buttons */
.btn {
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  line-height: 1.5;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

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

.btn-primary:hover:not(:disabled) {
  background-color: #1E3A8A;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--secondary-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
  background-color: #6D28D9;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-success {
  background-color: var(--success-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-success:hover:not(:disabled) {
  background-color: #059669;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-danger {
  background-color: var(--danger-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-danger:hover:not(:disabled) {
  background-color: #DC2626;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-warning {
  background-color: var(--warning-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-warning:hover:not(:disabled) {
  background-color: #EA580C;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-outline {
  background-color: transparent;
  border: 2px solid var(--primary-color);
  color: var(--primary-color);
}

.btn-outline:hover:not(:disabled) {
  background-color: var(--primary-color);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-outline-secondary {
  background-color: transparent;
  border: 2px solid var(--secondary-color);
  color: var(--secondary-color);
}

.btn-outline-secondary:hover:not(:disabled) {
  background-color: var(--secondary-color);
  color: white;
}

.btn-full {
  width: 100%;
}

.btn-block {
  display: block;
  width: 100%;
}

/* Cards */
.card {
  background-color: var(--card-background);
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
  position: relative;
}

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

.card-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

.card-body {
  margin-bottom: 1rem;
}

.card-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Badges */
.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-block;
  line-height: 1.5;
}

.badge-success {
  background-color: #D1FAE5;
  color: #065F46;
}

.badge-warning {
  background-color: #FEF3C7;
  color: #92400E;
}

.badge-danger {
  background-color: #FEE2E2;
  color: #991B1B;
}

.badge-info {
  background-color: #DBEAFE;
  color: #1E40AF;
}

.badge-primary {
  background-color: #DBEAFE;
  color: #1E40AF;
}

.badge-secondary {
  background-color: #E9D5FF;
  color: #6B21A8;
}

[data-theme="dark"] .badge-success,
.dark-mode .badge-success {
  background-color: #065F46;
  color: #D1FAE5;
}

[data-theme="dark"] .badge-warning,
.dark-mode .badge-warning {
  background-color: #92400E;
  color: #FEF3C7;
}

[data-theme="dark"] .badge-danger,
.dark-mode .badge-danger {
  background-color: #991B1B;
  color: #FEE2E2;
}

[data-theme="dark"] .badge-info,
.dark-mode .badge-info {
  background-color: #1E40AF;
  color: #DBEAFE;
}

/* Form Elements */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-color);
}

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

.form-control {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background-color: var(--card-background);
  color: var(--text-color);
  font-size: 0.875rem;
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.form-control:disabled {
  background-color: var(--background-color);
  cursor: not-allowed;
  opacity: 0.6;
}

.form-control::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
}

.form-text {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.form-error {
  font-size: 0.8125rem;
  color: var(--danger-color);
  margin-top: 0.25rem;
}

/* Tables */
.table-container {
  overflow-x: auto;
  border-radius: 0.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--card-background);
  font-size: 0.875rem;
}

.table thead {
  background-color: var(--primary-color);
  color: white;
}

.table th {
  padding: 0.875rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-color);
}

.table tbody tr {
  transition: background-color 0.2s ease;
}

.table tbody tr:hover {
  background-color: rgba(30, 64, 175, 0.05);
}

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

/* Sidebar */
.sidebar {
  width: 260px;
  height: 100vh;
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  left: 0;
  top: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s ease;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

/* Smooth transitions for sidebar */
.sidebar {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background-color: rgba(0, 0, 0, 0.1);
}

.sidebar-header h2 {
  color: var(--sidebar-text);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.2;
}

.sidebar-header h2 i {
  font-size: 1.5rem;
  color: var(--accent-color);
}

.sidebar-menu {
  padding: 1rem 0;
}

.sidebar-menu-item {
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.sidebar-menu-item i {
  font-size: 1.125rem;
  width: 20px;
  text-align: center;
}

.sidebar-menu-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-left-color: var(--accent-color);
  padding-left: 1.75rem;
}

.sidebar-menu-item.active {
  background-color: rgba(30, 64, 175, 0.2);
  border-left-color: var(--primary-color);
  color: white;
  font-weight: 600;
}

.sidebar-menu-item-logout {
  margin-top: 2rem !important;
  color: #EF4444 !important;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 1rem;
}

.sidebar-menu-item-logout:hover {
  background-color: rgba(239, 68, 68, 0.2) !important;
  border-left-color: #EF4444 !important;
  color: #FCA5A5 !important;
}

/* Main Content */
.main-content {
  margin-left: 260px;
  min-height: 100vh;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background-color: var(--background-color);
}

.main-content.expanded {
  margin-left: 0;
}

/* Navbar */
.navbar {
  background-color: var(--card-background);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 70px;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.navbar .btn {
  background: transparent;
  border: none;
  padding: 0.5rem;
  color: var(--text-color);
}

.navbar .btn:hover {
  background-color: var(--background-color);
  transform: none;
}

/* Desktop: Hamburger button styling */
.sidebar-toggle-btn {
  background: transparent !important;
  color: var(--text-color) !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle-btn:hover {
  background-color: var(--background-color) !important;
}

/* Ensure hamburger is always visible */
#sidebar-toggle {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Notification Bell */
.notification-bell {
  position: relative;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.5rem;
  transition: background-color 0.2s ease;
}

.notification-bell:hover {
  background-color: var(--background-color);
}

.notification-badge {
  position: absolute;
  top: 0;
  right: 0;
  background-color: var(--danger-color);
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  border: 2px solid var(--card-background);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal.active {
  display: flex;
}

.modal-content {
  background-color: var(--card-background);
  border-radius: 0.75rem;
  padding: 2rem;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: modalSlideIn 0.3s ease-out;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-color);
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-color);
  padding: 0.25rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  transition: background-color 0.2s ease;
}

.modal-close:hover {
  background-color: var(--background-color);
}

.modal-body {
  margin-bottom: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Loading Spinner */
.spinner {
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

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

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background-color: var(--card-background);
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: slideInRight 0.3s ease-out;
  max-width: 400px;
  border-left: 4px solid var(--primary-color);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

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

.toast-success {
  border-left-color: var(--success-color);
}

.toast-error {
  border-left-color: var(--danger-color);
}

.toast-warning {
  border-left-color: var(--warning-color);
}

.toast-info {
  border-left-color: var(--info-color);
}

/* Alerts */
.alert {
  padding: 0.875rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-left: 4px solid;
}

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

.alert-error {
  background-color: #FEE2E2;
  color: #991B1B;
  border-left-color: var(--danger-color);
}

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

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

[data-theme="dark"] .alert-success,
.dark-mode .alert-success {
  background-color: rgba(16, 185, 129, 0.1);
  color: #6EE7B7;
}

[data-theme="dark"] .alert-error,
.dark-mode .alert-error {
  background-color: rgba(239, 68, 68, 0.1);
  color: #FCA5A5;
}

[data-theme="dark"] .alert-warning,
.dark-mode .alert-warning {
  background-color: rgba(245, 158, 11, 0.1);
  color: #FCD34D;
}

[data-theme="dark"] .alert-info,
.dark-mode .alert-info {
  background-color: rgba(59, 130, 246, 0.1);
  color: #93C5FD;
}

/* Record Lock Indicator */
.record-locked {
  opacity: 0.7;
  background-color: rgba(239, 68, 68, 0.05);
  pointer-events: none;
}

/* Allow member name links to be clickable even in locked rows */
.record-locked .member-name-link,
.record-locked a.member-name-link {
  pointer-events: auto !important;
  cursor: pointer !important;
  position: relative;
  z-index: 10;
}

/* Allow delete buttons to be clickable in locked rows (for admins) */
.record-locked .finance-action-btn[data-action="delete"],
.record-locked button[data-action="delete"],
.record-locked .btn-danger.finance-action-btn,
.record-locked td .finance-action-btn[data-action="delete"],
.record-locked td button[data-action="delete"],
.record-locked .btn-danger,
.record-locked button.btn-danger,
.record-locked td .btn-danger,
.record-locked td button.btn-danger {
  pointer-events: auto !important;
  cursor: pointer !important;
  position: relative;
  z-index: 10;
  opacity: 1 !important;
}

.lock-icon {
  color: var(--danger-color);
  font-size: 1.25rem;
}

.timer-badge {
  background-color: var(--success-color);
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.3s;
  border-radius: 24px;
}

.toggle-switch .slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.toggle-switch input:checked + .slider {
  background-color: var(--primary-color);
}

.toggle-switch input:checked + .slider:before {
  transform: translateX(20px);
}

/* Mobile-First Responsive Design */
/* ============================================ */

/* Sidebar Overlay for Mobile */
@media (max-width: 1024px) {
  /* Sidebar - Hidden by default on mobile */
  .sidebar {
    transform: translateX(-100%);
    z-index: 1000 !important;
    box-shadow: var(--shadow-xl);
    width: 280px;
    max-width: 85vw;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    display: block !important;
    visibility: visible !important;
  }
  
  /* Sidebar - Show when active */
  .sidebar.active {
    transform: translateX(0) !important;
    display: block !important;
    visibility: visible !important;
  }
  
  /* Sidebar - Also show if not collapsed (for compatibility) */
  .sidebar:not(.collapsed).active {
    transform: translateX(0) !important;
  }
  
  /* Sidebar overlay backdrop */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
  }
  
  .sidebar-overlay.active {
    display: block !important;
  }
  
  .main-content {
    margin-left: 0 !important;
  }
  
  .main-content.expanded {
    margin-left: 0 !important;
  }
  
  /* Ensure hamburger is visible on tablet */
  #sidebar-toggle {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    background-color: var(--primary-color) !important;
    color: white !important;
    min-width: 44px;
    min-height: 44px;
  }
  
  #sidebar-toggle i {
    color: white !important;
    display: block !important;
  }
}

/* Tablet Styles (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
  .sidebar {
    width: 240px;
  }
  
  .navbar {
    padding: 1rem 1.25rem;
  }
  
  .navbar-left input {
    width: 250px;
  }
  
  .card {
    padding: 1.25rem;
  }
  
  .modal-content {
    max-width: 550px;
    padding: 1.75rem;
  }
}

/* Mobile Styles (up to 767px) */
@media (max-width: 767px) {
  /* Prevent horizontal scrolling */
  html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    width: 100% !important;
  }
  
  * {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* Base Typography */
  html {
    font-size: 14px;
  }
  
  h1 {
    font-size: 1.75rem;
    word-wrap: break-word;
  }
  
  h2 {
    font-size: 1.5rem;
    word-wrap: break-word;
  }
  
  h3 {
    font-size: 1.25rem;
    word-wrap: break-word;
  }
  
  /* Container */
  .container {
    padding: 0 1rem;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden !important;
  }
  
  /* Page Content Padding */
  .page-content,
  body > div > div[style*="padding: 2rem"],
  #main-content > div[style*="padding"] {
    padding: 1rem !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }
  
  /* Main Content - Prevent overflow */
  .main-content {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    width: 100% !important;
  }
  
  /* Sidebar - Mobile */
  .sidebar {
    width: 280px !important;
    max-width: 85vw !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    z-index: 1000 !important;
    display: block !important;
    visibility: visible !important;
  }
  
  /* Sidebar - Show when active on mobile */
  .sidebar.active {
    transform: translateX(0) !important;
    display: block !important;
    visibility: visible !important;
  }
  
  .sidebar-header {
    padding: 1.25rem 1rem;
  }
  
  .sidebar-header h2 {
    font-size: 1.125rem;
  }
  
  .sidebar-menu-item {
    padding: 1rem 1.25rem;
    font-size: 0.9375rem;
  }
  
  /* Main Content */
  .main-content {
    width: 100%;
  }
  
  /* Navbar */
  .navbar {
    padding: 0.875rem 1rem;
    flex-wrap: nowrap;
    gap: 0.75rem;
    min-height: auto;
  }
  
  .navbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    order: 1;
  }
  
  /* Hamburger Menu Button - Mobile */
  #sidebar-toggle {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
    background-color: var(--primary-color) !important;
    color: white !important;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    z-index: 1001;
    position: relative;
  }
  
  #sidebar-toggle:hover,
  #sidebar-toggle:active {
    background-color: #1E3A8A !important;
    transform: scale(1.05);
  }
  
  #sidebar-toggle i {
    font-size: 1.25rem !important;
    color: white !important;
    display: block !important;
    visibility: visible !important;
  }
  
  /* Ensure button is visible even if parent has display issues */
  .navbar-left #sidebar-toggle {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .navbar-left input {
    flex: 1;
    font-size: 0.875rem;
    min-width: 0;
  }
  
  .navbar-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    order: 2;
    justify-content: flex-end;
    gap: 0.5rem;
  }
  
  /* Hide user name/role text on mobile, show only avatar */
  .navbar-right > div[onclick="toggleUserMenu()"] > div:last-child {
    display: none;
  }
  
  .navbar-right > div[onclick="toggleUserMenu()"] > div:first-child {
    width: 36px;
    height: 36px;
    font-size: 0.875rem;
  }
  
  /* Cards */
  .card {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
  }
  
  .card-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }
  
  .card-title {
    font-size: 1.125rem;
  }
  
  /* Buttons - Touch Friendly */
  .btn {
    padding: 0.75rem 1.25rem;
    font-size: 0.9375rem;
    min-height: 44px; /* iOS touch target minimum */
    min-width: 44px;
  }
  
  .btn-sm {
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
    min-height: 40px;
  }
  
  .btn-lg {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    min-height: 48px;
  }
  
  /* Forms - Stack vertically, prevent overflow */
  .form-group {
    margin-bottom: 1rem;
    width: 100% !important;
    max-width: 100% !important;
    position: relative !important;
    z-index: 1;
  }
  
  .form-label {
    font-size: 0.875rem;
    margin-bottom: 0.375rem;
    display: block;
    width: 100%;
    color: var(--text-color);
  }
  
  .form-control {
    padding: 0.75rem;
    font-size: 1rem; /* Prevents zoom on iOS */
    min-height: 44px;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    position: relative;
  }
  
  /* Select dropdowns - Ensure proper positioning on mobile */
  .form-select,
  select.form-control,
  select {
    padding-right: 2.25rem;
    min-height: 44px;
    width: 100% !important;
    max-width: 100% !important;
    position: relative !important;
    z-index: 2;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    /* Ensure select maintains positioning context */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
  
  /* When select is focused, ensure it's properly positioned */
  select:focus,
  .form-select:focus,
  select.form-control:focus {
    z-index: 1002 !important;
    position: relative !important;
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }
  
  /* Form group with focused select - elevate for dropdown positioning */
  .form-group.select-focused {
    z-index: 1001 !important;
    position: relative !important;
  }
  
  /* Ensure select dropdowns appear correctly positioned */
  .form-group:has(select:focus),
  .form-group:has(.form-select:focus) {
    z-index: 10;
  }
  
  /* Modal positioning context for dropdowns */
  .modal-content {
    position: relative !important;
    overflow: visible !important;
  }
  
  .modal-body {
    position: relative !important;
    overflow: visible !important;
  }
  
  /* Ensure form groups in modals maintain positioning */
  .modal-content .form-group {
    position: relative !important;
    z-index: auto;
  }
  
  .modal-content .form-group:has(select:focus),
  .modal-content .form-group:has(.form-select:focus) {
    z-index: 1001;
  }
  
  textarea.form-control {
    width: 100% !important;
    max-width: 100% !important;
    resize: vertical;
  }
  
  /* Form Grids - Force single column on mobile */
  form div[style*="grid-template-columns"],
  .form-grid,
  div[style*="repeat(2, 1fr)"],
  div[style*="repeat(3, 1fr)"],
  div[style*="repeat(4, 1fr)"] {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  
  /* Form flex layouts - Stack vertically */
  form div[style*="display: flex"],
  .form-actions,
  div[style*="justify-content: flex-end"] {
    flex-direction: column !important;
    gap: 0.75rem !important;
    width: 100% !important;
  }
  
  form div[style*="display: flex"] button,
  .form-actions button {
    width: 100% !important;
  }
  
  /* Tables - Contained scrolling, no page overflow */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.5rem;
    margin: 0;
    padding: 0;
    width: 100% !important;
    max-width: 100% !important;
    display: block;
  }
  
  .table {
    font-size: 0.8125rem;
    min-width: 600px;
    width: 100%;
    display: table;
  }
  
  .table th {
    padding: 0.75rem 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
  }
  
  .table td {
    padding: 0.75rem 0.5rem;
    word-break: break-word;
  }
  
  /* Modals */
  .modal {
    padding: 1rem;
    align-items: flex-end; /* Slide up from bottom on mobile */
  }
  
  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    padding: 1.25rem;
    border-radius: 1rem 1rem 0 0;
    margin: 0;
    animation: modalSlideUp 0.3s ease-out;
  }
  
  @keyframes modalSlideUp {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
  
  .modal-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }
  
  .modal-title {
    font-size: 1.25rem;
  }
  
  .modal-close {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.25rem;
  }
  
  .modal-body {
    margin-bottom: 1rem;
    max-height: calc(90vh - 150px);
  }
  
  .modal-footer {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .modal-footer .btn {
    width: 100%;
  }
  
  /* Grid Layouts */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }
  
  /* Dashboard Cards - Force single column on mobile */
  .dashboard-grid,
  div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }
  
  /* Override inline grid styles for mobile */
  div[style*="repeat(2, 1fr)"] {
    grid-template-columns: 1fr !important;
  }
  
  div[style*="repeat(auto-fit"] {
    grid-template-columns: 1fr !important;
  }
  
  div[style*="repeat(auto-fill"] {
    grid-template-columns: 1fr !important;
  }
  
  /* Filter Sections */
  .filter-section,
  [style*="grid-template-columns"][style*="repeat"] {
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }
  
  /* Badges */
  .badge {
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
  }
  
  /* Dropdowns */
  .dropdown-menu {
    position: fixed !important;
    top: auto !important;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    width: auto;
    max-width: calc(100% - 2rem);
    max-height: 50vh;
    overflow-y: auto;
  }
  
  /* Notification Dropdown */
  #notification-dropdown {
    position: fixed !important;
    top: auto !important;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    width: auto;
    max-width: calc(100% - 2rem);
    max-height: 50vh;
  }
  
  /* User Menu Dropdown */
  #user-menu-dropdown {
    position: fixed !important;
    top: auto !important;
    bottom: 1rem;
    right: 1rem;
    left: auto;
    width: auto;
    min-width: 200px;
  }
  
  /* Toast Notifications */
  .toast {
    left: 1rem;
    right: 1rem;
    width: auto;
    max-width: calc(100% - 2rem);
  }
  
  /* Spacing Utilities */
  .mb-4 {
    margin-bottom: 1rem !important;
  }
  
  .mt-4 {
    margin-top: 1rem !important;
  }
  
  .p-4 {
    padding: 1rem !important;
  }
  
  /* Settings Page */
  .settings-layout {
    grid-template-columns: 1fr !important;
  }
  
  .settings-menu {
    order: 2;
    margin-top: 1rem;
  }
  
  .settings-content {
    order: 1;
  }
  
  /* Finance Summary Cards */
  .finance-summary {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem;
  }
  
  .finance-summary .card {
    padding: 0.875rem;
  }
  
  /* Member Finance Modal */
  #member-finance-modal .modal-content {
    max-height: 95vh;
  }
  
  /* Charts */
  .chart-container {
    height: 250px !important;
  }
  
  /* Search Input */
  .navbar-left input {
    font-size: 1rem; /* Prevents zoom on iOS */
  }
  
  /* Touch Targets */
  a, button, input, select, textarea {
    touch-action: manipulation;
  }
  
  /* Prevent text selection on buttons */
  .btn {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }
  
  /* Smooth Scrolling */
  html {
    scroll-behavior: smooth;
  }
  
  /* Search Input - Full width */
  .navbar-left input {
    font-size: 1rem; /* Prevents zoom on iOS */
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* All inputs and selects - Prevent overflow */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="date"],
  input[type="number"],
  input[type="password"],
  select,
  textarea {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* Buttons - Full width on mobile when in forms */
  form .btn,
  .modal-footer .btn {
    width: 100% !important;
    max-width: 100% !important;
  }
  
  /* Prevent any element from causing horizontal scroll */
  img, video, iframe, embed, object {
    max-width: 100% !important;
    height: auto !important;
  }
  
  /* Ensure all flex containers don't overflow */
  [style*="display: flex"] {
    flex-wrap: wrap !important;
    max-width: 100% !important;
  }
  
  /* Cards - Prevent overflow */
  .card {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  /* Remove hover effects on touch devices */
  @media (hover: none) {
    .card:hover {
      transform: none;
      box-shadow: var(--shadow-md);
    }
    
    .btn:hover:not(:disabled) {
      transform: none;
    }
    
    .sidebar-menu-item:hover {
      padding-left: 1.5rem;
    }
  }
}

/* Small Mobile (up to 480px) */
@media (max-width: 480px) {
  html {
    font-size: 13px;
  }
  
  .container {
    padding: 0 0.75rem;
  }
  
  .card {
    padding: 0.875rem;
  }
  
  .modal-content {
    padding: 1rem;
    border-radius: 0.75rem 0.75rem 0 0;
  }
  
  .navbar {
    padding: 0.75rem;
  }
  
  .sidebar {
    width: 100%;
    max-width: 100%;
  }
  
  .finance-summary {
    grid-template-columns: 1fr !important;
  }
  
  .table {
    font-size: 0.75rem;
  }
  
  .table th,
  .table td {
    padding: 0.5rem 0.375rem;
  }
}

/* Print Styles */
@media print {
  .sidebar,
  .navbar,
  .btn,
  .modal {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* Login Page Specific Styles - Modern Dark Mode */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: #212121;
  position: relative;
  overflow: hidden;
}

/* Animated background gradient */
.login-page::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: transparent;
  animation: none;
}

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

/* Grid pattern overlay */
.login-page::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  opacity: 0;
  pointer-events: none;
}

.login-container {
  background: #2B2B2B;
  border: none;
  border-radius: 1.5rem;
  box-shadow: none;
  max-width: 360px;
  width: 100%;
  padding: 1.75rem 1.5rem;
  animation: fadeInUp 0.6s ease-out;
  position: relative;
  z-index: 1;
}

[data-theme="dark"] .login-container,
.dark-mode .login-container {
  background: #2B2B2B;
  border-color: transparent;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.login-logo {
  font-size: 3.5rem;
  background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1rem;
  display: inline-block;
  animation: pulse 2s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(59, 130, 246, 0.5));
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 0 20px rgba(59, 130, 246, 0.5));
  }
  50% {
    transform: scale(1.05);
    filter: drop-shadow(0 0 30px rgba(59, 130, 246, 0.8));
  }
}

.login-title {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, #FFFFFF 0%, #E5E7EB 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.login-subtitle {
  color: rgba(156, 163, 175, 0.9);
  font-size: 0.9rem;
  font-weight: 400;
}

/* Login form styles */
.login-container .form-group {
  margin-bottom: 1.25rem;
}

.login-container .form-label {
  color: rgba(229, 231, 235, 0.9);
  font-weight: 500;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.login-container .form-label i {
  color: #3B82F6;
  font-size: 0.875rem;
}

.login-container .form-control {
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: #F9FAFB;
  padding: 0.875rem 1rem;
  border-radius: 0.75rem;
  transition: all 0.3s ease;
  font-size: 1rem;
}

.login-container .form-control::placeholder {
  color: rgba(156, 163, 175, 0.6);
}

.login-container .form-control:focus {
  background: rgba(17, 24, 39, 0.8);
  border-color: #3B82F6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1), 0 0 20px rgba(59, 130, 246, 0.2);
  outline: none;
}

.login-container .btn-primary {
  background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
  border: none;
  padding: 0.875rem 1.5rem;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 0.75rem;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
  transition: all 0.3s ease;
  margin-top: 0.5rem;
}

.login-container .btn-primary:hover {
  background: linear-gradient(135deg, #2563EB 0%, #1E40AF 100%);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
  transform: translateY(-2px);
}

.login-container .btn-primary:active {
  transform: translateY(0);
}

/* Remember me checkbox */
.login-container input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #3B82F6;
  cursor: pointer;
}

.login-container label[for="remember"] {
  color: rgba(229, 231, 235, 0.8);
  font-size: 0.875rem;
  user-select: none;
}

/* Alert styles for login page */
.login-container .alert {
  padding: 0.875rem 1rem;
  border-radius: 0.75rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.login-container .alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #FCA5A5;
}

.login-container .alert-success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6EE7B7;
}

.login-container .alert i {
  font-size: 1.125rem;
}

/* Links */
.login-container a {
  color: #60A5FA;
  transition: color 0.2s ease;
  text-decoration: none;
}

.login-container a:hover {
  color: #3B82F6;
  text-decoration: underline;
}

/* Demo credentials section */
.login-container > div:last-child {
  background: transparent;
  border: none;
  border-radius: 0.75rem;
  padding: 0;
  margin-top: 1.5rem;
}

.login-container > div:last-child p {
  color: rgba(229, 231, 235, 0.7);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.login-container > div:last-child p:first-child {
  color: rgba(229, 231, 235, 0.9);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

/* Mobile responsive */
@media (max-width: 767px) {
  .login-container {
    padding: 2rem 1.5rem;
    border-radius: 1.25rem;
  }
  
  .login-logo {
    font-size: 3rem;
  }
  
  .login-title {
    font-size: 1.75rem;
  }
  
  .login-subtitle {
    font-size: 0.9rem;
  }
}

/* Global mobile filter layout */
@media (max-width: 768px) {
  /* Card grids: 2-up on mobile (safe scope) */
  .container > div[style*="grid-template-columns"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
  }

  /* Reports summary grids: force 2-up on mobile */
  #finance-summary-cards-grid,
  #member-summary-cards-grid,
  #offerings-summary-cards-grid,
  #monetary-summary-cards-grid,
  #attendance-summary-cards-grid,
  #bulk-attendance-summary-cards-grid,
  #event-summary-cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
  }

  /* Single-column filter grids */
  .collapsible-panel-inner > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  .members-filter-content,
  .offerings-filter-content,
  .monetary-filter-content,
  .momo-filter-content,
  .ministry-filter-content,
  .ministries-filter-content,
  .member-filter-content,
  .bulk-attendance-filter-content,
  .ministry-member-filter-content {
    padding: 0.75rem !important;
  }

  .collapsible-panel-inner {
    padding: 0.75rem !important;
  }

  .card .form-label {
    font-size: 0.8rem;
  }
}
