/*
 * SureEntry.io Admin Dashboard Styles
 * Version: 2.0 (Responsive Overhaul)
 * This file contains styles for the admin dashboard, focusing on a mobile-first, responsive design.
 */

/* --- General & Typography --- */
body {
  background-color: #f8f9fa;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* --- Main Layout: Sidebar & Content --- */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 250px;
  background-color: #212529;
  color: white;
  z-index: 1030;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease-in-out;
  transform: translateX(0);
}

.main-content {
  margin-left: 250px;
  padding: 20px;
  padding-top: 70px; /* Header height (50px) + space (20px) */
  transition: margin-left 0.3s ease-in-out;
  min-height: 100vh;
}

/* --- Sidebar Components --- */
.sidebar-brand {
  padding: 1rem 1.25rem;
  font-size: 1.5rem;
  font-weight: bold;
  color: white;
  text-decoration: none;
  text-align: center;
  flex-shrink: 0; /* Prevent shrinking */
}
.sidebar-brand:hover {
  color: rgba(255, 255, 255, 0.9);
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
  flex-grow: 1; /* Allow nav to fill space */
  overflow-y: auto; /* Allow scrolling if items overflow */
}

.sidebar-nav-item {
  border-left: 4px solid transparent;
  transition: all 0.2s ease;
}
.sidebar-nav-item a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  display: flex;
  align-items: center;
  padding: 12px 20px;
  transition: all 0.2s ease;
}

.sidebar-nav-item:hover a,
.sidebar-nav-item.active a {
  color: white;
  background-color: rgba(255, 255, 255, 0.1);
}
.sidebar-nav-item.active {
  border-left-color: #0d6efd;
}

.sidebar-nav-item i {
  margin-right: 12px;
  font-size: 1.1rem;
  width: 22px;
  text-align: center;
}

.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: auto; /* Pushes footer to the bottom */
  text-align: center;
  flex-shrink: 0;
}

.admin-name-logout {
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  display: inline-block;
  padding: 5px;
  transition: color 0.2s ease;
  font-weight: 500;
  font-size: 0.9rem;
}
.admin-name-logout:hover {
  color: white;
  text-decoration: underline;
}

/* --- Location Header --- */
.location-header {
    position: fixed;
    top: 0;
    left: 250px; /* Start after sidebar */
    width: calc(100% - 250px); /* Fill remaining space */
    background-color: #ffffff;
    padding: 0 20px;
    z-index: 1025;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: left 0.3s ease-in-out, width 0.3s ease-in-out;
}

.location-tabs-container {
    overflow-x: auto;
    white-space: nowrap;
    flex-grow: 1;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}
.location-tabs-container::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.location-tabs {
    border-bottom: none;
    flex-wrap: nowrap;
    margin-bottom: 0;
    display: inline-flex;
}

.location-tabs .nav-link {
    color: #495057;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 12px 15px;
    margin-right: 5px;
    transition: all 0.2s ease-in-out;
    font-weight: 500;
    font-size: 0.9rem;
}
.location-tabs .nav-link:hover {
    color: #0d6efd;
    border-bottom-color: #a7caff;
}
.location-tabs .nav-link.active {
    color: #0d6efd;
    background-color: transparent;
    border-bottom-color: #0d6efd;
    font-weight: 600;
}

.location-add-button {
    margin-left: 15px;
    flex-shrink: 0;
}

/* --- Main Content & Cards --- */
.content-header {
  padding-bottom: 15px;
  margin-bottom: 25px;
  border-bottom: 1px solid #e9ecef;
}

.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    margin-bottom: 1.5rem;
    height: 100%;
}
.card-header {
    background-color: #ffffff;
    border-bottom: 1px solid #e9ecef;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    padding: 1rem 1.25rem;
    font-weight: 600;
}
.card-footer {
    background-color: #f8f9fa;
    border-top: 1px solid #e9ecef;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    padding: 0.75rem 1.25rem;
}

.stat-card {
  padding: 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}
