/* 
 * Mobile-Friendly Dashboard Layout for ERPAthos
 * 
 * This CSS ensures all dashboard widgets/cards are stacked vertically
 * on mobile devices (< 768px) while preserving the desktop grid layout.
 * 
 * Breakpoints:
 * - Mobile: < 768px (stacked layout)
 * - Tablet: 768px - 1023px (partial grid)
 * - Desktop: >= 1024px (full grid preserved)
 */

/* ==========================================
   MOBILE: < 768px - Stack All Widgets/Cards
   ========================================== */
@media (max-width: 767px) {
    /* Force all dashboard cards to full width (stacked) */
    .container-fluid .row > [class*="col-"],
    .container .row > [class*="col-"],
    .row > [class*="col-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        width: 100% !important;
        margin-bottom: 1rem;
    }

    /* Reduce container padding for mobile */
    .container-fluid,
    .container {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Stack header sections vertically */
    .d-flex.justify-content-between,
    .d-flex.justify-content-between.align-items-center {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem;
    }

    /* Center page titles on mobile - scoped to dashboard containers */
    .container-fluid h1, 
    .container-fluid h2, 
    .container-fluid h3,
    .support-dashboard h1,
    .support-dashboard h2,
    .support-dashboard h3 {
        text-align: center;
    }

    .container-fluid .text-muted,
    .support-dashboard .text-muted {
        text-align: center;
    }

    /* Stack button groups vertically */
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }

    .btn-group > .btn {
        width: 100%;
        border-radius: 0.375rem !important;
    }

    /* Touch-optimized buttons */
    .btn {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 1rem;
    }

    /* Card optimizations */
    .card {
        border-radius: 8px;
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card h3, .card h4 {
        font-size: 1.25rem;
    }

    .card p {
        font-size: 0.875rem;
    }

    /* Responsive tables - rely on Bootstrap's .table-responsive */
    table {
        font-size: 0.875rem;
    }

    /* Charts and visualizations */
    canvas {
        max-width: 100%;
        height: auto !important;
    }

    .chart-container {
        position: relative;
        height: 250px !important;
        margin-bottom: 1rem;
    }

    /* Action buttons at top of page */
    .d-flex.gap-2 {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    .d-flex.gap-2 > .btn {
        width: 100%;
    }
}

/* ==========================================
   EXTRA SMALL MOBILE: < 480px
   ========================================== */
@media (max-width: 479px) {
    /* Even tighter spacing */
    .container-fluid,
    .container {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Scoped heading sizes for dashboards */
    .container-fluid h1,
    .support-dashboard h1 {
        font-size: 1.5rem;
    }

    .container-fluid h2,
    .support-dashboard h2 {
        font-size: 1.3rem;
    }

    .container-fluid h3,
    .support-dashboard h3 {
        font-size: 1.1rem;
    }

    .card-body {
        padding: 0.75rem;
    }

    .btn {
        padding: 10px 12px;
        font-size: 0.95rem;
    }
}

/* ==========================================
   VERY SMALL SCREENS: < 360px
   ========================================== */
@media (max-width: 359px) {
    /* Minimal layout for very small phones */
    .container-fluid,
    .container {
        padding-left: 6px;
        padding-right: 6px;
    }

    /* Scoped heading size for very small screens */
    .container-fluid h1,
    .support-dashboard h1 {
        font-size: 1.3rem;
    }

    .card-body {
        padding: 0.5rem;
    }

    /* Simplify charts on tiny screens */
    .chart-container {
        height: 200px !important;
    }

    /* Hide optional visual elements on tiny screens */
    .fa-2x, .fa-3x {
        font-size: 1.25rem !important;
    }
}

/* ==========================================
   DESKTOP: >= 1024px - Preserve Grid Layout
   ========================================== */
@media (min-width: 1024px) {
    /* Ensure desktop grid classes work as expected */
    .row > .col-lg-1 { flex: 0 0 8.333333%; max-width: 8.333333%; }
    .row > .col-lg-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }
    .row > .col-lg-3 { flex: 0 0 25%; max-width: 25%; }
    .row > .col-lg-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
    .row > .col-lg-6 { flex: 0 0 50%; max-width: 50%; }
    .row > .col-lg-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }
    .row > .col-lg-9 { flex: 0 0 75%; max-width: 75%; }
    .row > .col-lg-12 { flex: 0 0 100%; max-width: 100%; }

    /* Desktop spacing */
    .container-fluid {
        padding-left: 24px;
        padding-right: 24px;
    }
}

/* ==========================================
   LEGACY: Support Dashboard Specific Styles
   ========================================== */
.support-dashboard {
    padding: 20px;
}

@media (max-width: 767px) {
    .support-dashboard {
        padding: 10px;
    }

    /* Agent cards */
    .support-dashboard .agent-card {
        margin-bottom: 12px;
    }
}

@media (max-width: 479px) {
    .support-dashboard {
        padding: 8px;
    }

    /* Force single column on small phones */
    .support-dashboard .row.g-3 > [class*="col-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}
