body {
    font-family: Arial, sans-serif;
    font-size: 18px;
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
}

/* Make width calculations predictable across elements */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Header styles */
.header {
    background-color: rgb(86, 27, 92);
    color: #fff;
    text-align: center;
    padding: 12px 16px;
    width: 100%;
}

/* Main content area styles */
.main-content {
    display: grid;
    grid-template-columns: 1fr 3fr; /* Left column takes 1/4 and right column takes 3/4 of the space */
    grid-gap: 20px;
    padding: 20px;
    flex-grow: 1;
}

/* Container styles within columns */
.container {
    background-color: #fff;
    padding: 12px;
    border-radius: 5px;
    text-align: left;
}

/* Set minimum height for the first container (address and suggestions) */
.container:first-child {
    width: 100%;
    max-width: 600px; /* Limit max-width for larger screens */
    margin: 0 auto;
}

/* Footer styles */
.footer {
    background-color: rgb(86, 27, 92);
    color: #fff;
    text-align: center;
    padding: 12px 16px;
    width: 100%;
}

.footer a {
    color: #fff;
    text-decoration: underline;
}

.footer a:hover {
    text-decoration: underline;
}

.layer-toggle {
    position: absolute;
    z-index: 1;
    background-color: white;
    padding: 10px;
    margin: 10px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

/* Input and button styles */
#addressInput {
    width: 100%; /* Takes up the full width of the parent container */
    max-width: 600px; /* Add a maximum width for larger screens */
    padding: 10px;
    box-sizing: border-box;
    font-size: 18px;
}

button {
    padding: 10px 20px;
    /* modest default padding for buttons */
    margin-top: 10px;
    font-size: 18px;
}

/* Specific styles for the main search button so it isn't too tall */
.search-button {
    padding: 8px 16px; /* smaller vertical padding */
    line-height: 1;
    height: auto;
    font-size: 16px;
    border-radius: 4px;
    display: inline-block;
    vertical-align: middle;
}

/* Suggestions styles */
#suggestions {
    background-color: #fff;
    border: 1px solid #ccc;
    overflow-y: auto;
    z-index: 1000; /* Ensure it appears above other elements */
    display: none;
    position: absolute; /* Position absolutely */
    width: 100%; /* Match parent width */
    box-sizing: border-box;
    max-width: 600px; /* Match the max-width of the input */
    /* Constrain height so the box scrolls instead of growing indefinitely */
    max-height: 250px;
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
    margin-top: 0; /* Remove margin */
}

/* Create a container for the search input and suggestions */
.search-container {
    position: relative; /* Make this a positioning context */
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.suggestion {
    padding: 10px;
    border-bottom: 1px solid #ccc;
    cursor: pointer;
    text-align: left;
}

.suggestion:hover {
    background-color: #f9f9f9;
}

/* Search result styles */
#result {
    margin-top: 20px;
}

/* Adjust the width of the result cards to match the search bar */
.school-card {
    border: 1px solid #ccc;
    border-radius: 5px;
    margin-bottom: 20px;
    width: 100%; /* Allow the card to take the full width of its container */
    max-width: 600px; /* Set a maximum width */
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    font-size: 18px;
    margin: 0 auto;
}

/* Adjust the icon size */
.school-card i {
    margin-right: 15px;
    /* Adjust icon margin */
    font-size: 24px;
    /* Increase icon size */
}

.elementary {
    background-color: #f9f9f9;
    /* Set background color for elementary schools */
}

.middle {
    background-color: #e0f7fa;
    /* Set background color for middle schools */
}

.high {
    background-color: #ffe0b2;
    /* Set background color for high schools */
}

.error {
    background-color: #f53d57;
    /* Set background color for error card */
}

.note {
    background-color: #E2F0CB;
    /* Set background color for note card */
}

#map {
    width: 100%;
    /* Let the map fill its parent container; parent will be sized by flex/grid so footer stays at the bottom */
    height: auto;
}

/* Floating share button inside the map container */
.map-share-button {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2000; /* above map controls and layers */
    background-color: #ffffff;
    border: 1px solid #ccc;
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px; /* icon size */
}

.map-share-button:hover {
    background-color: #f5f5f5;
}

