/*
 * Site-wide mobile compatibility layer.
 *
 * This file is intentionally limited to mobile breakpoints so every page keeps
 * its existing desktop appearance. Page-specific responsive rules still win
 * where they are more specific; these rules provide safe fallbacks elsewhere.
 */

@media (max-width: 768px) {
    html {
        max-width: 100%;
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    body {
        width: 100%;
        max-width: 100%;
        min-width: 0 !important;
        overflow-x: hidden;
    }

    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

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

    .container,
    .wrapper,
    .page-container,
    .dashboard-container,
    .content-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding-inline: 16px !important;
    }

    .main,
    main,
    .main-content,
    .main-area,
    .content,
    .content-area,
    .dashboard-content,
    .page-content {
        max-width: 100%;
        min-width: 0;
    }

    h1 {
        font-size: clamp(1.5rem, 7vw, 2rem) !important;
        line-height: 1.2;
        overflow-wrap: anywhere;
    }

    h2 {
        font-size: clamp(1.25rem, 5.5vw, 1.65rem) !important;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }

    h3,
    h4,
    p,
    a,
    label,
    span {
        overflow-wrap: anywhere;
    }

    .header,
    .topbar,
    .navbar,
    .page-header,
    .dashboard-header,
    .section-header,
    .header-content,
    .header-actions,
    .toolbar,
    .actions,
    .action-buttons,
    .button-group,
    .filter-actions {
        max-width: 100%;
        flex-wrap: wrap !important;
        gap: 10px;
    }

    .nav-links,
    .nav-menu,
    .tabs,
    .tab-list,
    .subnav,
    .breadcrumb {
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .row,
    .form-row,
    .form-grid,
    .filter-row,
    .filters-grid,
    .search-filter,
    .search-filters,
    .dashboard-grid,
    .content-grid,
    .profile-grid,
    .details-grid,
    .two-column,
    .two-columns {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .stats-grid,
    .cards-grid,
    .card-grid,
    .summary-grid,
    .metrics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .card,
    .panel,
    .section,
    .widget,
    .stat-card,
    .content-card,
    .form-card {
        max-width: 100%;
        min-width: 0;
    }

    input,
    select,
    textarea,
    button,
    .btn {
        max-width: 100%;
        font-size: 16px;
    }

    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
    select,
    textarea {
        width: 100%;
        min-width: 0;
    }

    button,
    .btn,
    [role="button"] {
        min-height: 44px;
        touch-action: manipulation;
    }

    textarea {
        resize: vertical;
    }

    table {
        display: block;
        width: 100% !important;
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    th,
    td {
        min-width: max-content;
    }

    th {
        white-space: nowrap;
    }

    .table-container,
    .table-responsive,
    .table-wrapper,
    .responsive-table {
        width: 100%;
        max-width: 100%;
        overflow-x: auto !important;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
    }

    .modal,
    .modal-overlay,
    .dialog-overlay {
        padding: 12px !important;
    }

    .modal-content,
    .dialog,
    [role="dialog"] {
        width: min(100%, 42rem) !important;
        max-width: 100% !important;
        max-height: calc(100dvh - 24px) !important;
        margin: auto !important;
        overflow-y: auto;
    }

    .sidebar {
        max-width: min(86vw, 320px);
    }

    pre,
    code,
    .code-block {
        max-width: 100%;
        overflow-x: auto;
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }

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

@media (max-width: 480px) {
    .container,
    .wrapper,
    .page-container,
    .dashboard-container,
    .content-wrapper {
        padding-inline: 12px !important;
    }

    .stats-grid,
    .cards-grid,
    .card-grid,
    .summary-grid,
    .metrics-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .header-actions,
    .actions,
    .action-buttons,
    .button-group,
    .filter-actions {
        width: 100%;
    }

    .header-actions > .btn,
    .actions > .btn,
    .action-buttons > .btn,
    .button-group > .btn,
    .filter-actions > .btn {
        flex: 1 1 auto;
    }

    .card,
    .panel,
    .section,
    .widget,
    .content-card,
    .form-card,
    .modal-content,
    .dialog,
    [role="dialog"] {
        padding-inline: 14px;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .modal-content,
    .dialog,
    [role="dialog"] {
        max-height: calc(100dvh - 16px) !important;
    }
}

