/* ===== THEME SYSTEM ===== */

/* Functional Button System - Standardized Dimensions */
:root {
    --btn-height-standard: 40px;
    --btn-font-size-standard: 14px;
    --btn-font-weight-standard: 500;
    --btn-padding-standard: 8px 16px;
    --btn-border-radius-standard: 6px;
    
    /* Action-Specific Button Colors */
    --btn-bg-record-donation: #16a34a;      /* Green for donation recording */
    --btn-bg-create-contact: #2563eb;       /* Blue for contact creation */
    --btn-bg-create-grant: #0891b2;         /* Teal for grant creation */
    --btn-bg-create-organization: #7c3aed;  /* Purple for organization creation */
    --btn-bg-create-touch: #059669;         /* Green for touch creation */
    --btn-bg-touch-management: #2563eb;     /* Blue for touch management */
    --btn-bg-view-director: #2563eb;        /* Blue for staff directory */
    --btn-bg-create-staff: #059669;         /* Green for staff creation */
    --btn-bg-manage-staff: #dc2626;         /* Red for staff management */
    --btn-bg-edit-item: #f59e0b;            /* Yellow for edit actions */
    --btn-bg-delete-item: #dc2626;          /* Red for delete actions */
    --btn-bg-save-changes: #16a34a;         /* Green for save actions */
    --btn-bg-cancel-action: #6b7280;        /* Gray for cancel actions */
}

/* Theme-responsive text colors */
[data-bs-theme="light"] {
    --text-primary: var(--text-primary-light);
    --text-secondary: var(--text-secondary-light);
    --text-muted: var(--text-muted-light);
    --text-link: var(--text-link-light);
}

[data-bs-theme="dark"] {
    --text-primary: var(--text-primary-dark);
    --text-secondary: var(--text-secondary-dark);
    --text-muted: var(--text-muted-dark);
    --text-link: var(--text-link-dark);
    
    /* Button Text Colors for Dark Mode */
    --btn-text-primary: #ffffff;        /* White text for dark backgrounds */
    --btn-text-secondary: #e9ecef;      /* Light gray text for secondary buttons */
    --btn-text-on-color: #ffffff;       /* White text for colored backgrounds */
}

/* Apply theme-aware text colors */
[data-bs-theme="dark"] h1,
[data-bs-theme="dark"] h2,
[data-bs-theme="dark"] h3,
[data-bs-theme="dark"] h4,
[data-bs-theme="dark"] h5,
[data-bs-theme="dark"] h6 {
    color: var(--text-primary-dark);
}

/* Theme-aware body text */
[data-bs-theme="dark"] body {
    color: var(--text-primary-dark);
}

/* Dark Mode Button Text System */
[data-bs-theme="dark"] .btn {
    color: var(--btn-text-primary);
}

/* Secondary/outline buttons get secondary text color */
[data-bs-theme="dark"] .btn-outline-secondary,
[data-bs-theme="dark"] .btn-light {
    color: var(--btn-text-secondary);
}

/* Colored background buttons always get white text */
[data-bs-theme="dark"] .btn-primary,
[data-bs-theme="dark"] .btn-success,
[data-bs-theme="dark"] .btn-danger,
[data-bs-theme="dark"] .btn-info,
[data-bs-theme="dark"] .btn-warning {
    color: var(--btn-text-on-color) !important;
}

/* Ensure hover and focus states maintain proper contrast */
[data-bs-theme="dark"] .btn-primary:hover,
[data-bs-theme="dark"] .btn-primary:focus,
[data-bs-theme="dark"] .btn-success:hover,
[data-bs-theme="dark"] .btn-success:focus,
[data-bs-theme="dark"] .btn-danger:hover,
[data-bs-theme="dark"] .btn-danger:focus,
[data-bs-theme="dark"] .btn-info:hover,
[data-bs-theme="dark"] .btn-info:focus,
[data-bs-theme="dark"] .btn-warning:hover,
[data-bs-theme="dark"] .btn-warning:focus {
    color: var(--btn-text-on-color) !important;
}

