/* Asana-Style Theme */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* UI scale: the screens were sized large; laptops and desktops show them at 75% (what the
   browser shows at 75% zoom), smaller laptops / tablets at 85%, phones unchanged.
   Anything sized with vh divides by --ui-zoom so it still fills the screen. */
:root { --ui-zoom: 1; }
@media (min-width: 769px) and (max-width: 1199.98px) { :root { --ui-zoom: 0.85; } }
@media (min-width: 1200px) { :root { --ui-zoom: 0.75; } }

html {
    zoom: var(--ui-zoom);
    overflow-x: hidden; /* CRITICAL: Prevent horizontal scroll on root element */
    width: 100%; /* Ensure html doesn't expand beyond viewport */
}

/* Full-screen layers sized in vw / vh by Bootstrap */
.modal-backdrop, .offcanvas-backdrop {
    width: calc(100vw / var(--ui-zoom));
    height: calc(100vh / var(--ui-zoom));
}
.min-vh-100 { min-height: calc(100vh / var(--ui-zoom)) !important; }
.vh-100 { height: calc(100vh / var(--ui-zoom)) !important; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #fafbfc;
    color: #2d3748;
    overflow-x: hidden; /* CRITICAL: Prevent horizontal scroll caused by sidebar flyouts extending beyond viewport */
    width: 100%; /* Ensure body doesn't expand beyond viewport */
    position: relative; /* ADDED: Create positioning context */
}

/* Navbar */
.navbar {
    background: white;
    border-bottom: 1px solid #e6ebf1;
    padding: 0 24px;
    height: 64px;
    box-shadow: none;
}

.navbar-brand {
    color: #2d3748;
    font-weight: 600;
    font-size: 1.25rem;
}

/* Sidebar */
.sidebar {
    background: white;
    bottom: 0; /* to the bottom of the screen (100vh would stop short when the UI is scaled) */
    width: 220px;
    padding: 16px 0;
    border-right: 1px solid #e6ebf1;
    position: fixed; /* fixed with its own vertical scroll */
    left: 0;
    top: 64px;
    overflow-y: auto; /* vertical scroll when menu is long */
    overflow-x: hidden; /* CHANGED: Hide horizontal overflow to prevent page scroll */
    transition: width 0.2s ease, transform 0.3s ease;
    z-index: 1050; /* Must be above main content (which has no z-index) */
    /* Smooth scrolling */
    scroll-behavior: smooth;
    /* Better scrollbar styling for webkit browsers */
    scrollbar-width: thin;
    scrollbar-color: #d1d9e6 transparent;
}

/* Custom scrollbar for webkit browsers (Chrome, Safari, Edge) */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #d1d9e6;
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #b8bfd1;
}

/* Remove z-index from sidebar when modal is open */
body.modal-open .sidebar,
body:has(.modal.show) .sidebar,
body:has(.modal-backdrop) .sidebar {
    z-index: auto !important;
}

.sidebar-item {
    display: flex;
    align-items: center;
    padding: 10px 24px;
    color: #4a5568;
    text-decoration: none;
    font-weight: 500;
    font-size: 15px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    position: relative;
}

.sidebar-item:hover {
    background: #f7fafc;
    border-left-color: #8b70d0;
    color: #8b70d0;
    text-decoration: none;
}

.sidebar-item.active {
    background: #f7fafc;
    border-left-color: #8b70d0;
    color: #8b70d0;
    font-weight: 600;
}

