/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

:root {
    /* Color Palette - Premium Midnight Dark Theme (Matches website) */
    --bg-primary: #040712;
    --bg-secondary: #080d22;
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f4f6;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    
    --accent: #00c2ff; /* Cyan accent */
    --accent-hover: #0084ff; /* Blue accent hover */
    --accent-light: rgba(0, 194, 255, 0.1);
    
    --success: #00a854;
    --success-light: rgba(0, 168, 84, 0.1);
    --warning: #f59e0b;
    --danger: #ef4444;
    
    /* Layout Sizes */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 78px;
    --current-sidebar-width: var(--sidebar-width);
    --header-height: 56px; /* Dashboard internal header height */
    
    /* Shadows & Borders */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

body.sidebar-collapsed {
    --current-sidebar-width: var(--sidebar-collapsed-width);
}

/* Sidebar Styling */
.sidebar {
    width: var(--current-sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1005;
    transition: width var(--transition-normal);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    transition: padding var(--transition-normal);
    position: relative;
}

body.sidebar-collapsed .sidebar-header {
    padding: 0 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all var(--transition-normal);
    width: 100%;
}

body.sidebar-collapsed .logo {
    justify-content: center;
    gap: 0;
}

.logo-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--bg-primary);
}

.logo-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    transition: opacity 0.15s ease, width var(--transition-normal);
    opacity: 1;
    white-space: nowrap;
    overflow: hidden;
}

body.sidebar-collapsed .logo-text {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

/* Sidebar Toggle Button */
.sidebar-toggle-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: -14px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    border-radius: 50%;
    cursor: pointer;
    color: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    z-index: 110;
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.sidebar-toggle-btn:hover {
    background-color: var(--bg-primary);
    color: var(--success);
    border-color: var(--success);
    box-shadow: 0 0 8px rgba(0, 168, 84, 0.4);
}

.toggle-icon {
    transition: transform var(--transition-normal);
}

body.sidebar-collapsed .toggle-icon {
    transform: rotate(180deg);
}

.sidebar-nav {
    padding: 24px 16px;
    flex-grow: 1;
    transition: padding var(--transition-normal);
}

body.sidebar-collapsed .sidebar-nav {
    padding: 24px 8px;
}

.nav-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast), padding var(--transition-normal);
    white-space: nowrap;
    overflow: hidden;
}

body.sidebar-collapsed .nav-item a {
    padding: 12px 0;
    justify-content: center;
}

body.sidebar-collapsed .nav-item a svg {
    margin: 0;
}

.nav-text {
    transition: opacity 0.15s ease, width var(--transition-normal);
    opacity: 1;
}

body.sidebar-collapsed .nav-text {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

.nav-item a:hover {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.nav-item.active a {
    background-color: var(--accent-light);
    color: var(--accent);
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    min-width: 0; /* Prevents flex items from overflowing */
    display: flex;
    flex-direction: column;
    margin-top: 56px;
    margin-left: var(--current-sidebar-width);
    min-height: calc(100vh - 56px);
    transition: margin-left var(--transition-normal);
}

/* Dashboard Sub-Header Bar Styling */
.dashboard-header-bar {
    display: none;
}

.dashboard-header-bar h1 {
    font-size: 1.5rem;
    font-weight: 600;
    white-space: nowrap;
}

.dashboard-header-title-container {
    display: flex;
    align-items: center;
}

.dashboard-header-logo {
    display: none;
}

.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    width: 320px;
}

.search-input {
    background: none;
    border: none;
    outline: none;
    width: 100%;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.dashboard-header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Dashboard Container */
.dashboard-container {
    padding: 10px 24px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex-grow: 1;
}

/* Metrics Section */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}



.metric-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.metric-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.metric-value {
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--text-primary);
}

.metric-trend {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 500;
}

.trend-up {
    color: var(--success);
}

.trend-down {
    color: var(--danger);
}

/* Charts Section */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 24px;
}





.chart-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0; /* Prevents overflow inside flex and grid containers */
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.html-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.legend-color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.chart-canvas-container {
    position: relative;
    width: 100%;
    min-width: 0; /* Allows container to shrink dynamically */
    min-height: 250px;
    display: block; /* Required for proper Chart.js canvas resize detection */
}