/* ===== DARK MODE COMPONENT STYLES ===== */

/* Dark Mode Card Styles */
[data-bs-theme="dark"] .card {
    background-color: var(--bg-elevated-dark);
    border-color: #374151;
}

[data-bs-theme="dark"] .card-header,
[data-bs-theme="dark"] .card-header.bg-light {
    background-color: #2d3748 !important;
    color: var(--text-primary-dark) !important;
    border-bottom-color: #374151 !important;
}

/* Dark Mode Table Styles */
[data-bs-theme="dark"] .table thead th {
    color: var(--text-secondary-dark);
    border-bottom-color: #374151;
}

[data-bs-theme="dark"] .table tbody td {
    border-bottom-color: #374151;
}

[data-bs-theme="dark"] .table tbody tr:hover {
    background-color: var(--bg-secondary-dark);
}

/* Dark Mode Form Styles */
[data-bs-theme="dark"] .form-section-title {
    color: var(--text-secondary-dark);
    border-bottom-color: #374151;
}

[data-bs-theme="dark"] .form-label {
    color: var(--text-secondary-dark);
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background-color: var(--bg-secondary-dark);
    border-color: #374151;
    color: var(--text-primary-dark);
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    background-color: var(--bg-secondary-dark);
    border-color: var(--text-link-dark);
    box-shadow: 0 0 0 0.2rem rgba(96, 165, 250, 0.25);
}

/* Dark Mode KPI Cards */
[data-bs-theme="dark"] .kpi-card,
[data-bs-theme="dark"] .stat-card {
    background-color: var(--bg-elevated-dark);
    border-color: #374151;
    color: var(--text-primary-dark);
}

[data-bs-theme="dark"] .kpi-value,
[data-bs-theme="dark"] .stat-card h4 {
    color: var(--text-primary-dark);
}

[data-bs-theme="dark"] .kpi-label,
[data-bs-theme="dark"] .stat-card small {
    color: var(--text-secondary-dark);
}

/* Dark Mode Page Elements */
[data-bs-theme="dark"] .page-header {
    border-bottom-color: #374151;
}

[data-bs-theme="dark"] .page-title {
    color: var(--text-primary-dark);
}

[data-bs-theme="dark"] .empty-state {
    color: var(--text-muted-dark);
}

[data-bs-theme="dark"] .main-content {
    background-color: var(--bg-primary-dark);
    color: var(--text-primary-dark);
}

/* Dark Mode Navigation and Dropdown Styles */
[data-bs-theme="dark"] .navbar {
    background-color: var(--bg-elevated-dark) !important;
    border-bottom-color: #374151;
}

[data-bs-theme="dark"] .navbar-brand .brand-name {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] .navbar-brand .brand-subtitle {
    color: var(--text-secondary-dark) !important;
}

[data-bs-theme="dark"] .nav-link {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] .nav-link:hover {
    color: var(--text-link-dark) !important;
}

[data-bs-theme="dark"] .dropdown-menu {
    background-color: var(--bg-elevated-dark) !important;
    border-color: #374151 !important;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5) !important;
}