/* Visual feedback states: inverted/negative coloring */
.map-share-button.copied {
    background-color: #111 !important;
    color: #fff !important;
    border-color: #333 !important;
}
.map-share-button.copy-error {
    background-color: #a00 !important;
    color: #fff !important;
    border-color: #700 !important;
}

/* Screen-reader only text for accessible buttons */
.sr-only {
    position: absolute !important;
    height: 1px; width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap; /* added line */
}

/* Ensure the map container forms a positioning context for the absolute button */
#map-container {
    position: relative;
}

/* Ensure the main content can shrink/grow correctly inside the flex column body */
.main-content {
    flex-grow: 1;
    min-height: 0; /* allow children to not force overflow */
    align-items: stretch;
}

/* Allow containers to shrink inside the grid/flex layout */
.container {
    min-height: 0;
}

/* Make the map's container a flex column so the #map can flex to fill remaining space */
.container:nth-child(2) {
    display: flex;
    flex-direction: column;
    padding: 0; /* map should reach full width inside this area; inner padding may be handled elsewhere */
}

.container:nth-child(2) #map {
    flex: 1 1 auto;
    height: auto;
}

/* Media query for portrait screens */
@media only screen and (orientation: portrait) {
    .header {
        font-size: 0.95em;
    }

    /* Let header/footer span exactly the viewport width on phones */
    .footer, .header {
        width: 100%;
        padding-left: 12px;
        padding-right: 12px;
    }

    .main-content {
        padding-left: 8px;
        padding-right: 8px;
        width: 100%;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .container {
        margin: 0 auto 16px auto;
        align-self: center;
        width: 100%;
        max-width: 680px; /* create whitespace on both sides */
        padding: 12px;
    }

    #addressInput {
        width: 100%;
        margin-top: 12px;
        padding: 10px;
    }

    .school-card {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .container {
        margin-bottom: 20px;
        padding: 12px;
        align-self: center;
        width: 100%;
        max-width: 680px;
    }

    #addressInput {
        max-width: 95%; /* Shrinks the input width on smaller screens */
        font-size: 14px;
    }

    button,
    .school-card {
        width: 100%; /* Take the available width inside the centered container */
        font-size: 14px; /* Reduce the font size to fit better */
        padding: 8px; /* Adjust padding for smaller screens */
    }

    #map {
        margin-left: 0px;
        margin-right: 0px;
    }

    .layer-toggle {
        display: none;
    }
    /* Hide the map and its container on small devices to save space */
    #map {
        display: none;
        height: 0;
        visibility: hidden;
    }
    #map-container {
        display: none;
    }
    /* Ensure the grid collapses to a single column when the map container is hidden */
    .main-content {
        grid-template-columns: 1fr;
    }
}


/* Tablet screens (e.g. iPad portrait/landscape) */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Make the grid narrower so the left column isn't too wide */
    .main-content {
        grid-template-columns: 1fr 2fr;
        grid-gap: 18px;
        padding-left: 16px;
        padding-right: 16px;
    }

    /* Center containers and give comfortable whitespace */
    .container {
        width: 100%;
        max-width: 820px;
        margin: 0 auto 18px auto;
        padding: 12px;
    }

    /* Search column slightly narrower than map column */
    .container:first-child {
        max-width: 640px;
    }

    /* Inputs and suggestion box should not exceed their parent */
    #addressInput,
    #suggestions,
    .school-card,
    #databaseSelect {
        width: 100%;
        max-width: 100%;
    }

    /* Keep header/footer spanning the viewport with consistent padding */
    .header, .footer {
        padding-left: 18px;
        padding-right: 18px;
    }

    /* Reduce map height a bit on tablets to avoid forcing horizontal scroll */
    #map {
        height: 55vh;
        max-height: 640px;
    }
    /* Hide the map on tablet to use space for search/results */
    #map {
        display: none;
        height: 0;
        visibility: hidden;
    }
    #map-container {
        display: none;
    }
    /* Collpase main grid to a single column when the map container is hidden */
    .main-content {
        grid-template-columns: 1fr;
    }
}
.database-selector {
    margin-bottom: 15px;
}

#databaseSelect {
    padding: 8px;
    font-size: 16px;
    width: 100%;
    max-width: 600px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

@media (max-width: 768px) {
    #databaseSelect {
    max-width: 95%;
    font-size: 14px;
    }
}