/*
================================================
General Styles & Theme Variables
================================================
*/
:root {
    /* Core Color Palette */
    --c-primary: #3f8efc;
    --c-primary-rgb: 63, 142, 252;
    --c-primary-dark: #2667ff;
    --c-primary-deep: #3b28cc;
    --c-secondary: #87bfff;
    --c-accent: #add7f6;

    /* Light Theme */
    --bg-light: #f4f7fc;
    --content-bg-light: #ffffff;
    --sidebar-bg-light-start: #3b28cc;
    --sidebar-bg-light-end: #3f8efc;
    --text-primary-light: #212529;
    --text-secondary-light: #6c757d;
    --border-light: #dee2e6;
    --sidebar-text-light: #ffffff;
    --sidebar-hover-bg-light: rgba(255, 255, 255, 0.15);
    --sidebar-active-bg-light: #2667ff; /* var(--c-primary-dark) */

    /* Dark Theme */
    --bg-dark: #1a1d21;
    --content-bg-dark: #212529;
    --sidebar-bg-dark-start: #1c1f23;
    --sidebar-bg-dark-end: #2a2e34;
    --text-primary-dark: #e9ecef;
    --text-secondary-dark: #adb5bd;
    --border-dark: #343a40;
    --sidebar-text-dark: #e9ecef;
    --sidebar-hover-bg-dark: rgba(255, 255, 255, 0.05);
    --sidebar-active-bg-dark: #3f8efc; /* var(--c-primary) */
}

[data-theme="light"] {
    --bg-main: var(--bg-light);
    --bg-content: var(--content-bg-light);
    --sidebar-bg-start: var(--sidebar-bg-light-start);
    --sidebar-bg-end: var(--sidebar-bg-light-end);
    --text-primary: var(--text-primary-light);
    --text-secondary: var(--text-secondary-light);
    --border-color: var(--border-light);
    --sidebar-text: var(--sidebar-text-light);
    --sidebar-hover-bg: var(--sidebar-hover-bg-light);
    --sidebar-active-bg: var(--sidebar-active-bg-light);
}

[data-theme="dark"] {
    --bg-main: var(--bg-dark);
    --bg-content: var(--content-bg-dark);
    --sidebar-bg-start: var(--sidebar-bg-dark-start);
    --sidebar-bg-end: var(--sidebar-bg-dark-end);
    --text-primary: var(--text-primary-dark);
    --text-secondary: var(--text-secondary-dark);
    --border-color: var(--border-dark);
    --sidebar-text: var(--sidebar-text-dark);
    --sidebar-hover-bg: var(--sidebar-hover-bg-dark);
    --sidebar-active-bg: var(--sidebar-active-bg-dark);
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    transition: background-color 0.2s linear, color 0.2s linear;
}

/*
================================================
Sidebar Styles
================================================
*/
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 260px;
    background: linear-gradient(180deg, var(--sidebar-bg-start), var(--sidebar-bg-end));
    color: var(--sidebar-text);
    display: flex; /* <-- Use flexbox to manage layout */
    flex-direction: column; /* <-- Stack body and footer vertically */
    transition: all 0.3s ease;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}

.sidebar-body {
    flex-grow: 1; /* Allows this element to fill available space */
    overflow-y: auto; /* Adds a scrollbar only when needed */
    padding: 1.25rem; /* Use the original sidebar padding */
}

.sidebar-brand {
    display: flex;
    align-items: center;
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--sidebar-text);
    text-decoration: none;
    margin-bottom: 2.5rem;
    padding: 0.5rem 0;
}

.sidebar-brand i {
    font-size: 2.2rem;
    margin-right: 0.75rem;
    color: var(--c-accent);
    transition: transform 0.3s ease;
}

.sidebar-brand:hover i {
    transform: rotate(15deg);
}

.sidebar-nav {
    list-style: none;
    padding-left: 0;
    flex-grow: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    font-size: 1rem;
    font-weight: 500;
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 0.85rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 0.5rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-link:hover {
    background-color: var(--sidebar-hover-bg);
    color: var(--sidebar-text);
}

.sidebar-item.active > .sidebar-link {
    background-color: var(--sidebar-active-bg);
    color: #ffffff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.sidebar-link i {
    margin-right: 1rem;
    font-size: 1.25rem;
    width: 20px;
    text-align: center;
}

.sidebar-section-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--sidebar-text);
    opacity: 0.6;
    padding: 1rem 1rem 0.5rem;
    margin-top: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-submenu {
    list-style: none;
    padding-left: 1.5rem;
}