[data-bs-theme="dark"] .dropdown-item {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:focus {
    background-color: var(--bg-secondary-dark) !important;
    color: var(--text-link-dark) !important;
}

[data-bs-theme="dark"] .dropdown-divider {
    border-top-color: #374151 !important;
}

/* Comprehensive Dark Mode Text and Element Fixes */
[data-bs-theme="dark"] h1,
[data-bs-theme="dark"] .h1 {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] h2,
[data-bs-theme="dark"] .h2 {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] h3,
[data-bs-theme="dark"] .h3 {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] .card-title,
[data-bs-theme="dark"] .modal-title,
[data-bs-theme="dark"] .card-header h5,
[data-bs-theme="dark"] .card-header h6,
[data-bs-theme="dark"] .card-header .h5,
[data-bs-theme="dark"] .card-header .h6,
[data-bs-theme="dark"] .card-header *,
[data-bs-theme="dark"] .card-header .fas,
[data-bs-theme="dark"] .card-header i {
    color: var(--text-primary-dark) !important;
}

/* Dark Mode Support for CRM Card (used in donations dashboard) */
[data-bs-theme="dark"] .crm-card {
    background-color: var(--bg-elevated-dark);
    border-color: #374151;
}

[data-bs-theme="dark"] .crm-card .card-header {
    background-color: var(--bg-secondary-dark);
    border-bottom-color: #374151;
}

[data-bs-theme="dark"] .crm-card .card-header h5,
[data-bs-theme="dark"] .crm-card .card-header h6 {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] .crm-card .card-body {
    color: var(--text-primary-dark);
}

[data-bs-theme="dark"] .text-muted {
    color: var(--text-muted-dark) !important;
}

[data-bs-theme="dark"] small {
    color: var(--text-secondary-dark) !important;
}

[data-bs-theme="dark"] .btn-warning {
    background-color: #f59e0b !important;
    border-color: #f59e0b !important;
    color: var(--btn-text-on-color) !important;
}

[data-bs-theme="dark"] .btn-warning:hover,
[data-bs-theme="dark"] .btn-warning:focus {
    color: var(--btn-text-on-color) !important;
}
/* Dark Mode Theme Toggle Fix */
[data-bs-theme="dark"] .theme-toggle {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] .theme-toggle:hover {
    background-color: var(--bg-secondary-dark) !important;
    color: var(--text-link-dark) !important;
}

/* Comprehensive Dark Mode Table and Text Fixes */
[data-bs-theme="dark"] .table thead th a,
[data-bs-theme="dark"] .table tbody td a {
    color: var(--text-link-dark) !important;
}

[data-bs-theme="dark"] .table thead th,
[data-bs-theme="dark"] .table tbody td {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] .table tbody td strong {
    color: var(--text-primary-dark) !important;
}

/* Ensure all pipeline elements are visible */
[data-bs-theme="dark"] .pipeline-header h5,
[data-bs-theme="dark"] .pipeline-header h6 {
    color: white !important;
}

/* Fix any remaining dark text issues */
[data-bs-theme="dark"] strong,
[data-bs-theme="dark"] b {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] .card-body,
[data-bs-theme="dark"] .card-text {
    color: var(--text-primary-dark) !important;
}

[data-bs-theme="dark"] th[role="columnheader"] {
    color: var(--text-primary-dark) !important;
}

/* Systematic dark mode text visibility fixes */
[data-bs-theme="dark"] .text-muted {
    color: #9ca3af !important;
}

[data-bs-theme="dark"] dt {
    color: #d1d5db !important;
}

[data-bs-theme="dark"] dd {
    color: #f3f4f6 !important;
}

[data-bs-theme="dark"] p {
    color: #e5e7eb !important;
}

[data-bs-theme="dark"] strong {
    color: #f9fafb !important;
}

[data-bs-theme="dark"] small {
    color: #9ca3af !important;
}

[data-bs-theme="dark"] .badge.bg-light {
    background-color: #374151 !important;
    color: #f9fafb !important;
}

/* URL wrapping fix for all pages */
.website-url,
a[href*="http"] {
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    hyphens: auto !important;
}

/* Organization detail page specific fixes */
[data-bs-theme="dark"] .section-title {
    color: #f3f4f6 !important;
}

[data-bs-theme="dark"] .stat-item h4 {
    color: #f9fafb !important;
}

/* Comprehensive header visibility for dark mode - v2024 */
[data-bs-theme="dark"] h4,
[data-bs-theme="dark"] h5,
[data-bs-theme="dark"] h6 {
    color: #f3f4f6 !important;
}

/* Force cache bust test */
body::before {
    content: "CSS-LOADED-v2024";
    display: none;
}
