html, body, #viewDiv {
    padding: 0;
    margin: 0;
    height: 100%;
    width: 100%;
    font-family: Arial, sans-serif;
    /* Prevent text size adjustment on orientation change */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Screen-reader only: visually hidden but accessible */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Improve touch targets for mobile */
button, input[type="checkbox"], label {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#map {
    flex: 1;
    width: 100%;
}

.header {
    background-color: #4CAF50;
    color: white;
    padding: 10px;
    text-align: center;
}

.file-input {
    margin: 10px;
}

/* Layer Panel Styles */
#layerPanel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    z-index: 90;
    max-width: 300px;
    width: auto;
    /*width: 250px; /* Fixed width to prevent resize on hover */
    box-sizing: border-box;
    /* Height will be dynamic based on content */
}

/* Search Widget Styles */
#searchWidget {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
    width: 350px;
    max-width: 90%;
    box-sizing: border-box;
}

.search-container {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
    overflow: hidden;
}

.search-container label {
    display: block;
    font-size: 0.9em;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.search-title {
    margin: 0 0 10px 0;
    font-size: 16px;
    font-weight: bold;
    color: #323232;
}

.search-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    width: 100%;
    box-sizing: border-box;
}

.search-input {
    flex: 1;
    min-width: 0; /* Prevents flex item from overflowing */
    padding: 8px 12px;
    border: 1px solid #767676;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.search-input:focus {
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.1);
}

.search-button {
    padding: 8px 20px;
    background-color: #0078d4;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.search-button:hover {
    background-color: #45a049;
    transform: translateY(-1px);
}

.search-button:active {
    transform: translateY(0);
}

.clear-button {
    padding: 8px 12px;
    background-color: #f44336;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease, opacity 0.2s ease;
    line-height: 1;
    display: none; /* Hidden by default */
}

.clear-button.visible {
    display: block;
}

.clear-button:hover {
    background-color: #da190b;
    transform: translateY(-1px);
}

.clear-button:active {
    transform: translateY(0);
}

.search-hint {
    margin: 0;
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

#layerPanel h3 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #333;
    border-bottom: 2px solid #0079c1;
    padding-bottom: 5px;
}

.layer-control {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    padding: 4px 8px;
    box-sizing: border-box;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    min-height: 28px;
}

.layer-control:last-child {
    margin-bottom: 0;
}

.layer-control input[type="checkbox"] {
    margin-right: 10px;
    transform: scale(1.2);
    cursor: pointer;
}

.layer-control input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.layer-control label {
    font-size: 14px;
    color: #333;
    cursor: pointer;
    user-select: none;
    flex: 1;
    line-height: 1.2; /* Consistent line height */
}

.layer-control input[type="checkbox"]:disabled + label {
    color: #999;
    cursor: not-allowed;
}

.layer-control:hover {
    background-color: #f5f5f5;
    /* No dimension changes - only background color */
}

/* Fix popup text visibility */
.esri-popup__main-container {
    color: #323232 !important;
}

.esri-popup__header-title {
    color: #323232 !important;
}

.esri-popup__content {
    color: #323232 !important;
}

.esri-popup__header {
    background-color: #f3f3f3 !important;
}

.esri-popup__footer {
    background-color: #f3f3f3 !important;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet and smaller screens (max-width: 768px) */
@media screen and (max-width: 768px) {
    /* Search widget - leave space for home button on left */
    #searchWidget {
        top: 10px;
        right: 10px;
        left: 110px;
        width: auto;
        max-width: none;
    }
    
    .search-container {
        padding: 12px;
    }
    
    .search-title {
        font-size: 14px;
    }
    
    .search-input-group {
        flex-direction: column;
        gap: 6px;
    }
    
    .search-input,
    .search-button,
    .clear-button {
        width: 100%;
    }
    
    /* Layer panel - move to bottom left, reduce size */
    #layerPanel {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        padding: 12px;
    }
    
    #layerPanel h3 {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    .layer-control {
        padding: 6px 4px;
        margin-bottom: 6px;
    }
    
    .layer-control label {
        font-size: 13px;
    }
    
    /* Home button and zoom controls - adjust for mobile */
    .esri-ui-corner .esri-component {
        margin: -10px;
    }
    
    /* Ensure home button is visible and accessible on mobile */
    .esri-widget--button {
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
    }
    
    /* Position zoom controls and home button for mobile */
    .esri-ui-top-left {
        top: 5px !important;
        left: 5px !important;
        z-index: 101 !important;
    }
}

/* Mobile phones (max-width: 480px) */
@media screen and (max-width: 480px) {
    #searchWidget {
        top: 5px;
        right: 5px;
        left: 100px;
    }
    
    .search-container {
        padding: 10px;
    }
    
    .search-title {
        font-size: 13px;
        margin-bottom: 8px;
    }
    
    .search-input,
    .search-button,
    .clear-button {
        padding: 10px;
        font-size: 14px;
    }
    
    .search-hint {
        font-size: 11px;
    }
    
    #layerPanel {
        bottom: 5px;
        right: 5px;
        left: 5px;
        padding: 10px;
    }
    
    #layerPanel h3 {
        font-size: 13px;
    }
    
    .layer-control {
        margin-bottom: 4px;
        padding: 4px 2px;
    }
    
    .layer-control label {
        font-size: 12px;
    }
    
    .layer-control input[type="checkbox"] {
        transform: scale(1.1);
        margin-right: 8px;
    }
    
    #controls {
        top: 5px;
        bottom: auto;
        left: 5px;
        right: 5px;
        padding: 10px;
        max-height: 35vh;
    }
    
    .controls-header {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .message-list {
        max-height: 120px;
    }
    
    .message-item {
        padding: 6px 8px;
        font-size: 11px;
    }
    
    /* Ensure home button and zoom controls are larger on small mobile */
    .esri-widget--button {
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
    }
    
    .esri-ui-top-left {
        top: 0px !important;
        left: 0px !important;
        z-index: 101 !important;
    }
}

/* Large screens (min-width: 1200px) */
@media screen and (min-width: 1200px) {
    #searchWidget {
        width: 400px;
    }
    
    #layerPanel {
        max-width: 320px;
    }
}

/* Landscape orientation on mobile devices */
@media screen and (max-width: 768px) and (orientation: landscape) {
    #searchWidget {
        top: 5px;
        right: 5px;
        width: 300px;
        left: auto;
    }
    
    #layerPanel {
        right: 5px;
        left: auto;
        bottom: 5px;
        max-width: 250px;
    }
    
    /* Ensure home button is visible in landscape */
    .esri-ui-top-left {
        top: 3px !important;
        left: 3px !important;
        z-index: 101 !important;
    }
}

/* Print styles */
@media print {
    #searchWidget,
    #layerPanel,
    .esri-ui {
        display: none !important;
    }
    
    #viewDiv {
        height: 100vh;
        width: 100vw;
    }
}