.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.09);
}
.stat-card a { color: inherit; text-decoration: none; }
.stat-card a:hover .stat-card-label { text-decoration: underline; }

.stat-card-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15px;
  font-size: 1.5rem;
}
.stat-card-value {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 5px;
}
.stat-card-label {
  color: #6c757d;
  font-size: 0.9rem;
}

/* --- Table Styles --- */
.table-responsive {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #dee2e6;
}
.table { margin-bottom: 0; }
.table th {
  background-color: #f8f9fa;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  vertical-align: middle;
  padding: 0.75rem 1rem;
}
.table td {
  vertical-align: middle;
  font-size: 0.9rem;
  padding: 0.75rem 1rem;
  white-space: nowrap;
}

/* Sortable table header styles */
th[data-sortable] { cursor: pointer; position: relative; padding-right: 25px; }
th[data-sortable] a { color: inherit; text-decoration: none; }
th[data-sortable] a:hover { color: #0d6efd; }

/* Default state - show both arrows to indicate sortability */
th[data-sortable]::after {
  content: '↕'; /* Unicode up-down arrow */
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.4;
  font-size: 14px;
}

/* Active sort states - override with single arrow */
th[data-sortable].sort-asc::after {
  content: '↑'; /* Unicode up arrow */
  opacity: 1;
}

th[data-sortable].sort-desc::after {
  content: '↓'; /* Unicode down arrow */
  opacity: 1;
}

/* --- Activity Feed & Tabs --- */
.activity-card .card-body { padding: 0; }
.activity-card .list-group-item {
    border-left: none;
    border-right: none;
    padding: 1rem 1.25rem;
}
.activity-card .list-group-item:first-child { border-top: none; }
.activity-card .list-group-item:last-child {
    border-bottom: none;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

.activity-tabs { border-bottom: 1px solid #dee2e6; }
.activity-tabs .nav-link {
    font-size: 0.9rem;
    color: #6c757d;
    border-color: transparent;
    border-top-left-radius: 0.375rem;
    border-top-right-radius: 0.375rem;
}
.activity-tabs .nav-link.active {
    color: #0d6efd;
    background-color: #fff;
    border-color: #dee2e6 #dee2e6 #fff;
    font-weight: 600;
}
.activity-tab-pane { min-height: 300px; position: relative; }
.activity-loading-overlay {
    position: absolute; inset: 0;
    background-color: rgba(255, 255, 255, 0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 10;
    border-radius: 0 0 12px 12px;
}

/* --- Login & Modal Styles --- */
.login-card {
  max-width: 420px;
  margin: 80px auto;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}
.login-header {
  background-color: #0d6efd;
  color: white;
  padding: 30px;
  text-align: center;
}
.login-body { padding: 30px; }

/* --- Onboarding Styles --- */
#onboarding-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.65);
    z-index: 1040;
    display: none;
}
#onboarding-card {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1041;
    background-color: #fff;
    padding: 25px 30px;
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: none;
}
#onboarding-content-area .action-buttons {
    margin-top: 1rem; padding-top: 1rem;
    border-top: 1px solid #eee;
    display: flex; justify-content: space-between;
}
#onboarding-content-area .mapping-container,
#onboarding-content-area .preview-container,
#onboarding-content-area .duplicates-container {
    max-height: 45vh;
    overflow-y: auto;
}

/* --- Password Requirements --- */
#password-requirements { list-style: none; padding-left: 0; margin-top: 0.5rem; font-size: 0.875em; }
#password-requirements li { margin-bottom: 0.25rem; color: #dc3545; transition: color 0.3s ease; }
#password-requirements li::before { content: "✗ "; display: inline-block; margin-right: 0.5em; font-weight: bold; }
#password-requirements li.met { color: #198754; }
#password-requirements li.met::before { content: "✓ "; }