.sidebar-submenu .sidebar-link {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    font-size: 0.9rem;
}

.sidebar-link .bi-chevron-down {
    transition: transform 0.3s ease;
    font-size: 0.8rem;
}

.sidebar-link:not(.collapsed) .bi-chevron-down {
    transform: rotate(180deg);
}

.sidebar-submenu-item.active > .sidebar-link {
    color: #ffffff;
    font-weight: 600;
}

.sidebar-submenu-item:not(.active) > .sidebar-link:hover {
    background-color: var(--sidebar-hover-bg);
}

/* --- Fixed Footer Styling --- */
.sidebar-footer {
    flex-shrink: 0; /* Prevents the footer from shrinking */
    padding: 0.75rem 1.25rem; /* Match sidebar padding */
    position: relative;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-footer::before {
    content: '';
    position: absolute;
    top: -21px;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.15), transparent);
    pointer-events: none;
}

.sidebar-footer .sidebar-link {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
}

[data-theme="dark"] .sidebar-footer::before {
    background: linear-gradient(to top, rgba(0, 0, 0, 0.5), transparent);
}

/*
================================================
Main Content & Layout
================================================
*/
.main-content {
    margin-left: 260px;
    padding: 2rem;
    transition: margin-left 0.3s ease;
}

.main-content h1 {
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.main-content p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* When sidebar is hidden, remove the margin */
body.no-sidebar .main-content {
    margin-left: 0;
}

/* When sidebar is hidden, login container should take full height */
body.no-sidebar .login-container {
    min-height: 100vh;
}

/*
================================================
Theme Toggle Styles (Global) - Custom Switch
================================================
*/
.theme-toggle-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1050;
}

.theme-switch {
    display: inline-block;
    cursor: pointer;
}

/* Hide the actual checkbox */
.theme-switch input[type="checkbox"] {
    display: none;
}

/* The track (the background of the switch) */
.switch-track {
    position: relative;
    width: 60px;   /* Smaller width */
    height: 32px;  /* Smaller height */
    background-color: var(--c-primary-deep);
    border-radius: 16px; /* Adjusted for new height */
    transition: background-color 0.3s ease-in-out;
}

/* The thumb (the sliding circle) */
.switch-thumb {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    background-color: #fff;
    border-radius: 50%;
    transition: transform 0.3s ease-in-out;
    /* We no longer use flexbox for centering here */
}

/* Styling for the icons */
.switch-thumb i {
    /* This is the new, robust centering technique */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    font-size: 14px;
    color: var(--c-primary-deep);
    transition: color 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

.switch-thumb .bi-sun-fill {
    opacity: 0; /* Sun is hidden by default */
}

/* --- The Magic: Styles for the "checked" state (Dark Mode) --- */

/* When checkbox is checked, move the thumb */
.theme-switch input:checked + .switch-track .switch-thumb {
    transform: translateX(28px); /* Adjusted travel distance */
}

/* When checked, change the track's background color */
.theme-switch input:checked + .switch-track {
    background-color: var(--c-primary);
}

/* When checked, change the icon color */
.theme-switch input:checked + .switch-track .switch-thumb i {
    color: var(--c-primary);
}

/* When checked, hide the moon icon */
.theme-switch input:checked + .switch-track .switch-thumb .bi-moon-stars-fill {
    opacity: 0;
}

/* When checked, show the sun icon */
.theme-switch input:checked + .switch-track .switch-thumb .bi-sun-fill {
    opacity: 1;
}

/*
================================================
Login Page Styles
================================================
*/
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background-color: var(--bg-content);
    border-radius: 0.75rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

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

.login-header i {
    font-size: 3rem;
    color: var(--c-primary);
}

.login-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
    margin-bottom: 0.25rem;
}

.login-header p {
    color: var(--text-secondary);
}

.login-card .btn-primary {
    background-color: var(--c-primary-dark);
    border-color: var(--c-primary-dark);
    padding: 0.75rem;
    font-weight: 500;
}

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

/*
================================================
Logout Link Styles
================================================
*/
.logout-section .sidebar-link {
    padding: 0.5rem 1rem;
    margin-top: 1rem;
    background-color: rgba(0,0,0,0.1);
}

.logout-section .sidebar-link:hover {
    background-color: rgba(0,0,0,0.2);
}

/*
================================================
Status Bar Styles (Work Order View)
================================================
*/
.status-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 0.5rem;
}

