:root {
    /* Light Mode Colors */
    --bg-primary: #f8f9fa; /* Neutral background similar to login page */
    --bg-secondary: #ffffff;
    --text-primary: #1f2937; /* gray-800 */
    --text-secondary: #6b7280; /* gray-500 */
    --border-color: #e5e7eb; /* gray-200 */
    --shadow: rgba(0, 0, 0, 0.05);
    
    color-scheme: light; /* Browser native controls */
}

[data-theme="dark"] {
    /* Dark Mode Colors */
    --bg-primary: #111827; /* gray-900 */
    --bg-secondary: #1f2937; /* gray-800 */
    --text-primary: #f9fafb; /* gray-50 */
    --text-secondary: #9ca3af; /* gray-400 */
    --border-color: #374151; /* gray-700 */
    --shadow: rgba(0, 0, 0, 0.3);
    
    color-scheme: dark; /* Browser native controls */
}

/* Global Body Styles */
body {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* =========================================
   Tailwind Utility Overrides for Dark Mode
   ========================================= */

/* Backgrounds */
[data-theme="dark"] .bg-white {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .bg-gray-50 {
    background-color: #263042 !important; /* Custom dark shade for contrast */
    border-color: #374151 !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .bg-gray-100 {
    background-color: #374151 !important;
    color: var(--text-primary) !important;
}

/* Colored Badges/Backgrounds (Light variants become dark transparent variants) */
[data-theme="dark"] .bg-blue-50,
[data-theme="dark"] .bg-blue-100 {
    background-color: rgba(59, 130, 246, 0.15) !important;
    color: #60a5fa !important; /* blue-400 */
    border-color: rgba(59, 130, 246, 0.2) !important;
}

[data-theme="dark"] .bg-green-50,
[data-theme="dark"] .bg-green-100 {
    background-color: rgba(34, 197, 94, 0.15) !important;
    color: #4ade80 !important; /* green-400 */
    border-color: rgba(34, 197, 94, 0.2) !important;
}

[data-theme="dark"] .bg-purple-50,
[data-theme="dark"] .bg-purple-100 {
    background-color: rgba(168, 85, 247, 0.15) !important;
    color: #c084fc !important; /* purple-400 */
    border-color: rgba(168, 85, 247, 0.2) !important;
}

[data-theme="dark"] .bg-red-50,
[data-theme="dark"] .bg-red-100 {
    background-color: rgba(239, 68, 68, 0.15) !important;
    color: #f87171 !important; /* red-400 */
    border-color: rgba(239, 68, 68, 0.2) !important;
}

[data-theme="dark"] .bg-yellow-50,
[data-theme="dark"] .bg-yellow-100 {
    background-color: rgba(234, 179, 8, 0.15) !important;
    color: #facc15 !important; /* yellow-400 */
    border-color: rgba(234, 179, 8, 0.2) !important;
}

[data-theme="dark"] .bg-indigo-50 {
    background-color: rgba(99, 102, 241, 0.15) !important;
    color: #818cf8 !important;
}

/* Buttons */
[data-theme="dark"] .bg-blue-600 {
    background-color: #2563eb !important;
    border: 1px solid rgba(255,255,255,0.1);
}
[data-theme="dark"] .bg-blue-600:hover {
    background-color: #1d4ed8 !important;
}

[data-theme="dark"] .bg-green-600 {
    background-color: #16a34a !important;
    border: 1px solid rgba(255,255,255,0.1);
}

[data-theme="dark"] .bg-gray-800 {
    background-color: #4b5563 !important; /* Lighter gray for visibility */
    border: 1px solid rgba(255,255,255,0.1);
    color: #f9fafb !important;
}
[data-theme="dark"] .bg-gray-800:hover {
    background-color: #374151 !important;
}

/* Text Colors */
[data-theme="dark"] .text-blue-600 { color: #60a5fa !important; }
[data-theme="dark"] .text-blue-700 { color: #93c5fd !important; }
[data-theme="dark"] .text-green-600 { color: #4ade80 !important; }
[data-theme="dark"] .text-red-600, [data-theme="dark"] .text-red-500 { color: #f87171 !important; }
[data-theme="dark"] .text-gray-900, [data-theme="dark"] .text-gray-800, [data-theme="dark"] .text-gray-700 { color: #f3f4f6 !important; }
[data-theme="dark"] .text-gray-600, [data-theme="dark"] .text-gray-500 { color: #d1d5db !important; }
[data-theme="dark"] .text-gray-400 { color: #9ca3af !important; }

/* Borders */
[data-theme="dark"] .border-gray-200,
[data-theme="dark"] .border-gray-100,
[data-theme="dark"] .border-gray-300 {
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .divide-gray-100 > :not([hidden]) ~ :not([hidden]) {
    border-color: var(--border-color) !important;
}

/* Shadows */
[data-theme="dark"] .shadow-sm,
[data-theme="dark"] .shadow-md,
[data-theme="dark"] .shadow-lg {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5) !important;
}

/* =========================================
   Specific Component Fixes
   ========================================= */

/* Input/Select/Textarea Dark Mode */
[data-theme="dark"] input:not(.theme-toggle-input), 
[data-theme="dark"] select, 
[data-theme="dark"] textarea {
    background-color: #1f2937 !important; /* gray-800 */
    color: #f3f4f6 !important;
    border-color: #4b5563 !important;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
    color: #6b7280 !important;
}

/* Login Page Specifics */
[data-theme="dark"] .input-group {
    background-color: #1f2937 !important;
    color: #f3f4f6 !important;
    box-shadow: none !important;
    border: 1px solid #374151;
}
[data-theme="dark"] .input-group input {
    background-color: transparent !important;
    color: #f3f4f6 !important;
}
[data-theme="dark"] .input-group ion-icon {
    color: #9ca3af !important;
}
[data-theme="dark"] .screen-1 {
    background-color: #1f2937 !important; /* Ensure card matches secondary bg */
    box-shadow: 0 0 2em rgba(0, 0, 0, 0.3) !important;
}

/* Search Suggestions Hover */
[data-theme="dark"] .hover\:bg-gray-50:hover {
    background-color: #374151 !important;
}

/* File Manager */
[data-theme="dark"] #fileListContainer {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}
[data-theme="dark"] #fileListContainer .text-gray-700 {
    color: #f3f4f6 !important;
}

/* Modal Specifics */
[data-theme="dark"] .modal-container {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
}
[data-theme="dark"] .modal-container .bg-gray-50 {
    background-color: #263042 !important; /* Header/Footer */
}

/* Request Modal Date Picker */
[data-theme="dark"] ::-webkit-calendar-picker-indicator {
    filter: invert(1);
    cursor: pointer;
}

/* Focus States */
[data-theme="dark"] input:focus,
[data-theme="dark"] textarea:focus,
[data-theme="dark"] select:focus {
    border-color: #3b82f6 !important; /* blue-500 */
    outline: 2px solid #3b82f6 !important;
    outline-offset: -1px;
}

/* Navigation Bar */
[data-theme="dark"] nav.bg-white {
    background-color: #1f2937 !important;
    border-bottom: 1px solid #374151;
}

/* =========================================
   Theme Toggle Widget
   ========================================= */
.theme-toggle-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 50;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 0.75rem;
}

.theme-toggle-btn {
    width: 3rem;
    height: 3rem;
    border-radius: 9999px;
    background-color: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid #e5e7eb;
    font-size: 1.25rem;
    user-select: none;
    color: #374151;
}

.theme-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-color: #d1d5db;
}

.theme-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
    margin-bottom: 0.5rem;
}

.theme-options.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.theme-option-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background-color: white;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    color: #4b5563;
    min-width: 80px;
}

.theme-option-item:hover {
    background-color: #f9fafb;
    transform: translateX(-4px);
    border-color: #d1d5db;
}

.theme-option-item.active {
    background-color: #eff6ff;
    border-color: #3b82f6;
    color: #2563eb;
    font-weight: 500;
}

/* Dark Mode Styles for Toggle */
[data-theme="dark"] .theme-toggle-btn {
    background-color: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .theme-toggle-btn:hover {
    background-color: #374151;
}

[data-theme="dark"] .theme-option-item {
    background-color: #1f2937;
    border-color: #374151;
    color: #9ca3af;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

[data-theme="dark"] .theme-option-item:hover {
    background-color: #374151;
    color: #f3f4f6;
}

[data-theme="dark"] .theme-option-item.active {
    background-color: #1e3a8a;
    border-color: #60a5fa;
    color: #93c5fd;
}