.sidebar-item i {
    width: 20px;
    margin-right: 12px;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar hr {
    margin: 8px 0;
    border-top: 1px solid #e6ebf1;
}

/* Sidebar Groups (Collapsible) */
.sidebar-group {
    margin-bottom: 4px;
    position: relative; /* IMPORTANT: Create positioning context for absolute flyout */
    z-index: auto; /* Allow children to control their own z-index */
}

.sidebar-group-header {
    display: flex;
    align-items: center;
    padding: 10px 24px;
    color: #2d3748;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    user-select: none;
    background: #e6ebf1;
}

.sidebar-group-header:hover {
    background: #d1d9e6;
    color: #8b70d0;
}

.sidebar-group-header i:first-child {
    width: 20px;
    margin-right: 12px;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-group-icon {
    margin-left: auto;
    font-size: 11px;
    transition: transform 0.2s;
}

.sidebar-group.expanded .sidebar-group-icon {
    transform: rotate(180deg);
}

.sidebar-group-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: white;
}

.sidebar-group.expanded .sidebar-group-items {
    max-height: 1000px;
}

/* Only style items that are direct children of sidebar-group-items */
.sidebar-group .sidebar-group-items > .sidebar-item {
    padding-left: 24px;
    padding-top: 7px;
    padding-bottom: 7px;
    font-size: 10px;
    font-weight: 500;
    color: #718096;
}

.sidebar-group .sidebar-group-items > .sidebar-item span {
    font-size: 10px;
}

.sidebar-group .sidebar-group-items > .sidebar-item i {
    width: 14px;
    margin-right: 8px;
    font-size: 12px;
    flex-shrink: 0;
}

.sidebar-group .sidebar-group-items > .sidebar-item:hover {
    background: #f7fafc;
    color: #8b70d0;
    border-left-color: #8b70d0;
}

/* Ensure standalone items (direct children of sidebar) maintain proper styling */
.sidebar > .sidebar-item {
    padding-left: 24px;
}


/* Main Content */
.main-content {
    margin-left: 220px;
    padding: 32px;
    background: #fafbfc;
    min-height: calc(100vh / var(--ui-zoom) - 64px);
    transition: margin-left 0.2s ease;
    /* REMOVED overflow-x: visible - this was causing the horizontal scroll! */
}

/* Collapsed sidebar - allow scrolling while keeping flyouts visible */
.sidebar.collapsed {
    width: 60px;
    overflow-y: hidden; /* FIXED: Remove scroll when collapsed - only scroll when open */
    overflow-x: hidden; /* CHANGED: Hide horizontal overflow to prevent page scroll */
}

.sidebar.collapsed .sidebar-item {
    justify-content: center;
    padding-left: 10px;
    padding-right: 10px;
}

.sidebar.collapsed .sidebar-item i {
    margin-right: 0;
}

.sidebar.collapsed .sidebar-item span {
    display: none;
}

/* Parent menu items (group headers) when sidebar collapsed - center icon, hide text and chevron */
.sidebar.collapsed .sidebar-group-header {
    padding: 10px;
    justify-content: center;
}

.sidebar.collapsed .sidebar-group-header span {
    display: none;
}

.sidebar.collapsed .sidebar-group-header i:first-child {
    margin-right: 0;
}

.sidebar.collapsed .sidebar-group-icon {
    display: none;
}

/* When collapsed: show child items in a flyout on hover over parent (both admin and user dashboard) */
.sidebar.collapsed .sidebar-group {
    position: static; /* CHANGED: Don't create positioning context - let flyout use fixed */
}

/* Flyout: fixed positioning to avoid creating horizontal scroll */
.sidebar.collapsed .sidebar-group-items {
    position: fixed; /* CHANGED: Fixed positioning prevents any scroll issues */
    left: 60px; /* Position from left edge of viewport (sidebar width when collapsed) */
    top: auto; /* Will be positioned via JavaScript or inherit from parent */
    margin-top: -38px; /* SHIFTED UP: Align with top of hovered menu header */
    min-width: 200px;
    max-width: 250px;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    background: white;
    box-shadow: 4px 4px 16px rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    padding: 8px 0;
    z-index: 9999 !important; /* FORCE: Must be above main content */
    visibility: hidden;
    opacity: 0;
    transition: visibility 0.15s, opacity 0.15s;
    border: 1px solid #e6ebf1;
    pointer-events: none; /* Don't capture mouse when hidden */
}

/* Re-enable pointer events when visible */
.sidebar.collapsed .sidebar-group-header:hover ~ .sidebar-group-items,
.sidebar.collapsed .sidebar-group-items:hover {
    visibility: visible;
    opacity: 1;
    pointer-events: auto; /* Enable clicking when visible */
}

/* Child items inside flyout: full style (icon + text), clickable */
.sidebar.collapsed .sidebar-group .sidebar-group-items > .sidebar-item {
    padding: 8px 16px;
    padding-left: 16px;
    justify-content: flex-start;
    min-height: 36px;
    white-space: nowrap; /* Show full text without wrapping */
    overflow: hidden; /* CHANGED: Clip if text is too long */
    text-overflow: ellipsis; /* ADDED: Show ... if text overflows */
}

.sidebar.collapsed .sidebar-group .sidebar-group-items > .sidebar-item span {
    display: inline;
}

.sidebar.collapsed .sidebar-group .sidebar-group-items > .sidebar-item i {
    margin-right: 8px;
    width: 18px;
    font-size: 14px;
}

.sidebar.collapsed + .main-content,
body.sidebar-collapsed .main-content {
    margin-left: 60px;
}

/* Dashboard Stats */
.stats-card {
    background: white;
    border-radius: 8px;
    padding: 24px;
    border: 1px solid #e6ebf1;
    transition: all 0.2s;
    height: 100%;
}

.stats-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-2px);
    border-color: #d1d9e6;
}

