/* =========================================
   1. GLOBAL LAYOUT (THE MOBILE FIX)
   ========================================= */
html, body {
    height: 100dvh; /* Dynamic Viewport Height (handles mobile URL bars) */
    height: 100vh;  /* Fallback */
    margin: 0; 
    padding: 0;
    
    /* CRITICAL FOR MOBILE: Lock the body scroll */
    overflow: hidden; 
    
    /* Turn body into a column: Navbar on top, Content below */
    display: flex;
    flex-direction: column;
}

/* Ensure the Bootstrap Navbar doesn't shrink or scroll away */
nav {
    flex-shrink: 0;
    z-index: 1030;
}

/* The Main Container (Sidebar + Content) takes all remaining space */
body > .container-fluid {
    flex: 1;            /* Grow to fill space below Navbar */
    height: 100%;       /* Ensure it fills the flex parent */
    overflow: hidden;   /* Container itself shouldn't scroll */
    position: relative;
}

/* Ensure the inner flex wrapper fills the container */
body > .container-fluid > .d-flex {
    height: 100%;
}


/* =========================================
   2. Sidebar Container
   ========================================= */
.sidebar {
    width: 250px; /* Increased slightly for readability */
    height: 100%; /* Fill the flex container, not screen height */
    padding: 15px;
    
    /* Visuals */
    /* border-top-right-radius: 8px; */
    /* border-bottom-right-radius: 8px; */
    
    /* Logic */
    transition: width 0.3s ease, justify-content 0.3s ease, padding 0.3s ease, overflow 0.3s ease;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom); /* iPhone Home Bar padding */
    
    /* Allow sidebar to scroll internally if menu is long */
    overflow-y: auto; 
    overflow-x: hidden;
    flex-shrink: 0; /* Prevent sidebar from getting squashed */
    justify-content: center;
}

/* Collapsed State Override */
.sidebar.collapsed {
    width: 60px !important;
    padding-left: 5px !important;
    padding-right: 5px !important;
    overflow: visible !important;
    justify-content: flex-start;
}

.sidebar-inner-content {
    width: 250px;
    min-width: 250px; /* Prevent shrinking */
}

/* =========================================
   3. Logo & Text Styling
   ========================================= */
.sidebar-logo {
    width: 150px;
    height: auto;
    margin-bottom: 10px;
    transition: width 0.4s, height 0.3s;
}

.sidebar.collapsed .sidebar-logo {
    width: 40px;
    object-fit: contain;
    transition: width 0.2s, height 0.2s;
}

.sidebar-title,
.sidebar-text {
    opacity: 1;
    visibility: visible;
    white-space: nowrap;
    width: auto;
    transition: 
        opacity 0.4s ease-in 0.2s,
        max-height 0.4s ease-in,
        margin 0.4s ease-in;
}

.sidebar .sidebar-title {
    /* Set the "open" margins here */
    margin-top: 10px; 
    margin-bottom: 15px;
    
    /* Prepare for animation */
    max-height: 50px; /* Arbitrary number larger than the text height */
    overflow: hidden;
}

.sidebar.collapsed .sidebar-title {
    /* Shrink margins to 0 */
    margin-top: 0;
    margin-bottom: 0;
    
    /* Shrink the element itself so it takes 0 space */
    max-height: 0;
    opacity: 0;
    
    /* Optional: Ensure padding is gone too if you have any */
    padding: 0;
    transition: 
        opacity 0s,
        max-height 0s,
        margin 0s; 
}

.sidebar.collapsed .sidebar-text {
    opacity: 0;
    width: 0;
    margin-left: 0 !important;
    margin-top: 0 !important;
    visibility: hidden;
    overflow: hidden;
}

/* =========================================
   4. Navigation Links
   ========================================= */
.sidebar .nav-link {
    transition: background-color 0.2s, border-left 0.2s;
}

.sidebar .nav-link:hover {
    background-color: transparent;
    border-left: 2px solid #fbff07;
}

.sidebar .nav-link.active {
    background-color: transparent;
    border-left: 4px solid #ffc107;
    font-weight: bold;
}

/* =========================================
   5. Dropdowns & Toggles
   ========================================= */
.sidebar #sidebarToggle {
    width: 100%;
} 

/* .sidebar.collapsed #sidebarToggle {
    margin-left: auto;
} */

.sidebar.collapsed .dropdown-menu {
    position: absolute;
    left: 100%;
    bottom: 0;
    top: auto;
    margin-left: 10px;
}

.sidebar.collapsed .dropdown-toggle {
    justify-content: center;
    /* padding-left: 0 !important; */
    padding-right: 0 !important;
}

.sidebar.collapsed .dropdown-toggle::after {
    display: none;
}

