/**
 * 粮点地图 v2 样式
 * ========== 布局 ==========
 * .map-wrap: fixed 全屏（手机）/ margin 留边（PC）
 *   #txmap: 100% 填满
 *   .map-search-bar: 顶部 iOS 胶囊
 *   .map-controls: 右侧竖排（定位 + 缩放）
 *   .grain-sheet: 底部 iOS bottom sheet
 * .search-modal: 全屏搜索弹窗
 *   .search-modal-header: 取消 + 输入 + 确定
 *   .search-modal-map: 中间小地图
 *   .search-modal-list: 底部结果列表
 */

.grain-page {
    padding: 0;
    background: #f5f5f7;
}

/* ================================================================
 *  地图主容器
 * ============================================================== */
.map-wrap {
    position: fixed;
    top: 48px;        /* 手机 header 高度 */
    bottom: 60px;     /* 手机 tabbar 高度 */
    left: 0;
    right: 0;
    z-index: 1;
    overflow: hidden;
    background: #e9ecef;
}

#txmap {
    width: 100%;
    height: 100%;
}

/* ================================================================
 *  顶部搜索栏（iOS 胶囊风格）
 * ============================================================== */
.map-search-bar {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 72px;             /* 留空间给右侧控件 */
    z-index: 100;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 22px;
    padding: 11px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 3px 16px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    user-select: none;
    transition: transform 0.15s, box-shadow 0.15s;
}
.map-search-bar:active {
    transform: scale(0.98);
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1);
}

.search-icon {
    font-size: 16px;
    flex-shrink: 0;
}
.search-placeholder {
    flex: 1;
    font-size: 14px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-caret {
    font-size: 10px;
    color: #999;
    flex-shrink: 0;
}

/* ================================================================
 *  右侧竖排控件（定位 + 指南针 + 缩放）
 * ============================================================== */
.map-controls {
    position: absolute;
    right: 12px;
    top: 12px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.ctrl-locate,
.ctrl-compass,
.ctrl-zoom {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 50%;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
    border: none;
    padding: 0;
    font-family: inherit;
}
.ctrl-locate { font-size: 18px; }
.ctrl-compass { font-size: 18px; }
.ctrl-zoom {
    font-size: 20px;
    font-weight: 300;
    color: #333;
    line-height: 1;
}
.ctrl-locate:active,
.ctrl-compass:active,
.ctrl-zoom:active {
    background: rgba(255, 255, 255, 1);
    transform: scale(0.92);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.ctrl-zoom-group {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
    overflow: hidden;
}
.ctrl-zoom-group .ctrl-zoom {
    box-shadow: none;
    border-radius: 0;
}
.ctrl-zoom-sep {
    height: 1px;
    background: #eee;
    margin: 0 8px;
}

/* ================================================================
 *  底部粮点 Sheet（iOS bottom sheet 风格）
 * ============================================================== */
.grain-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 55%;
    background: #fff;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    z-index: 9997;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: max-height 0.3s ease;
    -webkit-overflow-scrolling: touch;
}
.grain-sheet.collapsed {
    max-height: 44px;
}

.sheet-handle {
    flex-shrink: 0;
    padding: 8px 16px 10px;
    text-align: center;
    cursor: pointer;
    user-select: none;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}
.handle-bar {
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
}
.sheet-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    text-align: center;
}
.sheet-toggle-icon {
    font-size: 10px;
    color: #999;
}

.sheet-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;
}

/* 粮点列表项 */
.grain-item {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #f3f3f3;
    cursor: pointer;
    transition: background 0.15s;
}
.grain-item:last-child {
    border-bottom: none;
}
.grain-item:active {
    background: #f7f7f7;
}

