/* ============================================
   RESPONSIVE.CSS — Media queries
   Dashboard Clientes — Acelera tu CRM
   ============================================ */

/* --- Global overflow protection (aplica siempre) --- */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

.app-layout,
.main-content,
.content {
    min-width: 0;
    max-width: 100%;
}

.content {
    overflow-x: hidden;
}

/* Flex/grid children don't grow past their container */
.chart-card,
.card,
.scorecard,
.bento-item,
.scorecard-grid > *,
.grid-2 > *,
.grid-3 > *,
.grid-2-1 > *,
.grid-1-2 > *,
.bento-grid > * {
    min-width: 0;
    max-width: 100%;
}

/* Charts nunca desbordan su card */
.chart-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.chart-container .apexcharts-canvas,
.chart-container svg {
    max-width: 100% !important;
}

/* Tablas: scroll interno, nunca empujan el layout */
.data-table-wrapper {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Tablet (≤1024px) --- */
@media (max-width: 1024px) {
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }

    .scorecard-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

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

    .bento-item.span-3,
    .bento-item.span-4 { grid-column: span 2; }
}

/* --- Mobile (≤768px) --- */
@media (max-width: 768px) {
    /* Sidebar hidden by default */
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Show hamburger */
    .menu-toggle {
        display: flex;
    }

    /* Show overlay when sidebar open */
    .sidebar-overlay.active {
        display: block;
    }

    /* Main content full width */
    .main-content {
        margin-left: 0;
        width: 100%;
    }

    /* Compact top bar */
    .top-bar {
        padding: var(--space-sm) var(--space-md);
        padding-left: 56px;
        flex-wrap: wrap;
        gap: var(--space-sm);
    }

    .top-bar-left {
        flex-direction: column;
        gap: 2px;
        min-width: 0;
        flex: 1;
    }

    .top-bar-right {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .section-title {
        font-size: var(--font-size-md);
    }

    /* Filters scroll horizontally within their bar */
    .filters-bar {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }

    .filter-date {
        width: 200px;
        flex-shrink: 0;
    }

    .filter-select {
        flex-shrink: 0;
    }

    /* Hide preset pills on mobile to save space */
    .pill-tabs {
        display: none;
    }

    /* Hide top bar branding on mobile */
    .top-bar-brand {
        display: none;
    }

    /* Content padding reduced */
    .content {
        padding: var(--space-md);
    }

    /* Scorecards: 2 columns */
    .scorecard-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: var(--space-sm);
    }

    .scorecard {
        padding: var(--space-md);
    }

    .scorecard-value {
        font-size: var(--font-size-lg);
        word-break: break-word;
    }

    .scorecard-label {
        font-size: var(--font-size-xs);
    }

    /* Charts smaller */
    .chart-container {
        min-height: 220px;
    }

    /* Grids: all collapse to 1 col */
    .grid-2, .grid-3, .grid-2-1, .grid-1-2 {
        grid-template-columns: 1fr !important;
        gap: var(--space-md);
    }

    /* Tables */
    .data-table {
        font-size: var(--font-size-xs);
    }

    .data-table th,
    .data-table td {
        padding: var(--space-xs) var(--space-sm);
    }

    /* Card padding compact */
    .card, .chart-card {
        padding: var(--space-md);
    }

    /* Chart card headers wrap */
    .chart-card-header {
        flex-wrap: wrap;
        gap: var(--space-sm);
    }

    .chart-card-title {
        font-size: var(--font-size-sm);
    }

    /* Bento grid: 1 col */
    .bento-grid {
        grid-template-columns: 1fr !important;
    }

    .bento-item.span-2,
    .bento-item.span-3,
    .bento-item.span-4 { grid-column: span 1 !important; }

    /* Funnel vertical */
    .funnel-step {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-xs);
    }

    .funnel-step-info {
        text-align: left;
        min-width: auto;
        display: flex;
        gap: var(--space-sm);
        flex-wrap: wrap;
    }

    .funnel-with-cumulative {
        flex-direction: column;
    }

    .funnel-cumulative {
        width: 100%;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
    }

    /* Any inline grids dentro de secciones */
    [class*="grid-"] {
        grid-template-columns: 1fr !important;
    }

    /* Forms vs Landing / tablas comparativas flex */
    .comparison-row,
    .split-row {
        flex-direction: column;
        gap: var(--space-sm);
    }

    /* Tabs sticky con scroll */
    .tabs-nav,
    .tab-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        white-space: nowrap;
    }

    /* Bloquea cualquier min-width accidental en children */
    .chart-card *,
    .card * {
        max-width: 100%;
    }

    /* Imágenes siempre fluid */
    img {
        max-width: 100%;
        height: auto;
    }
}

/* --- Small Mobile (≤480px) --- */
@media (max-width: 480px) {
    .scorecard-grid {
        grid-template-columns: 1fr !important;
    }

    .top-bar {
        padding-left: 48px;
    }

    .filter-select {
        font-size: 11px;
        padding: 5px 24px 5px 8px;
    }

    .filter-date {
        width: 170px;
        font-size: 11px;
    }

    .chart-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }

    .chart-container {
        min-height: 200px;
    }

    .content {
        padding: var(--space-sm);
    }

    /* Scorecards smaller padding en super-pequeño */
    .scorecard {
        padding: var(--space-sm) var(--space-md);
    }

    .scorecard-value {
        font-size: var(--font-size-md);
    }

    /* Section title truncate si es necesario */
    .section-title {
        font-size: var(--font-size-sm);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: calc(100vw - 80px);
    }
}
