/* ==========================================================================
   地图页专属样式
   --------------------------------------------------------------------------
   仅由 app/views/map/show.html.erb 通过 content_for :css 引入，
   data-turbo-track="dynamic" 保证离开地图页后样式会被移除。
   这里只写“全屏海图”相关的规则，通用品牌样式见 pages.css。
   ========================================================================== */

/* 让地图页的主容器突破 Bootstrap 的 1140px 宽度限制。
   只命中 body 的直接子元素 main.site-main，不污染导航栏与页脚里的 .container。 */
body > main.site-main {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
}

.map-page {
    position: relative;
    padding: 12px 16px 18px;
}

#map {
    width: 100%;
    height: calc(100vh - var(--nav-h, 64px) - 42px);
    height: calc(100dvh - var(--nav-h, 64px) - 42px);
    min-height: 420px;
    border: 1px solid rgba(8, 21, 40, 0.1);
    border-radius: 18px;
    /* 海图主海色：瓦片缝隙或加载间隙露出的底色与海面一致，不显黑边 */
    background: #357595;
    box-shadow: 0 20px 48px rgba(8, 21, 40, 0.18);
    overflow: hidden;
}

/* 悬浮标题卡：不拦截地图拖拽 */
.map-panel {
    position: absolute;
    top: 28px;
    right: 32px;
    z-index: 500;
    min-width: 190px;
    margin: 0;
    padding: 0.9rem 1.1rem;
    color: #fff;
    background: rgba(8, 21, 40, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 14px;
    box-shadow: 0 14px 34px rgba(6, 15, 28, 0.28);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    pointer-events: none;
}

.map-panel__eyebrow {
    margin: 0 0 0.25rem;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: #e6c985;
}

.map-panel__title {
    margin: 0 0 0.25rem;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.map-panel__hint {
    margin: 0;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
}

/* Leaflet 缩放控件换成本站配色 */
.leaflet-control-zoom {
    overflow: hidden;
    border: 0 !important;
    border-radius: 10px !important;
    box-shadow: 0 8px 20px rgba(8, 21, 40, 0.18) !important;
}

.leaflet-control-zoom a {
    color: #103153 !important;
    background: #fff !important;
    border-bottom-color: #e5e9f1 !important;
}

.leaflet-control-zoom a:hover {
    color: #081528 !important;
    background: #f4f6fa !important;
}

.leaflet-control-zoom a:last-child {
    border-bottom: 0 !important;
}

.leaflet-control-zoom a:focus-visible {
    outline: 3px solid rgba(217, 178, 95, 0.55);
    outline-offset: -3px;
}

body .leaflet-control-attribution {
    display: none !important;
}

/* ==========================================================================
   图例（悬浮在地图左下角的 details 面板）
   --------------------------------------------------------------------------
   flex-direction: column-reverse 让 summary 排在面板下方，
   展开时面板向上生长，不会把 toggle 推出可视区。
   ========================================================================== */

.map-legend {
    position: absolute;
    left: 28px;
    bottom: 34px;
    z-index: 650;
    display: flex;
    flex-direction: column-reverse;
    max-width: min(78vw, 268px);
    color: #fff;
}

.map-legend__toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: .5rem .8rem;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .08em;
    color: #fff;
    cursor: pointer;
    list-style: none;
    background: rgba(8, 21, 40, .78);
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 999px;
    box-shadow: 0 10px 26px rgba(6, 15, 28, .28);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    user-select: none;
}

.map-legend__toggle::-webkit-details-marker {
    display: none;
}

.map-legend__toggle::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e6c985;
    box-shadow: 0 0 0 3px rgba(230, 201, 133, .18);
}

.map-legend__toggle:focus-visible {
    outline: 3px solid rgba(217, 178, 95, .6);
    outline-offset: 2px;
}

.map-legend__panel {
    margin-bottom: 8px;
    padding: .85rem .95rem;
    width: 252px;
    box-sizing: border-box;
    color: #fff;
    background: rgba(8, 21, 40, .86);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 14px;
    box-shadow: 0 16px 38px rgba(6, 15, 28, .34);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    max-height: 52vh;
    overflow-y: auto;
    overflow-wrap: anywhere;
}

details[open] .map-legend__panel {
    animation: legend-in .18s ease-out;
}

@keyframes legend-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.map-legend__title {
    margin: 0 0 .6rem;
    font-size: .62rem;
    font-weight: 600;
    letter-spacing: .24em;
    text-transform: uppercase;
    color: #e6c985;
}

.map-legend__list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: .55rem;
}

.map-legend__item {
    display: flex;
    gap: .55rem;
    align-items: flex-start;
}

.map-legend__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: .72rem;
    line-height: 1.45;
}

.map-legend__text strong {
    font-size: .76rem;
    font-weight: 600;
    color: #fff;
}

.map-legend__text span {
    color: rgba(255, 255, 255, .55);
}

.map-legend__dot {
    width: 11px;
    height: 11px;
    margin-top: 3px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #e6c985;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .85), 0 2px 6px rgba(0, 0, 0, .35);
}

.map-legend__area {
    width: 11px;
    height: 11px;
    margin-top: 3px;
    flex: 0 0 auto;
    border-radius: 3px;
    background: rgba(255, 255, 255, .9);
}

