
/* ==========================================================
   ATHERIOT ANALYTICS
   RESPONSIVE DASHBOARD - LIGHT / DARK THEME
   COMPACT CHARTS WITH INDEPENDENT SIZE CONTROLS
   ========================================================== */


/* ==========================================================
   1. CHART SIZE CONTROLS

   Change these values to resize charts.

   --analytics-chart-height:
       Daily and monthly charts

   --analytics-pie-height:
       Doughnut chart

   --analytics-overtime-height:
       Overtime line chart

   --analytics-chart-max-width:
       Maximum width of each chart card
   ========================================================== */

.analytics-container {
    --analytics-chart-height: 220px;
    --analytics-pie-height: 190px;
    --analytics-overtime-height: 210px;

    --analytics-chart-max-width: 650px;

    --analytics-chart-gap: 16px;

    --analytics-card-background:
        var(--surface-secondary, var(--surface));

    --analytics-muted:
        var(--muted, #64748b);

    --analytics-heading:
        var(--heading, var(--text));
}


/* ==========================================================
   2. MAIN ANALYTICS CONTAINER
   ========================================================== */

.analytics-container {
    width: calc(100% - 2 * var(--page-gutter));
    max-width: none;
    min-width: 0;

    margin: 16px auto 24px;
    padding: 0;

    box-sizing: border-box;

    display: flex;
    flex-direction: column;
    align-items: flex-start;

    gap: 16px;
}


/* ==========================================================
   3. GENERATE / CLOSE ANALYTICS BUTTON
   ========================================================== */

#generateAnalytics {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    gap: 10px;

    width: fit-content;
    max-width: 100%;
    min-height: 44px;

    margin: 0;
    padding: 12px 20px;

    box-sizing: border-box;

    border: none;
    border-radius: 10px;

    background: var(--primary);
    color: #ffffff;

    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;

    text-align: center;
    text-decoration: none;

    cursor: pointer;

    box-shadow:
        0 3px 12px rgba(8, 123, 255, 0.20);

    transition:
        background 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}


/* Button icon */

#generateAnalytics i {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;

    font-size: 17px;
    line-height: 1;
}


/* Button text */

#analyticsButtonText {
    display: inline-block;

    min-width: 0;

    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;

    overflow-wrap: anywhere;
}


/* Hover */

@media (hover: hover) {
    #generateAnalytics:hover:not(:disabled) {
        background:
            var(--primary-hover, var(--primary));

        transform: translateY(-2px);

        box-shadow:
            0 5px 16px rgba(8, 123, 255, 0.28);
    }
}


/* Active */

#generateAnalytics:active:not(:disabled) {
    transform: scale(0.98);
}


/* Keyboard focus */

#generateAnalytics:focus-visible {
    outline: 3px solid rgba(8, 123, 255, 0.35);
    outline-offset: 3px;
}


/* Loading */

#generateAnalytics:disabled {
    opacity: 0.65;
    cursor: wait;
    transform: none;
}


/* ==========================================================
   4. ANALYTICS RESULTS CONTAINER
   ========================================================== */

#analyticsResults {
    width: 100%;
    max-width: none;
    min-width: 0;

    margin: 0;
    padding: clamp(12px, 2vw, 24px);

    box-sizing: border-box;

    background: var(--surface);
    color: var(--text);

    border: 1px solid var(--border);
    border-radius: var(--radius, 12px);

    box-shadow: var(--shadow, none);

    overflow-wrap: anywhere;
}


/* Ensure hidden means hidden */

#analyticsResults[hidden] {
    display: none !important;
}


/* ==========================================================
   5. DASHBOARD CONTENT
   ========================================================== */

#analyticsResults .analytics-dashboard {
    width: 100%;
    min-width: 0;
}


/* Dashboard heading */

#analyticsResults .analytics-dashboard-heading {
    display: flex;
    flex-direction: column;

    gap: 6px;
    min-width: 0;
}


/* Headings */

#analyticsResults h2,
#analyticsResults h3 {
    margin: 0;

    color: var(--analytics-heading);

    font-weight: 700;
    line-height: 1.4;

    overflow-wrap: anywhere;
}


#analyticsResults h2 {
    font-size: clamp(17px, 1.8vw, 22px);
}


#analyticsResults h3 {
    font-size: clamp(14px, 1.3vw, 17px);
}


/* Heading icons */

#analyticsResults h2 i,
#analyticsResults h3 i {
    margin-right: 8px;
    color: var(--primary);
}


/* Paragraphs */

#analyticsResults p {
    margin: 0;

    color: var(--analytics-muted);

    font-size: 14px;
    line-height: 1.6;

    overflow-wrap: anywhere;
}


/* ==========================================================
   6. KPI GRID
   ========================================================== */

#analyticsResults .analytics-grid {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: clamp(10px, 1.5vw, 18px);

    width: 100%;
    min-width: 0;

    margin-top: 18px;
}


/* ==========================================================
   7. KPI CARDS
   ========================================================== */

