/* ==========
  GLOBAL PAGE STYLES
  ==========
*/
html,
body {
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Arial, sans-serif;
}

/* ==========
  APP WRAPPER (New Layout Root)
  ========== 
  This holds the Sidebar and Map Container side-by-side
*/
.app-wrapper {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevent full page scroll */
}

/* ==========
  SIDEBAR
  ========== 
*/
.sidebar {
    width: 560px; /* Fixed width */
    min-width: 560px; /* Prevent shrinking */
    height: 100%;
    background: #FCF7F1;
    display: flex;
    flex-direction: row; /* Nav strip | Content */
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    z-index: 20;
    position: relative;
}

/* 1. Navigation Strip (Icons) */
.sidebar-nav {
    width: 70px;
    min-width: 70px;  /* FORCE: Never let it be smaller than 70px */
    flex-shrink: 0;   /* FORCE: Do not allow flexbox to squeeze this item */
    background-color: #e8e1d9;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
    border-right: 1px solid #dcdcdc;
}

.nav-item {
    width: 100%;
    box-sizing: border-box; /* Ensures the active border-left is calculated inside the width */
    padding: 15px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    color: #57758F;
    transition: background 0.3s, color 0.3s;
}

.nav-item calcite-icon {
    margin-bottom: 5px;
    color: inherit;
}

.nav-item span {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.nav-item:hover {
    background-color: #fcf7f1;
}

.nav-item.active {
    background-color: #FCF7F1; /* Matches content bg */
    color: #333;
    border-left: 4px solid #57758F;
    margin-right: -1px;
}

/* 2. Sidebar Content Area */
.sidebar-content {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto; /* Scrollable content */
    padding-bottom: 140px; /* Space for fixed footer */
    position: relative;
}

/* Update inputs inside sidebar to fit nicely */
.sidebar-content input[type="text"],
.sidebar-content select {
    width: 100%;
    height: 25px;
    box-sizing: border-box; 
}

/* 3. Footer (Fixed Buttons) */
.sidebar-footer {
    position: absolute;
    bottom: 10px;
    right: 0;
    width: calc(100% - 111px); /* Full width minus nav strip */
    padding: 15px 20px;
    background: #FCF7F1;
    border-top: 1px solid #e0e0e0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ==========
  TABS LOGIC
  ========== 
*/
.tab-pane {
    display: none; /* Hidden by default */
    animation: fadeIn 0.3s ease-in-out;
}

.tab-pane.active {
    display: block; /* Show active */
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========
  MAP-CONTAINER
  ==========
  Updated to fill remaining space next to sidebar.
*/
.map-container {
    flex-grow: 1; /* Takes remaining width */
    width: auto;  /* IMPORTANT: Overrides default width to allow flex sizing */
    height: 100%;
    position: relative;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

/* ==========
  CONTENT CONTAINER
  ==========
  Holds the map and the foreground image.
*/
.content-container {
    position: relative;
    height: auto;
    /* Default fallback width */
    width: 65%;
    max-width: 65%;
    
    /* Ensure transitions are smooth when resizing */
    transition: width 0.9s ease-in, max-width 0.9s ease-out;
}

/* ORIENTATION-SPECIFIC SIZES 
   These classes are added/removed by JS in applyMapSize()
*/

/* Landscape: Can be wider because it's short vertically */
.content-container.landscape-mode {
    width: 70%;
    max-width: 70%;
    transition: width 0.9s ease-in, max-width 0.9s ease-out;
}

/* Portrait: Needs to be narrower to fit the tall height on screen */
.content-container.portrait-mode {
    width: 60%; /* Shrink width so the height fits within the viewport */
    max-width: 60%;
    transition: width 0.9s ease-in, max-width 0.9s ease-out;
}

/* ==========
  FOREGROUND IMAGE
  ==========
*/
.foreground-image {
    width: 100%;
    height: auto;
    display: block;
    pointer-events: none;
    transition: opacity 0.40s ease-in-out;
    opacity: 1;
}

/* ==========
  MAP DIV
  ==========
*/
#viewDiv {
    position: absolute;
    top: 46.23%;
    left: 50%;
    width: 83.08%;
    height: 53.48%;
    transform: translate(-50%, -50%);
}

/* ==========
  ZOOM-LEVEL OVERLAY
  ==========
*/
.zoom-level {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(255, 255, 255, 0.8);
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 14px;
    display: none;
}

/* ==========
  MAP LABELS (Title, Subtitle, Coords)
  ==========
*/
.map-title {
    position: absolute;
    top: 76.5%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0);
    padding: 2px 2px;
    border-radius: 5px;
    font-size: 1.6vw;
    font-weight: bold;
    pointer-events: none;
    z-index: 1;
}

.map-subtitle {
    position: absolute;
    top: 79.12%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0);
    padding: 2px 2px;
    border-radius: 5px;
    font-size: 0.95vw;
    font-weight: bold;
    pointer-events: none;
    z-index: 1;
}

.coordinates {
    position: absolute;
    top: 81%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0);
    padding: 2px 2px;
    border-radius: 5px;
    font-size: 0.48vw;
    pointer-events: none;
    z-index: 1;
}