.map-legend__route {
    width: 24px;
    height: 11px;
    margin-top: 4px;
    flex: 0 0 auto;
    border-top: 2px dashed #d9b25f;
}

.map-legend__subtitle {
    margin: .8rem 0 .4rem;
    font-size: .6rem;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .45);
}

.map-legend__port-list {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.map-legend__port {
    padding: .22rem .5rem;
    font-size: .68rem;
    color: #f2e4c2;
    background: rgba(230, 201, 133, .12);
    border: 1px solid rgba(230, 201, 133, .28);
    border-radius: 999px;
    cursor: pointer;
}

.map-legend__port:hover {
    background: rgba(230, 201, 133, .2);
}

.map-legend__port:focus-visible {
    outline: 3px solid rgba(217, 178, 95, .55);
    outline-offset: 2px;
}

/* 「显示全部港口」开关 */
.map-legend__all {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-top: .55rem;
    padding: .3rem .6rem;
    font-size: .68rem;
    font-weight: 600;
    color: #f2e4c2;
    background: rgba(230, 201, 133, .1);
    border: 1px solid rgba(230, 201, 133, .3);
    border-radius: 999px;
    cursor: pointer;
}

.map-legend__all:hover {
    background: rgba(230, 201, 133, .2);
}

.map-legend__all:focus-visible {
    outline: 3px solid rgba(217, 178, 95, .55);
    outline-offset: 2px;
}

.map-legend__all[aria-pressed="true"] {
    color: #081528;
    background: #e6c985;
    border-color: #e6c985;
}

/* 全部港口的 hover 提示 */
.leaflet-tooltip.map-port-tip {
    padding: 2px 6px;
    font-size: .66rem;
    color: #fff;
    background: rgba(8, 21, 40, .9);
    border: 0;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(6, 15, 28, .25);
}

.leaflet-tooltip.map-port-tip::before {
    display: none;
}

/* ==========================================================================
   港口 marker（divIcon）与弹窗
   ========================================================================== */

.map-port-icon {
    background: none;
    border: 0;
}

.map-port-icon__dot {
    display: block;
    width: 14px;
    height: 14px;
    margin: 5px;
    border-radius: 50%;
    background: #e6c985;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .92), 0 3px 8px rgba(6, 15, 28, .45);
    transition: transform .15s ease;
}

.map-port-icon:hover .map-port-icon__dot,
.map-port-icon:focus-visible .map-port-icon__dot {
    transform: scale(1.25);
}

.map-port-icon:focus-visible {
    outline: none;
}

.map-port-icon:focus-visible .map-port-icon__dot {
    box-shadow: 0 0 0 2px #fff, 0 0 0 5px rgba(217, 178, 95, .65), 0 3px 8px rgba(6, 15, 28, .45);
}

/* 显示全部港口时，精选港口也缩成与其余港口一致的小圆点 */
[data-all-ports="on"] .map-port-icon__dot {
    box-sizing: border-box;
    width: 7px;
    height: 7px;
    margin: 8.5px;
    background: #e6c985;
    border: 1px solid #d9b25f;
    box-shadow: none;
}

.map-port-popup .leaflet-popup-content-wrapper {
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(6, 15, 28, .28);
}

.map-port-popup .leaflet-popup-content {
    margin: 0;
}

.map-port-popup__body {
    padding: .85rem .95rem;
    color: #0d2a45;
}

.map-port-popup__region {
    font-size: .6rem;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: #9a7a34;
}

.map-port-popup__name {
    margin: .15rem 0 .4rem;
    font-size: 1rem;
    font-weight: 700;
}

.map-port-popup__desc {
    margin: 0 0 .5rem;
    font-size: .76rem;
    line-height: 1.55;
    color: #33455c;
}

.map-port-popup__meta {
    margin: 0 0 .2rem;
    font-size: .66rem;
    color: #6b7a8c;
}

.map-port-popup__source {
    margin: 0 0 .5rem;
    font-size: .64rem;
    line-height: 1.5;
    color: #8a97a8;
}

.map-port-popup__link {
    display: inline-block;
    font-size: .7rem;
    font-weight: 600;
    color: #8a6a1f;
}

.map-port-popup__link:hover {
    color: #0d2a45;
}

@media (max-width: 991.98px) {
    /* 手机上导航下方还有一条常驻搜索栏，地图高度要相应扣掉 */
    #map {
        height: calc(100dvh - var(--nav-h, 64px) - 110px);
        min-height: 360px;
    }

    .map-panel {
        top: 22px;
        right: 22px;
        min-width: 0;
        padding: 0.7rem 0.85rem;
    }

    .map-panel__hint {
        display: none;
    }

    .map-legend {
        left: 22px;
        bottom: 22px;
    }
}

@media (max-width: 575.98px) {
    .map-page {
        padding: 8px 10px 12px;
    }

    #map {
        border-radius: 14px;
    }

    .map-panel {
        top: 18px;
        right: 18px;
    }

    /* 窄屏下图例横铺在底部，面板占满宽度；限高 + 内部滚动避免撑破地图 */
    .map-legend {
        left: 10px;
        right: 10px;
        bottom: 12px;
        max-width: none;
    }

    .map-legend__toggle {
        padding: .45rem .7rem;
    }

    .map-legend__panel {
        width: 100%;
        max-height: 46vh;
    }
}
