/* Mobile-first utility overrides for Sure CRM */

/* ===================================
   BASE / VIEWPORT
   =================================== */
html, body {
    overflow-x: hidden;
}

img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* ===================================
   TOPBAR / SIDEBAR
   =================================== */
@media (max-width: 1024px) {
    .modern-topbar.with-sidebar {
        padding-left: 1rem !important;
    }

    .mobile-menu-toggle {
        display: block !important;
    }

    .modern-sidebar {
        transform: translateX(-100%);
    }

    .modern-sidebar.show {
        transform: translateX(0);
    }

    .modern-main {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem !important;
    }

    .sidebar-overlay.show {
        display: block;
    }
}

@media (max-width: 480px) {
    .modern-topbar {
        padding: 0 0.75rem !important;
    }

    .topbar-brand {
        font-size: 1rem !important;
    }

    .topbar-actions .dropdown-menu {
        position: fixed !important;
        top: var(--topbar-height) !important;
        left: 0.5rem !important;
        right: 0.5rem !important;
        width: auto !important;
    }
}

/* ===================================
   PAGE HEADER
   =================================== */
.page-header .d-flex.justify-content-between,
.page-header .d-flex.justify-content-between.align-items-start,
.page-header .d-flex.justify-content-between.align-items-center {
    flex-wrap: wrap;
    gap: 1rem;
}

@media (max-width: 768px) {
    .page-header .d-flex.justify-content-between,
    .page-header .d-flex.justify-content-between.align-items-start,
    .page-header .d-flex.justify-content-between.align-items-center {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    .page-title {
        font-size: 1.5rem !important;
    }

    .page-subtitle {
        font-size: 0.875rem !important;
    }
}

/* ===================================
   CARDS
   =================================== */
@media (max-width: 768px) {
    .modern-card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem;
    }

    .modern-card-body {
        padding: 1rem !important;
    }

    .card-header {
        flex-wrap: wrap;
    }
}

/* ===================================
   BUTTON GROUPS
   =================================== */
