/* ============================================
   LOHMIA SAAS RESPONSIVE FIX v1.0
   Correcciones de responsividad para saas.html
   ============================================ */

/* === GLOBAL OVERFLOW PREVENTION === */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* === SAAS CONTAINER === */
.saas-container {
    width: 100%;
    max-width: 100%;
    padding: 0 8px;
    margin: 0 auto;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* === DASHBOARD CONTAINER === */
.dashboard {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* === MAIN CONTENT === */
.main-content {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding: 80px 16px 20px 16px;
    box-sizing: border-box;
}

/* === VIEW CONTAINERS === */
.view,
#dashboardView,
#tenantsView,
#apiKeysView,
#billingView,
#reportsView,
#settingsView {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* === PAGINATION FIX === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 24px;
    padding: 16px;
    background: var(--bg-secondary, #1e293b);
    border: 1px solid var(--border-color, #475569);
    border-radius: 12px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.pagination button {
    padding: 8px 12px;
    min-width: 40px;
    flex-shrink: 0;
}

.pagination select,
.pagination #pageLimit,
.pagination #pageLimitAPIKeys {
    padding: 8px 10px;
    max-width: 120px;
    width: auto;
    flex-shrink: 1;
    min-width: 80px;
}

.pagination span {
    white-space: nowrap;
    font-size: 0.85rem;
}

/* === TABLES FIX === */
.table-container,
.data-table-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    min-width: 600px; /* Allow horizontal scroll on small screens */
}

/* === STATS CARDS === */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 100%;
}

.stat-card {
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

/* === CHARTS GRID === */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    width: 100%;
    max-width: 100%;
}

.chart-container {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

/* === FORMS AND INPUTS === */
input, select, textarea, button {
    max-width: 100%;
    box-sizing: border-box;
}

.form-group {
    width: 100%;
    max-width: 100%;
}

/* === SEARCH BAR === */
.search-bar,
#globalSearch {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* === VIEW HEADER === */
.view-header {
    width: 100%;
    max-width: 100%;
    padding: 0 0 16px 0;
}

.view-header h1,
.view-header h2 {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* === ACTION BUTTONS === */
.action-buttons,
.header-actions,
.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    max-width: 100%;
}

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

/* TABLET (768px) */
@media (max-width: 768px) {
    .main-content {
        padding: 70px 12px 16px 12px;
        margin-left: 0 !important;
    }

    .saas-container {
        padding: 0 4px;
    }

    .pagination {
        padding: 12px;
        gap: 6px;
    }

    .pagination button {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .pagination select {
        padding: 6px 8px;
        font-size: 0.85rem;
        max-width: 100px;
    }

    .stats-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-value {
        font-size: 1.5rem;
    }
}

/* MOBILE SMALL (600px) */
@media (max-width: 600px) {
    .main-content {
        padding: 65px 8px 12px 8px;
    }

    .pagination {
        flex-direction: column;
        align-items: stretch;
        padding: 10px;
    }

    .pagination > * {
        width: 100%;
        text-align: center;
    }

    .pagination button {
        width: 100%;
        padding: 10px;
    }

    .pagination select {
        width: 100%;
        max-width: 100%;
    }

    .pagination span {
        order: -1;
        margin-bottom: 8px;
    }

    .stats-cards {
        grid-template-columns: 1fr;
    }
}

/* MOBILE EXTRA SMALL (480px) */
@media (max-width: 480px) {
    .main-content {
        padding: 60px 6px 10px 6px;
    }

    .saas-container {
        padding: 0 2px;
    }

    .view-header h1,
    .view-header h2 {
        font-size: 1.2rem;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-change {
        font-size: 0.7rem;
    }

    /* Force single column for pagination controls */
    .pagination {
        gap: 8px;
    }

    .pagination button {
        font-size: 0.8rem;
        padding: 8px;
    }
}

/* =============================================
   MODAL FIXES
   ============================================= */

.modal,
.modal-overlay {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

.modal-content {
    width: calc(100% - 32px);
    max-width: 500px;
    margin: 20px auto;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

@media (max-width: 600px) {
    .modal-content {
        width: calc(100% - 16px);
        margin: 10px auto;
        max-height: calc(100vh - 20px);
    }
}

/* =============================================
   SIDEBAR FIXES
   ============================================= */

@media (max-width: 768px) {
    .sidebar {
        display: none !important;
    }

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

/* =============================================
   TOAST NOTIFICATIONS
   ============================================= */

.toast {
    max-width: calc(100vw - 48px);
    right: 24px;
    left: auto;
}

@media (max-width: 480px) {
    .toast {
        right: 8px;
        left: 8px;
        max-width: calc(100vw - 16px);
    }
}

/* =============================================
   DATA TABLES
   ============================================= */

.tenants-table,
.api-keys-table {
    width: 100%;
    overflow-x: auto;
}

.tenants-table table,
.api-keys-table table {
    min-width: 800px;
}

/* Scrollable table wrapper */
.table-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
}

/* Table cell truncation */
td, th {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    td, th {
        max-width: 120px;
        padding: 8px 6px;
        font-size: 0.85rem;
    }
}

/* =============================================
   BILLING/REPORTS SECTIONS
   ============================================= */

.billing-summary,
.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    width: 100%;
}

@media (max-width: 600px) {
    .billing-summary,
    .reports-grid {
        grid-template-columns: 1fr;
    }
}

/* =============================================
   UTILITY CLASSES
   ============================================= */

.w-full {
    width: 100% !important;
}

.max-w-full {
    max-width: 100% !important;
}

.overflow-hidden {
    overflow: hidden !important;
}

.overflow-x-auto {
    overflow-x: auto !important;
}

.flex-wrap {
    flex-wrap: wrap !important;
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
