/* ==========================================================================
   Theme CSS - Light/Dark Theme Variations & Theme Toggle
   ========================================================================== */

/* 1. Light Theme (Default)
   ========================================================================== */
:root {
    /* Light Theme Colors */
    --theme-bg: var(--light-bg);
    --theme-text: var(--light-text);
    --theme-border: var(--light-border);
    --theme-input-bg: var(--light-input-bg);
    --theme-card-bg: var(--light-bg);
    --theme-hover: rgba(0, 0, 0, 0.05);
}

/* 2. Theme Toggle Component
   ========================================================================== */
.theme-toggle-wrapper {
    width: 48px;  /* Reduced from 96px */
    height: 48px;  /* Match other control items */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
}

.switch {
    position: relative;
    width: 44px;  /* Reduced width */
    height: 24px;  /* Reduced height */
    margin: 0;
}

.switch input { 
    display: none; 
}

.slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 24px;
    cursor: pointer;
    transition: 0.3s;
    border: 2px solid rgba(0, 0, 0, 0.1);
}

.slider:before {
    content: "";
    position: absolute;
    height: 18px;  /* Reduced knob size */
    width: 18px;  /* Reduced knob size */
    left: 3px;    /* Adjusted position */
    bottom: 1px;  /* Adjusted position */
    background-color: #ffffff;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.switch .fa-sun,
.switch .fa-moon {
    position: absolute;
    z-index: 1;
    top: 50%;
    transform: translateY(-50%);
    color: #ffffff;
    font-size: 12px;  /* Reduced icon size */
}

.switch .fa-moon { 
    left: 6px; 
}

.switch .fa-sun { 
    right: 6px;
}

input:checked + .slider:before {
    transform: translateX(20px);  /* Adjusted translation distance */
}

/* Hover effect */
.theme-toggle-wrapper:hover .slider {
    border-color: rgba(255, 255, 255, 0.3);
    background-color: rgba(0, 0, 0, 0.5);
}

/* 3. Dark Theme
   ========================================================================== */
body.dark-theme {
    --theme-bg: var(--dark-bg);
    --theme-text: var(--dark-text);
    --theme-border: var(--dark-border);
    --theme-input-bg: var(--dark-input-bg);
    --theme-card-bg: var(--dark-card-bg);
    --theme-hover: rgba(255, 255, 255, 0.05);
}

/* Dark theme slider adjustments */
body.dark-theme .slider {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-theme .slider:before {
    background-color: #ffffff;
}

body.dark-theme .theme-toggle-wrapper:hover .slider {
    border-color: rgba(255, 255, 255, 0.4);
    background-color: rgba(255, 255, 255, 0.3);
}

/* 4. Dark Theme Component Overrides
   ========================================================================== */

/* Date Controls Dark Theme */
body.dark-theme .date-preset {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
    color: var(--dark-text);
}

body.dark-theme .date-preset:hover {
    background-color: var(--dark-card-bg);
}

body.dark-theme .date-preset.active {
    background: var(--primary-color);
    color: var(--primary-text) !important; /* Force white text in both themes */
    border-color: var(--primary-color);
}

/* Input Elements Dark Theme */
body.dark-theme input::placeholder,
body.dark-theme select::placeholder,
body.dark-theme .form-control::placeholder {
    color: #999999;
}

/* Dropdown Dark Theme */
body.dark-theme .dropdown-menu {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

body.dark-theme .dropdown-item {
    color: var(--dark-text);
}

body.dark-theme .dropdown-item:hover {
    background-color: var(--dark-card-bg);
    color: var(--dark-text);
}

body.dark-theme .dropdown-item.active {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--primary-text);
}

body.dark-theme .dropdown-item:hover,
body.dark-theme .dropdown-item:focus,
body.dark-theme .dropdown-item.active:hover {
    background-color: rgba(255, 255, 255, 0.3);
    color: var(--primary-text);
}

/* Navigation Dark Theme */
body.dark-theme .nav-link:hover {
    background-color: var(--dark-card-bg);
    color: var(--dark-text);
}

/* Filter Controls Dark Theme */
body.dark-theme .filter-select {
    background-color: var(--dark-bg);
    color: var(--dark-text);
    border-color: var(--dark-border);
}

/* Export Button Dark Theme */
body.dark-theme .export-button {
    background-color: var(--dark-bg);
    color: var(--dark-text);
    border-color: var(--dark-border);
}

body.dark-theme .export-button:hover {
    background-color: var(--dark-card-bg);
}

/* 5. Dark Theme Text and Color Overrides
   ========================================================================== */

/* Update dropdown styles for dark theme */
body.dark-theme .dropdown-menu {
    background-color: var(--dark-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--dark-text);
}

body.dark-theme .dropdown-item {
    color: var(--dark-text);
}

body.dark-theme .dropdown-item:hover,
body.dark-theme .dropdown-item:focus {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--dark-text);
}

body.dark-theme .dropdown-item.active,
body.dark-theme .dropdown-item:active {
    background-color: var(--primary-color);
    color: var(--primary-text);
}

/* Update navbar styles for dark theme */
body.dark-theme .top-navbar {
    background-color: var(--primary-color) !important;
    color: var(--primary-text);
    border-bottom: none;
}

body.dark-theme .top-navbar .container-fluid {
    background: transparent;  /* Remove background color in dark mode */
}

/* Update light mode text colors for navbar */
.nav-controls .control-item .btn-link,
.nav-controls .control-item .nav-link {
    color: var(--primary-color);
}

.nav-controls .control-item i {
    color: var(--primary-color);
}

/* Dark theme text color overrides for all controls */
body.dark-theme .nav-controls .control-item .btn-link,
body.dark-theme .nav-controls .control-item .nav-link,
body.dark-theme .nav-controls .control-item i,
body.dark-theme .selector-container .dropdown-toggle,
body.dark-theme .selector-container .dropdown-toggle i,
body.dark-theme .selector-container .dropdown-toggle span {
    color: var(--primary-text) !important;
}

/* 6. Theme-Specific Content Adjustments
   ========================================================================== */

/* Dark theme content area adjustments */
body.dark-theme .content-area {
    background-color: var(--dark-bg);
}

body.dark-theme .card {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

body.dark-theme .card-header,
body.dark-theme .card-body,
body.dark-theme .card-footer {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

/* Dark theme form elements */
body.dark-theme .form-control {
    background-color: var(--dark-input-bg);
    border-color: var(--dark-border);
    color: var(--dark-text);
}

body.dark-theme .form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(var(--primary-color), 0.25);
}

body.dark-theme .form-label {
    color: var(--dark-text);
}

/* Dark theme table adjustments */
body.dark-theme .table {
    color: var(--dark-text);
}

body.dark-theme .table th,
body.dark-theme .table td {
    border-color: var(--dark-border);
}

body.dark-theme .table thead th {
    background-color: var(--dark-card-bg);
    color: var(--dark-text);
}

body.dark-theme .table tbody tr:hover {
    background-color: var(--dark-card-bg);
}

/* 7. Theme Transition Effects
   ========================================================================== */
body {
    transition: background-color 0.3s ease, color 0.3s ease;
}

.card,
.form-control,
.dropdown-menu,
.modal-content,
.table {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* Theme transition class for smooth switching */
.theme-transition {
    transition: all 0.3s ease;
}

.theme-transition * {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* 8. Theme-Specific Utility Classes
   ========================================================================== */

/* Light theme utilities */
.light-theme-only {
    display: block;
}

body.dark-theme .light-theme-only {
    display: none !important;
}

/* Dark theme utilities */
.dark-theme-only {
    display: none;
}

body.dark-theme .dark-theme-only {
    display: block !important;
}

/* Theme-aware text colors */
.theme-text {
    color: var(--theme-text);
}

.theme-bg {
    background-color: var(--theme-bg);
}

.theme-border {
    border-color: var(--theme-border);
}

/* 9. Print Theme Overrides
   ========================================================================== */
@media print {
    body.dark-theme {
        background-color: white !important;
        color: black !important;
    }
    
    body.dark-theme * {
        background-color: transparent !important;
        color: black !important;
        border-color: #ccc !important;
    }
    
    body.dark-theme .card,
    body.dark-theme .modal-content,
    body.dark-theme .dropdown-menu {
        background-color: white !important;
        border-color: #ccc !important;
    }
}
