/* =====================================================
   B2B.nu — Mobile Redesign Stylesheet
   Loaded AFTER app.css. Overrides & enhances mobile UX.
   DO NOT add desktop styles here.
   ===================================================== */

/* =====================================================
   1. MOBILE DESIGN TOKENS
   ===================================================== */

@media (max-width: 991.98px) {
    :root {
        --navbar-height: 52px;
        --mobile-bottom-nav: 60px;
        --mobile-content-pb: 76px;
    }
}

/* =====================================================
   2. BOTTOM NAVIGATION BAR
   ===================================================== */

.mobile-bottom-nav {
    display: none;
}

@media (max-width: 991.98px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--mobile-bottom-nav) + env(safe-area-inset-bottom, 0px));
        background: #ffffff;
        border-top: 1px solid var(--border-medium);
        z-index: 1050;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
    }

    .mobile-bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 0.65rem;
        font-weight: 500;
        padding: 6px 4px;
        border: none;
        background: none;
        cursor: pointer;
        transition: color var(--transition-fast);
        position: relative;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-bottom-nav-item i {
        font-size: 1.25rem;
        line-height: 1;
    }

    .mobile-bottom-nav-item span {
        line-height: 1;
        letter-spacing: 0.01em;
    }

    .mobile-bottom-nav-item.active {
        color: var(--primary-color);
    }

    .mobile-bottom-nav-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 3px;
        background: var(--primary-color);
        border-radius: 0 0 3px 3px;
    }

    .mobile-bottom-nav-item:active {
        color: var(--primary-color);
        opacity: 0.7;
    }

    /* Push main content above bottom nav */
    body .main-content {
        padding-bottom: var(--mobile-content-pb) !important;
    }
}

/* =====================================================
   2b. MOBILE FULL-PAGE MENU
   ===================================================== */

.mobile-menu-page {
    display: none;
}

