html,
body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* REMOVE window scrolling completely */
}

:root {
    --navbar-height: 60px; /* will be updated at runtime to actual toolbar height */
}

#view-div {
    background-color: var(--dx-surface-bg);
    height: 100vh; /* Use viewport height instead of 100% */
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* No scrolling at this level */
}
.results-and-detail-container {
    display: flex;
    height: calc(100vh - var(--navbar-height)); /* Fit below navbar */
    margin-top: 0;
    padding-top: 0;
    gap: 0; /* ensure no space between list and accordion */
}

.results-list-container {
    width: fit-content;
    background-color: var(--dx-component-color-bg);
    min-width: 300px;
    height: calc(100vh - var(--navbar-height));
    overflow-y: auto; /* ADD THIS - let the container scroll */
    overflow-x: hidden;
    margin: 0; /* snug to accordion */
    padding: 0; /* remove inner gap next to accordion */
    border-right: 2px solid var(--dx-color-primary, #880707); /* match navbar line */
}

/* Results list: grey background with white card-like items (separation between items) */
#search-results-list,
#search-results-list .dx-list,
#search-results-list .dx-scrollview-content {
    background-color: var(--dx-surface-bg) !important;
    padding: 0px 4px 8px 0px !important;
}

#search-results-list .dx-list .dx-list-item,
#search-results-list .dx-list .dx-list-item-border,
#search-results-list .dx-list-item,
#search-results-list .dx-list-item-border {
    background-color: transparent !important;
    border: none !important;
    margin: 6px 8px !important; /* grey gutters */
}

#search-results-list .dx-list .dx-list-item .dx-list-item-content,
#search-results-list .dx-list-item .dx-list-item-content {
    background-color: #ffffff !important; /* card */
    border-radius: 6px;
    padding: 10px 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Hover elevation */
#search-results-list .dx-list .dx-list-item.dx-state-hover .dx-list-item-content,
#search-results-list .dx-list-item.dx-state-hover .dx-list-item-content {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

/* Selected/Focused state: maroon border + grey background */
#search-results-list .dx-list .dx-list-item.dx-state-focused .dx-list-item-content,
#search-results-list .dx-list .dx-list-item.dx-state-selected .dx-list-item-content,
#search-results-list .dx-list-item.dx-state-focused .dx-list-item-content,
#search-results-list .dx-list-item.dx-state-selected .dx-list-item-content {
    border: 2px solid var(--xsoft-burgundy, #5a0000) !important;
    background-color: var(--xsoft-gray-light) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Persistent selected item (programmatic) */
#search-results-list .dx-list-item .dx-list-item-content.xeng-selected {
    background-color: var(--xsoft-gray-100, #f2f2f2) !important;
    border: 2px solid var(--xsoft-burgundy, #5a0000) !important;
}

/* Removed xeng-selected persistent style */

/* Remove default separators for a clean card look */
#search-results-list .dx-list .dx-list-item::after,
#search-results-list .dx-list-item::after {
    display: none !important;
}

/* Ensure accordion DataGrids are non-compact (desktop) without changing theme */
@media (min-width: 768px) {
    #accordion-container-outer .dx-datagrid .dx-row > td,
    #accordion-container-outer .dx-datagrid .dx-header-row > td {
        padding: 10px 12px !important;
        font-size: 15px !important;
    }

    /* Strengthen non-compact feel across grid parts inside accordion */
    #accordion-container-outer .dx-datagrid-rowsview .dx-row {
        min-height: 36px !important;
    }
    #accordion-container-outer .dx-datagrid-rowsview .dx-row > td {
        line-height: 1.4 !important;
    }
    #accordion-container-outer .dx-datagrid-headers .dx-header-row > td {
        font-size: 14px !important;
    }
    #accordion-container-outer .dx-datagrid .dx-editor-cell .dx-texteditor-input {
        padding: 8px 10px !important;
        font-size: 14px !important;
    }
    #accordion-container-outer .dx-datagrid .dx-link {
        font-size: 14px !important;
    }
    #accordion-container-outer .dx-pager .dx-page,
    #accordion-container-outer .dx-pager .dx-info {
        padding: 0 8px !important;
        font-size: 13px !important;
    }
}