#analyticsResults .analytics-card {
    display: flex;
    flex-direction: column;

    gap: 10px;

    min-width: 0;

    padding: clamp(12px, 1.5vw, 20px);

    box-sizing: border-box;

    background: var(--analytics-card-background);
    color: var(--text);

    border: 1px solid var(--border);
    border-radius: 12px;

    overflow-wrap: anywhere;
}


/* KPI icon */

#analyticsResults .analytics-card i {
    color: var(--primary);
    font-size: 20px;
}


/* KPI label */

#analyticsResults .analytics-card span {
    color: var(--analytics-muted);

    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
}


/* KPI value */

#analyticsResults .analytics-card strong {
    color: var(--analytics-heading);

    font-size: clamp(18px, 2vw, 26px);
    font-weight: 700;
    line-height: 1.3;

    overflow-wrap: anywhere;
}


/* ==========================================================
   8. CHART GRID

   Desktop: 2 charts per row
   Tablet/mobile: 1 chart per row
   ========================================================== */

#analyticsResults .analytics-charts {
    display: grid;

    grid-template-columns:
        repeat(2, minmax(0, 1fr));

    gap: var(--analytics-chart-gap);

    width: 100%;
    min-width: 0;

    margin-top: 20px;

    align-items: start;
}


/* ==========================================================
   9. INDIVIDUAL CHART CARD
   ========================================================== */

#analyticsResults .analytics-chart {
    width: 100%;
    max-width: var(--analytics-chart-max-width);

    min-width: 0;

    margin: 0;
    padding: 16px;

    box-sizing: border-box;

    background: var(--analytics-card-background);

    border: 1px solid var(--border);
    border-radius: 12px;

    overflow: hidden;
}


/* Chart title */

#analyticsResults .analytics-chart h3 {
    margin: 0 0 12px;

    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
}


/* ==========================================================
   10. CHART CANVAS WRAPPER

   Chart.js uses this container to determine
   its rendered width and height.
   ========================================================== */

#analyticsResults .analytics-canvas-wrap {
    position: relative;

    display: block;

    width: 100%;
    height: var(--analytics-chart-height);

    min-width: 0;
    min-height: 0;

    margin: 0;
    padding: 0;

    box-sizing: border-box;

    overflow: hidden;
}


/* ==========================================================
   11. DAILY TRAVEL EXPENSES - BAR CHART
   ========================================================== */

#analyticsResults
.analytics-chart:has(#analyticsDailyChart)
.analytics-canvas-wrap {
    height: var(--analytics-chart-height);
}


/* ==========================================================
   12. TRAVEL METHOD - DOUGHNUT / PIE CHART
   ========================================================== */

#analyticsResults
.analytics-chart:has(#analyticsMethodChart)
.analytics-canvas-wrap {
    height: var(--analytics-pie-height);
}


/* ==========================================================
   13. MONTHLY TRAVEL EXPENSES - LINE CHART
   ========================================================== */

#analyticsResults
.analytics-chart:has(#analyticsMonthlyChart)
.analytics-canvas-wrap {
    height: var(--analytics-chart-height);
}


/* ==========================================================
   14. OVERTIME HOURS - LINE CHART
   ========================================================== */

#analyticsResults
.analytics-chart:has(#analyticsOvertimeChart)
.analytics-canvas-wrap {
    height: var(--analytics-overtime-height);
}


/* ==========================================================
   15. CHART.JS CANVAS

   Prevent canvas from expanding beyond its wrapper.
   ========================================================== */

#analyticsResults .analytics-canvas-wrap canvas {
    display: block;

    width: 100% !important;
    height: 100% !important;

    max-width: 100% !important;
    max-height: 100% !important;

    min-width: 0;
    min-height: 0;

    margin: 0;
    padding: 0;

    box-sizing: border-box;
}


/* ==========================================================
   16. GENERATED INSIGHTS
   ========================================================== */

#analyticsResults .analytics-insights {
    width: 100%;
    min-width: 0;

    margin-top: 20px;
    padding: clamp(12px, 1.5vw, 20px);

    box-sizing: border-box;

    background: var(--analytics-card-background);

    border: 1px solid var(--border);
    border-radius: 12px;
}


/* Insights list */

#analyticsResults .analytics-insights ul {
    margin: 12px 0 0;
    padding-left: 20px;
}


/* Insight items */

#analyticsResults .analytics-insights li {
    margin-bottom: 10px;

    color: var(--text);

    font-size: 14px;
    line-height: 1.6;

    overflow-wrap: anywhere;
}


#analyticsResults .analytics-insights li:last-child {
    margin-bottom: 0;
}


/* ==========================================================
   17. TABLET - MAX 900px
   ========================================================== */

@media (max-width: 900px) {

    .analytics-container {
        --analytics-chart-height: 200px;
        --analytics-pie-height: 180px;
        --analytics-overtime-height: 190px;

        margin-block: 14px 20px;
        gap: 14px;
    }

    #analyticsResults .analytics-grid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

    #analyticsResults .analytics-charts {
        grid-template-columns:
            minmax(0, 1fr);
    }

    #analyticsResults .analytics-chart {
        max-width: 100%;
    }
}