/*
  ==========
  TEXT BACKGROUND
  ==========
*/
.text-background {
    position: absolute;
    pointer-events: none;
    z-index: 0;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    opacity: 0;
    box-shadow: 0 0 5px 5px rgba(255, 255, 255, 0.8);
}

/* Only applied during toggle interactions */
.text-background.fade-enabled {
    transition: opacity 0.8s ease-in-out;
}

.text-background.borderless-style-active {
    opacity: 1;
}

/*
  ==========
  NORTH ARROW
  ==========
*/
.north-arrow {
    position: absolute;
    z-index: 10;
    pointer-events: none;
    transform-origin: center center;
    transition: top 0.4s ease, left 0.4s ease, width 0.4s ease, opacity 0.8s ease;
    opacity: 0.9;
}

.north-arrow.hidden {
    opacity: 0;
}

/* ==========
  LEGEND BACKGROUND (Live View)
  ==========
*/
.legend-background {
    position: absolute;
    pointer-events: none;
    z-index: 1;
    background-color: rgba(255, 255, 255, 0.65);
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.8s ease-in-out, top 0.4s ease, left 0.4s ease, right 0.4s ease, bottom 0.4s ease, width 0.4s ease, height 0.4s ease, transform 0.4s ease;
}

.legend-background.visible {
    opacity: 1;
}

#liveLegendCanvas {
    transition: top 0.4s ease, left 0.4s ease, right 0.4s ease, bottom 0.4s ease, width 0.4s ease, height 0.4s ease, transform 0.4s ease;
}