/* --- Backdrop for when mobile sidebar is open --- */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1039; /* Below sidebar, above everything else */
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}
.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* --- Scrollbar styling for table containers --- */
.reports-page .table-responsive::-webkit-scrollbar,
.reports-page #locationPeakHeatmapContainer::-webkit-scrollbar,
.reports-page #orgPeakHeatmapContainer::-webkit-scrollbar,
.reports-page #locationTopBusyPeriodsTable::-webkit-scrollbar,
.reports-page #orgTopBusyPeriodsTable::-webkit-scrollbar {
    height: 8px;
}

.reports-page .table-responsive::-webkit-scrollbar-track,
.reports-page #locationPeakHeatmapContainer::-webkit-scrollbar-track,
.reports-page #orgPeakHeatmapContainer::-webkit-scrollbar-track,
.reports-page #locationTopBusyPeriodsTable::-webkit-scrollbar-track,
.reports-page #orgTopBusyPeriodsTable::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.reports-page .table-responsive::-webkit-scrollbar-thumb,
.reports-page #locationPeakHeatmapContainer::-webkit-scrollbar-thumb,
.reports-page #orgPeakHeatmapContainer::-webkit-scrollbar-thumb,
.reports-page #locationTopBusyPeriodsTable::-webkit-scrollbar-thumb,
.reports-page #orgTopBusyPeriodsTable::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

/* ===================================================================== */
/* RESPONSIVE DESIGN - Tablets (less than 992px)                        */
/* ===================================================================== */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-250px);
    z-index: 1040;
    padding-top: 50px;
  }
  .sidebar.show {
    transform: translateX(0);
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
    padding-top: 50px;
  }
  .main-content {
    margin-left: 0;
  }
  .location-header {
    width: 100%;
    left: 0;
  }
}