/* ==========================================================
   18. MOBILE - MAX 600px
   ========================================================== */

@media (max-width: 600px) {

    .analytics-container {
        --analytics-chart-height: 190px;
        --analytics-pie-height: 170px;
        --analytics-overtime-height: 180px;

        width: calc(100% - 2 * var(--page-gutter));

        margin: 12px auto 18px;
        gap: 12px;
    }

    #generateAnalytics {
        width: 100%;
        min-height: 46px;

        padding: 12px 14px;

        font-size: 16px;
    }

    #analyticsResults {
        padding: 12px;
        border-radius: 12px;
    }

    #analyticsResults .analytics-grid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));

        gap: 10px;
    }

    #analyticsResults .analytics-card {
        padding: 12px;
        gap: 8px;
    }

    #analyticsResults .analytics-card i {
        font-size: 18px;
    }

    #analyticsResults .analytics-card span {
        font-size: 12px;
    }

    #analyticsResults .analytics-card strong {
        font-size: 18px;
    }

    #analyticsResults .analytics-charts {
        grid-template-columns:
            minmax(0, 1fr);

        gap: 12px;
    }

    #analyticsResults .analytics-chart {
        max-width: 100%;
        padding: 12px;
    }

    #analyticsResults .analytics-chart h3 {
        font-size: 14px;
    }

    #analyticsResults .analytics-insights {
        padding: 12px;
    }

    #analyticsResults .analytics-insights li {
        font-size: 13px;
    }
}


/* ==========================================================
   19. SMALL MOBILE - MAX 360px
   ========================================================== */

@media (max-width: 360px) {

    .analytics-container {
        --analytics-chart-height: 170px;
        --analytics-pie-height: 150px;
        --analytics-overtime-height: 165px;
    }

    #generateAnalytics {
        gap: 8px;

        padding: 11px 10px;
        font-size: 15px;
    }

    #analyticsResults {
        padding: 10px;
    }

    #analyticsResults .analytics-grid {
        grid-template-columns:
            minmax(0, 1fr);
    }

    #analyticsResults .analytics-card strong {
        font-size: 20px;
    }

    #analyticsResults .analytics-chart {
        padding: 10px;
    }
}


/* ==========================================================
   20. VERY NARROW SCREENS - MAX 260px
   ========================================================== */

@media (max-width: 260px) {

    .analytics-container {
        --analytics-chart-height: 150px;
        --analytics-pie-height: 135px;
        --analytics-overtime-height: 145px;

        gap: 8px;
    }

    #generateAnalytics {
        padding: 10px 8px;
        font-size: 13px;
    }

    #analyticsResults {
        padding: 8px;
        border-radius: 9px;
    }
}


/* ==========================================================
   21. REDUCED MOTION
   ========================================================== */

@media (prefers-reduced-motion: reduce) {

    #generateAnalytics {
        transition: none;
    }
}

/* ==========================================
   DATE RANGE SELECTOR - THEME ADAPTIVE
   ========================================== */

#analyticsDateRange {
    appearance: none;
    -webkit-appearance: none;

    padding: 10px 38px 10px 15px;
    min-width: 115px;

    font-family: inherit;
    font-size: 14px;
    font-weight: 600;

    color: var(--text, #202123);
    background-color: var(--surface, #ffffff);

    border: 1px solid var(--border, #d1d5db);
    border-radius: 12px;

    cursor: pointer;
    outline: none;

    /* Dropdown arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;

    color-scheme: light;

    transition:
        border-color 0.25s ease,
        background-color 0.25s ease,
        box-shadow 0.25s ease,
        transform 0.25s ease;
}

/* Hover */
#analyticsDateRange:hover {
    border-color: var(--primary, #087bff);
    background-color:
        var(--surface-secondary, var(--surface, #ffffff));

    transform: translateY(-1px);
}

/* Focus */
#analyticsDateRange:focus {
    border-color: var(--primary, #087bff);
    box-shadow: 0 0 0 4px rgba(8, 123, 255, 0.12);
}

/* Dropdown options */
#analyticsDateRange option {
    background-color: var(--surface, #ffffff);
    color: var(--text, #202123);
    font-size: 14px;
    padding: 10px;
}

/* ==========================================
   DARK + AMOLED THEMES
   ========================================== */

[data-theme="dark"] #analyticsDateRange,
[data-theme="amoled"] #analyticsDateRange {
    color-scheme: dark;

    /* Light arrow for dark backgrounds */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23cbd5e1' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* ==========================================
   MOBILE
   ========================================== */

@media (max-width: 425px) {
    #analyticsDateRange {
        min-width: 100px;
        padding: 8px 34px 8px 12px;
        font-size: 13px;
        border-radius: 10px;
    }
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */

@media (prefers-reduced-motion: reduce) {
    #analyticsDateRange {
        transition: none;
    }
}
