/* Final phone layout contract, loaded after the shared map and account styles.
   Reserve separate rows for navigation, attribution, actions and zoom. */
@media (max-width: 820px) {
    /* Phone controls live in Tools; map gestures replace the zoom widget. */
    body.ui-hidden .map-mobile-restore-ui { display: block !important; visibility: visible !important; opacity: 1 !important; pointer-events: auto !important; position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); right: 16px; z-index: 10000; min-height: 48px; padding: 10px 18px; border: 1px solid #bae6fd; border-radius: 14px; background: #fff; color: #0369a1; font: inherit; }
    .desktop-map-zoom-control,
    .leaflet-control-zoom,
    .maplibregl-ctrl-group:has(.maplibregl-ctrl-zoom-in),
    #map-action-rail .map-rail-utility-group {
        display: none !important;
    }
    body.ui-hidden #map-action-rail { display: none !important; }

    .map-mobile-tools-tabs {
        display: flex;
        gap: 6px;
        padding: 5px;
        margin-bottom: 16px;
        background: var(--map-surface, #fff);
        border: 1px solid var(--map-border, #dce5ef);
        border-radius: 16px;
    }

    .map-mobile-tools-tabs button {
        flex: 1;
        min-height: 46px;
        border: 0;
        border-radius: 12px;
        background: transparent;
        color: var(--map-text, #334155);
        font: inherit;
        font-size: 13px;
    }

    .map-mobile-tools-tabs [aria-selected="true"] {
        color: #0369a1;
        background: #e0f2fe;
    }

    .map-mobile-controls:not([hidden]) { display: block; }
    #map-mobile-controls-host .map-rail-utility-group {
        position: static !important;
        display: flex !important;
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        align-items: stretch !important;
        inset: auto !important;
        gap: 10px !important;
        width: 100%;
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

    #map-mobile-controls-host .map-rail-utility,
    .map-mobile-fit-button {
        display: flex;
        position: relative !important;
        inset: auto !important;
        transform: none !important;
        align-items: center;
        gap: 16px;
        width: 100% !important;
        min-height: 58px !important;
        height: auto !important;
        flex: 0 0 auto !important;
        padding: 14px 18px;
        border: 1px solid var(--map-border, #dce5ef);
        border-radius: 16px;
        background: var(--map-surface, #fff);
        color: var(--map-text, #334155);
        font: inherit;
        text-align: right;
    }

    #map-mobile-controls-host .map-rail-utility[hidden] { display: none !important; }
    #map-mobile-controls-host .map-rail-utility .map-mobile-control-label { display: block; font-size: 14px; }
    #map-mobile-controls-host .map-rail-utility[aria-pressed="true"] { border-color: #0ea5e9; background: #e0f2fe; color: #0369a1; }
    .map-mobile-fit-button { margin-top: 10px; }
    .map-mobile-controls > p { font-size: 12px; line-height: 1.9; color: var(--map-text-muted, #64748b); margin: 16px 8px; }

    html.workspace-detail-open .map-workspace-drawer.is-company-summary {
        height: auto !important;
        max-height: min(52dvh, 360px) !important;
    }
    html.workspace-detail-open .is-company-summary .map-workspace-header { display: none; }
    html.workspace-detail-open .map-branding-dock { visibility: hidden !important; }
    html.workspace-detail-open .map-search-result-navigator { display: none !important; }
    html.workspace-detail-open .is-company-summary .map-workspace-body { flex: 0 1 auto; }
    .is-company-summary .map-company-full-detail { display: none; }
    .is-company-summary .map-mobile-company-summary { display: block; }
    html.workspace-detail-open .is-company-expanded { height: min(82dvh, 780px) !important; }
    html.workspace-detail-open .map-company-detail-actions [data-company-detail-action="route"] { display: none; }
    .map-mobile-company-heading { display: flex; align-items: center; gap: 12px; }
    .map-mobile-company-heading > div { flex: 1; min-width: 0; }
    .map-mobile-company-heading h3 { font-size: 17px; line-height: 1.8; margin: 0; overflow-wrap: anywhere; }
    .map-mobile-company-heading p { font-size: 12px; line-height: 1.8; color: var(--map-text-muted, #64748b); margin: 3px 0 8px; }
    .map-mobile-company-icon { display: grid; place-items: center; width: 52px; height: 60px; flex-shrink: 0; border-radius: 14px; background: #e0f2fe; color: #0284c7; font-size: 24px; }
    .map-mobile-company-summary .map-company-detail-badges { margin: 10px 0 14px; }
    .map-mobile-company-expand { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; min-height: 48px; border: 0; border-radius: 14px; background: #0755a1; color: #fff; font: inherit; font-weight: 700; }
    .map-mobile-company-dismiss { border: 0; background: transparent; color: var(--map-text-muted, #64748b); font: inherit; min-height: 44px; width: 100%; margin-top: 4px; }
    @media (orientation: landscape) {
        html.workspace-detail-open .map-workspace-drawer.is-company-summary { max-height: calc(100dvh - 82px) !important; }
        html.workspace-detail-open .map-company-sheet-handle { display: grid; }
    }
    :root {
        --mobile-map-actions-bottom: calc(var(--mobile-map-nav-height, 70px) + env(safe-area-inset-bottom) + 22px);
        --mobile-map-zoom-bottom: calc(var(--mobile-map-nav-height, 70px) + env(safe-area-inset-bottom) + 86px);
    }

    .map-top-shell {
        box-sizing: border-box;
    }

    .map-quick-filter-row {
        box-sizing: border-box;
        min-width: 0;
        width: 100%;
        flex-shrink: 0;
    }

    .map-quick-chip {
        min-height: 40px;
        font-size: 11px;
    }

    .map-global-search input {
        font-size: 13px;
    }

    .map-action-rail .map-rail-label {
        font-size: 10px;
        line-height: 1.5;
    }

    .map-action-rail .map-rail-utility-group {
        bottom: var(--mobile-map-actions-bottom) !important;
        gap: 2px !important;
    }

    .map-action-rail .map-rail-utility {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        flex-basis: 44px !important;
    }

    .desktop-map-zoom-control {
        bottom: var(--mobile-map-zoom-bottom);
        grid-template-columns: repeat(3, 44px);
        grid-template-rows: 44px;
        gap: 4px;
        padding: 4px;
        border-radius: 16px;
    }

    .desktop-map-zoom-control input {
        display: none;
    }

    .desktop-map-zoom-control .desktop-map-zoom-button {
        width: 44px;
        height: 44px;
    }

    .desktop-map-zoom-control [data-map-zoom="in"] {
        grid-area: 1 / 1;
    }

    .desktop-map-zoom-control [data-map-zoom="out"] {
        grid-area: 1 / 2;
    }

    .desktop-map-zoom-control .map-initial-view-reset {
        grid-area: 1 / 3;
    }

    .map-demo-banner {
        top: calc(env(safe-area-inset-top) + 120px);
        right: 10px;
        bottom: auto;
        left: auto;
        width: auto;
        max-width: calc(100vw - 20px);
        padding: 5px 10px;
        transform: none;
        border-radius: 10px;
        box-sizing: border-box;
        pointer-events: none;
    }

    .map-demo-banner > div {
        min-width: 0;
    }

    .map-demo-banner strong {
        font-size: 11px;
    }

    .map-demo-banner p {
        display: none;
    }

    .map-branding-dock {
        position: fixed;
        right: 8px !important;
        bottom: calc(var(--mobile-map-actions-bottom) + 2px) !important;
        width: 56px;
        display: block;
        transform: none !important;
    }

    .map-branding-dock .brand-right-group {
        width: 56px;
        gap: 2px;
    }

    .map-branding-dock .park-brand-link img {
        width: 40px;
        height: 40px;
        object-fit: contain;
    }

    .map-branding-dock .app-version-label {
        font-size: 8px;
    }

    .map-branding-dock .brand-left-group {
        position: fixed;
        right: 8px;
        bottom: calc(var(--mobile-map-nav-height, 70px) + env(safe-area-inset-bottom) + 3px);
        left: 8px;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 6px;
        font-size: 8px;
    }

    .map-branding-dock .map-data-attribution {
        min-height: 0;
        padding: 1px 4px;
        border: 0;
        box-shadow: none;
        font-size: 8px;
        line-height: 1.4;
    }

    .neshan-branding-slot img {
        max-height: 14px;
        width: auto;
    }

    .map-workspace-header {
        min-height: 72px;
        height: auto;
        padding: 10px 12px;
    }

    .map-workspace-heading h2,
    .map-workspace-heading h6 {
        font-size: 18px;
    }

    .map-workspace-eyebrow {
        font-size: 11px;
        line-height: 1.7;
    }

    .map-workspace-view {
        padding: 14px 12px 24px;
        scroll-padding-block: 12px 24px;
    }

    .map-workspace-tools-view {
        --toolbox-card-height: 84px;
        --toolbox-card-padding-x: 12px;
        --toolbox-icon-size: 44px;
    }

    .map-workspace-tools-view .map-admin-tools-heading {
        display: none;
    }

    .map-workspace-tools-view .map-tools-intro {
        padding: 12px;
        line-height: 1.8;
    }

    .map-workspace-tools-view .map-tools-intro strong {
        font-size: 14px;
    }

    .map-workspace-tools-view .map-tools-intro span {
        font-size: 11px;
    }

    .map-workspace-tools-view .map-role-tool-grid {
        grid-template-columns: minmax(0, 1fr);
        align-items: start;
        gap: 10px;
    }

    .map-workspace-tools-view .map-role-tool-card {
        min-height: 84px;
        height: auto;
        grid-template-columns: 44px minmax(0, 1fr) 16px !important;
        grid-template-rows: auto;
        align-items: center;
        align-content: center;
        justify-items: stretch;
        padding: 12px;
        gap: 12px;
    }

    .map-workspace-tools-view .map-role-tool-icon {
        width: 44px;
        height: 44px;
        grid-area: 1 / 1;
    }

    .map-workspace-tools-view .map-role-tool-copy {
        grid-area: 1 / 2;
        align-self: center;
        gap: 4px;
    }

    .map-workspace-tools-view .map-role-tool-copy strong,
    .map-workspace-tools-view .admin-tool-summary-text .filter-title,
    .map-workspace-tools-view .map-click-picker-copy strong,
    .map-workspace-tools-view .map-image-export-heading-copy strong {
        font-size: 14px !important;
        line-height: 1.8 !important;
        overflow-wrap: anywhere;
    }

    .map-workspace-tools-view .map-role-tool-copy small,
    .map-workspace-tools-view .admin-tool-summary-text small,
    .map-workspace-tools-view .map-click-picker-copy small,
    .map-workspace-tools-view .map-image-export-heading-copy small {
        display: block;
        font-size: 11px;
        line-height: 1.8;
        -webkit-line-clamp: unset;
    }

    .map-workspace-tools-view .map-role-tool-arrow {
        position: static;
        grid-area: 1 / 3;
    }

    .map-workspace-view :is(input[type="text"], input[type="search"], select, textarea),
    .filter-page-content :is(input[type="text"], input[type="search"], select, textarea) {
        font-size: 16px;
    }

    html:is(.workspace-drawer-open, .filter-page-open, .workspace-search-open) :is(.desktop-map-zoom-control, .map-demo-banner) {
        visibility: hidden;
        pointer-events: none;
    }

    html.mobile-map-keyboard-open .desktop-map-zoom-control {
        display: none;
    }

    /* Every tool launcher shares one box model, including legacy summaries.
       Expanded workflow contents remain free to grow beneath their launcher. */
    .map-workspace-tools-view { --toolbox-card-height: 96px; }
    #map-mobile-controls-host .map-rail-utility,
    .map-mobile-fit-button,
    .map-workspace-tools-view .map-role-tool-card,
    .map-workspace-tools-view .admin-tool-toggle,
    .map-workspace-tools-view .map-click-picker-card,
    .map-workspace-tools-view .map-image-export-heading {
        box-sizing: border-box !important;
        width: 100% !important;
        height: var(--toolbox-card-height) !important;
        min-height: var(--toolbox-card-height) !important;
        max-height: var(--toolbox-card-height) !important;
        padding: 12px !important;
        border: 1px solid var(--map-border, #dce5ef) !important;
        border-radius: 16px !important;
        box-shadow: none !important;
        margin-inline: 0 !important;
        align-items: center !important;
    }
    #map-mobile-controls-host .map-rail-utility,
    .map-mobile-fit-button {
        flex-direction: row !important;
        justify-content: flex-start !important;
        direction: rtl;
        gap: 12px !important;
    }
    #map-mobile-controls-host .map-mobile-control-label,
    .map-mobile-fit-button > span { flex: 1; text-align: right; }
    #map-mobile-controls-host .map-rail-utility > i,
    .map-mobile-fit-button > i {
        display: grid;
        place-items: center;
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        margin: 0;
        border-radius: 12px;
        background: #e0f2fe;
        color: #0374a8;
        font-size: 18px;
    }
    #map-mobile-controls-host .map-mobile-control-label,
    .map-mobile-fit-button > span { font-size: 14px; line-height: 1.8; font-weight: 700; }
    .map-workspace-tools-view .map-role-tool-grid { gap: 10px; }
    .map-toolbox-draw-host:has(#btn-draw-finish[style*="display: none"]):has(#btn-draw-clear[style*="display: none"]) { display: none; }
    .map-workspace-tools-view .map-role-tool-copy,
    .map-workspace-tools-view .admin-tool-summary-text,
    .map-workspace-tools-view .map-image-export-heading-copy,
    .map-workspace-tools-view .map-click-picker-copy { min-width: 0; gap: 3px; }
    .map-workspace-tools-view .map-role-tool-copy strong,
    .map-workspace-tools-view .admin-tool-summary-text .filter-title,
    .map-workspace-tools-view .map-image-export-heading-copy strong,
    .map-workspace-tools-view .map-click-picker-copy strong { font-size: 13px !important; line-height: 1.65 !important; }
    .map-workspace-tools-view .map-role-tool-copy small,
    .map-workspace-tools-view .admin-tool-summary-text small,
    .map-workspace-tools-view .map-image-export-heading-copy > span,
    .map-workspace-tools-view .map-click-picker-copy small {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        font-size: 11px;
        line-height: 1.65;
    }
}