#map-div {
    width: 100%;
    height: 100%;
    position: relative; /* anchor absolute children like attribution */
    transition: margin-left 200ms ease; /* Smooth transition for map adjustment */
}

/* Overview mini-map (inside Esri UI bottom-right container) */
#overview-thumbnail {
    position: relative;
    width: 150px;
    height: 150px;
    border: 1px solid var(--dx-color-primary, #880707);
    background: #fff;
    pointer-events: auto;
    order: 99; /* push minimap to the far right in flex row */
    margin-left: auto;
}
#extentDiv {
    position: absolute;
    border: 2px dashed rgba(136, 7, 7, 0.8);
    box-sizing: border-box;
}

/* Optional delayed visibility without JS: keep space, reveal after 3s */
#overview-thumbnail.delayed-visibility {
    opacity: 0;
    pointer-events: none;
    animation: xeng-fade-in 250ms ease 3s forwards;
}

@keyframes xeng-fade-in {
    to {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Remove any ::after line under the map canvas (from ArcGIS or theme) */
#map-div canvas::after,
#view-div canvas::after,
.esri-view canvas::after,
#map-div::after,
#view-div::after {
    content: none !important;
    display: none !important;
}

/* removed legacy overview-thumbnail styles */

#feature-buttons {
    position: relative;
    float: right;
    top: 0;
    padding: 1em;
    pointer-events: none;
    height: auto;
    z-index: 3000; /* above map overlays so clicks are not blocked */
    transition: margin-left 200ms ease; /* Match map transition */
}

#distanceButton,
#areaButton,
#print-map-btn,
#arcgisjsPrintBtn,
#measure-tool {
    pointer-events: initial;
}

.map-layer {
    position: fixed;
}

#map-overlays {
    flex: 0 0 auto; /* Takes up only the necessary space */
    display: inline-flex; /* shrink to content width */
    flex-direction: column;
    z-index: 2002;
    position: fixed; /* overlay floats above map but only at its content size */
    top: var(--navbar-height); /* keep under navbar */
    left: 0;
    pointer-events: none; /* allow map/buttons behind to be clickable */
    margin-top: 0;
}

/* Make accordion flush on all sides */
#accordion-container-outer {
    margin: 0;
    padding: 0;
}
#accordion-container-outer .dx-accordion {
    margin: 0 !important;
}
#accordion-container-outer .dx-accordion-item {
    margin: 0 !important;
}

/* Navbar styling now lives in the DevExtreme theme override */

/* Re-enable interaction for overlay children that must be clickable */
.results-and-detail-container,
.results-list-container,
#accordion-container-outer,
#accordion-resize-handle,
#sketch-popup-container,
.documents-popup {
    pointer-events: auto;
}

.esri-ui {
    overflow: visible;
}

#map-div .esri-ui {
    /*    width: 50%;
    margin-left: 50%;*/
    margin-bottom: 0; /* ensure UI hugs the bottom */
    padding-bottom: 10px; /* reserve space so controls and ribbon are fully visible (reduced) */
}

#esri-ui calcite-mode-light {
    inset: var(--navbar-height) 0px 0px 0px;
}

.esri-ui-top-right {
    top: var(--navbar-height);
}

.esri-ui-bottom-right {
    margin-right: 0; /* no extra right margin */
    margin-bottom: 10px; /* extra breathing room at bottom */
    display: flex; /* lay out controls horizontally */
    flex-direction: row;
    align-items: flex-end;
    gap: 2px;
}

/* Tighten inter-widget spacing */
.esri-ui-bottom-right .esri-widget {
    margin: 0 2px !important;
}

/* Explicit ordering of Esri UI controls in bottom-right (right -> left) */
#overview-thumbnail {
    order: 1;
}
.esri-ui-bottom-right .esri-basemap-toggle {
    order: 2;
}
.esri-ui-bottom-right .esri-zoom {
    order: 3;
}
.esri-ui-bottom-right #xeng-print {
    order: 4;
}
.esri-ui-bottom-right #select-by-polygon {
    order: 5;
}
.esri-ui-bottom-right #select-by-circle {
    order: 6;
}
.esri-ui-bottom-right #xeng-measure {
    order: 7;
}
.esri-ui-bottom-right .esri-home {
    order: 8;
}
.esri-ui-bottom-right .esri-compass {
    order: 9;
}
.esri-ui-bottom-right .esri-scale-bar {
    order: 10;
}

