/* staff/css/analytics.css */

/* 1. Main View Container - Fixes Height & Alignment */
/* IMPORTANT: Don't set display here - let .view/.view.active handle visibility */
#view-analytics.active {
    flex-direction: column;
    padding-top: 60px; /* CLEARANCE FOR MAIN APP HEADER */
}

/* 2. Analytics Header (Tabs) - Fixed at Top */
.analytics-header {
    flex-shrink: 0; /* Don't shrink */
    background: var(--bg-surface);
    padding: 10px 16px 0;
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.analytics-header h2 {
    margin: 0 0 12px 0;
    font-size: 1.25rem;
    color: var(--text-primary);
}

/* Tab Navigation Styling */
.analytics-tabs {
    display: flex;
    gap: 16px;
    overflow-x: auto; /* Allow scrolling tabs on small screens */
    white-space: nowrap;
}

.tab-btn {
    background: none;
    border: none;
    padding: 8px 4px;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* 3. Scrollable Content Area - THE SCROLL FIX */
.analytics-content {
    flex-grow: 1; /* Take remaining space */
    overflow-y: auto; /* Enable scrolling here */
    padding: 16px;
    padding-bottom: 100px; /* EXTRA PADDING FOR BOTTOM NAV (Safety) */
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
}

/* Panel Visibility */
.analytics-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.analytics-panel.active {
    display: block;
}

/* 4. Chart Cards & Grid */
.chart-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
}

.chart-card {
    background: var(--bg-surface);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    flex: 1 1 100%; /* Default full width */
    /* CRITICAL FIX: Prevent infinite flex growth */
    min-width: 0; /* Tells flexbox it can shrink if needed */
    overflow: hidden; /* Contain the child elements */
}

.chart-card.half {
    flex: 1 1 300px; /* Side by side on larger screens */
}

.chart-card h3 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Canvas Container - Responsive Fix */
.canvas-container {
    position: relative;
    height: 250px; /* Fixed height for charts */
    width: 100%;
    /* CRITICAL FIX: Stop canvas from pushing boundaries */
    overflow: hidden;
}

/* Chart Wrapper - CRITICAL: Fixed dimensions to prevent resize loops */
.chart-wrapper {
    position: relative;
    width: 100%;
    height: 200px; /* Fixed height */
    min-width: 0;
    overflow: hidden;
}

.chart-wrapper canvas {
    max-width: 100% !important;
    max-height: 100% !important;
}

.chart-wrapper-doughnut {
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-wrapper-bar {
    height: 160px;
}

.chart-wrapper-line {
    height: 220px;
}

/* Doughnut Center Label */
.doughnut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}

.doughnut-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.doughnut-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* KPI Grid (Sales) */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.kpi-card {
    background: var(--bg-surface);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    display: block;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.kpi-trend {
    font-size: 0.75rem;
    margin-top: 4px;
    display: block;
}
.kpi-trend.up { color: #10b981; }
.kpi-trend.down { color: #ef4444; }

/* Table Styling */
.table-responsive {
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th {
    text-align: left;
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding-bottom: 8px;
}
.table td {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

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