.status-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.5rem;
    border: 1px solid var(--border-color);
    background-color: transparent;
    color: var(--text-secondary);
    border-radius: 0.5rem; /* Rounded square */
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
}

.status-btn:hover {
    background-color: var(--bg-main);
    border-color: var(--c-secondary);
    color: var(--text-primary);
}

.status-btn i {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

/* --- Active State Colors --- */
.status-btn.active.status-primary {
    background-color: var(--c-primary);
    border-color: var(--c-primary);
    color: #fff;
}
.status-btn.active.status-warning {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #000;
}
.status-btn.active.status-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
    color: #fff;
}
.status-btn.active.status-success {
    background-color: #198754;
    border-color: #198754;
    color: #fff;
}

/*
================================================
Dashboard Styles
================================================
*/
.icon-circle {
display: inline-flex;
align-items: center;
justify-content: center;
width: 64px;
height: 64px;
border-radius: 50%;
}

.fc-event-urgent, .fc-event-critical {
background-color: #dc3545 !important;
border-color: #dc3545 !important;
}
.fc-event-high {
background-color: #ffc107 !important;
border-color: #ffc107 !important;
color: #000 !important;
}

/*
================================================
Print Styles
================================================
*/
@media print {

    /* Hide elements that should not be printed */
    .sidebar,
    .sidebar-footer,
    .theme-toggle-container,
    .btn, /* Hides all Bootstrap buttons */
    .breadcrumb,
    .d-print-none { /* A utility class you can add to anything else you want to hide */
        display: none !important;
    }

    /* Ensure the main content takes up the full page width */
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        background-color: transparent !important;
    }

    /* Also remove padding from the card-body to bring content closer together */
    .card-body {
        padding: 0 !important;
    }

    .qr-code-bg {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        background-color: transparent !important;
    }

    /* Ensure QR image itself is not inverted by dark mode filters */
    .qr-code-img {
        filter: none !important;
    }

    /* Optional: Ensure text is black for readability, overriding dark mode colors */
    body, h1, h2, h3, h4, h5, h6, p, div, li, td, th {
        color: #000 !important;
        background-color: #fff !important;
    }

    a {
        text-decoration: none !important;
        color: #000 !important;
    }
    .mb-print-2 {
        margin-bottom: 0.5rem !important;
    }
    .mb-print-3 {
        margin-bottom: 1rem !important;
    }
}

