/* 通学バス 路線図（bus_map.html）。方面ごとの色は JS が --line-color に入れる */

.bmap-page {
    --bmap-time-w: 3.3em;

    & .bmap-overview,
    & .bmap-notices {
        background-color: #fff;
        border-radius: 1.25rem;
        padding: clamp(1rem, 4vw, 2rem);
        box-shadow: 0 6px 20px rgb(0 0 0 / 0.06);
    }

    & .bmap-heading {
        text-align: center;

        & h2 {
            font-size: clamp(1.3rem, 4.5vw, 1.7rem);
            margin: 0.1rem 0 0.3rem;
        }
    }

    & .bmap-kicker {
        font-family: "Anton", sans-serif;
        letter-spacing: 0.15em;
        color: var(--symbol-red);
        font-size: 0.85rem;
    }

    & .bmap-lead {
        color: #555;
        font-size: 0.92rem;
    }

    /* ── 探す・表示の切り替え ── */

    & .bmap-tools {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.6rem 1rem;
        max-width: 760px;
        margin: 1rem auto 0.5rem;

        @media (min-width: 1000px) {
            max-width: none;
        }
    }

    & .bmap-search {
        flex: 1 1 260px;
        min-width: 0;
        z-index: 5;

        /* スマホは検索欄で1行を使い、切り替えはその下へ */
        @media (max-width: 600px) {
            flex-basis: 100%;
        }
    }

    & .bmap-search-box {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
        min-width: 0;
        padding: 0 0.9rem;
        border: 2px solid #e2ddd5;
        border-radius: 999px;
        background-color: #fafafa;

        &:focus-within {
            border-color: var(--symbol-blue);
            background-color: #fff;
        }

        & input {
            flex: 1 1 0;
            width: 100%;
            min-width: 0;
            font-size: 1rem; /* 16px 未満だと iPhone が拡大する */
            padding: 0.65rem 0;
            border: none;
            border-radius: 0;
            background: none;
            outline: none;
            /* iPhone の Safari は type="search" に独自の見た目と幅を付け、枠からはみ出すので外す */
            -webkit-appearance: none;
            appearance: none;
            text-overflow: ellipsis;
        }
    }

    /* 「路線図｜一覧」：スマホでは検索欄の下に横いっぱい */
    @media (max-width: 600px) {
        & .bmap-views {
            width: 100%;

            & .bmap-view {
                flex: 1;
            }
        }
    }

    /* 虫めがね */
    & .bmap-search-icon {
        width: 0.9rem;
        height: 0.9rem;
        border: 2px solid #888;
        border-radius: 50%;
        flex-shrink: 0;

        &::after {
            content: "";
            position: absolute;
            right: -0.35rem;
            bottom: -0.3rem;
            width: 0.4rem;
            height: 2px;
            background-color: #888;
            transform: rotate(45deg);
        }
    }

    & .bmap-suggest {
        position: absolute;
        left: 0;
        right: 0;
        top: calc(100% + 0.35rem);
        max-height: min(60vh, 26rem);
        overflow-y: auto;
        padding: 0.35rem;
        border-radius: 1rem;
        background-color: #fff;
        box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);

        &[hidden] {
            display: none;
        }
    }

    & .bmap-suggest-item {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        width: 100%;
        padding: 0.55rem 0.7rem;
        border: none;
        border-radius: 0.7rem;
        background: none;
        text-align: left;
        cursor: pointer;

        &:hover,
        &:focus-visible {
            background-color: color-mix(in srgb, var(--line-color) 10%, #fff);
            outline: none;
        }
    }

    & .bmap-suggest-dot {
        width: 0.75rem;
        height: 0.75rem;
        border-radius: 50%;
        background-color: var(--line-color);
        flex-shrink: 0;
    }

    & .bmap-suggest-text {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
    }

    & .bmap-suggest-name {
        font-size: 0.95rem;
        color: #222;
    }

    & .bmap-suggest-line {
        font-size: 0.75rem;
        color: color-mix(in srgb, var(--line-color) 75%, #000);
    }

    & .bmap-suggest-time {
        font-size: 0.9rem;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    & .bmap-suggest-empty {
        padding: 0.7rem;
        font-size: 0.9rem;
        color: #777;
    }

    /* 路線図／一覧 */
    & .bmap-views {
        display: inline-flex;
        padding: 0.2rem;
        border-radius: 999px;
        background-color: #f1ede6;
    }

    & .bmap-view {
        padding: 0.45rem 1.1rem;
        border: none;
        border-radius: 999px;
        background: none;
        font-size: 0.9rem;
        font-weight: 700;
        color: #777;
        cursor: pointer;

        &[aria-selected="true"] {
            background-color: #fff;
            color: var(--symbol-red);
            box-shadow: 0 1px 4px rgb(0 0 0 / 0.12);
        }
    }

    /* ── 一覧（全方面） ── */

    & .bmap-listview {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
        gap: 1rem;
        align-items: start;
        margin-top: 0.8rem;

        &[hidden] {
            display: none;
        }
    }

    & .bmap-empty {
        grid-column: 1 / -1;
        text-align: center;
        padding: 1.5rem;
        color: #666;
    }

    /* 探した停留所の印 */
    & .bmap-stop.is-hit .bmap-stop-name {
        background: linear-gradient(transparent 55%, #ffe36b 55%);
        font-weight: 700;
    }

    /* ── 路線図と詳細の枠 ── */

    & .bmap-stage {
        max-width: 760px;
        margin: 0.5rem auto 0;
        scroll-margin-top: 6rem;

        &[hidden] {
            display: none;
        }

        /* スマホ・タブレット：詳細を開いている間は路線図を隠す（同じ枠で切り替え）。PC 幅は下で上書き */
        &.is-detail .bmap-figure {
            display: none;
        }

        /* スマホでは枠の内側の余白を削って、路線図を画面いっぱいに */
        @media (max-width: 600px) {
            margin-inline: calc(clamp(1rem, 4vw, 2rem) * -1 + 0.25rem);
        }

        /* PC 幅：路線図｜パネル（440px）を横に並べる（JS の wideMql と同じ幅） */
        @media (min-width: 1000px) {
            max-width: none;
            display: grid;
            grid-template-columns: minmax(0, 1fr) 440px;
            gap: 1.5rem;
            align-items: start;

            &.is-detail .bmap-figure {
                display: block;
            }

            /* 路線図は画面の高さに収まる大きさまで（ヘッダーの分を引く） */
            & .bmap-figure {
                position: sticky;
                top: 6rem;
                width: 100%;
                max-width: calc(100vh - 8rem);
                justify-self: center;
            }

            & .bmap-mini {
                display: none;
            }

            & .bmap-status {
                grid-column: 1 / -1;
            }
        }
    }

    & .bmap-svg {
        display: block;
        width: 100%;
        height: auto;
        overflow: visible;

        /* 方面を選んでいるとき（PC 幅で路線図が見えている）・探しているときは、ほかを薄く */
        &.has-selection .bmap-spoke:not(.is-selected),
        &.has-search .bmap-spoke:not(.is-match) {
            opacity: 0.25;
        }

        & .bmap-spoke {
            transition: opacity 0.2s;
        }
    }

    & .bmap-ring {
        fill: none;
        stroke: #eee6d8;
        stroke-width: 1.5;
        stroke-dasharray: 4 6;
    }

    & .bmap-compass {
        fill: #999;

        & text {
            font-size: 15px;
            font-weight: 700;
            text-anchor: middle;
        }
    }

    & .bmap-spoke {
        cursor: pointer;
        outline: none;

        &:hover .bmap-spoke-line,
        &:focus-visible .bmap-spoke-line {
            stroke-width: 14;
        }

        &:hover .bmap-label-bg,
        &:focus-visible .bmap-label-bg {
            stroke: #222;
            stroke-width: 3;
        }
    }

    & .bmap-spoke-hit {
        stroke: transparent;
        stroke-width: 36;
        stroke-linecap: round;
    }

    & .bmap-spoke-line {
        stroke: var(--line-color);
        stroke-width: 10;
        stroke-linecap: round;
        transition: stroke-width 0.2s;
    }

    & .bmap-spoke-stop {
        fill: #fff;
        stroke: var(--line-color);
        stroke-width: 3.5;
    }

    & .bmap-label-bg {
        fill: var(--line-color);
    }

    & .bmap-label-text {
        fill: #fff;
        font-size: 26px;
        font-weight: 700;
    }

    & .bmap-hub-circle {
        fill: #fff;
        stroke: var(--symbol-red);
        stroke-width: 4;
    }

    & .bmap-hub-text {
        text-anchor: middle;
        font-size: 17px;
        font-weight: 700;
        fill: var(--symbol-red);
    }

    /* 小さい路線図（詳細の左上）：選んだ方面だけ色、ほかは灰色 */
    & .bmap-svg.is-mini {
        & .bmap-spoke {
            cursor: default;
        }

        & .bmap-spoke-line {
            stroke: #e2ddd5;
            stroke-width: 18;
        }

        & .bmap-spoke.is-selected .bmap-spoke-line {
            stroke: var(--line-color);
            stroke-width: 44;
        }

        & .bmap-hub-circle {
            fill: var(--symbol-red);
            stroke: none;
        }
    }

    & .bmap-status {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.8rem;
        padding: 2.5rem 1rem;
        color: #555;
        text-align: center;

        &[hidden] {
            display: none;
        }
    }

    & .bmap-loader {
        width: 2rem;
        height: 2rem;
        border: 3px solid #ddd;
        border-top-color: var(--symbol-red);
        border-radius: 50%;
        animation: bmap-spin 0.9s linear infinite;
    }

    /* ── 詳細 ── */

    & .bmap-panel {
        &[hidden] {
            display: none;
        }

        &.anim-zoom {
            animation: bmap-zoom 0.28s ease-out;
        }

        &.anim-next {
            animation: bmap-from-right 0.22s ease-out;
        }

        &.anim-prev {
            animation: bmap-from-left 0.22s ease-out;
        }

        &.anim-fade {
            animation: bmap-fade 0.2s ease-out;
        }
    }

    /* PC 幅で方面を選ぶ前のパネル */
    & .bmap-panel-inner.is-placeholder {
        padding: 1.2rem;
        border: 2px dashed #e4ddd0;
        background-color: #fcfbf9;
    }

    & .bmap-placeholder-lead {
        font-size: 0.92rem;
        color: #555;
        margin: 0 0 1rem;
    }

    & .bmap-placeholder-list {
        display: flex;
        flex-wrap: wrap;
        gap: 0.45rem;
    }

    & .bmap-pick {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        font-size: 0.85rem;
        padding: 0.35rem 0.75rem 0.35rem 0.55rem;
        border: 2px solid var(--line-color);
        border-radius: 999px;
        background-color: #fff;
        color: #333;
        cursor: pointer;

        &::before {
            content: "";
            width: 0.7rem;
            height: 0.7rem;
            border-radius: 50%;
            background-color: var(--line-color);
        }

        &:hover {
            background-color: color-mix(in srgb, var(--line-color) 12%, #fff);
        }
    }

    & .bmap-panel-inner {
        border-radius: 1rem;
        border: 2px solid color-mix(in srgb, var(--line-color) 35%, #fff);
        overflow: clip;
    }

    & .bmap-panel-head {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.7rem 0.8rem;
        background-color: color-mix(in srgb, var(--line-color) 10%, #fff);
        border-bottom: 4px solid var(--line-color);
    }

    & .bmap-mini {
        width: 3.6rem;
        height: 3.6rem;
        flex-shrink: 0;
        padding: 0.2rem;
        border: none;
        border-radius: 0.7rem;
        background-color: #fff;
        cursor: pointer;
        box-shadow: 0 1px 4px rgb(0 0 0 / 0.12);
    }

    & .bmap-panel-title {
        flex: 1;
        min-width: 0;

        & h3 {
            font-size: 1.1rem;
            font-weight: 700;
            line-height: 1.35;
            margin: 0 0 0.25rem;
            color: color-mix(in srgb, var(--line-color) 75%, #000);
            outline: none;
        }
    }

    & .bmap-line-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 0.3rem 0.5rem;
        margin: 0;
        font-size: 0.78rem;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
    }

    & .bmap-meta-arrive {
        color: #fff;
        background-color: var(--line-color);
        padding: 0.05rem 0.55rem;
        border-radius: 999px;
    }

    & .bmap-meta-fee {
        color: #444;
        background-color: color-mix(in srgb, var(--line-color) 13%, #fff);
        padding: 0.05rem 0.55rem;
        border-radius: 999px;
    }

    & .bmap-close {
        width: 2.4rem;
        height: 2.4rem;
        flex-shrink: 0;
        border: none;
        border-radius: 50%;
        background-color: #fff;
        cursor: pointer;
        box-shadow: 0 1px 4px rgb(0 0 0 / 0.12);

        &::before,
        &::after {
            content: "";
            position: absolute;
            top: 50%;
            left: 50%;
            width: 1rem;
            height: 2.5px;
            background-color: #555;
            border-radius: 2px;
        }

        &::before {
            transform: translate(-50%, -50%) rotate(45deg);
        }

        &::after {
            transform: translate(-50%, -50%) rotate(-45deg);
        }
    }

    & .bmap-panel-body {
        padding: 0.3rem 0.9rem 0.9rem;
    }

    & .bmap-line-note {
        font-size: 0.85rem;
        color: #444;
        margin: 0.5rem 0 0;
    }

    & .bmap-trip-legend {
        display: flex;
        margin: 0.6rem 0 0;
        color: #777;

        & .bmap-time {
            font-size: 0.72rem;
        }
    }

    /* 時刻｜線と丸｜停留所 */

    & .bmap-route {
        list-style: none;
        margin: 0;
        padding: 0.5rem 0 0.8rem;
    }

    & .bmap-stop {
        display: grid;
        grid-template-columns: calc(var(--bmap-time-w) * var(--trip-count, 1)) 2.7rem 1fr auto;
        align-items: center;
        min-height: 3.1rem;
    }

    & .bmap-stop-times {
        display: flex;
        font-variant-numeric: tabular-nums;
    }

    & .bmap-time {
        width: var(--bmap-time-w);
        text-align: right;
        font-weight: 700;
        font-size: 1.05rem;

        &.is-skip {
            color: #bbb;
            font-weight: 400;
        }
    }

    & .bmap-node {
        align-self: stretch;
        display: grid;
        place-items: center;

        &::before {
            content: "";
            position: absolute;
            top: 0;
            bottom: 0;
            left: 50%;
            width: 6px;
            transform: translateX(-50%);
            background-color: var(--line-color);
        }

        &::after {
            content: "";
            width: 1.05rem;
            height: 1.05rem;
            border-radius: 50%;
            background-color: #fff;
            border: 4px solid var(--line-color);
            z-index: 1;
        }
    }

    & .bmap-stop:first-child .bmap-node::before {
        top: 50%;
    }

    & .bmap-stop:last-child .bmap-node::before {
        bottom: 50%;
    }

    & .bmap-stop-body {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.2rem;
        padding: 0.35rem 0 0.35rem 0.4rem;
        min-width: 0;
    }

    & .bmap-stop-name {
        display: inline-flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.15rem 0.4rem;
        font-size: 0.97rem;
        line-height: 1.4;
        color: #222;
        word-break: break-all;
    }

    /* 地図（行の右端・縦に揃える） */
    & .bmap-map-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.1rem;
        width: 2.7rem;
        min-height: 2.6rem;
        margin-left: 0.4rem;
        border: 1.5px solid color-mix(in srgb, var(--line-color) 55%, #fff);
        border-radius: 0.6rem;
        color: var(--line-color);
        text-decoration: none;
        background-color: #fff;
        transition: background-color 0.2s;

        &:hover,
        &:focus-visible {
            background-color: color-mix(in srgb, var(--line-color) 10%, #fff);
        }
    }

    & .bmap-map-icon {
        width: 0.8rem;
        height: 0.8rem;
        margin-top: 0.15rem;
        border-radius: 50% 50% 50% 0;
        transform: rotate(-45deg);
        background-color: currentColor;

        &::after {
            content: "";
            position: absolute;
            inset: 0;
            margin: auto;
            width: 0.3rem;
            height: 0.3rem;
            border-radius: 50%;
            background-color: #fff;
        }
    }

    & .bmap-map-text {
        font-size: 0.62rem;
        font-weight: 700;
        line-height: 1;
    }

    & .bmap-fee {
        font-size: 0.75rem;
        font-weight: 700;
        color: #444;
        background-color: color-mix(in srgb, var(--line-color) 13%, #fff);
        padding: 0.05rem 0.5rem;
        border-radius: 0.4rem;
    }

    & .bmap-stop.is-school {
        & .bmap-node::after {
            display: none;
        }

        & .bmap-stop-name {
            font-weight: 700;
        }

        & .bmap-time {
            color: color-mix(in srgb, var(--line-color) 80%, #000);
        }
    }

    & .bmap-school-mark {
        display: grid;
        place-items: center;
        width: 2.4rem;
        height: 2.4rem;
        border-radius: 50%;
        background-color: var(--line-color);
        color: #fff;
        font-size: 0.68rem;
        letter-spacing: 0.02em;
        font-weight: 700;
        box-shadow: 0 0 0 3px #fff;
        z-index: 1;
    }

    /* 下校便 */

    & .bmap-returns {
        padding: 0.7rem 0.9rem;
        border-radius: 0.8rem;
        background-color: #f6f5f2;

        & table {
            width: 100%;
            border-collapse: collapse;
        }

        & th {
            width: 1%;
            white-space: nowrap;
            text-align: left;
            font-size: 0.8rem;
            font-weight: 700;
            color: #666;
            padding: 0.3rem 0.8rem 0.3rem 0;
            vertical-align: middle;
        }

        & td {
            padding: 0.3rem 0;
            display: flex;
            flex-wrap: wrap;
            gap: 0.3rem;
        }

        & tr.is-today th {
            color: var(--symbol-red);
        }

        & tr.is-today .bmap-chip-time {
            border-color: var(--symbol-red);
        }
    }

    & .bmap-returns-title {
        font-size: 0.8rem;
        font-weight: 700;
        color: #555;
        margin: 0 0 0.3rem;
    }

    & .bmap-today {
        display: inline-block;
        margin-left: 0.35rem;
        font-size: 0.65rem;
        color: #fff;
        background-color: var(--symbol-red);
        padding: 0 0.4rem;
        border-radius: 999px;
        vertical-align: 0.1em;
    }

    & .bmap-chip-time {
        font-size: 0.85rem;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        background-color: #fff;
        border: 1px solid #ddd;
        border-radius: 0.4rem;
        padding: 0.05rem 0.45rem;
    }

    & .bmap-pending {
        font-size: 0.8rem;
        color: #999;
    }

    /* 前後の方面 */

    & .bmap-panel-nav {
        display: flex;
        justify-content: space-between;
        gap: 0.6rem;
        padding: 0.7rem 0.8rem;
        border-top: 1px solid #eee;
        background-color: #fcfbf9;
    }

    & .bmap-nav-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.4rem;
        max-width: 48%;
        padding: 0.45rem 0.8rem;
        border: 2px solid var(--line-color);
        border-radius: 999px;
        background-color: #fff;
        color: #333;
        font-size: 0.85rem;
        cursor: pointer;

        &.is-next {
            margin-left: auto;
            flex-direction: row-reverse;
        }
    }

    & .bmap-nav-arrow {
        font-size: 1.2rem;
        line-height: 1;
        color: var(--line-color);
        font-weight: 700;
    }

    & .bmap-nav-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* 注記 */

    & .bmap-notices {
        margin-top: 2rem;

        & h2 {
            font-size: 1.15rem;
            margin: 0 0 0.8rem;
        }

        & ul {
            list-style: none;
            margin: 0;
            padding: 0;
            display: grid;
            gap: 0.7rem;
        }

        & li {
            padding-left: 1.1rem;
            font-size: 0.92rem;
            line-height: 1.7;

            &::before {
                content: "";
                position: absolute;
                left: 0;
                top: 0.65em;
                width: 0.45rem;
                height: 0.45rem;
                border-radius: 50%;
                background-color: var(--symbol-blue);
            }

            &.is-alert {
                color: var(--symbol-red);
                font-weight: 700;

                &::before {
                    background-color: var(--symbol-red);
                }
            }

            & strong {
                display: block;
            }
        }
    }

    & .bmap-updated {
        margin-top: 1rem;
        text-align: right;
        font-size: 0.8rem;
        color: #777;
    }
}

@keyframes bmap-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes bmap-zoom {
    from {
        opacity: 0;
        transform: scale(0.6);
    }
}

@keyframes bmap-fade {
    from {
        opacity: 0;
    }
}

@keyframes bmap-from-right {
    from {
        opacity: 0;
        transform: translateX(2rem);
    }
}

@keyframes bmap-from-left {
    from {
        opacity: 0;
        transform: translateX(-2rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .bmap-page .bmap-panel {
        animation: none !important;
    }
}