.sidebar-icon {
    width: 50px;
    height: 50px;
    transition: width 0.3s ease, height 0.3s ease;
}
.sidebar.collapsed .sidebar-icon {
    width: 30px;
    height: 30px;

}

/* =========================================
   6. MAIN CONTENT (The Grid Logic)
   ========================================= */
#mainContent {
    /* Flex Logic: Fill remaining width/height */
    flex-grow: 1;
    height: 100%;
    
    /* Grid Logic: For Page Swapping */
    display: grid; 
    grid-template-areas: "stack"; 
    
    position: relative;
    overflow: hidden; /* The container doesn't scroll, the children do */
}

/* The Swappable Panes */
#currentContent,
#futureContent {
    grid-area: stack; 
    
    /* Scroll Logic: The panes scroll independently */
    width: 100%;
    height: 100%;
    overflow-y: auto; 
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    
    /* Animation */
    transition: opacity 0.5s ease-in-out;
    opacity: 1;
    visibility: visible;
    background-color: var(--bs-body-bg, #ffffff); 
    z-index: 10;
    padding-bottom: 80px; /* Extra padding at bottom so content isn't cut off */
}

#timesheet-detail-table {
    transition: max-height 0.5s ease, opacity 0.5s ease;
}

#timesheet-detail-table.hidden {
    max-height: 0 !important;
}

#timeentry-editor {
    transition: max-height 0.5s ease, opacity 0.5s ease;
}

#timeentry-editor.hidden {
    max-height: 0 !important;
}

/* The Hidden State for Swapping */
.hidden {
    opacity: 0 !important;
    visibility: hidden;
    pointer-events: none;
    z-index: 0;
}

/* =========================================
   7. UI Components (Cards, Alerts, etc.)
   ========================================= */
.quick-link-box {
    background-color: var(--bs-secondary-dark);
    transition: background-color 0.3s, transform 0.3s;
    cursor: pointer;
}
.quick-link-box:hover {
    background-color: var(--bs-secondary);
    transform: translateY(-5px);
}

.policy-item {
    transition: background-color 0.3s, transform 0.3s;
    cursor: pointer;
}

.policy-item .card-header {
    background-color: var(--bs-primary-bg-subtle) !important;
    /* color: var(--bs-info-text-emphasis) !important; */
    transition: background-color 0.3s;
}

.policy-item:hover {
    background-color: var(--bs-primary) !important;
    transform: translateY(-5px);
}

.disabled {
    pointer-events: none;
    opacity: 0.6;
}

/* Global Alert / Toast Notification */
#globalAlert {
    position: fixed;
    top: 20px; /* Might need adjustment if Navbar is tall */
    right: 20px;
    z-index: 1100;
    
    width: auto;
    min-width: 250px;
    max-width: 90vw; /* Mobile Friendly */
    
    @media (min-width: 576px) {
        max-width: 400px;
    }
    
    display: flex;
    align-items: flex-start;
    gap: 15px;
    
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#globalAlert.alert-dismissed {
    opacity: 0;
    transform: translateX(120%);
    pointer-events: none;
}

#globalAlert span {
    flex: 1;
    overflow-wrap: break-word;
}

#globalAlert .btn-close {
    flex-shrink: 0;
}

/* =========================================
   8. Dark Mode for Grid.js Tables
   ========================================= */

/* =========================================
   1. SHARED STYLES (Layout & Sizing) 
   ========================================= */
.gridjs-sort {
    width: 30px; 
    height: 30px;
    background-size: 20px;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.7;
    margin-left: 5px;
}
.gridjs-sort svg { display: none !important; }

/* =========================================
   2. LIGHT MODE (Default - Black Arrows) 
   ========================================= */
