/* ============================================================
   Sefari Customer Portal – Hotfix CSS
   Injected directly into dist to avoid full rebuild.
   ============================================================ */

/* ── Global scroll unlock for portal pages ────────────────── */
html:has(body.sefari-portal) {
    overflow-y: auto !important;
    height: auto !important;
}

body.sefari-portal {
    overflow-y: auto !important;
    height: auto !important;
    max-height: none !important;
}

body.sefari-portal .sefari-next-container,
body.sefari-portal .fleetbase-next-container {
    overflow: visible !important;
    height: auto !important;
    min-height: 100vh !important;
    max-height: none !important;
}

/* ── Order workspace toolbar: keep buttons in a row ───────── */
.sefari-portal .portal-order-workspace-actions {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 0.5rem !important;
}

/* The map/table toggle group */
.sefari-portal .portal-order-view-toggle {
    display: inline-flex !important;
    flex-shrink: 0 !important;
}

/* ── Section header: row layout on all sizes ──────────────── */
.sefari-portal .portal-section-header.portal-order-workspace-header {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.75rem !important;
}

/* ── Mobile-specific overrides (≤ 1024px) ─────────────────── */
@media (max-width: 1024px) {
    /* Keep toolbar horizontal */
    .sefari-portal .portal-order-workspace-actions,
    .sefari-portal .portal-order-workspace-header {
        flex-direction: row !important;
        align-items: center !important;
        flex-wrap: wrap !important;
    }

    /* Sidebar: compact horizontal grid on tablet */
    .sefari-portal .portal-nav-group {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.25rem !important;
    }

    .sefari-portal .portal-nav-label {
        grid-column: 1 / -1 !important;
    }
}

/* ── Small mobile overrides (≤ 640px) ─────────────────────── */
@media (max-width: 640px) {
    /* Keep the order workspace header content flowing */
    .sefari-portal .portal-section-header.portal-order-workspace-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }

    /* But KEEP the actions row horizontal */
    .sefari-portal .portal-order-workspace-actions {
        flex-direction: row !important;
        align-items: center !important;
        gap: 0.375rem !important;
        width: 100% !important;
    }

    /* Buttons: compact sizing on mobile */
    .sefari-portal .portal-order-workspace-actions .btn {
        padding: 0.375rem 0.625rem !important;
        font-size: 0.8125rem !important;
        min-height: 2rem !important;
    }

    .sefari-portal .portal-order-view-toggle .btn {
        padding: 0.375rem 0.5rem !important;
    }

    /* New Order button gets pushed to end */
    .sefari-portal .portal-order-workspace-actions > .btn-wrapper:last-child {
        margin-left: auto !important;
    }

    /* Topbar on mobile: keep items in a row */
    .sefari-portal .portal-topbar {
        flex-direction: row !important;
        align-items: center !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    .sefari-portal .portal-topbar-actions {
        flex-wrap: wrap !important;
        gap: 0.375rem !important;
    }

    /* Main content area: reduce padding on mobile */
    .sefari-portal .portal-container > .portal-main {
        padding: 0.5rem !important;
        gap: 0.5rem !important;
    }

    /* Order list panel: full width on mobile */
    .sefari-portal .portal-order-list-panel {
        position: relative !important;
        width: 100% !important;
        max-height: 50vh !important;
        overflow-y: auto !important;
    }

    /* Order route panel / detail sidebar */
    .sefari-portal .portal-order-route-panel {
        position: relative !important;
        width: 100% !important;
        min-height: auto !important;
    }

    /* Form actions: horizontal */
    .sefari-portal .portal-form-actions {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    /* Invoice summary: 2 cols instead of 4 */
    .sefari-portal .portal-invoice-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Dashboard quick actions: wrap nicely */
    .sefari-portal .portal-dashboard-quick-actions {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    /* Sidebar nav: single column on very small screens */
    .sefari-portal .portal-nav-group {
        grid-template-columns: 1fr !important;
    }
}

/* ── Map container: proper sizing ─────────────────────────── */
.sefari-portal .portal-order-map-stage {
    position: relative !important;
    min-height: 400px !important;
}

/* Leaflet map: ensure it fills container */
.sefari-portal .portal-order-map-stage .leaflet-container {
    min-height: 400px !important;
}

/* ── Fix broken avatar fallback ───────────────────────────── */
.sefari-portal img[src*="no-avatar"]:not([src*="s3.sefari.io"]),
.sefari-portal img.avatar-image[src=""],
.sefari-portal img.avatar-image:not([src]) {
    content: url("https://s3.sefari.io/flb-assets/static/no-avatar.png") !important;
}