/* ==========
  BUTTONS
  ==========
*/
.export-button {
    display: block;
    width: 100%;
    padding: 10px 20px;
    margin-top: 10px; /* Space inside footer */
    background-color: #57758F;
    color: white;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.export-button:hover {
    background-color: #e2e2e2;
    color: rgb(0, 0, 0);
}

.add-to-cart-button {
    display: block;
    width: 100%;
    padding: 10px 20px;
    margin-top: 10px;
    background-color: #57758F;
    color: white;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    position: relative;
    transition: background-color 0.3s ease, opacity 0.3s ease;
}

.add-to-cart-button:hover {
    background-color: #e2e2e2;
    color: rgb(0, 0, 0);
}

/* Button Loading/Success/Error States */
.add-to-cart-button.loading {
    pointer-events: none;
    opacity: 0.8;
}

.add-to-cart-button.loading::after {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.add-to-cart-button.success {
    /* background-color: #28a745; */
    color: white;
    pointer-events: none;
}
.add-to-cart-button.success::after,
.add-to-cart-button.error::after {
    display: none;
}
.add-to-cart-button.error {
    background-color: #dc3545;
    color: white;
}

/* ==========
  CUSTOMIZATION CONTROLS
  ==========
  Styles for labels, inputs, etc. inside the sidebar
*/

/* Hide old floating panel if it exists */
.customization-panel {
    display: none;
}

.customization-panel-title {
    font-family: 'Barlow', sans-serif;
    letter-spacing: 1px;
    word-spacing: 4px;
    text-align: center;
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 30px;
}

.panel-label {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    display: block;
    margin: 20px 0px 10px 0px;
}

.search-label {
    margin: 10px 0px 10px 0px;
}

.reset-view-button {
    display: block;
    width: 100%;
    padding: 5px 10px;
    margin-top: 10px;
    margin-bottom: 25px;
    background-color: #ffffff;
    color: #333;
    font-size: 14px;
    font-weight: normal;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.3s, color 0.3s;
}
.reset-view-button:hover {
    background-color: #e2e2e2;
    color: #000;
}

/* Format/Style/Size Buttons */
.map-size-buttons,
.map-orientation-buttons,
.format-buttons,
.map-style-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 10px;
    margin-bottom: 10px;
}

.map-size-btn,
.map-orientation-btn,
.format-btn,
.map-style-btn {
    cursor: pointer;
    padding: 5px 10px;
    font-size: 14px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background-color: #ffffff;
    transition: background-color 0.3s, color 0.3s;
    position: relative;
    margin-bottom: 20px; /* Space for price text */
}

/* Dynamic Prices for Sizes */
.map-size-btn::after {
    display: block;
    position: absolute;
    bottom: -22px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 1.00em;
    color: #555;
    font-weight: 600;
    font-family: 'Barlow', sans-serif;
}
.map-size-btn[data-size="12x16"]::after { content: "$ 39.99"; }
.map-size-btn[data-size="18x24"]::after { content: "$ 64.99"; }
.map-size-btn[data-size="24x36"]::after { content: "$ 84.99"; }
.map-size-btn[data-size="33.11x46.81 A0"]::after { content: "$ 99.99"; }
.map-size-btn[data-size="36x48"]::after { content: "$ 99.99"; }

/* Digital Pricing Override */
.map-size-buttons.digital-pricing-active .map-size-btn::after {
    content: "$19.99";
}

.map-size-btn:hover, .map-orientation-btn:hover, .format-btn:hover, .map-style-btn:hover {
    background-color: #e2e2e2;
}
.map-size-btn.selected, .map-orientation-btn.selected, .format-btn.selected, .map-style-btn.selected {
    background-color: #57758F;
    color: #fff;
    border-color: #57758F;
}

/* Multiline Size Buttons */
.map-size-btn {
  text-align: center;
  line-height: 1.4;
  padding-top: 8px;
  padding-bottom: 8px;
}

/* Basemap Swatches (If needed later for City Map) */
.basemap-swatches {
    margin-top: 10px;
    margin-bottom: 10px;
    display: flex;
    gap: 15px;
}
.swatch-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.basemap-swatch {
    width: 70px;
    height: auto;
    margin-bottom: 5px;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 15px;
}
.basemap-swatch:hover { border-color: #999; }
.swatch-label { font-size: 14px; text-align: center; }

/* Hillshade/Toggle Checkboxes */
.hillshade-wrapper {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    white-space: nowrap;
    margin-top: 30px;
    margin-bottom: 30px;
}
.hillshade-checkbox {
    accent-color: #57758F;
    transform: scale(1.7);
    cursor: pointer;
    margin-right: 5px;
}
.hillshade-label {
    display: inline-block;
    margin: 10px;
    font-weight: bold;
    white-space: nowrap;
}

/* ==========
  ELEVATION RENDERER CONTROLS
  ==========
*/
.renderer-control {
    margin-bottom: 30px;
}

.renderer-control label {
    display: block;
    font-weight: bold;
    font-size: 14px;
    margin: 10px 0px 10px 0px;
}
.renderer-control select {
    width: 100%;
    height: 35px;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #b4b4b4;
    background-color: #fff;
    font-size: 14px;
}

/* Custom Select Dropdown */
.custom-select-container {
    position: relative; width: 100%;
}

.select-selected {
    display: flex;
    align-items: center;
    padding: 8px;
    margin: 10px 0px 20px 0px;
    border: 1px solid #b4b4b4;
    border-radius: 4px;
    background-color: #fff;
    cursor: pointer;
    user-select: none;
}
.selected-text {
    flex-grow: 1;
    font-size: 14px;
    font-weight: normal;
}

.color-ramp-preview {
    height: 15px;
    width: 100px;
    margin: 0 10px;
    border: 1px solid #898989;
    flex-shrink: 0;
}
.select-arrow {
    width: 0; height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #555;
    transition: transform 0.2s ease-in-out;
}
.select-arrow.arrow-up { transform: rotate(180deg); }
.select-items {
    position: absolute;
    top: 100%; left: 0; right: 0;
    background-color: #fff;
    border: 1px solid #b4b4b4; border-top: none;
    border-radius: 0 0 4px 4px;
    z-index: 99;
    max-height: 200px;
    overflow-y: auto;
    padding: 0; margin: 0;
    list-style: none;
}
.select-hide { display: none; }
.select-items li {
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-size: 14px;
    font-weight: normal;
}
.select-items li:hover { background-color: #f0f0f0; }
.option-text { flex-grow: 1; }

/* Dual Thumb Slider */
.elevation-slider-container {
    position: relative;
    width: 95.6%;
    height: 25px;
    padding: 0px 0px 0px 0px;
    margin: 0px 0px 0px 10px;
    display: flex;
    align-items: center;
}
.slider-track {
    position: absolute;
    width: 100%; height: 8px;
    background-color: #ddd;
    border-radius: 5px;
    top: 50%;
    transform: translateY(-50%);
}
.slider-range {
    position: absolute;
    height: 8px;
    background-color: #57758F;
    border-radius: 5px;
    top: 50%;
    transform: translateY(-50%);
}
.slider-thumb {
    position: absolute;
    width: 20px; height: 20px;
    background-color: #57758F;
    border-radius: 50%;
    cursor: pointer;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
}
.slider-values {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 12px;
    color: #333;
}

/* Opacity Slider */
.opacity-slider-wrapper {
    position: relative;
    margin: 15px 0px 10px 0px;
    padding: 6px 0px 10px 0px;
}
.opacity-value {
    position: absolute;
    top: -10px;
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: bold;
    color: #333;
    pointer-events: none;
    background-color: #FCF7F1;
    padding: 0 2px;
}
.renderer-control input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 23px;
    background: #ddd;
    border-radius: 5px;
    outline: none;
    cursor: pointer;
}
.renderer-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px; height: 20px;
    background: #57758F;
    border-radius: 50%;
    cursor: pointer;
}

.panel-note {
    font-size: 12px;
    font-style: italic;
    color: #555;
    margin-bottom: 25px;
}

/* ==========
  CUSTOM ATTRIBUTION
  ==========
*/
#pageAttribution {
    position: absolute;
    bottom: 10px;
    z-index: 9999;
    pointer-events: auto;
}
#pageAttribution .esri-attribution__sources {
    display: inline-block;
    width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    background-color: rgba(255, 255, 255, 0.8);
    color: #929292;
    font-size: 10px;
    font-family: Arial, sans-serif;
    padding: 10px 0px 0px 8px;
    border-top-right-radius: 5px;
    vertical-align: middle;
}
#pageAttribution .esri-attribution__sources.expanded {
    width: auto;
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
}
#pageAttribution .info-button {
    display: inline-block;
    margin-left: 10px;
    width: 20px; height: 20px;
    border-radius: 50%;
    line-height: 15px;
    text-align: center;
    font-size: 16px;
    font-family: Arial, sans-serif;
    padding: 0px;
    background: #ccc;
    border: 1px solid #999;
    cursor: pointer;
    pointer-events: auto;
    vertical-align: middle;
}
#pageAttribution .info-button:hover { background: #bbb; }
.esri-attribution__powered-by {
    text-align: right;
    white-space: nowrap;
    padding: 0 5px;
    font-weight: 400;
}
.esri-attribution__powered-by a.esri-attribution__link {
    text-decoration: none;
    color: #0079c1;
    font-weight: bold;
}

