/* Global mobile adaptation for public + admin pages */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

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

* {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.table-container,
.table-responsive,
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-menu-toggle {
    display: none;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #1f2937;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    flex: 0 0 40px;
}

.mobile-menu-toggle.active {
    background: #16a34a;
    border-color: #16a34a;
    color: #ffffff;
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 1024px) {
    .container,
    .section-container,
    .footer-container,
    .footer-nav-container,
    .agreement-container,
    .main-content,
    .content,
    .card,
    .module-card {
        max-width: 100%;
    }

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

    .agreement-content {
        padding: 24px !important;
    }
}

@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

    body {
        overflow-x: hidden !important;
    }

    nav,
    .top-nav {
        width: 100%;
        left: 0;
        right: 0;
    }

    .top-nav {
        padding: 10px 12px !important;
        height: auto !important;
        min-height: 0 !important;
    }

    .top-nav-left,
    .top-nav-right {
        width: 100%;
        min-width: 0;
        gap: 10px !important;
        flex-wrap: wrap;
    }

    .mobile-menu-toggle {
        display: inline-flex;
    }

    .top-nav-right .logout-btn {
        width: 100%;
        justify-content: center;
    }

    .main-container {
        margin-top: 80px !important;
    }

    .content {
        margin-left: 0 !important;
        padding: 12px !important;
    }

    .dashboard-footer {
        margin-left: 0 !important;
        padding: 16px 12px;
    }

    .sidebar {
        max-width: min(82vw, 300px);
        position: fixed;
        left: 0;
        top: 72px;
        bottom: 0;
        z-index: 1202;
    }

    .sidebar-overlay.show {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(2, 6, 23, 0.45);
        z-index: 1201;
    }

    .card-header,
    .card-body,
    .module-header,
    .module-body {
        padding: 14px !important;
    }

    .card-header,
    .module-header,
    .profile-modal-actions,
    .form-actions,
    .action-bar,
    .toolbar,
    .list-toolbar,
    .filter-bar {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
    }

    .profile-modal,
    .modal-content,
    .dialog,
    .panel {
        width: calc(100vw - 24px) !important;
        max-width: calc(100vw - 24px) !important;
        margin: 0 auto;
    }

    .search-box,
    .search-box input,
    .nav-search,
    .nav-search input,
    .search-suggestions,
    .form-control,
    input,
    select,
    textarea,
    button,
    .btn {
        max-width: 100%;
    }

    .auth-switch {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .login-layout {
        grid-template-columns: 1fr !important;
    }

    .login-card,
    .design-panel {
        padding: 16px !important;
    }

    .message,
    #toast-container.toast-top-center,
    #toast-container.toast-top-center > div {
        min-width: 0 !important;
        width: calc(100vw - 24px) !important;
        max-width: calc(100vw - 24px) !important;
        left: 50%;
        transform: translateX(-50%);
    }

    .stats-row,
    .system-info-grid,
    .dashboard-grid,
    .quick-links,
    .biz-stats,
    .insights-grid,
    .join-grid,
    .trend-legend,
    .subpage-nav {
        grid-template-columns: 1fr !important;
    }

    #agreements-panel .agreement-item-header {
        flex-direction: column;
        align-items: flex-start;
    }

    #agreements-panel .expand-btn {
        width: 100%;
        text-align: center;
    }

    table,
    .table {
        min-width: 620px;
    }

    .footer-nav-container {
        grid-template-columns: 1fr !important;
    }

    .footer-contact {
        border-left: none !important;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
    }

    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .logo,
    .page-title,
    .hero h1,
    .agreement-header h1 {
        font-size: clamp(1.15rem, 5.5vw, 1.4rem) !important;
        line-height: 1.35;
    }

    .hero,
    .card,
    .agreement-content,
    .module-hero {
        border-radius: 12px !important;
    }

    .card,
    .module-card,
    .agreement-content {
        padding: 12px !important;
    }
}