/*
================================================
Analytics Page Styles
================================================
*/
.table-header-sticky th {
    position: sticky;
    top: 0;
    /* Use the main background variable so it adapts to light/dark mode */
    background-color: var(--bg-main); 
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

/*
================================================
Dark Mode Component Overrides
================================================
*/
[data-theme="dark"] {
    /* --- Tables, Cards, and Headers --- */
    .table {
        --bs-table-color: var(--text-primary-dark);
        --bs-table-bg: var(--content-bg-dark);
        --bs-table-border-color: var(--border-dark);
        --bs-table-striped-color: var(--text-primary-dark);
        --bs-table-striped-bg: rgba(255, 255, 255, 0.05);
        --bs-table-active-color: var(--text-primary-dark);
        --bs-table-active-bg: rgba(255, 255, 255, 0.1);
        --bs-table-hover-color: var(--text-primary-dark);
        --bs-table-hover-bg: rgba(255, 255, 255, 0.075);
    }
    .card {
        background-color: var(--content-bg-dark);
        border-color: var(--border-dark);
        color: var(--text-primary-dark); /* <-- THIS IS THE FIX */
    }
    .card-header {
        border-bottom-color: var(--border-dark);
    }

    /* --- Form Controls & Search Boxes --- */
    .form-control, .form-select {
        background-color: var(--bg-dark);
        color: var(--text-primary-dark);
        border-color: var(--border-dark);
    }
    .form-control:focus, .form-select:focus {
        background-color: var(--bg-dark);
        color: var(--text-primary-dark);
        border-color: var(--c-primary);
        box-shadow: 0 0 0 0.2rem rgba(var(--c-primary-rgb), 0.25);
    }
    .form-control::placeholder {
        color: var(--text-secondary-dark);
    }
    .input-group-text {
        background-color: var(--content-bg-dark);
        color: var(--text-secondary-dark);
        border-color: var(--border-dark);
    }

    /* --- Buttons in Forms --- */
    .btn-outline-secondary {
        --bs-btn-color: #adb5bd;
        --bs-btn-border-color: #495057;
        --bs-btn-hover-bg: #495057;
        --bs-btn-hover-color: #fff;
    }
    .btn-outline-danger {
        --bs-btn-color: #dc3545;
        --bs-btn-border-color: #dc3545;
        --bs-btn-hover-bg: #dc3545;
        --bs-btn-hover-color: #fff;
    }
    
    /* --- Muted Text --- */
    .text-muted {
        color: var(--text-secondary-dark) !important;
    }

    /* --- Badges --- */
    .badge.bg-secondary {
        background-color: #495057 !important;
        color: #e9ecef !important;
    }

    /* --- Modals --- */
    .modal-content {
        background-color: var(--content-bg-dark);
        border-color: var(--border-dark);
        color: var(--text-primary-dark);
    }

    .modal-header {
        border-bottom-color: var(--border-dark);
    }

    .modal-footer {
        border-top-color: var(--border-dark);
    }

    /* --- Alerts / Flash Messages --- */
    .alert-success {
        --bs-alert-color: #a3cfbb;
        --bs-alert-bg: #19875426; /* Green with low opacity */
        --bs-alert-border-color: #19875480; /* Green with higher opacity */
    }
    .alert-info {
        --bs-alert-color: #9eeaf9;
        --bs-alert-bg: #0dcaf026;
        --bs-alert-border-color: #0dcaf080;
    }
    .alert-warning {
        --bs-alert-color: #ffc107;
        --bs-alert-bg: #ffc10726;
        --bs-alert-border-color: #ffc10780;
    }
    .alert-danger {
        --bs-alert-color: #f1aeb5;
        --bs-alert-bg: #dc354526;
        --bs-alert-border-color: #dc354580;
    }
    /* Special override for the 'password' flash message */
    .alert-info strong {
        color: #9eeaf9;
    }

    /* --- Nav Tabs (for Add User page) --- */
    .nav-tabs {
        --bs-nav-tabs-border-color: var(--border-dark);
    }
    .nav-tabs .nav-link {
        color: var(--text-secondary-dark);
        border-color: transparent; /* Make inactive tabs have no border */
    }
    .nav-tabs .nav-link:hover, .nav-tabs .nav-link:focus {
        border-color: var(--border-dark);
        isolation: isolate; /* Fixes a hover border issue */
    }
    .nav-tabs .nav-link.active {
        color: var(--text-primary-dark);
        background-color: var(--content-bg-dark);
        border-color: var(--border-dark) var(--border-dark) var(--content-bg-dark); /* Top, sides, bottom */
    }

    /* --- List Groups (for Quick Actions panel) --- */
    .list-group-item {
        background-color: var(--content-bg-dark);
        border-color: var(--border-dark);
        color: var(--text-primary-dark);
    }

    .list-group-item-action:hover, .list-group-item-action:focus {
        background-color: var(--bg-dark);
        color: var(--text-primary-dark);
    }
    
    /* --- Code Blocks (for Equipment ID) --- */
    code {
        color: #e83e8c; /* Bootstrap's default pinkish color for code */
        background-color: rgba(232, 62, 140, 0.1);
        border-radius: 0.2rem;
        padding: 0.2em 0.4em;
    }

    /* This makes the 'X' close button white */
    .btn-close {
        filter: invert(1) grayscale(100%) brightness(200%);
    }
    
    /* --- NEW RULES TO FIX BLACK TEXT --- */
    .form-label {
        color: var(--text-primary-dark);
    }
    
    h1, h2, h3, h4, h5, h6 {
        color: var(--text-primary-dark);
    }

    .status-btn:hover {
    background-color: var(--content-bg-dark);
    }

    .status-btn.active.status-warning {
    color: #000; /* Keep black text on yellow for contrast */
    }
    .qr-code-img {
        background-color: #fff !important; /* Keep the QR background white for scannability */
        filter: invert(0.9) hue-rotate(180deg);
    }
    .qr-code-bg {
        background-color: var(--content-bg-dark) !important; /* Use the dark card background color */
        border-color: var(--border-dark) !important;
    }
}

/* Animation for refresh icon */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.icon-spin {
    animation: spin 1s linear infinite;
}

.association-list {
    height: 200px;
    overflow-y: auto;
}

.association-list-table {
    height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
}
.association-list-table th {
    position: sticky; top: 0;
    background-color: var(--bg-main);
}
[data-theme="dark"] .form-check-input:checked {
    background-color: var(--c-primary-dark);
    border-color: var(--c-primary-dark);
}
.form-check-input[data-type="supplier"]:checked {
    background-color: #198754; /* Green */
    border-color: #198754;
}