/* ==========================================================
   GUIDANCE DATA ANALYTICS
   Separate stylesheet
   ========================================================== */

* {
    box-sizing: border-box;
}

.analytics-page {
    width: min(100%, 1180px);
    margin: 0 auto;
    padding: 24px 28px 40px;
    background: #f5f7fb;
    min-height: calc(100vh - 70px);
}

.analytics-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 22px;
}

.analytics-head h1 {
    margin: 0;
    color: #172b4d;
    font-size: 28px;
}

.analytics-head p {
    margin: 6px 0 0;
    color: #68788d;
}

.analytics-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.analytics-actions button {
    border: 0;
    border-radius: 7px;
    padding: 10px 14px;
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}

.print-btn {
    background: #0d6efd;
    color: #fff;
}

.filter-card {
    background: #fff;
    border: 1px solid #e7ebf1;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.filter-form {
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
}

.field label {
    font-size: 12px;
    font-weight: 700;
    color: #516173;
}

.field input {
    height: 40px;
    border: 1px solid #d8dee8;
    border-radius: 7px;
    padding: 0 10px;
}

.apply-btn {
    height: 40px;
    border: 0;
    border-radius: 7px;
    background: #173f7a;
    color: #fff;
    padding: 0 18px;
    font-weight: 700;
    cursor: pointer;
}

/* ==========================================================
   SUMMARY CARDS
   ========================================================== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: #fff;
    border: 1px solid #e7ebf1;
    border-radius: 12px;
    padding: 18px;
    min-height: 115px;
}

.stat-label {
    font-size: 12px;
    color: #708096;
    font-weight: 700;
    text-transform: uppercase;
}

.stat-value {
    font-size: 29px;
    font-weight: 800;
    color: #173f7a;
    margin-top: 9px;
}

.stat-note {
    font-size: 11px;
    color: #8a96a5;
    margin-top: 4px;
}

/* ==========================================================
   VERTICAL ANALYTICS LAYOUT
   One main panel per row.
   This prevents the page from becoming too wide.
   ========================================================== */

.analytics-stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.panel {
    width: 100%;
    background: #fff;
    border: 1px solid #e7ebf1;
    border-radius: 12px;
    padding: 20px;
    min-width: 0;
}

.panel h2 {
    font-size: 17px;
    margin: 0;
    color: #172b4d;
}

.panel p {
    font-size: 12px;
    color: #7b8797;
    margin: 5px 0 14px;
}

.chart-box {
    position: relative;
    width: 100%;
    height: 310px;
}

/* Smaller panels can sit vertically too, but remain readable. */
.insight-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.insight {
    border: 1px solid #e6ebf2;
    border-radius: 9px;
    padding: 14px;
    background: #fafbfd;
}

.insight strong {
    display: block;
    color: #173f7a;
    font-size: 14px;
    margin-bottom: 5px;
}

.insight span {
    font-size: 12px;
    color: #697789;
    line-height: 1.5;
}

.projection-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.projection-table th,
.projection-table td {
    padding: 10px;
    border-bottom: 1px solid #edf0f4;
    text-align: left;
    font-size: 13px;
}

.projection-table th {
    color: #65748a;
    font-size: 11px;
    text-transform: uppercase;
}

.trend-badge {
    display: inline-flex;
    padding: 5px 9px;
    border-radius: 20px;
    background: #eef5ff;
    color: #1757a6;
    font-size: 12px;
    font-weight: 700;
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */

@media (max-width: 900px) {
    .analytics-page {
        width: 100%;
        padding: 18px;
    }

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

    .insight-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .analytics-page {
        padding: 14px;
    }

    .analytics-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .stat-grid {
        grid-template-columns: 1fr;
    }

    .field {
        min-width: 100%;
    }

    .apply-btn {
        width: 100%;
    }

    .chart-box {
        height: 280px;
    }
}

/* ==========================================================
   PRINT
   ========================================================== */

@media print {
    .sidebar,
    .navbar,
    .analytics-actions,
    .filter-card {
        display: none !important;
    }

    .main {
        margin: 0 !important;
        width: 100% !important;
    }

    .analytics-page {
        width: 100% !important;
        padding: 0 !important;
        background: #fff !important;
    }

    .panel,
    .stat-card {
        break-inside: avoid;
    }
}


/* ==========================================================
   MODERN ANALYTICS ENHANCEMENTS
   ========================================================== */

.analytics-page {
    background:
        radial-gradient(circle at top right,
        rgba(37, 99, 235, 0.045),
        transparent 35%),
        #f5f7fb;
}

.analytics-head h1 {
    letter-spacing: -0.5px;
}

.filter-card,
.stat-card,
.panel {
    box-shadow:
        0 8px 25px rgba(15, 23, 42, 0.045);
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease,
        border-color 0.2s ease;
}

.filter-card:hover,
.stat-card:hover,
.panel:hover {
    box-shadow:
        0 14px 35px rgba(15, 23, 42, 0.075);
}

.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(
        180deg,
        #2563eb,
        #7c3aed
    );
}