/* Empty Canvas Placeholder States */
.canvas-placeholder {
    width: 100%;
    height: 100%;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 20px;
    text-align: center;
}

.canvas-placeholder svg {
    margin-bottom: 12px;
    color: var(--text-muted);
}

/* Cumulative Sales Chart full-width span */
#panel-cumm-chart {
    grid-column: 1 / -1;
}

/* --- Responsiveness Media Queries --- */

/* Tablet Layout (between 769px and 1200px) */
@media (min-width: 769px) and (max-width: 1200px) {
    .charts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Mobile & Tablet Breakpoint (768px and below) */
@media (max-width: 768px) {
    /* Sidebar drawer style */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        height: 100vh;
        left: 0;
        width: var(--current-sidebar-width);
        box-shadow: var(--shadow-lg);
        z-index: 10200;
        transition: width var(--transition-normal);
    }

    /* Backdrop overlay behind sidebar drawer when expanded (i.e. not collapsed) */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(15, 23, 42, 0.4);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 9999;
        opacity: 0;
        transition: opacity var(--transition-fast) ease-in-out;
    }

    body:not(.sidebar-collapsed) .sidebar-backdrop {
        display: block;
        opacity: 1;
    }

    /* Mobile toggle button layout and scaling */
    .sidebar-toggle-btn {
        position: absolute !important;
        width: 32px;
        height: 32px;
        right: -16px;
        top: 50%;
        transform: translateY(-50%);
        box-shadow: var(--shadow-sm);
        display: flex !important;
        background-color: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        z-index: 110;
    }

    /* Main content area padding */
    .main-content {
        margin-left: var(--sidebar-collapsed-width) !important;
    }

    .dashboard-header-bar {
        padding-left: 16px; /* Reset padding since main-content has margin-left */
        padding-right: 16px;
    }

    .dashboard-header-bar h1 {
        font-size: 1.25rem;
    }

    .dashboard-header-logo {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-right: 16px;
    }

    .dashboard-header-logo-img {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        object-fit: cover;
        box-shadow: 0 0 0 2px var(--bg-primary);
    }

    .dashboard-header-logo-text {
        font-size: 1rem;
        font-weight: 700;
        color: var(--text-primary);
        white-space: nowrap;
    }

    .dashboard-container {
        padding: 26px 16px 16px 16px; /* Shift elements down by 16px */
        gap: 16px;
    }

    .charts-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .metrics-grid {
        gap: 16px;
    }

    #business-view .metrics-grid {
        margin-top: 0;
    }

    #business-view .charts-grid {
        margin-top: 24px;
    }
}

/* Small Smartphone Breakpoint (640px and below) */
@media (max-width: 640px) {
    .dashboard-header-bar {
        height: auto;
        min-height: 80px;
        padding-top: 16px;
        padding-bottom: 16px;
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
    }

    .dashboard-header-title-container {
        padding-left: 0;
        text-align: center;
    }

    .dashboard-header-actions {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
    }

    .search-bar {
        flex-grow: 1;
        width: auto;
    }

    .user-profile {
        flex-shrink: 0;
    }
}

/* Mini Phone Breakpoint (480px and below) */
@media (max-width: 480px) {
    .dashboard-header-logo-text {
        display: none;
    }

    .dashboard-header-bar h1 {
        font-size: 1.15rem;
    }

    .metric-card {
        padding: 16px;
        gap: 8px;
    }

    .metric-value {
        font-size: 1.5rem;
    }

    .chart-card {
        padding: 16px;
        gap: 12px;
    }

    .chart-title {
        font-size: 1rem;
    }
}

/* --- Team Leaderboard Table Styles --- */
.leaderboard-section {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.leaderboard-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-sm);
    box-shadow: inset 0 0 0 1px var(--border-color);
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.95rem;
    min-width: 600px; /* Force minimum width to prevent squeezed header on mobile */
}

.leaderboard-table th {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.leaderboard-table tr:last-child td {
    border-bottom: none;
}

.leaderboard-table tbody tr {
    transition: background-color var(--transition-fast);
}

.leaderboard-table tbody tr:hover {
    background-color: var(--accent-light);
}

/* Rank Badge Styles */
.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.8rem;
}