/* ===================================================================== */
/* RESPONSIVE DESIGN - Mobile (less than 768px)                         */
/* ===================================================================== */
@media (max-width: 767.98px) {
    .main-content {
        padding: 15px;
        padding-top: 110px; /* Adjust for header height */
    }
    .content-header {
        margin-bottom: 20px;
    }
    .content-header .d-flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 15px;
    }
    .location-header {
        height: auto;
        padding: 5px 15px;
    }
    .location-tabs-container {
        width: auto;
        padding: 0;
    }
    .location-add-button {
        margin-left: 15px;
        align-self: auto;
    }
    .stat-card {
        padding: 15px;
    }
    .stat-card-value {
        font-size: 1.7rem;
    }
    .table td, .table th {
        font-size: 0.85rem;
        padding: 0.6rem;
    }
    
    /* Responsive table cards */
    .responsive-table-cards thead {
        display: none;
    }

    .responsive-table-cards tbody tr {
        display: block;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        margin-bottom: 1rem;
        padding: 0.75rem;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }

    .responsive-table-cards td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        text-align: right;
        padding: 0.6rem 0 !important;
        border-bottom: 1px solid #e9ecef;
        white-space: normal !important;
    }

    .responsive-table-cards td:last-child {
        border-bottom: none;
    }

    .responsive-table-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        padding-right: 1rem;
        min-width: 110px;
        flex-shrink: 0;
    }

    .responsive-table-cards td .d-flex.gap-1,
    .responsive-table-cards td[data-label="Actions"] .d-flex {
        justify-content: flex-end !important;
        width: 100%;
    }

    /* Special handling for the Subscription Plan Comparison table */
    .plan-comparison-table { border: none !important; }
    .plan-comparison-table tr { padding: 0; }
    .plan-comparison-table td:first-child {
        background-color: #f8f9fa;
        font-weight: 600;
        justify-content: center;
        border-bottom: 2px solid #0d6efd;
    }
    .plan-comparison-table td:first-child::before { display: none; }
    .plan-comparison-table td::before { color: #6c757d; min-width: auto; }
    .plan-comparison-table tbody td:nth-of-type(2)::before { content: "Basic:"; }
    .plan-comparison-table tbody td:nth-of-type(3)::before { content: "Professional:"; }
    .plan-comparison-table tbody td:nth-of-type(4)::before { content: "Enterprise:"; }
    
    /* Reports page specific mobile styles */
    .reports-page .report-container .table-responsive,
    .reports-page #attendanceReportContainer .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .reports-page .report-container table,
    .reports-page #attendanceReportContainer table {
        min-width: 600px;
        font-size: 0.85rem;
    }
    
    .reports-page .report-container .card-body {
        padding-left: 0;
        padding-right: 0;
    }
    
    .reports-page .report-container .table-responsive {
        margin: 0;
        padding: 0 1rem;
        width: 100%;
    }
    
    .reports-page section.bg-white {
        overflow-x: visible !important;
        overflow-y: visible !important;
    }
    
    .reports-page section .card-body {
        overflow-x: visible !important;
        overflow-y: visible !important;
    }
    
    //* Heatmap specific styles */
    .reports-page #locationPeakHeatmapContainer,
    .reports-page #orgPeakHeatmapContainer {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        position: relative;
        /* Negative margins to extend to viewport edges */
        margin-left: -0.75rem;
        margin-right: -0.75rem;
        /* Add padding to compensate */
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    /* Ensure heatmap content can overflow */
    .reports-page #locationPeakHeatmapContainer > *,
    .reports-page #orgPeakHeatmapContainer > * {
        display: inline-block;
        min-width: 700px;
    }
    
    /* Heatmap tables */
    .reports-page #locationPeakHeatmapContainer table,
    .reports-page #orgPeakHeatmapContainer table {
        width: 700px !important;
        min-width: 700px !important;
        max-width: none !important;
        table-layout: fixed;
        margin: 0;
    }
    
    .reports-page #locationPeakHeatmapContainer th,
    .reports-page #orgPeakHeatmapContainer th {
        text-align: center !important;
        padding: 8px 4px !important;
        font-size: 0.75rem;
        white-space: nowrap;
        vertical-align: middle;
    }
    
    .reports-page #locationPeakHeatmapContainer td,
    .reports-page #orgPeakHeatmapContainer td {
        text-align: center !important;
        padding: 4px !important;
        font-size: 0.7rem;
        min-width: 40px;
        white-space: nowrap;
    }
    
    /* Top Busiest Periods - NO SCROLL */
    .reports-page #locationTopBusyPeriodsTable,
    .reports-page #orgTopBusyPeriodsTable {
        overflow-x: hidden !important;
        overflow-y: visible !important;
        margin: 0;
        padding: 0 0.75rem;
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .reports-page #locationTopBusyPeriodsTable table,
    .reports-page #orgTopBusyPeriodsTable table {
        width: 100% !important;
        max-width: 100% !important;
        min-width: unset !important;
        table-layout: auto !important;
    }
    
    .reports-page #locationTopBusyPeriodsTable td,
    .reports-page #orgTopBusyPeriodsTable td,
    .reports-page #locationTopBusyPeriodsTable th,
    .reports-page #orgTopBusyPeriodsTable th {
        white-space: normal !important;
        word-break: break-word !important;
        font-size: 0.75rem;
        padding: 4px !important;
    }
    
    /* Parent containers don't clip */
    .reports-page #locationPeakActivityContainer,
    .reports-page #orgPeakActivityContainer,
    .reports-page #locationTopBusyPeriodsContainer,
    .reports-page #orgTopBusyPeriodsContainer {
        overflow: visible !important;
        position: relative;
    }
    
    /* Attendance report container */
    .reports-page #attendanceReportContainer .card-body {
        padding-left: 0;
        padding-right: 0;
    }
    
    .reports-page #attendanceReportContainer .table-responsive {
        margin: 0;
        padding: 0 1rem;
        width: 100%;
    }
    
    .reports-page .table-responsive,
    .reports-page #locationPeakHeatmapContainer,
    .reports-page #orgPeakHeatmapContainer {
        position: relative;
        z-index: 1;
    }
    
    /* Visual scroll indicator for heatmaps only */
    #locationPeakHeatmapContainer::after,
    #orgPeakHeatmapContainer::after {
        content: "← Swipe to see all days →";
        display: block;
        text-align: center;
        color: #6c757d;
        font-size: 0.75rem;
        padding: 0.5rem 0;
        font-style: italic;
    }
}