/* ==========
  RESPONSIVE DESIGN (Mobile)
  ==========
*/
@media (max-width: 1080px) {
    html, body {
        height: auto;
        overflow-y: auto;
    }
    /* Switch to column layout for mobile */
    .app-wrapper {
        flex-direction: column-reverse; /* Sidebar below map */
        overflow-y: auto;
        height: auto;
    }
    .sidebar {
        width: 100%;
        min-width: 0;
        height: auto;
        flex-direction: column;
        box-shadow: none;
    }
    /* Nav strip goes to the top, full width */
    .sidebar-nav {
        width: 100%; /* Full width */
        height: auto;
        flex-direction: row; /* Icons side-by-side */
        padding: 0;
        border-right: none;
        border-bottom: 1px solid #dcdcdc;
    }

    /* Adjust nav items for horizontal layout */
    .nav-item {
        padding: 10px 0;
        border-left: none; /* Remove left border used on desktop */
        border-bottom: 4px solid transparent; /* Prepare for bottom border */
    }
    /* Active state for horizontal nav */
    .nav-item.active {
        border-left: none;
        border-bottom: 4px solid #57758F; /* Highlight on bottom */
        margin-right: 0;
        background-color: transparent; /* Optional: cleaner look */
    }

    /* Content area needs less padding */
    .sidebar-content {
        padding-bottom: 20px; /* Remove large padding for absolute footer */
        flex-grow: 0; /* Don't force growth, just take needed space */
    }
    /* Footer becomes a normal block element at the bottom */
    .sidebar-footer {
        position: relative; /* No longer absolute */
        width: 100%; /* Full width */
        bottom: auto; right: auto; /* Reset positions */
        box-sizing: border-box; /* Ensure padding doesn't break width */
        border-top: 2px solid #e0e0e0; /* Add separator line */
    }
    .map-container {
        width: 100%;
        flex-grow: 0;
        /* IMPORTANT: Stop vertically centering content to reduce gaps */
        justify-content: flex-start; /* <--- CHANGED FROM CENTER */
        padding-bottom: 10px;
    }
    .content-container {
        width: 100%;
        max-width: 100%;
    }
    .sidebar-footer {
        width: 100%;
        position: relative;
    }
    .sidebar-content {
        padding-bottom: 20px;
    }
    
    #viewDiv {
        position: relative;
        top: 0; left: 0;
        transform: none;
        width: 100%;
        height: 60vh;
    }
    /* Attribution moves below the map */
    #pageAttribution {
        position: static; /* Not absolute anymore */
        margin-top: 5px;  /* <--- REDUCED: was 20px, shrinks the gap */
        width: 90%; /* Ensure it doesn't hit edges */
        max-width: 400px; /* Keep it tidy */
    }
    .map-title { font-size: 3.4vw; }
    .map-subtitle { font-size: 2vw; }
    .coordinates { font-size: 1vw; }
}

/* Popup Warning */
.popup-warning {
    position: fixed;
    top: 10%; left: 50%;
    transform: translateX(-50%);
    background-color: #FCF7F1;
    color: #57758F;
    padding: 20px 25px;
    border: 2px solid #57758F;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    font-size: 16px;
    text-align: center;
}
.popup-warning .close-btn {
    position: absolute;
    top: 5px; right: 10px;
    cursor: pointer;
    font-size: 20px;
    color: #57758F;
}
.blur-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 9999;
}