/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

:root {
    /* Color Palette - Premium Light Theme */
    --bg-primary: hsl(210, 20%, 98%);
    --bg-secondary: hsl(0, 0%, 100%);
    --border-color: hsl(210, 16%, 93%);
    --text-primary: hsl(210, 24%, 16%);
    --text-secondary: hsl(210, 10%, 46%);
    --text-muted: hsl(210, 8%, 65%);
    
    --accent: hsl(256, 75%, 58%);
    --accent-hover: hsl(256, 68%, 52%);
    --accent-light: hsl(256, 100%, 97%);
    
    --success: hsl(150, 80%, 36%);
    --success-light: hsl(150, 80%, 95%);
    --warning: hsl(35, 90%, 50%);
    --danger: hsl(350, 80%, 50%);
    
    /* Layout Sizes */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 78px;
    --current-sidebar-width: var(--sidebar-width);
    --header-height: 70px;
    
    /* Shadows & Borders */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    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;
    bottom: 0;
    left: 0;
    z-index: 100;
    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 var(--transition-fast), width var(--transition-fast);
    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(--text-secondary);
    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), box-shadow var(--transition-fast);
}

.sidebar-toggle-btn:hover {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
}

.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 var(--transition-fast), width var(--transition-fast);
    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 {
    margin-left: var(--current-sidebar-width);
    flex-grow: 1;
    min-width: 0; /* Prevents flex items from overflowing */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition-normal);
}

/* Header Styling */
.header {
    height: var(--header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 90;
}

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

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

.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);
}

.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: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    flex-grow: 1;
}

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

.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, 1fr);
    gap: 24px;
}



.chart-card {
    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;
}

.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-height: 320px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 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, 1fr);
    }
}

/* Mobile & Tablet Breakpoint (768px and below) */
@media (max-width: 768px) {
    :root {
        --current-sidebar-width: 0px;
    }

    body {
        --current-sidebar-width: 0px;
    }

    /* Sidebar drawer style */
    .sidebar {
        width: 260px;
        left: -260px;
        transform: none !important;
        transition: left var(--transition-normal);
        box-shadow: var(--shadow-lg);
        z-index: 1000;
    }

    body.sidebar-open .sidebar {
        left: 0;
    }

    /* Backdrop overlay behind sidebar drawer */
    .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: 999;
        opacity: 0;
        transition: opacity var(--transition-fast) ease-in-out;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
    }

    /* Mobile toggle button layout and scaling */
    .sidebar-toggle-btn {
        position: fixed;
        top: 15px;
        left: 16px;
        z-index: 1001; /* Position above sidebar backdrop */
        width: 40px;
        height: 40px;
        border-radius: var(--radius-sm);
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: var(--shadow-sm);
    }

    body.sidebar-open .sidebar-toggle-btn {
        left: 216px; /* Shift with drawer for easy close */
        box-shadow: none;
        border: none;
        background-color: transparent;
    }

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

    /* Main content area padding */
    .main-content {
        margin-left: 0 !important;
    }

    .header {
        padding-left: 72px; /* Prevent clashing with floating toggle btn */
        padding-right: 16px;
    }

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

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

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

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

    .dashboard-container {
        padding: 20px 16px;
        gap: 20px;
    }

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

    .metrics-grid {
        gap: 16px;
    }
}

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

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

    .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) {
    .header-logo-text {
        display: none;
    }

    .header 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;
    }
}