.esri-ui-bottom-left {
    margin-bottom: 16px; /* keep controls fully on-screen */
    bottom: 12px !important; /* anchor above edge */
}

.esri-view .esri-ui-corner .esri-component.esri-widget--panel-height-only {
    width: 250px;
    max-height: calc(100% - 45px) !important;
    position: fixed;
}

.esri-popup__main-container {
    background: rgba(255, 255, 255, 0.9);
}

.esri-popup__content {
    background: rgba(255, 255, 255, 0.9);
}

.esri-feature__content-node {
    background: rgba(255, 255, 255, 0.5);
}

.esri-attribution {
    position: absolute; /* inside #map-div */
    left: 0;
    right: 0;
    bottom: 8px; /* small offset above edge to avoid clipping */
    margin: 0 !important;
    z-index: 1001;
}

/* Brand Esri/Calcite outlines and accents with our primary color */
#view-div,
#overview-thumbnail,
.esri-view,
calcite-mode-light,
calcite-mode-dark {
    --calcite-color-brand: var(--dx-color-primary, #880707);
    --esri-view-outline-color: var(--dx-color-primary, #880707);
    --esri-view-outline: 2px solid var(--dx-color-primary, #880707);
}

#accordion-container-outer {
    width: 543px;
    min-width: 300px;
    height: calc(100vh - var(--navbar-height));
    overflow-y: auto;
    overflow-x: hidden;
    resize: horizontal;
    display: none; /* Hidden until list item clicked */
    position: fixed;
    top: var(--navbar-height);
    left: 0; /* Position on LEFT side of screen */
    transition: all 200ms ease; /* Smooth transition for sliding */
    z-index: 2002;
}

/* When drawer is open, push accordion over */
#accordion-container-outer.drawer-open {
    left: 320px; /* Push over by drawer width */
}

#accordion-resize-handle {
    width: 10px;
    background: transparent;
    cursor: ew-resize;
    position: fixed;
    top: var(--navbar-height);
    left: 543px; /* Position to the right of accordion */
    height: calc(100vh - var(--navbar-height));
    z-index: 2003;
    transition: all 200ms ease; /* Match accordion transition */
}

/* When drawer is open, push resize handle over too */
#accordion-resize-handle.drawer-open {
    left: 863px; /* 320px (drawer) + 543px (accordion) */
}

/* Simple centered spinner for initial load */
.xeng-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--xsoft-red, #880707);
    border-radius: 50%;
    animation: xeng-spin 1s linear infinite;
}
@keyframes xeng-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Ensure map area adjusts when both panels are visible */
#map-div {
    width: 100%;
    height: 100%;
    position: relative; /* anchor absolute children like attribution */
    transition: margin-left 200ms ease; /* Smooth transition for map adjustment */
}

/* Ensure proper z-index layering */
.xeng-hoisted-panel {
    z-index: 2002; /* Highest priority - search results drawer */
}

#accordion-container-outer {
    z-index: 1000; /* Below drawer but above map */
}

#accordion-resize-handle {
    z-index: 1001; /* Above accordion for interaction */
}

/* Responsive behavior for small screens */
@media (max-width: 767px) {
    /* Ensure map container is properly sized on small screens */
    #view-div {
        height: 100vh;
        width: 100vw;
        position: fixed;
        top: var(--navbar-height);
        left: 0;
        right: 0;
        bottom: 0;
    }

    #map-div {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    /* Ensure map view is properly constrained on small screens */
    .esri-view {
        width: 100% !important;
        height: 100% !important;
    }

    /* Adjust feature buttons for small screens */
    #feature-buttons {
        padding: 0.5em;
        right: 0.5em;
        top: 0.5em;
    }

    /* Ensure proper viewport constraints */
    .esri-view .esri-view-surface {
        width: 100% !important;
        height: 100% !important;
    }
}

/* PDF Viewer Popup Styles */
#documents-pdf-view-popup {
    z-index: 3000; /* Higher than all other elements */
}