[data-bs-theme="light"] .gridjs-sort-neutral { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 15l5 5 5-5'/%3E%3Cpath d='M7 9l5-5 5 5'/%3E%3C/svg%3E") !important; }
[data-bs-theme="light"] .gridjs-sort-asc     { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5'/%3E%3Cpath d='M5 12l7-7 7 7'/%3E%3C/svg%3E") !important; }
[data-bs-theme="light"] .gridjs-sort-desc    { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14'/%3E%3Cpath d='M19 12l-7 7-7-7'/%3E%3C/svg%3E") !important; }

/* =========================================
   3. DARK MODE (Targeted via Attribute) 
   ========================================= */
[data-bs-theme="dark"] .gridjs-head,
[data-bs-theme="dark"] .gridjs-footer {
    background-color: var(--bs-body-bg) !important;
    border: none !important;
}

[data-bs-theme="dark"] .gridjs-th {
    background-color: var(--bs-primary-bg-subtle) !important;
    color: var(--bs-info-text-emphasis) !important;
    border-color: var(--bs-border-color) !important;
}

[data-bs-theme="dark"] .gridjs-footer {
    background-color: var(--bs-primary-bg-subtle) !important;
    border-top: 1px solid var(--bs-border-color) !important;
}

[data-bs-theme="dark"] .gridjs-td {
    background-color: var(--bs-dark) !important;
    color: var(--bs-light) !important;
    border-color: var(--bs-border-color) !important;
}

/* Hover Effect */
[data-bs-theme="dark"] .gridjs-tr:hover .gridjs-td {
    cursor: default;
    background-color: #1f2937 !important;
    color: var(--bs-info-text-emphasis) !important;
}

/* Zebra Striping */
[data-bs-theme="dark"] .gridjs-container.zebra .gridjs-tr:nth-child(even) .gridjs-td {
    background-color: rgba(0, 0, 0, 0.773) !important;
}



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

/* Pagination Buttons */
[data-bs-theme="dark"] .gridjs-pagination button {
    background-color: var(--bs-dark) !important;
    color: var(--bs-light) !important;
    border: 1px solid var(--bs-border-color) !important;
}
[data-bs-theme="dark"] .gridjs-pagination button:hover {
    background-color: var(--bs-primary) !important;
    color: white !important;
}

/* Search Input */
[data-bs-theme="dark"] .gridjs-search input {
    background-color: var(--bs-body-bg) !important;
    color: var(--bs-light) !important;
    border: 1px solid var(--bs-border-color) !important;
}

/* Dark Mode Sort Icons (White) */
[data-bs-theme="dark"] .gridjs-sort-neutral { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 15l5 5 5-5'/%3E%3Cpath d='M7 9l5-5 5 5'/%3E%3C/svg%3E") !important; }
[data-bs-theme="dark"] .gridjs-sort-asc     { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5'/%3E%3Cpath d='M5 12l7-7 7 7'/%3E%3C/svg%3E") !important; }
[data-bs-theme="dark"] .gridjs-sort-desc    { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14'/%3E%3Cpath d='M19 12l-7 7-7-7'/%3E%3C/svg%3E") !important; }

.badge-subtle-warning { background-color: rgba(235, 245, 38, 0.427); color: #7c5d03 !important; border: 1px solid rgba(255, 193, 7, 0.3); }
[data-bs-theme="dark"] .badge-subtle-warning { background-color: rgba(255, 193, 7, 0.2); color: #ffc107 !important; border: 1px solid rgba(255, 193, 7, 0.3); }
.badge-subtle-success { background-color: rgba(25, 135, 84, 0.2); color: #198754 !important; border: 1px solid rgba(30, 159, 99, 0.498); }
[data-bs-theme="dark"] .badge-subtle-success { background-color: rgba(17, 95, 59, 0.2); color: #1ea466 !important; border: 1px solid rgba(25, 135, 84, 0.498); }
.badge-subtle-danger  { background-color: rgba(220, 53, 69, 0.2); color: #dc3545 !important; border: 1px solid rgba(220, 53, 69, 0.3); }
[data-bs-theme="dark"] .badge-subtle-danger  { background-color: rgba(220, 53, 69, 0.2); color: #ff6b6b !important; border: 1px solid rgba(220, 53, 69, 0.3); }
.badge-subtle-info    { background-color: rgba(13, 110, 253, 0.2); color: #0d6efd !important; border: 1px solid rgba(13, 110, 253, 0.3); }
[data-bs-theme="dark"] .badge-subtle-info    { background-color: rgba(13, 110, 253, 0.2); color: #66b0ff !important; border: 1px solid rgba(13, 110, 253, 0.3); }
.badge-subtle-medium  { background-color: rgba(48, 97, 244, 0.2); color: #ffc107 !important; border: 1px solid rgba(255, 193, 7, 0.3); }
.badge-subtle-critical { background-color: rgba(88, 1, 125, 0.2); color: #dc3545 !important; border: 1px solid rgba(223, 13, 34, 0.784); }

.active-message-row.gridjs-td {
    background-color: rgba(31, 17, 89, 0.838) !important;
    color: var(--bs-light) !important;
}

/* =========================================
   Spinner Styles
   ========================================= */

.vital-loader-overlay {
    /* Absolute Positioning */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    /* Centering logic */
    display: flex;
    justify-content: center;
    align-items: center;
    
    /* Visuals */
    background-color: rgba(33, 37, 41, 0.85); /* Dark semi-transparent background */
    backdrop-filter: blur(2px); /* Optional: Blurs the content behind it */
    z-index: 10000; /* Sit on top of form inputs/tables */
    border-radius: inherit; /* Inherit rounded corners from parent */
}

/* Container for the monitor */
.vital-loader-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 200px; /* Adjust based on where you place it */
    background-color: #1a1a1a; /* Dark Monitor Background */
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    border: 1px solid #333;
}

/* Optional: The Monitor Grid Background */
.vital-grid-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(0, 255, 0, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 255, 0, 0.1) 1px, transparent 1px);
    background-size: 20px 20px;
    z-index: 0;
}

/* The EKG Line */
.ekg-svg {
    width: 200px; /* Size of the heartbeat */
    height: auto;
    z-index: 1;
    filter: drop-shadow(0 0 4px rgba(57, 255, 20, 0.8)); /* Glow effect */
}

.ekg-path {
    fill: none;
    stroke: #39ff14; /* Neon Green */
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    /* The Magic: Create a dash that is the length of the line, followed by a huge gap */
    stroke-dasharray: 450; 
    stroke-dashoffset: 450; /* Start hidden */
    animation: heartbeat 2s linear infinite;
}

/* The Animation Loop */
@keyframes heartbeat {
    0% {
        stroke-dashoffset: 450; /* Line is hidden to the left */
    }
    40% {
        stroke-dashoffset: 0; /* Line is fully drawn */
    }
    100% {
        stroke-dashoffset: -450; /* Line disappears to the right (gap) */
    }
}

.btn-loading {
    /* HIDE the original button background/border so our pseudo-elements show up */
    background-color: transparent !important;
    border-color: transparent !important;
    color: rgba(255, 255, 255, 0.8) !important; /* Dim text */
    
    /* CRITICAL: This clips the spinning square to your border-radius */
    overflow: hidden !important; 
    position: relative;
    z-index: 1; /* Establishes a stacking context */
    pointer-events: none;
    transition: none; /* Stop transition interference */
}

/* 2. The Spinner (The Rotating Gradient) */
/* This is a giant square spinning BEHIND the button content */
.btn-loading::before {
    content: '';
    position: absolute;
    z-index: -2;
    
    /* Make it huge (200%) so we never see the edges of the square */
    width: 300%;
    height: 300%;
    top: -50%;
    left: -50%;
    
    /* The Gradient: Transparent -> Color -> Transparent */
    background: conic-gradient(
        transparent, 
        #00ff88, 
        transparent 30%
    );
    
    animation: spin-border 1.5s linear infinite;
}

/* 3. The Mask (The Inner Background) */
/* This sits on top of the spinner but behind the text */
.btn-loading::after {
    content: '';
    position: absolute;
    z-index: -1;
    
    /* This defines the border thickness (3px) */
    inset: 3px; 
    
    /* !!! CHANGE THIS TO MATCH YOUR BUTTON'S NORMAL COLOR !!! */
    background-color: #1f2937; 
    
    /* Matches the parent button's rounded corners */
    border-radius: inherit; 
}

@keyframes spin-border {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.stat-card.active {
    background-color: var(--bs-primary) !important;
}
.stat-card.active .stat-label {
    color: var(--bs-light) !important;
}
.stat-card.active .stat-icon {
    color: var(--bs-light) !important;
}

.avatar {
    font-size: 1.6rem !important;
}

.protocol-link {
    transition: background-color 0.3s, transform 0.3s;
    cursor: pointer;
    /* font-size: 0.9rem; */
}

#company_logo {
    max-width: 300px !important;
    margin: 0 auto;
    /* Or use: border-radius: 12px; for rounded corners */
}

.shiftcommand-icon {
    max-height: 40px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    transition: all 0.2s;
}

.btn-icon:hover {
    background-color: rgba(var(--bs-secondary-rgb), 0.2) !important;
    color: var(--bs-primary) !important;
}


@media (max-height: 796px) and (orientation: portrait) {
    .protocols-ui {
        max-height: 90dvh !important;
    }
}

@media (max-width: 576px) {
    #protocols-header {
        font-size: 1.1rem !important;
    }
    .page-text {
        font-size: 0.8rem !important;
        padding-right: 10px;
    }
}

@media (max-width: 576px) {
    [mobile-truncate="true"] {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .page-title {
        font-size: 1rem !important;
    }
}

@media (max-height: 796px) and (orientation: portrait) {
    #protocolsList {
        max-height: 150px !important;
    }
}

.ring-bell {
    animation: ring 1s ease-in-out infinite;
}

@keyframes ring {
    0% { transform: rotate(0deg); }
    15% { transform: rotate(15deg); }
    30% { transform: rotate(-10deg); }
    45% { transform: rotate(15deg); }
    60% { transform: rotate(-10deg); }
    75% { transform: rotate(15deg); }
    90% { transform: rotate(-10deg); }
    100% { transform: rotate(0deg); }
}
