/* ==========================================================================
 * 移动端原生化样式 (App 化 v2)
 * 设计理念: 地图为主, 搜索面板做成可拖动 Bottom Sheet
 * 三档高度: peek(只露顶条) / half(50vh) / full(全屏减状态栏)
 * 桌面端 (>=769px) 完全不受影响, 走 style.css 的桌面布局。
 * ========================================================================== */

/* 桌面端: 顶栏按钮统一点击反馈, 避免给桌面带来 mobile 副作用 */
.btn-search:active, .act-btn:active, .header-btn:active,
.qf-chip:active, .map-tool-btn:active, .grid-action-btn:active {
    transform: scale(.97);
}

/* 浮动按钮 (FAB) — 移动端 + 桌面共用样式, 但只在 mobile 出现 */
.mobile-fab-row {
    display: none;
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    z-index: 40;
    gap: 8px;
    align-items: center;
}
.mobile-fab-row.left { left: 12px; }
.mobile-fab-row.right { right: 12px; }
.mobile-fab {
    width: 42px; height: 42px;
    border-radius: 50%;
    border: 0;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #1F2937;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(0,0,0,.16), 0 1px 3px rgba(0,0,0,.08);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform .12s, box-shadow .15s;
}
.mobile-fab:active { transform: scale(.92); box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.mobile-fab.primary { background: #2563EB; color: #fff; }
.mobile-fab.warn-dot::after {
    content: '';
    position: absolute;
    top: 8px; right: 8px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #f44336;
    border: 1.5px solid #fff;
}
/* Sheet 收起/展开 切换 FAB: 浮在 bottom sheet 右上角 */
.mobile-fab.sheet-toggle {
    position: fixed;
    right: 14px;
    z-index: 25;
    width: 38px; height: 38px;
    font-size: 14px;
    color: #475569;
    background: rgba(255,255,255,.96);
}

/* ============== Bottom Sheet (核心) ==============
 * handle 区域故意做得高 (32px), 确保手指容易抓住; 视觉上还是一条小 "横杠"。
 * .bs-tabs 内空白处也能拖动 (JS 里非 .bs-tab 元素触发拖). */
.bottom-sheet-handle {
    display: none;
    width: 100%;
    height: 32px;
    padding: 0;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    flex-shrink: 0;
}
.bottom-sheet-handle::before {
    content: '';
    position: absolute;
    top: 12px; left: 50%;
    transform: translateX(-50%);
    width: 44px; height: 5px;
    border-radius: 3px;
    background: #cbd5e1;
    transition: background .15s, width .15s;
}
.bottom-sheet-handle:active::before {
    background: #94a3b8;
    width: 56px;
}
.bs-tabs {
    display: none;
    padding: 4px 8px 8px;
    gap: 6px;
    border-bottom: 1px solid #f0f1f4;
    background: #fff;
    touch-action: none;
    flex-shrink: 0;
}
.bs-tab {
    flex: 1;
    background: transparent;
    border: 0;
    padding: 8px 0;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s;
}
.bs-tab:active { transform: scale(.96); }
.bs-tab.active {
    background: #EFF6FF;
    color: #2563EB;
    font-weight: 600;
}
.bs-tab[data-tab="address"].active { background: #FFF7ED; color: #EA580C; }
.bs-tab[data-tab="box"].active { background: #ECFDF5; color: #059669; }

/* ============== Mobile Media (<=768px) ============== */
@media (max-width: 768px) {
    /* 全局: 让 body/html 完全占满 viewport, 防止 webview 内多滚动条 */
    html, body {
        height: 100%;
        overflow: hidden;
        background: #f7f8fa;
    }

    /* 顶部 header 完全隐藏, 改用浮动 FAB */
    header { display: none; }
    .mobile-fab-row { display: flex; }

    /* main 区域: 全屏堆叠 (地图 + 浮在上方的 bottom sheet) */
    .main {
        flex-direction: column;
        height: 100vh; height: 100dvh;
        position: relative;
    }

    /* 地图占满, 不再被 sidebar 挤压 */
    .map-area {
        order: 1;
        width: 100%;
        height: 100%;
        flex: 1;
        position: absolute;
        inset: 0;
        z-index: 1;
    }
    #map { width: 100%; height: 100%; }

    /* 隐藏顶部 search-tabs (重复了, 用 bs-tabs 代替) */
    .search-tabs { display: none; }
    /* 显示 sheet 内顶部 tab + 拖动条 */
    .bottom-sheet-handle { display: block; }
    .bs-tabs { display: flex; }

    /* ===== Sidebar 变 Bottom Sheet ===== */
    .sidebar {
        order: 2;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        width: 100%;
        height: 78dvh;
        max-height: calc(100dvh - 80px);
        margin: 0 !important;
        background: #ffffff;
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -8px 30px rgba(15,23,42,.16), 0 -1px 4px rgba(15,23,42,.06);
        z-index: 20;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        transition: transform .28s cubic-bezier(.22,.8,.36,1);
        padding-bottom: env(safe-area-inset-bottom);
        will-change: transform;
    }
    /* sheet 三档高度: 用 translateY 控制 (因为 .sidebar 是 fixed bottom:0, translateY+ 把 sheet 推下去)
     * 默认进 APP 直接 bs-half, sheet 占屏 ~70%, 地图占顶 30%.
     * peek 时只露 handle(32) + bs-tabs(~42) + 一行提示 = 96px, 方便单手拉回来. */
    .sidebar.bs-peek    { transform: translateY(calc(78dvh - 96px)); }
    .sidebar.bs-half    { transform: translateY(28dvh); }
    .sidebar.bs-full    { transform: translateY(0); }
    .sidebar.dragging   { transition: none; }

    .search-section {
        padding: 10px 14px 8px;
        max-height: none;
        overflow: visible;
    }
    /* 列表区独立滚动, sheet 不整体滚 */
    .community-list, .result-info {
        max-height: 100%;
        padding: 0 14px 14px;
    }
    .community-list {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-height: 0;
    }

    /* ===== 卡片样式 (iOS 风格) ===== */
    .comm-card, .nearest-card, .box-card-tile {
        background: #ffffff !important;
        border: 0 !important;
        border-radius: 14px;
        padding: 14px 14px !important;
        margin-bottom: 10px;
        box-shadow: 0 1px 2px rgba(15,23,42,.05), 0 1px 8px rgba(15,23,42,.04);
        transition: transform .1s, background .15s;
    }
    .comm-card:active, .nearest-card:active, .box-card-tile:active {
        transform: scale(.985);
        background: #f7f8fa !important;
    }
    .nearest-name, .comm-name, .box-name {
        font-size: 15px;
        font-weight: 600;
        color: #0f172a;
    }
    .comm-addr, .poi-addr {
        font-size: 12.5px;
        color: #64748b;
        line-height: 1.5;
        margin-top: 4px;
    }
    .nearest-dist { font-size: 12px; color: #2563EB; font-weight: 600; }
    .tag {
        font-size: 11px;
        padding: 3px 8px;
        border-radius: 6px;
        font-weight: 500;
    }
    .tag-engineer { background: #FEF3C7; color: #92400E; }
    .tag-grid    { background: #EFF6FF; color: #1D4ED8; }
    .tag-branch  { background: #FDF2F8; color: #BE185D; }
    .tag-port    { background: #ECFDF5; color: #047857; }
    .tag-time    { background: #F5F3FF; color: #6D28D9; }
    .tag-comm    { background: #FFF7ED; color: #C2410C; }
    .comm-meta { gap: 6px; flex-wrap: wrap; }

    /* ===== 输入框 + 按钮 (大触控目标 44px+) ===== */
    .search-box input {
        font-size: 15px !important;
        padding: 12px 14px 12px 38px !important;
        border-radius: 12px !important;
        border: 1.5px solid #e2e8f0 !important;
        background: #f8fafc !important;
    }
    .search-box input:focus { border-color: #2563EB !important; background: #fff !important; }
    .search-icon { left: 12px !important; }
    .clear-btn { width: 24px !important; height: 24px !important; right: 8px !important; }

    .filter-row { gap: 8px; flex-wrap: wrap; margin-top: 8px; }
    .filter-row select {
        flex: 1; min-width: 0;
        padding: 11px 12px !important;
        font-size: 14px !important;
        border-radius: 10px !important;
        background: #f8fafc !important;
        border: 1.5px solid #e2e8f0 !important;
        appearance: none;
        -webkit-appearance: none;
    }
    .btn-search {
        min-height: 44px;
        padding: 0 18px !important;
        font-size: 14px !important;
        font-weight: 600 !important;
        border-radius: 10px !important;
        background: #2563EB !important;
        color: #fff !important;
        border: 0 !important;
        letter-spacing: .5px;
    }
    .btn-search.btn-addr { background: #EA580C !important; }
    .btn-search.btn-pick { background: #475569 !important; }
    .btn-search.btn-locate { background: #059669 !important; }

    /* 行动按钮 (拨号 / 复制 / 导航 / 查附近 / 定位) */
    .act-row { gap: 8px !important; margin-top: 10px !important; flex-wrap: wrap; }
    .act-btn, .act-call {
        min-height: 40px;
        font-size: 13px !important;
        border-radius: 10px !important;
        font-weight: 500 !important;
    }
    .act-call { background: #059669 !important; color: #fff !important; }
    .act-navi { background: #2563EB !important; color: #fff !important; border-color: transparent !important; }
    .act-box  { background: #FF6D00 !important; color: #fff !important; border-color: transparent !important; }

    /* quick filter chips */
    .qf-chip {
        padding: 7px 12px !important;
        font-size: 12.5px !important;
        border-radius: 16px !important;
        background: #f1f5f9 !important;
        border: 0 !important;
        color: #475569 !important;
    }
    .qf-chip.active { background: #2563EB !important; color: #fff !important; }

    /* ===== 地图工具按钮: 浮动右下, 不占顶部 ===== */
    .map-toolbar {
        position: fixed !important;
        top: auto !important;
        bottom: calc(96px + env(safe-area-inset-bottom));
        right: 12px !important;
        left: auto !important;
        flex-direction: column;
        gap: 8px;
        z-index: 15;
    }
    .map-tool-btn {
        background: rgba(255,255,255,.94) !important;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        width: 40px; height: 40px;
        padding: 0 !important;
        border-radius: 50% !important;
        box-shadow: 0 4px 10px rgba(0,0,0,.12) !important;
        border: 0 !important;
        font-size: 11px !important;
        color: #475569 !important;
        line-height: 1.1 !important;
    }
    .map-tool-btn.active { background: #2563EB !important; color: #fff !important; }

    /* 隐藏老的折叠/底部 tabbar (架构换了) */
    .mobile-tabbar { display: none !important; }
    .toggle-sidebar { display: none !important; }

    /* result-info 提示条 */
    .result-info {
        background: #EFF6FF !important;
        border-left: 0 !important;
        border-radius: 10px;
        margin: 0 14px 8px !important;
        padding: 10px 14px !important;
        font-size: 13px;
        color: #1E40AF;
    }
    .result-info.addr-result-info { background: #FFF7ED !important; color: #9A3412; }

    /* InfoWindow: 高德 SDK 内容过宽会跳到左下方, 这里限制宽度 + 缩字体 让它稳定在正上方 */
    .amap-info-content {
        border-radius: 10px !important;
        max-width: 240px !important;
        padding: 8px 10px !important;
    }
    .iw-card { max-width: 220px; }
    .iw-card h3 {
        font-size: 14px;
        margin: 0 0 6px;
        line-height: 1.35;
        font-weight: 600;
        color: #0f172a;
    }
    .iw-card p {
        margin: 3px 0;
        font-size: 12px;
        line-height: 1.45;
        color: #334155;
        word-break: break-all;
    }
    .iw-card p b { color: #64748b; font-weight: 500; }
    .iw-card .iw-tel { font-size: 13px; font-weight: 600; }
    .iw-card .iw-coord { font-size: 10.5px; color: #94a3b8; margin-top: 6px; }
    .iw-card .act-row { gap: 6px !important; margin-top: 6px !important; }
    .iw-card .act-btn {
        min-height: 32px !important;
        padding: 5px 8px !important;
        font-size: 11.5px !important;
        border-radius: 7px !important;
    }

    /* empty state */
    .empty-state {
        padding: 50px 20px !important;
        text-align: center;
        color: #94a3b8;
    }
    .empty-state .icon { font-size: 48px; margin-bottom: 12px; }
    .empty-state p { font-size: 13.5px; line-height: 1.6; }

    /* Toast */
    .toast-root { top: calc(70px + env(safe-area-inset-top)) !important; }
    .toast {
        font-size: 13px !important;
        padding: 10px 18px !important;
        border-radius: 22px !important;
        background: rgba(17,24,39,.94) !important;
        color: #fff !important;
        box-shadow: 0 6px 20px rgba(0,0,0,.18) !important;
    }

    /* 地图拾取提示, 浮在地图上 */
    .map-tip {
        top: calc(64px + env(safe-area-inset-top)) !important;
        left: 50% !important;
        transform: translateX(-50%);
        right: auto !important;
        padding: 8px 14px !important;
        border-radius: 22px !important;
        background: rgba(17,24,39,.92) !important;
        color: #fff !important;
        font-size: 12.5px;
        z-index: 35;
        box-shadow: 0 6px 16px rgba(0,0,0,.2);
    }

    /* 网格筛选区: 限制高度可滑 */
    .grid-checkboxes { max-height: 30dvh; overflow-y: auto; }

    /* 地址提示 */
    .addr-hint {
        font-size: 12px !important;
        padding: 8px 12px !important;
        border-radius: 10px !important;
        background: #f1f5f9 !important;
        border-left: 3px solid #2563EB !important;
        color: #475569;
        margin-bottom: 10px;
    }

    /* options (复选/半径选择) */
    .addr-options { gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: #475569; }
    .opt-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: #2563EB; }
}

/* ============== 骨架屏 (loading) ============== */
.skeleton-list { padding: 8px; }
.skeleton-card {
    height: 78px;
    margin-bottom: 8px;
    border-radius: 14px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: skeleton 1.2s ease-in-out infinite;
}
@keyframes skeleton {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
