/* Smartphone-first layout adjustments */

@media (max-width: 600px) {
    html,
    body {
        width: 100%;
        height: 100%;
        height: 100dvh;
    }

    .topbar {
        top: calc(env(safe-area-inset-top, 0px) + 6px);
        left: 8px;
        right: 8px;
        min-height: 62px;
        padding: 7px 10px;
        border-radius: 16px;
        gap: 8px;
    }

    .brand {
        min-width: 0;
        gap: 8px;
    }

    .brandMark {
        flex: 0 0 42px;
        width: 42px;
        height: 42px;
    }

    .brandMark img {
        top: -18%;
        left: -23%;
        width: 146% !important;
        height: 146% !important;
    }

    .brandCopy {
        min-width: 0;
    }

    .productName {
        display: block;
        font-size: 7px;
    }

    .brandCopy h1 {
        font-size: 16px;
        line-height: 1.15;
    }

    .locationStatus {
        max-width: 150px;
        margin-top: 3px;
        overflow: hidden;
        font-size: 10px;
        line-height: 1.2;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .searchSummary {
        flex: 0 0 auto;
        gap: 3px;
    }

    .radiusBadge {
        padding: 6px 8px 5px;
    }

    .radiusBadge span {
        display: none;
    }

    .radiusBadge select {
        min-width: 51px;
        font-size: 13px;
    }

    .dataFreshness {
        max-width: 58px;
        font-size: 8px;
    }

    #filterBar {
        top: calc(env(safe-area-inset-top, 0px) + 74px);
        left: 8px;
        right: 8px;
        gap: 6px;
        padding: 3px 0 6px;
        scroll-snap-type: x proximity;
    }

    .chip {
        width: auto;
        height: 44px;
        min-width: 58px;
        padding: 0 10px;
        flex-direction: row;
        gap: 4px;
        border-radius: 13px;
        scroll-snap-align: start;
    }

    .chipIcon {
        font-size: 17px;
    }

    .chipIcon img {
        width: 20px !important;
        height: 20px !important;
    }

    .chip span {
        font-size: 11px;
    }

    #sheet {
        height: 112px;
        min-height: 112px;
        max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 86px);
        overflow: hidden;
        border-radius: 22px 22px 0 0;
        transition: height 0.25s ease;
    }

    #sheet.expanded {
        height: min(72dvh, 620px);
        min-height: 230px;
    }

    #sheet:not(.expanded) #messageArea,
    #sheet:not(.expanded) .dataNotice,
    #sheet:not(.expanded) #cardList {
        display: none;
    }

    .sheetHandle {
        height: 44px;
        min-height: 44px;
    }

    .sheetHandle span {
        width: 46px;
        height: 5px;
    }

    .sheetHeader {
        padding: 0 14px 9px;
    }

    .sheetSubTitle {
        font-size: 9px;
    }

    .sheetHeader h2 {
        margin-top: 2px;
        font-size: 19px;
        line-height: 1.15;
    }

    .spotCount {
        min-width: 46px;
        height: 28px;
        padding: 0 8px;
        font-size: 12px;
    }

    #messageArea {
        padding: 7px 12px;
        font-size: 11px;
        line-height: 1.35;
    }

    .dataNotice {
        margin: 0 10px 5px;
        padding: 7px 9px;
        font-size: 9px;
    }

    .dataNoticeIcon {
        flex-basis: 18px;
        width: 18px;
        height: 18px;
    }

    #messageArea:empty {
        display: none;
    }

    #messageArea[data-tone="warning"] {
        background: #fff7e8;
        color: #9a6100;
    }

    #cardList {
        padding: 8px 10px calc(14px + env(safe-area-inset-bottom, 0px));
    }

    .facility-card {
        min-height: 72px;
        margin-bottom: 8px;
        padding: 10px;
        border-radius: 16px;
    }

    .facility-card .nav-btn {
        min-height: 44px;
        padding: 6px 8px;
        font-size: 9px;
    }

    .facility-loading {
        min-height: 96px;
        padding: 18px 12px;
        font-size: 12px;
    }

    .facility-loading-icon {
        margin-bottom: 6px;
        font-size: 26px;
    }

    .utilityRail {
        right: 10px;
        bottom: 126px;
        transition: opacity 0.2s ease;
    }

    .mapButton {
        width: 48px;
        height: 48px;
        font-size: 22px;
    }

    .sheet-expanded .utilityRail {
        opacity: 0;
        pointer-events: none;
    }

    .leaflet-control-zoom,
    .leaflet-control-scale {
        display: none;
    }

    .leaflet-control-attribution {
        max-width: 62vw;
        overflow: hidden;
        font-size: 9px !important;
        line-height: 1.2;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #loadingScreen {
        background: rgba(238, 248, 255, 0.86);
        backdrop-filter: blur(8px);
    }

    .loadingCard {
        width: min(82vw, 300px);
        padding: 24px 18px;
        border: 1px solid var(--line);
        border-radius: 22px;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: var(--shadow);
    }

    .loadingBrand {
        width: 112px;
        height: 112px;
        margin: -16px auto -8px;
        overflow: hidden;
    }

    .loadingBrand img {
        width: 100%;
        height: 100%;
        object-fit:contain;
    }

    .spinner {
        width: 46px;
        height: 46px;
        margin: 0 auto;
        border-width: 5px;
    }

    .loadingCard h2 {
        margin-top: 14px;
        font-size: 18px;
    }

    .loadingCard p {
        font-size: 12px;
    }
}