.stats-card .icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 16px;
    color: white;
}

.stats-card h3 {
    font-size: 2rem;
    font-weight: 700;
    margin: 8px 0;
    color: #2d3748;
}

.stats-card p {
    color: #718096;
    margin: 0;
    font-size: 14px;
}

/* Asana Color Scheme */
.bg-asana-purple { background: #8b70d0; }
.bg-asana-green { background: #1aac4c; }
.bg-asana-yellow { background: #ffaa00; }
.bg-asana-blue { background: #2563eb; }
.bg-asana-red { background: #ff4337; }

/* Tables */
.table-container {
    padding-bottom: 36px;
    background: white;
    border-radius: 8px;
    padding: 24px;
    border: 1px solid #e6ebf1;
}

/* Extra bottom padding for better spacing below tables */
.table-container {
    padding-bottom: 36px;
}

.table {
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
}

.table thead {
    background: #fafbfc;
}

.table thead th {
    border-bottom: 2px solid #e6ebf1;
    padding: 10px 8px;
    font-weight: 600;
    color: #4a5568;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fafbfc;
}

.table tbody td {
    padding: 12px 8px;
    vertical-align: middle;
    border-bottom: 1px solid #f0f0f0;
    font-size: 12px;
}

.table tbody tr:hover {
    background: #fafbfc;
}

/* Forms - Login Page Specific */
.auth-page {
    min-height: calc(100vh / var(--ui-zoom));
    background: #fafbfc;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    background: white;
    border-radius: 8px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid #e6ebf1;
}

.auth-card h2 {
    color: #2d3748;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 24px;
}

.auth-card .subtitle {
    color: #718096;
    font-size: 14px;
    margin-bottom: 32px;
}

.form-label {
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 8px;
    font-size: 14px;
}

.form-control {
    border: 1px solid #d1d9e6;
    border-radius: 6px;
    padding: 12px;
    transition: all 0.2s;
    font-size: 15px;
}

.form-control:focus {
    border-color: #8b70d0;
    box-shadow: 0 0 0 3px rgba(139, 112, 208, 0.1);
    outline: none;
}

.form-control::placeholder {
    color: #a0aec0;
}

/* Buttons */
.btn {
    border-radius: 6px;
    padding: 12px 24px;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background: #8b70d0;
    color: white;
}

.btn-primary:hover {
    background: #755db8;
    color: white;
}

.btn-success {
    background: #1aac4c;
    color: white;
}

.btn-warning {
    background: #ffaa00;
    color: white;
}

.btn-danger {
    background: #ff4337;
    color: white;
}

.btn-info {
    background: #2563eb;
    color: white;
}

.btn-outline-secondary {
    background: white;
    border: 1px solid #d1d9e6;
    color: #4a5568;
}

.btn-outline-secondary:hover {
    background: #fafbfc;
    color: #2d3748;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-lg {
    padding: 14px 24px;
    font-size: 15px;
}

/* Badges */
.badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bg-success { background: #1aac4c; color: white; }
.bg-warning { background: #ffaa00; color: white; }
.bg-danger { background: #ff4337; color: white; }
.bg-info { background: #2563eb; color: white; }
.bg-secondary { background: #718096; color: white; }

/* Homepage */
.hero-page {
    min-height: calc(100vh / var(--ui-zoom));
    background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.hero-card {
    background: white;
    border-radius: 12px;
    padding: 48px;
    max-width: 480px;
    width: 100%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.hero-card img {
    max-width: 100px;
    margin-bottom: 24px;
}

.hero-card h1 {
    color: #2d3748;
    font-weight: 700;
    margin-bottom: 12px;
    font-size: 32px;
}

.hero-card p {
    color: #718096;
    margin-bottom: 32px;
    font-size: 15px;
}

.hero-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Instructions */
.instruction-item {
    padding: 16px;
    margin-bottom: 12px;
    background: #fafbfc;
    border-left: 3px solid #8b70d0;
    border-radius: 6px;
}

.instruction-item strong {
    color: #2d3748;
    display: block;
    margin-bottom: 4px;
}

.instruction-item p {
    color: #718096;
    margin: 0;
    font-size: 14px;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    border: 1px solid #e6ebf1;
    overflow: hidden;
}

.card-body {
    padding: 24px;
}

.card-title {
    color: #2d3748;
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 16px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%) !important;
        width: 220px !important;
        box-shadow: 2px 0 8px rgba(0,0,0,0.1);
        transition: transform 0.3s ease !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .sidebar.show {
        transform: translateX(0) !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Remove collapsed state on mobile */
    .sidebar.collapsed {
        width: 220px !important;
    }
    
    .sidebar.collapsed .sidebar-item span {
        display: block !important;
    }
    
    .sidebar.collapsed .sidebar-item {
        justify-content: flex-start !important;
    }
    
    .sidebar.collapsed .sidebar-item i {
        margin-right: 12px !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 16px;
    }
    
    body.sidebar-collapsed .main-content {
        margin-left: 0 !important;
    }
    
    .auth-card {
        padding: 32px 24px;
    }
    
    /* Overlay when sidebar is open on mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 64px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
}

/* DataTables Custom Styling */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    margin: 0 8px 8px 0;
}

/* Left align the length control, right align the search bar */
.dataTables_wrapper .dataTables_length { float: left; }
.dataTables_wrapper .dataTables_filter { float: right; text-align: right; }

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #d1d9e6;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    height: 28px;
}

.dataTables_wrapper .dataTables_length select {
    width: auto;
    min-width: 80px;
}

.dataTables_wrapper .dataTables_filter input {
    width: 180px;
}

.dataTables_wrapper .dataTables_length select:focus,
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: #8b70d0;
    outline: none;
    box-shadow: 0 0 0 3px rgba(139, 112, 208, 0.1);
}

.dataTables_wrapper .dataTables_paginate {
    margin-top: 6px;
    float: right;
    text-align: right;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    margin-bottom: 10px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border: 1px solid #e6ebf1;
    border-radius: 6px;
    padding: 2px 8px;
    margin: 0 2px;
    transition: all 0.2s;
    font-size: 12px;
}

/* Bootstrap 5 pagination used by DataTables */
.dataTables_wrapper .dataTables_paginate ul.pagination { margin: 0; }
.dataTables_wrapper .dataTables_paginate .page-item .page-link {
    padding: 2px 8px;
    font-size: 12px;
    line-height: 1.2;
}
.dataTables_wrapper .dataTables_paginate .page-item.disabled .page-link {
    opacity: 0.6;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #f7fafc;
    border-color: #8b70d0;
    color: #8b70d0 !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: #8b70d0 !important;
    border-color: #8b70d0 !important;
    color: white !important;
}

.dataTables_wrapper .dataTables_info {
    color: #718096;
    font-size: 12px;
    float: left;
}

.dataTables_wrapper .dataTables_processing {
    border: 1px solid #e6ebf1;
    background: white;
    color: #2d3748;
    border-radius: 8px;
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* ── Smaller screens: header and button rows ───────────────────────────── */
/* Laptops / tablets: drop the login email from the header so the tools fit on one line */
@media (max-width: 1199.98px) {
    .navbar .hdr-email { display: none !important; }
    /* Rows of page buttons / filters wrap instead of running off the screen */
    .main-content .d-flex.justify-content-between,
    .main-content .d-flex.gap-2,
    .main-content .d-flex.gap-3 { flex-wrap: wrap; }
    /* a button group inside such a row may not be wider than the row */
    .main-content .d-flex > .d-flex { min-width: 0; max-width: 100%; }
}
/* Phones: icons only in the header, compact spacing */
@media (max-width: 768px) {
    .navbar { padding: 0 8px; }
    .navbar .container-fluid { flex-wrap: nowrap; padding: 0; }
    .navbar .hdr-text, #selectedBranchBadge { display: none !important; }
    .navbar .hdr-tools { flex-wrap: nowrap; min-width: 0; }
    .navbar .hdr-tools > * { margin-right: 6px !important; }
    .navbar .hdr-tools > *:last-child { margin-right: 0 !important; }
    #headerBranchSelect { min-width: 96px !important; max-width: 130px !important; }
    .navbar .dropdown-menu { max-width: calc(100vw - 16px); }
    .main-content { padding: 12px; }
    .main-content .card-body { padding: 12px; }
    .main-content .nav-tabs, .main-content .nav-pills { flex-wrap: wrap; }
    .modal-dialog { margin: 8px; }
}