.stat-value {
    letter-spacing: -0.8px;
}

.panel {
    overflow: hidden;
}

.panel h2 {
    letter-spacing: -0.2px;
}

.chart-box {
    height: 350px;
    padding: 8px 4px 2px;
}

#statusChart {
    max-width: 100%;
}

#statusChart + * {
    margin-top: 4px;
}

.trend-badge {
    box-shadow:
        0 4px 12px rgba(23, 87, 166, 0.10);
}

@media (max-width: 600px) {
    .chart-box {
        height: 300px;
    }
}

@media print {
    .filter-card,
    .analytics-actions {
        display: none !important;
    }

    .panel,
    .stat-card {
        box-shadow: none !important;
    }

    .analytics-page {
        background: #fff !important;
    }
}



/* ==========================================================
   FINAL PRINT FIX
   - Hides sidebar/navbar/filter/actions
   - Removes layout offsets
   - Keeps every analytics panel intact
   - Prevents horizontal clipping
   - Uses legal paper (8.5 x 13)
   ========================================================== */

@media print {

    @page {
        size: 8.5in 13in;
        margin: 0.45in;
    }

    html,
    body {
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        background: #ffffff !important;
    }

    /* Hide navigation and controls */
    .sidebar,
    aside.sidebar,
    #sidebar,
    .navbar,
    nav.navbar,
    .topbar,
    .top-navbar,
    .main-navbar,
    header.navbar,
    .analytics-actions,
    #printAnalytics,
    .filter-card,
    .filter-form,
    button,
    .no-print {
        display: none !important;
    }

    /* Remove common sidebar/main-content offsets */
    .main,
    .main-content,
    .content,
    .content-wrapper,
    .page-content,
    .dashboard-content,
    .dashboard-main,
    .analytics-page {
        position: static !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: none !important;
        min-height: 0 !important;
        transform: none !important;
        overflow: visible !important;
    }

    .analytics-page {
        display: block !important;
        background: #ffffff !important;
    }

    .analytics-head {
        display: flex !important;
        width: 100% !important;
        margin: 0 0 16px !important;
        padding: 0 !important;
        break-after: avoid !important;
        page-break-after: avoid !important;
    }

    .analytics-stack {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        width: 100% !important;
        overflow: visible !important;
    }

    .stat-grid {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        width: 100% !important;
        gap: 8px !important;
        margin: 0 0 12px !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .stat-card {
        min-height: 90px !important;
        padding: 12px !important;
        box-shadow: none !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .stat-value {
        font-size: 22px !important;
    }

    .panel {
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 14px !important;
        overflow: visible !important;
        box-shadow: none !important;

        /*
         * Keep each chart and its title together.
         * If it cannot fit, the whole panel moves to the next page.
         */
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .panel h2,
    .panel p {
        break-after: avoid !important;
        page-break-after: avoid !important;
    }

    .chart-box {
        position: relative !important;
        width: 100% !important;
        height: 300px !important;
        max-height: 300px !important;
        padding: 4px 0 !important;
        overflow: visible !important;

        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .chart-box canvas,
    canvas {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        overflow: visible !important;

        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .insight-grid,
    .insight,
    .projection-table,
    .trend-badge {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .insight-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
    }

    .projection-table {
        width: 100% !important;
        table-layout: fixed !important;
    }

    .projection-table th,
    .projection-table td {
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
    }

    /*
     * Do not allow any parent to create a clipped print viewport.
     */
    .analytics-page *,
    .analytics-stack *,
    .panel *,
    .chart-box * {
        overflow-x: visible !important;
    }

    /*
     * Preserve chart/background colors in the printed output.
     */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    a {
        color: inherit !important;
        text-decoration: none !important;
    }
}

/*
 * JS adds this class immediately before printing.
 * It guarantees charts are in a stable state.
 */
.analytics-printing .panel,
.analytics-printing .chart-box {
    overflow: visible !important;
}