@media (max-width: 360px), (max-height: 650px) and (max-width: 600px) {
    .topbar {
        min-height: 52px;
    }

    .brandMark {
        flex-basis: 36px;
        width: 36px;
        height: 36px;
    }

    .brandMark img {
        width: 146% !important;
        height: 146% !important;
    }

    .locationStatus {
        max-width: 122px;
    }

    #filterBar {
        top: calc(env(safe-area-inset-top, 0px) + 68px);
    }

    .chip {
        height: 44px;
        min-width: 54px;
        padding: 0 8px;
    }

    #sheet {
        height: 108px;
        min-height: 108px;
    }

    #sheet.expanded {
        height: 66dvh;
        min-height: 205px;
    }

    .utilityRail {
        bottom: 120px;
    }
}

@media (min-width: 601px) and (max-width: 899px) and (min-height: 501px) {
    #sheet {
        height: 116px;
        min-height: 116px;
        overflow: hidden;
        transition: height 0.25s ease;
    }

    #sheet.expanded {
        height: min(72dvh, 620px);
        min-height: 240px;
    }

    #sheet:not(.expanded) #messageArea,
    #sheet:not(.expanded) .dataNotice,
    #sheet:not(.expanded) #cardList {
        display: none;
    }

    .utilityRail {
        bottom: 130px;
    }

    .sheet-expanded .utilityRail {
        opacity: 0;
        pointer-events: none;
    }
}

@media (min-width: 601px) and (max-width: 899px) and (max-height: 500px) {
    #sheet {
        top: auto;
        right: 8px;
        bottom: 8px;
        left: auto;
        width: min(42vw, 340px);
        height: 108px;
        min-height: 0;
        max-height: none;
        overflow: hidden;
        border-radius: 20px;
    }

    #sheet.expanded {
        top: 152px;
        height: auto;
    }

    #sheet:not(.expanded) #messageArea,
    #sheet:not(.expanded) .dataNotice,
    #sheet:not(.expanded) #cardList {
        display: none;
    }

    .sheetHeader {
        padding-bottom: 8px;
    }

    .dataNotice {
        display: none;
    }

    #cardList {
        padding-top: 6px;
    }

    .utilityRail {
        right: calc(min(42vw, 340px) + 20px);
        bottom: 124px;
    }

    .sheet-expanded .utilityRail {
        opacity: 0;
        pointer-events: none;
    }
}

@media (min-width: 900px) {
    .topbar {
        width: 420px;
        top: 16px;
        left: 16px;
        right: auto;
        z-index: 1100;
        box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    }

    #filterBar {
        width: 420px;
        top: 96px;
        left: 16px;
        right: auto;
        z-index: 1050;
        padding: 0;
    }

    #sheet {
        width: 420px;
        top: 164px;
        left: 16px;
        right: auto;
        bottom: 16px;
        height: calc(100dvh - 180px);
        min-height: 0;
        border-radius: 24px;
        z-index: 1000;
        box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    }

    .sheetHandle {
        display: none;
    }

    .utilityRail {
        right: 20px;
        bottom: 30px;
    }
}