.rank-1 {
    background-color: hsl(45, 100%, 90%);
    color: hsl(45, 100%, 35%);
    border: 1px solid hsl(45, 100%, 75%);
}

.rank-2 {
    background-color: hsl(0, 0%, 90%);
    color: hsl(0, 0%, 35%);
    border: 1px solid hsl(0, 0%, 75%);
}

.rank-3 {
    background-color: hsl(28, 60%, 90%);
    color: hsl(28, 60%, 40%);
    border: 1px solid hsl(28, 60%, 75%);
}

.rank-default {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
}

/* User Drilldown Select Dropdown Styles */
.drilldown-selector {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.drilldown-selector:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

/* --- Squeezed 5-column Row for Teams Dashboard KPIs on desktop --- */
@media (min-width: 1025px) {
    .teams-metrics-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 16px; /* slightly smaller gap to help them fit cleanly */
    }
    .teams-metrics-grid .metric-card {
        padding: 16px 20px;
        gap: 8px;
    }
    .teams-metrics-grid .metric-value {
        font-size: 1.55rem; /* slightly smaller font size to fit long names */
    }
}

/* --- Login Overlay and Card Styles --- */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999; /* Higher than everything */
}

.login-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.login-logo {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    align-self: center;
    object-fit: cover;
    margin-bottom: 8px;
    box-shadow: var(--shadow-md);
}

.login-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

.login-header p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group input {
    height: 40px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.login-btn {
    height: 44px;
    background-color: var(--accent);
    color: white;
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast), transform var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.login-btn:hover {
    background-color: var(--accent-hover);
}

.login-btn:active {
    transform: scale(0.98);
}

.login-error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    background-color: hsl(350, 80%, 95%);
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid hsl(350, 80%, 90%);
}

/* --- Access Control Switch Toggles --- */
.user-switch-toggle {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

/* User management specific card layout styles */
.admin-card-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

/* Admin Panel Settings Grid Layout */
.admin-panel-layout {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
    margin-top: 0;
    align-items: start;
}

@media (max-width: 1200px) {
    .admin-panel-layout {
        grid-template-columns: 1fr;
    }
}

/* --- Desktop layout vertical gaps adjustment (exactly 32px) --- */
@media (min-width: 769px) {
    #business-view .metrics-grid,
    #business-view .charts-grid,
    #teams-view .metrics-grid,
    #teams-view .leaderboard-section,
    #teams-view .charts-grid {
        padding-top: 0;
        padding-bottom: 0;
        margin-top: 0;
        margin-bottom: 0;
    }

    #business-view .charts-grid,
    #teams-view .leaderboard-section,
    #teams-view .charts-grid {
        margin-top: 32px;
    }

    .dashboard-container {
        padding: 48px 24px 32px 24px; /* Shift elements down by 16px */
    }

    .header {
        left: var(--current-sidebar-width);
        width: calc(100% - var(--current-sidebar-width));
        transition: left var(--transition-normal), width var(--transition-normal);
    }

    .header .logo-area {
        display: none;
    }
}

/* --- Live Pulse Indicator --- */
.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 0 0 rgba(0, 194, 255, 0.45);
    animation: pulse-animation 2s infinite;
}

@keyframes pulse-animation {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(0, 194, 255, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(0, 194, 255, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(0, 194, 255, 0);
    }
}

/* Mobile and tablet view header and navigation z-index fixes */
@media (max-width: 1024px) {
    .header {
        z-index: 10100; /* Higher than sidebar */
    }
    .burger-menu {
        z-index: 10101; /* Higher than header */
    }
    .header-ctas {
        margin-left: auto; /* Push hamburger menu to the right when logo is hidden */
    }
    .mobile-nav {
        z-index: 10090; /* Higher than sidebar but below header */
        right: 0;
        left: auto;
        width: 75%; /* Slide-down drawer aligned to the right */
        background: rgba(15, 23, 42, 0.93) !important; /* Premium semi-transparent glassmorphism background */
        backdrop-filter: blur(10px);
        border-left: 1px solid rgba(255, 255, 255, 0.08);
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: -10px 10px 30px rgba(0, 0, 0, 0.5);
    }
    .sidebar-backdrop {
        z-index: 9998; /* Below sidebar and header */
    }
}