/* ===================================================================== */
/* RESPONSIVE DESIGN - Small phones (less than 576px)                   */
/* ===================================================================== */
@media (max-width: 575.98px) {
    .main-content {
        padding: 10px;
        padding-top: 105px;
    }
    .content-header h1 {
        font-size: 1.5rem;
    }
    .stat-card {
        text-align: center;
    }
    .stat-card-icon {
        margin-left: auto;
        margin-right: auto;
    }
    #onboarding-card {
        width: 95%;
        padding: 20px 15px;
        top: 20px;
        left: 2.5%;
        transform: none;
        max-height: calc(100vh - 40px);
    }
    #onboarding-content-area .mapping-container,
    #onboarding-content-area .preview-container,
    #onboarding-content-area .duplicates-container {
        max-height: 40vh;
    }
    
    .reports-page .report-container .table-responsive,
    .reports-page #attendanceReportContainer .table-responsive {
        padding: 0 0.5rem;
    }
    
    /* Separate rules for different table types */
    .reports-page #locationPeakHeatmapContainer,
    .reports-page #orgPeakHeatmapContainer {
        /* Maintain negative margins for scroll */
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    .reports-page #locationTopBusyPeriodsTable,
    .reports-page #orgTopBusyPeriodsTable {
        /* No negative margins - these should fit */
        padding: 0 0.5rem;
    }
    
    .reports-page #locationPeakHeatmapContainer th,
    .reports-page #orgPeakHeatmapContainer th {
        font-size: 0.65rem;
        padding: 6px 2px !important;
    }
    
    .reports-page #locationPeakHeatmapContainer td,
    .reports-page #orgPeakHeatmapContainer td {
        font-size: 0.65rem;
        padding: 2px !important;
        min-width: 35px;
    }
}

/* Global fixes for peak activity sections */
.reports-page section.p-4.p-md-6.rounded-lg.shadow-md {
    overflow: visible !important;
}

.reports-page .tab-content,
.reports-page .tab-pane {
    overflow: visible !important;
}

.table-responsive {
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}

/* ===================================================================== */
/* HEATMAP HORIZONTAL SCROLL FIX - Add at the very end of the file     */
/* ===================================================================== */
@media (max-width: 767.98px) {
  /* Force heatmap containers to be scrollable */
  .reports-page #locationPeakHeatmapContainer,
  .reports-page #orgPeakHeatmapContainer {
    display: block !important;
    width: calc(100vw - 30px) !important; /* Full viewport width minus padding */
    max-width: calc(100vw - 30px) !important;
    margin-left: calc(-50vw + 50%) !important; /* Center and extend to viewport edges */
    margin-right: calc(-50vw + 50%) !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x pan-y !important;
  }

  /* Force tables to be wider than viewport */
  .reports-page #locationPeakHeatmapContainer table,
  .reports-page #orgPeakHeatmapContainer table {
    width: 700px !important;
    min-width: 700px !important;
    max-width: 700px !important;
    table-layout: fixed !important;
    margin: 0 !important;
  }

  /* Remove any constraints from parent elements */
  .reports-page section.bg-white,
  .reports-page .tab-content,
  .reports-page .tab-pane {
    overflow: visible !important;
  }
}

@media (max-width: 575.98px) {
  .reports-page #locationPeakHeatmapContainer,
  .reports-page #orgPeakHeatmapContainer {
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
}

/* --- Mobile Header (for all pages) --- */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background-color: #212529;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    z-index: 1041; /* Higher than sidebar's 1040 */
}

.mobile-brand {
    color: white;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.2rem;
}

.mobile-brand:hover {
    color: rgba(255, 255, 255, 0.9);
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
}

@media (min-width: 992px) {
    .mobile-header {
        display: none;
    }
}

@media (max-width: 991.98px) {
    .location-header {
        top: 50px; /* Push below mobile header */
    }
}