/* Ensure DevExtreme popups (PDF Viewer, PDF Editor, Sketch, etc.) are above drawers/accordion */
.dx-popup-wrapper,
.dx-overlay-wrapper {
    z-index: 5000 !important;
}

.dx-overlay-shader {
    z-index: 4999 !important;
}

#pdf-viewer-container {
    background: #f5f5f5;
    border-radius: 4px;
    padding: 10px;
}

#pdf-canvas {
    display: block;
    margin: 0 auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background: white;
}

/* PDF Thumbnail Styles */
.pdf-thumbnail {
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.pdf-thumbnail:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.pdf-thumbnail img {
    border-radius: 4px;
}

/* Overview thumbnail occupies space but starts invisible */
#overview-thumbnail {
    opacity: 0;
    visibility: hidden;
}

/* FAB buttons - move to lower right */
.fab-btn {
    position: fixed;
    top: calc(var(--navbar-height, 48px) + 12px);
    bottom: auto;
    right: 16px;
    z-index: 1000;
    color: white;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.fab-btn:hover {
    background-color: var(--xsoft-red, #880707);
    transform: scale(1.05);
}

.details-btn {
    position: fixed;
    top: calc(var(--navbar-height, 48px) + 56px + 24px);
    bottom: auto;
    right: 16px;
    z-index: 1000;
    color: white;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.details-btn:hover {
    background-color: var(--xsoft-red, #880707);
    transform: scale(1.05);
}

/* Mobile responsive styles */
@media (max-width: 767px) {
    /* Hide ALL feature buttons on mobile */
    #feature-buttons {
        display: none !important;
        gap: 8px;
    }

    /* Hide the entire bottom-right container (and all widgets inside) */
    .esri-ui-bottom-right {
        display: none !important;
    }
    /* Hide ALL Esri UI corners on mobile (belt-and-suspenders) */
    .esri-ui-top-left,
    .esri-ui-top-right,
    .esri-ui-bottom-left,
    .esri-ui-bottom-right {
        display: none !important;
    }
    /* Also explicitly hide any custom-added tool buttons */
    #xeng-print,
    #xeng-measure,
    #select-by-polygon,
    #select-by-circle,
    #overview-thumbnail,
    #arcgisjsPrintBtn {
        display: none !important;
    }

    /* Larger buttons for mobile (bottom-right) */
    .fab-btn,
    .details-btn {
        width: 64px;
        height: 64px;
        right: 20px;
    }

    .fab-btn {
        top: auto;
        bottom: 24px;
    }
    .details-btn {
        top: auto;
        bottom: 104px;
    }

    /* Accordion responsive styling */
    .dx-drawer-content {
        width: 100% !important;
        max-width: 100% !important;
    }
    /* Make the accordion container take full width on mobile */
    #accordion-container-outer {
        width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
    }
    /* Hide or move the resize handle off-screen on mobile */
    #accordion-resize-handle {
        display: none !important;
        left: 100vw !important;
    }

    .dx-datagrid {
        width: 100% !important;
    }

    .dx-datagrid .dx-row {
        padding: 8px !important;
    }

    .dx-gallery {
        width: 100% !important;
    }

    /* Touch-friendly buttons only within accordion/map areas (avoid navbar) */
    #accordion-container-outer .dx-button,
    #accordion-container-outer .dx-buttongroup .dx-button,
    .documents-popup .dx-button {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    .dx-popup {
        width: 95% !important;
        max-width: 95% !important;
    }

    /* Make accordion content full width on mobile */
    .dx-accordion {
        width: 100% !important;
    }

    .dx-accordion-item {
        width: 100% !important;
    }

    .dx-accordion-item-body {
        width: 100% !important;
        padding: 8px !important;
    }

    /* Compact data grid rows for mobile */
    .dx-datagrid .dx-data-row > td {
        padding: 6px 8px !important;
        font-size: 14px !important;
    }

    .dx-datagrid .dx-header-row > td {
        padding: 8px !important;
        font-size: 14px !important;
    }

    /* ensure consistent bottom-right spacing overrides */
}

/* Keep overflow menu above map/drawers but don't change icon size */
.dx-dropdownmenu-popup-wrapper {
    z-index: 3000 !important;
}