.grain-item-icon {
    width: 40px;
    height: 40px;
    background: rgba(76, 175, 80, 0.1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.grain-item-main {
    flex: 1;
    min-width: 0;
}

.grain-item-name {
    font-size: 15px;
    font-weight: 600;
    color: #222;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.grain-item-distance {
    font-size: 12px;
    font-weight: 400;
    color: #4caf50;
    background: rgba(76, 175, 80, 0.1);
    padding: 1px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

.grain-item-addr {
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.grain-item-meta {
    font-size: 12px;
    color: #999;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}
.grain-item-meta span {
    white-space: nowrap;
}

.grain-item-action {
    width: 32px;
    height: 32px;
    background: rgba(0, 122, 255, 0.12);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #007aff;
    font-size: 14px;
    flex-shrink: 0;
    align-self: center;
    cursor: pointer;
    transition: background 0.15s;
}
.grain-item-action:active {
    background: rgba(0, 122, 255, 0.24);
}

/* 空状态 */
.sheet-body .empty {
    padding: 50px 20px;
    text-align: center;
    color: #999;
}
.sheet-body .empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.6;
}
.sheet-body .empty-hint {
    font-size: 12px;
    margin-top: 6px;
    color: #bbb;
}

/* ================================================================
 *  搜索弹窗（图5）
 * ============================================================== */
.search-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f5f5f7;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    animation: modalSlideDown 0.2s ease;
}
@keyframes modalSlideDown {
    from { transform: translateY(-100%); }
    to   { transform: translateY(0); }
}

.search-modal-header {
    flex-shrink: 0;
    background: #fff;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #eee;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.search-cancel,
.search-confirm {
    flex-shrink: 0;
    background: none;
    border: none;
    font-size: 15px;
    padding: 8px 6px;
    cursor: pointer;
    font-family: inherit;
}
.search-cancel { color: #999; }
.search-confirm { color: #4caf50; font-weight: 600; }
.search-cancel:active { color: #666; }
.search-confirm:active { opacity: 0.7; }

.search-input-wrap {
    flex: 1;
    background: #f2f2f5;
    border-radius: 18px;
    padding: 8px 14px;
}
.search-input-wrap input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 15px;
    outline: none;
    color: #333;
}
.search-input-wrap input::placeholder {
    color: #bbb;
}

/* 搜索弹窗里的小地图 */
.search-modal-map {
    flex-shrink: 0;
    height: 200px;
    background: #e9ecef;
    position: relative;
}
#search-map {
    width: 100%;
    height: 100%;
}

/* 搜索结果列表 */
.search-modal-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    padding-bottom: env(safe-area-inset-bottom);
}

.search-result-item {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #f3f3f3;
    cursor: pointer;
    align-items: center;
    transition: background 0.15s;
}
.search-result-item:active {
    background: #f5f5f5;
}
.search-result-item .sr-icon {
    font-size: 18px;
    width: 32px;
    text-align: center;
    flex-shrink: 0;
}
.search-result-item .sr-info {
    flex: 1;
    min-width: 0;
}
.search-result-item .sr-name {
    font-size: 15px;
    font-weight: 500;
    color: #333;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-result-item .sr-addr {
    font-size: 12px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-result-item .sr-dist {
    font-size: 12px;
    color: #007aff;
    flex-shrink: 0;
    font-weight: 500;
}

.search-empty {
    padding: 60px 20px;
    text-align: center;
    color: #bbb;
    font-size: 14px;
}

/* ================================================================
 *  腾讯地图默认控件 —— 全部隐藏（激进版，一网打尽）
 * ============================================================== */
/* 通配符：class 包含 tmap-control / tmap-toolbar / tmap-ui / tmap-operate / tmap-logo / tmap-copyright 的全部隐藏 */
#txmap [class*="tmap-control"],
#txmap [class*="tmap-toolbar"],
#txmap [class*="tmap-ui"],
#txmap [class*="tmap-operate"],
#txmap [class*="tmap-logo"],
#txmap [class*="tmap-copyright"],
#txmap [class*="tmap-zoom"],
#txmap [class*="tmap-scale"],
#txmap [class*="tmap-locate"],
#txmap [class*="tmap-compass"],
#txmap [class*="tmap-rotate"],
#txmap [class*="tmap-bottom"],
#search-map [class*="tmap-control"],
#search-map [class*="tmap-toolbar"],
#search-map [class*="tmap-ui"],
#search-map [class*="tmap-operate"],
#search-map [class*="tmap-logo"],
#search-map [class*="tmap-copyright"],
#search-map [class*="tmap-zoom"],
#search-map [class*="tmap-scale"],
#search-map [class*="tmap-locate"],
#search-map [class*="tmap-compass"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    max-width: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -99999px !important;
    top: -99999px !important;
}

/* 我们自己的控件必须在地图之上，且能接收事件 */
.map-search-bar,
.map-controls,
.grain-sheet {
    pointer-events: auto !important;
}
.map-search-bar { z-index: 2147483647 !important; }
.map-controls   { z-index: 2147483647 !important; }
.grain-sheet    { z-index: 2147483646 !important; }
.my-grain-fab    { z-index: 2147483647 !important; }

/* ================================================================
 *  PC 端适配（>=1025px）
 *  手机 header/tabbar 隐藏 → 地图容器顶到顶
 *  地图容器左右各 240px/300px 给侧边栏留空间
 * ============================================================== */
@media (min-width: 1025px) {
    /* 地图容器重新定位 */
    .map-wrap {
        top: 0;
        bottom: 0;
        left: 240px;       /* 给左侧 .desktop-nav 留位 */
        right: 300px;      /* 给右侧 .desktop-aside 留位 */
    }

    /* 搜索栏放大一点 */
    .map-search-bar {
        top: 20px;
        left: 20px;
        right: 80px;
        padding: 14px 20px;
        border-radius: 26px;
    }
    .search-placeholder { font-size: 15px; }
    .search-icon { font-size: 18px; }

    /* 右侧控件位置同步 */
    .map-controls {
        right: 20px;
        top: 20px;
    }

    /* 底部 sheet PC 端也正常显示 */
    .grain-sheet {
        max-height: 60%;
        border-radius: 20px 20px 0 0;
    }

    /* 搜索弹窗小地图 PC 端稍微高一点 */
    .search-modal-map {
        height: 280px;
    }

    /* header / tabbar PC 端隐藏（和 desktop-nav/aside 共存，PC 端用左侧导航） */
    .grain-page > .header { display: none; }
    /* tabbar 是 body 直接子元素（通过 _nav.php include），用 body 级选择器 */
    body > .tabbar { display: none; }
}

/* ================================================================
 *  中等屏幕适配（768 ~ 1024px）
 *  比如平板，地图全屏但 tabbar/header 还在
 * ============================================================== */
@media (min-width: 768px) and (max-width: 1024px) {
    .map-wrap {
        top: 48px;
        bottom: 56px;
        left: 0;
        right: 0;
    }
    .grain-sheet { max-height: 50%; }
}

/* ================================================================
 *  安全区适配（iPhone X+ 刘海屏）
 * ============================================================== */
@supports (padding-top: env(safe-area-inset-top)) {
    .map-search-bar { top: calc(12px + env(safe-area-inset-top)); }
    .map-controls { top: calc(12px + env(safe-area-inset-top)); }
}

/* ================================================================
 *  右下角浮动按钮：我的粮点（打开粮点管理页）
 * ============================================================== */
.my-grain-fab {
    position: fixed;
    right: 16px;
    bottom: calc(120px + env(safe-area-inset-bottom));  /* 在 tabbar 上方 */
    width: auto;
    min-width: 48px;
    height: 48px;
    padding: 0 16px;
    background: #34c759;
    color: #fff;
    border-radius: 24px;
    box-shadow: 0 4px 16px rgba(52, 199, 89, 0.4);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    z-index: 9999;
    font-size: 13px;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
    border: none;
    font-family: inherit;
}
.my-grain-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(52, 199, 89, 0.5);
}
.my-grain-fab:active { transform: scale(0.95); }

/* PC 端：位置调整（避开右侧侧边栏） */
@media (min-width: 1025px) {
    .my-grain-fab { right: 320px; bottom: 40px; }
}