@media (max-width: 991.98px) {
    body.mobile-menu-open {
        overflow: hidden;
    }

    .mobile-menu-page {
        display: none;
        position: fixed;
        top: var(--navbar-height);
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        z-index: 1040;
        background: #f8f9fa;
        transform: translateY(100%);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(var(--mobile-bottom-nav) + env(safe-area-inset-bottom, 0px));
        box-sizing: border-box;
    }

    .mobile-menu-page.is-visible {
        display: block;
    }

    .mobile-menu-page.open {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    body .sidebar-overlay {
        pointer-events: none;
    }

    body.sidebar-open .sidebar-overlay {
        pointer-events: auto;
    }

    .mobile-menu-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem 1.25rem;
        border-bottom: 1px solid var(--border-light, #e9ecef);
        background: #fff;
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .mobile-menu-header h5 {
        margin: 0;
        font-size: 1.1rem;
        font-weight: 600;
    }

    .mobile-menu-close {
        font-size: 1.3rem !important;
        color: var(--text-secondary, #495057) !important;
        padding: 0.25rem !important;
        line-height: 1;
    }

    .mobile-menu-fiscal-year {
        padding: 1rem 1.25rem 0.25rem;
        background: #fff;
        border-bottom: 1px solid var(--border-light, #e9ecef);
    }

    .mobile-menu-fiscal-year-label {
        display: block;
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-secondary, #6c757d);
        margin-bottom: 0.4rem;
    }

    .mobile-menu-fiscal-year .form-select {
        font-size: 1rem;
        padding: 0.55rem 2rem 0.55rem 0.75rem;
    }

    .mobile-menu-fiscal-year-value {
        font-size: 1rem;
        font-weight: 600;
        color: var(--text-primary, #212529);
        padding: 0.4rem 0;
    }

    .mobile-menu-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        padding: 1.25rem;
        max-width: 100%;
        box-sizing: border-box;
    }

    .mobile-menu-tile {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
        aspect-ratio: 1;
        min-width: 0;
        background: #fff;
        border-radius: 16px;
        border: 1px solid var(--border-light, #e9ecef);
        text-decoration: none;
        color: var(--text-secondary, #495057);
        font-size: 0.78rem;
        overflow: hidden;
        word-break: break-word;
        font-weight: 500;
        padding: 12px 8px;
        transition: background 0.15s, border-color 0.15s;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-menu-tile i {
        font-size: 1.6rem;
        line-height: 1;
    }

    .mobile-menu-tile span {
        text-align: center;
        line-height: 1.2;
    }

    .mobile-menu-tile:active {
        background: var(--surface-highlight, #e9ecef);
    }

    .mobile-menu-tile.active {
        color: var(--primary-color, #0d6efd);
        border-color: var(--primary-color, #0d6efd);
        background: rgba(13, 110, 253, 0.04);
    }
}

/* =====================================================
   3. NAVBAR REFINEMENTS
   ===================================================== */

@media (max-width: 991.98px) {
    body .navbar {
        height: auto !important;
        min-height: var(--navbar-height) !important;
        padding-top: max(0.35rem, env(safe-area-inset-top, 0px)) !important;
        padding-bottom: 0.35rem !important;
    }

    body .navbar .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Mobile header logo */
    .mobile-header-logo {
        display: flex;
        align-items: center;
        margin-left: 0.25rem;
        text-decoration: none;
        flex-shrink: 0;
    }

    .mobile-header-logo img {
        height: 28px;
        width: auto;
    }

    /* Fiscal year: compact */
    body .navbar .fiscal-year-select,
    body .navbar #fiscalYearForm .form-select {
        font-size: 0.75rem !important;
        padding: 0.2rem 1.5rem 0.2rem 0.4rem !important;
        min-height: 32px !important;
        max-width: 80px;
    }

    /* Uniform icon style for all navbar buttons */
    body .navbar .btn-link {
        padding: 0 !important;
        width: 36px;
        height: 36px;
        font-size: 1.2rem !important;
        line-height: 1 !important;
        color: #ffffff !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        vertical-align: middle;
    }

    body .navbar .btn-link:hover,
    body .navbar .btn-link:focus,
    body .navbar .btn-link:active {
        color: #ffffff !important;
    }

    /* Company switcher: borderless icon on mobile */
    body .navbar .navbar-company-btn {
        border: none !important;
        background: none !important;
        box-shadow: none !important;
        padding: 0 0.25rem !important;
        font-size: 1.2rem !important;
        color: #ffffff !important;
        height: 36px;
        display: inline-flex;
        align-items: center;
    }

    body .navbar .navbar-company-btn:hover,
    body .navbar .navbar-company-btn:focus,
    body .navbar .navbar-company-btn:active {
        color: #ffffff !important;
    }

    body .navbar .navbar-company-btn::after {
        display: none !important;
    }

    /* Fiscal-year single-year badge: white on mobile */
    body .navbar .fiscal-year-badge {
        background: transparent !important;
        border: none !important;
        color: #ffffff !important;
    }

    /* Constrain navbar dropdowns so they fit the mobile viewport */
    body .navbar .dropdown-menu {
        max-width: calc(100vw - 16px);
    }

    body .navbar .dropdown-menu .dropdown-item {
        white-space: normal;
        overflow-wrap: break-word;
        flex-wrap: wrap;
        row-gap: 0.25rem;
    }

    /* Reduce spacing between navbar items */
    body .navbar .me-3 {
        margin-right: 0.4rem !important;
    }
}

/* Extra small screens: hide company name, fiscal year text */
@media (max-width: 480px) {
    body .navbar .navbar-company-btn .d-md-inline {
        display: none !important;
    }

    body .navbar #fiscalYearForm {
        display: none !important;
    }

    body .navbar .fiscal-year-badge {
        display: none !important;
    }
}

/* =====================================================
   4. SIDEBAR DRAWER — GPU-accelerated
   ===================================================== */

@media (max-width: 991.98px) {
    body .sidebar {
        margin-left: 0 !important;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
        top: var(--navbar-height) !important;
        height: calc(100dvh - var(--navbar-height)) !important;
        max-height: calc(100dvh - var(--navbar-height)) !important;
    }

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

    /* Darker overlay */
    body .sidebar-overlay {
        top: var(--navbar-height) !important;
        background: rgba(0, 0, 0, 0.6) !important;
        transition: opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    /* Nav items: bigger touch targets */
    body .sidebar .nav-link {
        padding: 0.75rem 1.25rem !important;
        font-size: 0.9rem !important;
        min-height: 48px;
        display: flex !important;
        align-items: center !important;
    }

    body .sidebar .nav-link i {
        font-size: 1.15rem;
        min-width: 28px;
    }
}

/* =====================================================
   5. TYPOGRAPHY & SPACING
   ===================================================== */

@media (max-width: 767.98px) {
    /* Better mobile readability */
    body {
        line-height: 1.6;
        -webkit-text-size-adjust: 100%;
    }

    /* Tighter page titles */
    body h1,
    body .h3 {
        font-size: 1.25rem;
    }

    body h2 {
        font-size: 1.15rem;
    }

    /* Breadcrumbs: more compact */
    body .breadcrumb {
        font-size: 0.75rem;
        margin-bottom: 0.5rem;
    }

    body .breadcrumb-item + .breadcrumb-item::before {
        padding: 0 0.3rem;
    }
}

@media (max-width: 480px) {
    body .container-fluid {
        padding-left: 0.65rem !important;
        padding-right: 0.65rem !important;
    }

    body h1,
    body .h3 {
        font-size: 1.15rem;
    }
}

/* =====================================================
   6. CARDS & SURFACES
   ===================================================== */

@media (max-width: 767.98px) {
    body .card {
        border-radius: var(--radius-md);
        box-shadow: none;
        border: 1px solid var(--card-border);
    }

    body .card-body {
        padding: 0.85rem;
    }

    body .card-header {
        padding: 0.65rem 0.85rem;
    }

    body .card-footer {
        padding: 0.65rem 0.85rem;
    }

    /* Dashboard cards: compact */
    body .dashboard-card {
        border-radius: var(--radius-md);
        box-shadow: none;
    }

    /* Reduce vertical card spacing */
    body .card.mb-4 {
        margin-bottom: 0.85rem !important;
    }

    body .mb-4 {
        margin-bottom: 0.75rem !important;
    }
}

/* =====================================================
   7. MOBILE CARD VIEW ENHANCEMENTS
   ===================================================== */

@media (max-width: 767.98px) {
    /* Status accent bars on mobile cards */
    body .mobile-card {
        border-radius: var(--radius-md);
        border-left: 3px solid var(--border-medium);
        padding: 0.85rem;
        box-shadow: none;
        border-top: 1px solid var(--card-border);
        border-right: 1px solid var(--card-border);
        border-bottom: 1px solid var(--card-border);
    }

    /* Status variants */
    body .mobile-card[data-status="paid"],
    body .mobile-card[data-status="betald"],
    body .mobile-card.status-paid {
        border-left-color: var(--color-success);
    }

    body .mobile-card[data-status="overdue"],
    body .mobile-card[data-status="förfallen"],
    body .mobile-card.status-overdue {
        border-left-color: var(--color-danger);
    }

    body .mobile-card[data-status="sent"],
    body .mobile-card[data-status="skickad"],
    body .mobile-card.status-sent {
        border-left-color: var(--color-info);
    }

    body .mobile-card[data-status="draft"],
    body .mobile-card[data-status="utkast"],
    body .mobile-card.status-draft {
        border-left-color: var(--text-light);
    }

    /* Better title sizing */
    body .mobile-card-title {
        max-width: calc(100vw - 140px);
        font-size: 0.95rem;
    }

    body .mobile-card-header {
        margin-bottom: 0.6rem;
        padding-bottom: 0.6rem;
    }

    /* Better value alignment */
    body .mobile-card-row {
        padding: 0.15rem 0;
    }

    body .mobile-card-label {
        font-size: 0.8rem;
    }

    body .mobile-card-value {
        font-size: 0.875rem;
    }

    /* Action buttons: equal width */
    body .mobile-card-actions {
        margin-top: 0.6rem;
        padding-top: 0.6rem;
    }

    body .mobile-card-actions .btn {
        flex: 1 1 0;
        text-align: center;
        font-size: 0.8rem;
        min-height: 38px;
    }
}

/* =====================================================
   8. TABLES & DATA DISPLAY
   ===================================================== */

@media (max-width: 767.98px) {
    /* Scroll shadow indicator on right edge */
    body .table-responsive {
        position: relative;
    }

    body .table-responsive::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 24px;
        background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.04));
        pointer-events: none;
        z-index: 1;
        opacity: 1;
        transition: opacity 0.2s;
    }

    /* Scrolled to end — hide indicator */
    body .table-responsive.scrolled-end::after {
        opacity: 0;
    }

    /* Compact table headers */
    body .table thead th {
        font-size: 0.7rem;
        padding: 0.4rem;
        letter-spacing: 0.03em;
    }

    body .table tbody td {
        padding: 0.45rem 0.4rem;
        font-size: 0.82rem;
    }
}

@media (max-width: 480px) {
    body .table-responsive table {
        font-size: 0.78rem;
    }

    body .table tbody td {
        padding: 0.35rem 0.3rem;
    }
}

/* =====================================================
   9. FORMS & INPUTS
   ===================================================== */

@media (max-width: 767.98px) {
    /* Input groups: stack on narrow screens */
    body .input-group:not(.flex-nowrap) {
        flex-wrap: wrap;
    }

    body .input-group:not(.flex-nowrap) > .form-control,
    body .input-group:not(.flex-nowrap) > .form-select {
        width: 100%;
        border-radius: var(--radius-sm) !important;
        margin-bottom: 0.25rem;
    }

    body .input-group:not(.flex-nowrap) > .btn {
        width: 100%;
        border-radius: var(--radius-sm) !important;
    }

    /* Better form labels */
    body .form-label {
        font-size: 0.85rem;
        margin-bottom: 0.3rem;
        font-weight: 500;
    }

    /* Tom Select: better touch targets */
    body .ts-wrapper .ts-control {
        min-height: 44px !important;
        padding: 0.4rem 0.75rem !important;
        font-size: 1rem !important;
    }

    body .ts-wrapper .ts-dropdown {
        font-size: 0.9rem;
    }

    body .ts-wrapper .ts-dropdown .option {
        padding: 0.6rem 0.75rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Textarea: reasonable mobile size */
    body textarea.form-control {
        min-height: 80px;
    }

    /* Date inputs */
    body input[type="date"].form-control,
    body .smart-date-field {
        min-width: 0;
    }

    /* Help text: more readable */
    body .form-text {
        font-size: 0.78rem;
        line-height: 1.4;
    }

    /* Better switch/checkbox spacing */
    body .form-check {
        padding-left: 2rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    body .form-switch {
        padding-left: 3rem;
    }
}

/* =====================================================
   10. DASHBOARD WIDGETS
   ===================================================== */

@media (max-width: 767.98px) {
    /* Cashflow widget: stack chart + legend */
    body .dashboard-card .row > [class*="col-5"],
    body .dashboard-card .row > [class*="col-7"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Health gauge: fit mobile */
    body .dashboard-card canvas {
        max-width: 100%;
        height: auto !important;
    }

    /* Todo items: bigger tap area */
    body .todo-item {
        padding: 0.85rem;
        border-radius: var(--radius-md);
    }

    body .todo-checkbox {
        width: 28px;
        height: 28px;
    }

    /* Activity feed: prevent overflow */
    body .activity-item {
        overflow: hidden;
    }

    body .activity-item .text-truncate {
        max-width: calc(100vw - 120px);
    }

    /* Widget headers: compact */
    body .dashboard-card .card-header {
        padding: 0.6rem 0.85rem;
    }

    body .dashboard-card .card-header h5,
    body .dashboard-card .card-header .h5 {
        font-size: 0.9rem;
    }
}

/* =====================================================
   11. KPI & STAT CARDS
   ===================================================== */

@media (max-width: 480px) {
    /* KPIs: 2x2 grid for info density */
    body .kpi-col {
        padding: 0.5rem 0.75rem;
    }

    body .kpi-value {
        font-size: 1.15rem;
    }

    body .kpi-label {
        font-size: 0.7rem;
    }

    body .kpi-badge {
        font-size: 0.65rem;
        padding: 0.15rem 0.35rem;
    }

    /* Stat cards: tighter */
    body .row.g-3.mb-4 .card-body {
        padding: 0.6rem;
    }

    body .row.g-3.mb-4 .h3 {
        font-size: 1.1rem;
    }

    body .row.g-3.mb-4 .h4 {
        font-size: 0.95rem;
    }

    body .row.g-3.mb-4 small,
    body .row.g-3.mb-4 .text-muted {
        font-size: 0.72rem;
    }
}

/* =====================================================
   12. KANBAN TABS
   ===================================================== */

@media (max-width: 767.98px) {
    /* Tab bar for kanban column switching */
    body .kanban-mobile-tabs {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0.4rem;
        padding: 0.5rem 0;
        margin-bottom: 0.75rem;
        scroll-snap-type: x mandatory;
    }

    body .kanban-mobile-tabs::-webkit-scrollbar {
        display: none;
    }

    body .kanban-tab {
        flex: 0 0 auto;
        padding: 0.45rem 0.85rem;
        border-radius: var(--radius-pill);
        border: 1px solid var(--border-medium);
        background: var(--card-bg);
        color: var(--text-secondary);
        font-size: 0.82rem;
        font-weight: 500;
        cursor: pointer;
        white-space: nowrap;
        transition: all var(--transition-fast);
        scroll-snap-align: center;
        -webkit-tap-highlight-color: transparent;
    }

    body .kanban-tab.active,
    body .kanban-tab.selected {
        background: var(--primary-color);
        color: #fff;
        border-color: var(--primary-color);
    }

    body .kanban-tab .badge {
        font-size: 0.7rem;
        margin-left: 0.3rem;
    }

    /* Hide inactive columns, show active */
    body .kanban-column {
        display: none !important;
    }

    body .kanban-column.active {
        display: block !important;
    }
}

/* =====================================================
   13. MODALS — FULL SCREEN
   ===================================================== */

@media (max-width: 767.98px) {
    body .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        min-height: 100vh;
        min-height: 100dvh;
    }

    body .modal-content {
        border-radius: 0 !important;
        border: none !important;
        min-height: 100vh;
        min-height: 100dvh;
    }

    body .modal-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: #fff;
        border-radius: 0;
        padding: 0.75rem 1rem;
    }

    /* Swipe handle indicator */
    body .modal-header::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: var(--border-medium);
        border-radius: 2px;
    }

    body .modal-header .modal-title {
        font-size: 1rem;
        padding-top: 6px;
    }

    body .modal-body {
        padding: 1rem;
    }

    body .modal-footer {
        position: sticky;
        bottom: 0;
        background: #fff;
        border-top: 1px solid var(--border-light);
        padding: 0.75rem 1rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }

    body .modal-footer .btn {
        flex: 1 1 0;
    }

    /* Offcanvas: full width */
    body .offcanvas {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* =====================================================
   14. PAGINATION
   ===================================================== */

@media (max-width: 767.98px) {
    /* Simplified pagination: hide middle page numbers */
    body .pagination {
        justify-content: center;
        gap: 0.25rem;
    }

    body .pagination .page-item:not(:first-child):not(:last-child):not(.active):not(.disabled) {
        display: none;
    }

    body .pagination .page-link {
        border-radius: var(--radius-sm) !important;
        font-size: 0.85rem;
        min-width: 44px;
        min-height: 44px;
    }

    /* Show current page indicator */
    body .pagination .page-item.active .page-link {
        font-weight: 600;
        min-width: 48px;
    }
}

/* =====================================================
   15. ALERTS & FLASH MESSAGES
   ===================================================== */

@media (max-width: 767.98px) {
    body .alert {
        padding: 0.65rem 0.85rem;
        font-size: 0.85rem;
        border-radius: var(--radius-sm);
        margin-bottom: 0.75rem;
    }

    body .alert .btn-close {
        padding: 0.75rem;
        min-width: 44px;
        min-height: 44px;
    }

    body .alert i {
        font-size: 1rem;
    }
}

/* =====================================================
   16. BUG REPORT BUTTON — Reposition above bottom nav
   ===================================================== */

@media (max-width: 991.98px) {
    body .bug-report-container {
        transform: scale(0.78) !important;
        transform-origin: bottom right !important;
        bottom: calc(var(--mobile-bottom-nav) + 12px) !important;
        right: 12px !important;
    }
}

@media (max-width: 480px) {
    body .bug-report-container {
        transform: scale(0.66) !important;
    }
}

/* =====================================================
   17. BULK ACTIONS BAR — Above bottom nav
   ===================================================== */

@media (max-width: 991.98px) {
    body .bulk-action-bar {
        bottom: calc(var(--mobile-bottom-nav) + 12px) !important;
        left: 0.75rem !important;
        right: 0.75rem !important;
        transform: none !important;
        border-radius: var(--radius-md);
        padding: 0.5rem 0.75rem;
    }

    body .bulk-action-bar .btn {
        font-size: 0.8rem;
        min-height: 38px;
    }
}

/* =====================================================
   18. FLOATING ACTION BUTTON (FAB)
   ===================================================== */

@media (max-width: 767.98px) {
    .mobile-fab {
        position: fixed !important;
        bottom: calc(var(--mobile-bottom-nav) + 16px);
        right: 16px;
        z-index: 1040;
        width: 52px;
        height: 52px;
        border-radius: 50% !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 14px rgba(79, 125, 243, 0.35);
        font-size: 0 !important;
    }

    .mobile-fab i {
        font-size: 1.3rem !important;
    }

    .mobile-fab span:not(:has(i)) {
        display: none;
    }
}

/* =====================================================
   19. TOUCH & INTERACTION
   ===================================================== */

@media (max-width: 991.98px) {
    /* Remove tap highlight on all interactive elements */
    a,
    button,
    .btn,
    .nav-link,
    .dropdown-item,
    .page-link,
    .form-check-input,
    .form-select,
    [role="button"] {
        -webkit-tap-highlight-color: transparent;
    }

    /* Eliminate 300ms tap delay */
    a,
    button,
    .btn,
    input,
    select,
    textarea {
        touch-action: manipulation;
    }

    /* Scroll snap for horizontal scrollers */
    .nav-pills,
    .nav-tabs {
        scroll-snap-type: x proximity;
    }

    .nav-pills .nav-item,
    .nav-tabs .nav-item {
        scroll-snap-align: center;
    }

    /* Smooth scrolling for all scrollable areas */
    .table-responsive,
    .kanban-board,
    .offcanvas-body {
        -webkit-overflow-scrolling: touch;
    }

    /* Disable hover effects on touch (they cause sticky hover) */
    @media (hover: none) {
        body .card:hover {
            box-shadow: var(--shadow-card);
        }

        body .todo-item:hover {
            border-color: var(--border-light);
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.01);
        }

        body .btn:hover {
            filter: none;
        }
    }
}

/* =====================================================
   20. PWA STANDALONE MODE
   ===================================================== */

@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top, 0px);
    }

    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Extra padding for safe area */
    body .modal-footer {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }
}

/* =====================================================
   21. SUPPORT CHAT — Mobile adjustments
   ===================================================== */

@media (max-width: 767.98px) {
    body .support-chat-offcanvas {
        width: 100vw !important;
    }

    /* Keep input above bottom nav */
    body .support-chat-footer {
        padding-bottom: calc(12px + var(--mobile-bottom-nav) + env(safe-area-inset-bottom, 0px));
    }

    body .support-chat-messages {
        padding: 12px;
    }

    body .support-chat-msg {
        max-width: 95%;
        font-size: 0.85rem;
    }
}

/* =====================================================
   22. PAGE HEADERS — Better mobile layout
   ===================================================== */

@media (max-width: 767.98px) {
    /* Page header: tighter */
    body .content > .container-fluid > .d-flex:first-child {
        gap: 0.5rem;
    }

    /* Action buttons in header: full width, compact */
    body .d-flex.justify-content-between .btn {
        font-size: 0.82rem;
        padding: 0.4rem 0.65rem;
    }

    /* Badges: compact */
    body .badge {
        font-size: 0.72rem;
        padding: 0.3rem 0.5rem;
    }
}

/* =====================================================
   23. DROPDOWN MENUS — Better mobile
   ===================================================== */

@media (max-width: 767.98px) {
    body .dropdown-menu {
        font-size: 0.9rem;
        border-radius: var(--radius-md);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    }

    body .dropdown-header {
        font-size: 0.72rem;
    }
}

/* =====================================================
   24. LIST GROUPS — Touch friendly
   ===================================================== */

@media (max-width: 767.98px) {
    body .list-group-item {
        padding: 0.75rem 0.85rem;
        font-size: 0.9rem;
        min-height: 48px;
        display: flex;
        align-items: center;
    }

    body .list-group-item-action:active {
        background: var(--surface-highlight);
    }
}

/* =====================================================
   25. INVOICE FORM — Mobile optimizations
   ===================================================== */

@media (max-width: 767.98px) {
    /* Invoice line cards: tighter */
    body .invoice-line-table tbody tr {
        padding: 0.75rem;
        border-radius: var(--radius-md);
    }

    body .invoice-line-table td::before {
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

    /* Total summary: prominent */
    body .invoice-totals,
    body .card-body .fw-bold.fs-5 {
        font-size: 1.05rem !important;
    }
}

/* =====================================================
   26. EMPTY STATES — Better mobile
   ===================================================== */

@media (max-width: 767.98px) {
    body .text-center.py-5 {
        padding: 2rem 1rem !important;
    }

    body .text-center.py-5 .display-4,
    body .text-center.py-5 .fs-1 {
        font-size: 2.5rem !important;
    }

    body .text-center.py-5 p {
        font-size: 0.9rem;
    }
}

/* =====================================================
   27. TABLET REFINEMENTS (768px - 991.98px)
   Tablets get the mobile chrome (drawer sidebar, dark navbar,
   bottom nav) but desktop content sizing — these rules adapt
   the in-between range so layouts feel intentional rather than
   cramped-desktop or stretched-mobile.
   ===================================================== */

@media (min-width: 768px) and (max-width: 991.98px) {
    /* --- Container: comfortable horizontal padding --- */
    body .content > .container-fluid {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    /* --- Page headers: keep horizontal but allow wrap when buttons grow --- */
    body .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    body .d-flex.justify-content-between.align-items-center.mb-4 > .d-flex.gap-2 {
        flex-wrap: wrap;
    }

    /* --- Stat-card grids: 4-up too cramped, drop to 2-up at md.
       Many index pages use `row.g-3.mb-4 > col-md-3` for KPI tiles. --- */
    body .row.g-3.mb-4 > .col-md-3:not(.col-6):not(.col-12),
    body .row.g-3.mb-4 > .col-md-4:not(.col-6):not(.col-12) {
        flex: 0 0 50%;
        max-width: 50%;
    }

    body .row.g-3.mb-4 .card-body {
        padding: 0.85rem 1rem;
    }

    body .row.g-3.mb-4 .h3 {
        font-size: 1.4rem;
    }

    body .row.g-3.mb-4 .fs-1 {
        font-size: 1.75rem !important;
    }

    body .row.g-3.mb-4 .rounded-circle.p-3 {
        padding: 0.6rem !important;
    }

    /* --- Filter forms inside cards: 2-up instead of 4/6-up --- */
    body .filter-form .col-md-2,
    body .filter-form .col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* --- KPI widget (Verksamheten just nu): 5 auto-cols too tight,
       use 3-up with row borders --- */
    body .dashboard-card .row.g-0 > .kpi-col {
        flex: 0 0 33.333%;
        max-width: 33.333%;
        padding: 0.85rem 0.85rem;
        border-bottom: 1px solid var(--border-medium);
    }

    body .dashboard-card .row.g-0 > .kpi-col:nth-child(3n) {
        border-right: none;
    }

    body .dashboard-card .row.g-0 > .kpi-col:nth-last-child(-n+2):nth-child(n+4),
    body .dashboard-card .row.g-0 > .kpi-col:last-child {
        border-bottom: none;
    }

    body .dashboard-card .kpi-value {
        font-size: 1.3rem;
    }

    /* --- Buttons: medium touch targets (smaller than mobile, larger than desktop) --- */
    body .btn:not(.btn-link):not(.page-link):not(.mobile-bottom-nav-item):not(.btn-close):not(.btn-sm) {
        min-height: 38px;
        padding-top: 0.45rem;
        padding-bottom: 0.45rem;
    }

    body .btn-sm {
        min-height: 32px;
    }

    /* --- Form controls: comfortable on touch --- */
    body .form-control,
    body .form-select,
    body .input-group-text {
        min-height: 38px;
        font-size: 0.95rem;
    }

    body .ts-wrapper .ts-control {
        min-height: 38px !important;
        font-size: 0.95rem !important;
        padding: 0.4rem 0.75rem !important;
    }

    /* --- Modals: don't overflow viewport, keep some breathing room --- */
    body .modal-dialog {
        margin: 1.25rem auto;
        max-width: 90vw;
    }

    body .modal-lg,
    body .modal-xl {
        max-width: 90vw;
    }

    /* --- Offcanvas: leave breathing room on the side --- */
    body .offcanvas-w-680,
    body .offcanvas-end:not(.offcanvas-sm):not(.offcanvas-md):not(.offcanvas-lg):not(.offcanvas-xl) {
        width: 70vw !important;
        max-width: 600px !important;
    }

    body .support-chat-offcanvas {
        width: 60vw !important;
        max-width: 520px !important;
    }

    /* --- Dropdowns: don't overflow viewport --- */
    body .dropdown-menu {
        max-width: calc(100vw - 24px);
    }

    /* --- Tables: keep tabular layout, but slightly compact rows --- */
    body .table thead th {
        font-size: 0.78rem;
        padding-top: 0.55rem;
        padding-bottom: 0.55rem;
    }

    body .table tbody td {
        padding-top: 0.55rem;
        padding-bottom: 0.55rem;
        font-size: 0.875rem;
    }

    /* --- Pagination: balanced touch target --- */
    body .pagination .page-link {
        min-width: 38px;
        min-height: 38px;
    }

    /* --- List groups: touch-friendly --- */
    body .list-group-item {
        padding: 0.7rem 1rem;
        min-height: 44px;
    }

    /* --- Mobile menu (hamburger drawer) grid: 4 columns at tablet --- */
    body .mobile-menu-grid {
        grid-template-columns: repeat(4, 1fr);
        padding: 1.5rem;
        gap: 14px;
    }

    body .mobile-menu-tile {
        font-size: 0.85rem;
        padding: 14px 10px;
    }

    body .mobile-menu-tile i {
        font-size: 1.7rem;
    }

    /* --- Bottom nav: slightly larger items on tablet (more room available) --- */
    body .mobile-bottom-nav-item {
        font-size: 0.72rem;
    }

    body .mobile-bottom-nav-item i {
        font-size: 1.4rem;
    }

    /* --- Layout-grid (CRM company show): 3 columns on tablet --- */
    body .layout-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* --- Document grid (archive/expense docs): 3 cols on tablet --- */
    body #docGridInner .col-4 {
        flex: 0 0 33.333%;
        max-width: 33.333%;
    }

    /* --- Bug-report floating button: less aggressive scale than mobile --- */
    body .bug-report-container {
        transform: scale(0.85) !important;
        transform-origin: bottom right !important;
    }

    /* --- Page title sizing: slightly larger than mobile --- */
    body h1,
    body .h3 {
        font-size: 1.4rem;
    }

    body h2 {
        font-size: 1.2rem;
    }
}

/* =====================================================
   28. PRINT PROTECTION
   ===================================================== */

@media print {
    .mobile-bottom-nav,
    .mobile-fab {
        display: none !important;
    }
}