.btn-group-modern,
.page-header .btn-group-modern,
.modern-card-header .btn-group-modern {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.btn-group-modern .btn-modern,
.btn-group-modern .btn,
.btn-group-modern a {
    flex: 0 1 auto;
}

@media (max-width: 768px) {
    .btn-group-modern,
    .page-header .btn-group-modern,
    .modern-card-header .btn-group-modern {
        width: 100%;
    }

    .btn-group-modern .btn-modern,
    .btn-group-modern .btn,
    .btn-group-modern a {
        flex: 1 1 auto;
        min-width: 44px;
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .btn-group-modern .btn-modern,
    .btn-group-modern .btn,
    .btn-group-modern a {
        flex: 1 1 100%;
    }
}

/* ===================================
   TABLES
   =================================== */
.table-responsive-modern,
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.75rem;
}

.table-modern,
.table {
    min-width: 640px;
}

@media (max-width: 640px) {
    .table-mobile-cards,
    .table-responsive-modern .table-mobile-cards,
    .table-responsive .table-mobile-cards {
        min-width: 0;
        border: none;
    }

    .table-mobile-cards thead,
    .table-mobile-cards tbody,
    .table-mobile-cards th,
    .table-mobile-cards td,
    .table-mobile-cards tr {
        display: block;
    }

    .table-mobile-cards thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .table-mobile-cards tr {
        margin-bottom: 1rem;
        background: white;
        border: 1px solid var(--border-color, #E5E7EB);
        border-radius: 0.75rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        padding: 0.75rem;
    }

    .table-mobile-cards td {
        border: none;
        border-bottom: 1px solid var(--border-color, #E5E7EB);
        position: relative;
        padding-left: 40% !important;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .table-mobile-cards td:last-child {
        border-bottom: none;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        position: absolute;
        left: 0.75rem;
        width: 35%;
        font-weight: 600;
        color: var(--text-secondary, #6B7280);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
}

/* ===================================
   PAGINATION
   =================================== */
.pagination {
    flex-wrap: wrap;
    gap: 0.25rem;
}

@media (max-width: 576px) {
    .pagination .page-item:first-child .page-link::before {
        content: "\f100";
        font-family: "Font Awesome 6 Free";
        font-weight: 900;
    }

    .pagination .page-item:first-child .page-link {
        font-size: 0;
    }

    .pagination .page-item:last-child .page-link::before {
        content: "\f101";
        font-family: "Font Awesome 6 Free";
        font-weight: 900;
    }

    .pagination .page-item:last-child .page-link {
        font-size: 0;
    }

    .pagination .page-link {
        padding: 0.375rem 0.625rem;
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* ===================================
   FORMS
   =================================== */
.form-row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -0.5rem;
    margin-left: -0.5rem;
}

.form-row > [class*="col-"] {
    padding-right: 0.5rem;
    padding-left: 0.5rem;
    flex: 1 0 0%;
    max-width: 100%;
}

@media (max-width: 768px) {
    .form-row > [class*="col-md"],
    .form-row > [class*="col-lg"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

.input-group-append,
.input-group-prepend {
    display: flex;
}

.input-group > .form-control,
.input-group > .form-select,
.input-group > .input-group-text,
.input-group > .btn {
    min-height: 44px;
}

.form-control,
.form-select,
.form-control-modern,
textarea,
select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"] {
    min-height: 44px;
    font-size: 16px; /* prevent iOS zoom on focus */
}

/* ===================================
   EMBEDDED STYLES / FIXED WIDTHS
   =================================== */
[style*="width:"] {
    max-width: 100%;
}

[style*="width: "] {
    max-width: 100%;
}

@media (max-width: 768px) {
    .dashboard-welcome {
        padding: 1.5rem 1rem !important;
    }

    .dashboard-welcome h1 {
        font-size: 1.5rem !important;
    }

    .chart-container-wrapper {
        height: 220px !important;
    }

    .stat-card,
    .info-box-modern,
    .quick-actions-card {
        padding: 1rem !important;
    }

    .stat-icon,
    .info-box-icon {
        width: 2.5rem !important;
        height: 2.5rem !important;
        font-size: 1rem !important;
    }

    .stat-value,
    .info-box-content h3 {
        font-size: 1.5rem !important;
    }
}

/* ===================================
   PORTAL LAYOUT
   =================================== */
@media (max-width: 768px) {
    .portal-content {
        padding: 1rem 0 2rem !important;
    }

    .portal-tabs {
        overflow-x: auto;
        flex-wrap: nowrap !important;
    }

    .portal-tab-btn {
        flex: 0 0 auto;
    }

    .portal-tab-btn span {
        display: none;
    }
}

/* ===================================
   UTILITY HELPERS
   =================================== */
@media (max-width: 768px) {
    
    .hide-mobile {
        display: none !important;
    }

    .break-mobile {
        flex-basis: 100%;
    }

    .text-truncate-mobile {
        white-space: normal !important;
    }
}

@media (min-width: 769px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* ===================================
   TOUCH TARGETS
   =================================== */
.btn,
.nav-link,
.dropdown-item,
.page-link,
.form-check-input {
    min-height: 44px;
    min-width: 44px;
}

.btn-sm,
.btn-modern-sm,
.page-link {
    min-height: 36px;
    min-width: 36px;
}


/* ===================================
   COMPACT ACTION BUTTONS ON MOBILE
   =================================== */
@media (max-width: 768px) {
    .page-header .btn-group-modern .btn-modern,
    .page-header .btn-group-modern .btn,
    .modern-card-header .btn-group-modern .btn-modern,
    .modern-card-header .btn-group-modern .btn {
        flex: 0 0 auto;
        min-width: 36px;
        min-height: 36px;
        padding: 0.5rem;
    }

    .page-header .btn-group-modern .btn-modern span,
    .page-header .btn-group-modern .btn span,
    .modern-card-header .btn-group-modern .btn-modern span,
    .modern-card-header .btn-group-modern .btn span {
        display: none;
    }
}


/* ===================================
   FOOTER
   =================================== */
@media (max-width: 1024px) {
    footer.footer {
        margin-left: 0 !important;
        width: 100% !important;
    }

    footer.footer .d-flex.justify-content-between {
        justify-content: center !important;
        text-align: center;
    }
}
