* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body { overscroll-behavior: contain; }

body {
    font-family: -apple-system, 'Microsoft YaHei', 'Segoe UI', sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #f0f2f5;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
/* 输入框 + 卡片内容仍允许选中复制 */
input, textarea, .comm-card, .box-card-tile, .nearest-card,
.iw-card, .poi-card, .nearest-phone, .nearest-name, .comm-name, .box-name {
    user-select: text;
    -webkit-user-select: text;
    -webkit-touch-callout: default;
}

header {
    background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
    color: #fff;
    padding: 14px 24px;
    padding-top: calc(14px + env(safe-area-inset-top));
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
    z-index: 10;
    flex-shrink: 0;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1600px;
    margin: 0 auto;
}
header h1 { font-size: 20px; font-weight: 600; letter-spacing: .5px; }
.header-stats {
    font-size: 13px;
    opacity: .9;
    display: flex;
    gap: 16px;
}
.header-stats span { white-space: nowrap; }

.header-actions { margin-left: 12px; display: flex; gap: 8px; }
.header-btn {
    background: rgba(255,255,255,.18);
    color: #fff;
    border: 1px solid rgba(255,255,255,.32);
    border-radius: 18px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background .18s;
}
.header-btn:hover { background: rgba(255,255,255,.32); }

.source-wrap { position: relative; }
.source-badge {
    background: rgba(255,255,255,.16);
    color: #fff;
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 14px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.source-badge:hover { background: rgba(255,255,255,.3); }
.source-badge.online { border-color: #b9f6ca; }
.source-badge.offline { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.3); }
.sync-btn:disabled { opacity: .6; cursor: not-allowed; }
.source-menu {
    position: absolute;
    right: 0;
    top: 36px;
    background: #fff;
    color: #333;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,.18);
    padding: 6px 0;
    min-width: 200px;
    z-index: 50;
    border: 1px solid #e0e0e0;
}
.source-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    color: #333;
}
.source-menu button:hover { background: #f0f4ff; color: #1a73e8; }

.main {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.sidebar {
    width: 420px;
    background: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 12px rgba(0,0,0,.06);
    z-index: 5;
    transition: margin-left .3s ease;
}
.sidebar.collapsed { margin-left: -420px; }

.search-tabs {
    display: flex;
    border-bottom: 2px solid #e8e8e8;
    flex-shrink: 0;
}
.search-tab {
    flex: 1;
    padding: 12px 0;
    border: none;
    background: #fafafa;
    font-size: 14px;
    font-weight: 500;
    color: #888;
    cursor: pointer;
    transition: all .2s;
    position: relative;
}
.search-tab:hover { color: #1a73e8; background: #f0f4ff; }
.search-tab.active {
    color: #1a73e8;
    background: #fff;
    font-weight: 600;
}
.search-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 20%;
    width: 60%;
    height: 3px;
    background: #1a73e8;
    border-radius: 2px 2px 0 0;
}
.search-tab[data-tab="address"]:hover { color: #e65100; }
.search-tab[data-tab="address"].active { color: #e65100; }
.search-tab[data-tab="address"].active::after { background: #ff8f00; }

.search-tab[data-tab="box"]:hover { color: #2e7d32; }
.search-tab[data-tab="box"].active { color: #2e7d32; }
.search-tab[data-tab="box"].active::after { background: #43a047; }

.search-section {
    padding: 12px 14px;
    border-bottom: 1px solid #e8e8e8;
    flex-shrink: 0;
    max-height: 50vh;
    overflow-y: auto;
}

.search-box {
    position: relative;
    margin-bottom: 10px;
}
.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: #999;
    pointer-events: none;
}
#searchInput, #addrInput, #boxSearchInput {
    width: 100%;
    padding: 11px 36px 11px 40px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color .2s;
}
#searchInput:focus { border-color: #1a73e8; }
#addrInput:focus { border-color: #ff9100; }
#boxSearchInput:focus { border-color: #43a047; }
.clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    padding: 0 4px;
}

.filter-row {
    display: flex;
    gap: 8px;
}
#branchFilter, #boxBranchFilter {
    flex: 1;
    padding: 9px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    background: #fff;
}

.grid-filter-section {
    margin-top: 10px;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    overflow: hidden;
}
.grid-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f5f7fa;
    border-bottom: 1px solid #e8e8e8;
}
.grid-filter-title { font-size: 12px; font-weight: 600; color: #555; }
.grid-filter-actions { display: flex; gap: 4px; }
.grid-action-btn {
    padding: 3px 8px;
    font-size: 11px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    color: #1a73e8;
}
.grid-action-btn:hover { background: #e8f0fe; }
.grid-checkboxes {
    max-height: 200px;
    overflow-y: auto;
    padding: 6px 8px;
}
.grid-checkboxes.collapsed { max-height: 0; padding: 0 8px; overflow: hidden; }
.grid-cb-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #333;
}
.grid-cb-item:hover { background: #f0f4ff; }
.grid-cb-item input { width: 14px; height: 14px; cursor: pointer; }
.grid-summary {
    padding: 6px 12px;
    font-size: 11px;
    color: #888;
    background: #fafafa;
    border-top: 1px solid #e8e8e8;
}
.btn-search {
    padding: 9px 20px;
    background: #1a73e8;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background .2s;
    white-space: nowrap;
}
.btn-search:hover { background: #1557b0; }

.btn-addr {
    flex: 1;
    background: #ff8f00;
}
.btn-addr:hover { background: #e65100; }
.btn-pick {
    background: #455a64;
}
.btn-pick:hover { background: #263238; }
.btn-pick.active {
    background: #d32f2f;
}
.btn-locate {
    background: #00897b;
    flex: 0 0 auto;
}
.btn-locate:hover { background: #00695c; }

.quick-filters {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    margin-top: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: thin;
}
.quick-filters::-webkit-scrollbar { height: 4px; }
.quick-filters::-webkit-scrollbar-thumb { background: #d0e0ff; border-radius: 2px; }
.quick-filters .qf-chip { flex: 0 0 auto; white-space: nowrap; }
.qf-chip {
    padding: 5px 12px;
    background: #f0f4ff;
    border: 1px solid #d0e0ff;
    border-radius: 14px;
    font-size: 12px;
    color: #1a73e8;
    cursor: pointer;
    transition: all .18s;
}
.qf-chip:hover { background: #d2e3fc; }
.qf-chip.active { background: #1a73e8; color: #fff; border-color: #1557b0; }

.act-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #e6e6e6;
}
.act-btn {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid #d8d8d8;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    color: #333;
    transition: all .15s;
    white-space: nowrap;
    text-align: center;
}
.act-btn:hover { background: #f5f7fa; transform: translateY(-1px); }
.act-call {
    background: linear-gradient(135deg, #ff8f00, #e65100);
    color: #fff;
    border-color: #e65100;
    font-weight: 600;
    flex: 1 1 100%;
    padding: 10px;
    font-size: 13px;
}
.act-call:hover { background: linear-gradient(135deg, #e65100, #bf360c); }
.act-copy { color: #1a73e8; border-color: #c8dafd; }
.act-copy:hover { background: #e8f0fe; }
.act-box { color: #2e7d32; border-color: #c8e6c9; }
.act-box:hover { background: #e8f5e9; }
.act-locate { color: #6a1b9a; border-color: #e1bee7; }
.act-locate:hover { background: #f3e5f5; }

.toast-root {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    pointer-events: none;
}
.toast {
    background: rgba(33, 33, 33, .92);
    color: #fff;
    padding: 9px 18px;
    border-radius: 22px;
    font-size: 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,.2);
    opacity: 0;
    transform: translateY(-12px);
    transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: rgba(46, 125, 50, .95); }
.toast-error   { background: rgba(198, 40, 40, .95); }

.addr-hint {
    font-size: 12px;
    color: #777;
    margin-bottom: 10px;
    padding: 7px 10px;
    background: #fffde7;
    border-radius: 6px;
    border-left: 3px solid #ffb300;
    line-height: 1.5;
}

.addr-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 10px;
    padding: 8px 10px;
    background: #fafafa;
    border-radius: 6px;
    font-size: 12px;
    color: #333;
}
.opt-item { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.opt-item select {
    padding: 2px 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    font-size: 12px;
}

.addr-status {
    margin-top: 8px;
    font-size: 12px;
    color: #999;
    text-align: center;
    padding: 4px;
}

.poi-card {
    padding: 12px 14px;
    margin-bottom: 6px;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-left: 4px solid #ff9100;
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s;
}
.poi-card:hover {
    background: #fff8f0;
    border-left-color: #e65100;
    transform: translateX(3px);
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.poi-name {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 3px;
}
.poi-addr {
    font-size: 12px;
    color: #888;
    line-height: 1.4;
}
.poi-action {
    display: inline-block;
    margin-top: 6px;
    font-size: 11px;
    color: #ff6d00;
    font-weight: 500;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 6px 0 6px;
    padding: 0 4px;
}
.section-header .title {
    font-size: 13px;
    font-weight: 600;
    color: #444;
}
.section-header .count {
    font-size: 11px;
    background: #e8eaed;
    color: #555;
    padding: 1px 8px;
    border-radius: 10px;
}

.nearest-card {
    padding: 14px;
    margin-bottom: 8px;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-left: 4px solid #ff6d00;
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s;
}
.nearest-card.box-card { border-left-color: #43a047; }
.nearest-card:hover {
    background: #fff8f0;
    transform: translateX(3px);
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.nearest-card.box-card:hover { background: #f1f8e9; }
.nearest-card.active {
    background: #fff3e0;
    border-left-color: #e65100;
}
.nearest-card.box-card.active {
    background: #e8f5e9;
    border-left-color: #1b5e20;
}
.nearest-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.nearest-rank {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ff6d00;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}
.nearest-card.box-card .nearest-rank { background: #43a047; }
.nearest-dist {
    font-size: 12px;
    color: #ff6d00;
    font-weight: 600;
    background: #fff3e0;
    padding: 2px 8px;
    border-radius: 10px;
}
.nearest-card.box-card .nearest-dist { color: #2e7d32; background: #e8f5e9; }
.nearest-name {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 4px;
    word-break: break-all;
}
.nearest-phone {
    font-size: 17px;
    font-weight: 700;
    color: #e65100;
    margin: 6px 0;
}
.nearest-phone a {
    color: #e65100;
    text-decoration: none;
}
.nearest-phone a:hover { text-decoration: underline; }
.nearest-same-grid {
    padding: 10px 14px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #e8f5e9, #f1f8e9);
    border: 1px solid #c8e6c9;
    border-radius: 8px;
    font-size: 13px;
    color: #2e7d32;
    font-weight: 500;
    text-align: center;
}
.nearest-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 9px;
    margin-bottom: 10px;
    background: #fff;
    border: 1px dashed #ccc;
    border-radius: 8px;
    font-size: 13px;
    color: #888;
    cursor: pointer;
    text-align: center;
    transition: all .2s;
}
.nearest-back-btn:hover { background: #f5f5f5; border-color: #ff8f00; color: #e65100; }

.addr-result-info {
    background: #fff3e0;
    color: #e65100;
    border-bottom-color: #ffe0b2;
}
.box-result-info {
    background: #e8f5e9;
    color: #2e7d32;
    border-bottom-color: #c8e6c9;
}

.result-info {
    padding: 10px 16px;
    background: #e8f0fe;
    color: #1a73e8;
    font-size: 13px;
    font-weight: 500;
    border-bottom: 1px solid #d2e3fc;
}

.community-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.comm-card {
    padding: 14px;
    margin-bottom: 6px;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-left: 4px solid #1a73e8;
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s;
}
.comm-card:hover {
    background: #f8f9ff;
    border-left-color: #0d47a1;
    transform: translateX(3px);
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.comm-card.active {
    background: #e8f0fe;
    border-left-color: #0d47a1;
}
.comm-name {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.comm-name .highlight {
    background: #ffd54f;
    border-radius: 2px;
    padding: 0 2px;
}
.comm-addr {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.comm-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}
.tag-engineer { background: #e8f5e9; color: #2e7d32; }
.tag-phone { background: #fff3e0; color: #e65100; }
.tag-grid { background: #f3e5f5; color: #7b1fa2; }
.tag-branch { background: #e3f2fd; color: #1565c0; }
.tag-port { background: #ede7f6; color: #4527a0; }
.tag-time { background: #eceff1; color: #455a64; }
.tag-comm { background: #fce4ec; color: #ad1457; }

.box-card-tile {
    padding: 12px 14px;
    margin-bottom: 6px;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-left: 4px solid #43a047;
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s;
}
.box-card-tile:hover {
    background: #f1f8e9;
    transform: translateX(3px);
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.box-card-tile.active {
    background: #e8f5e9;
    border-left-color: #1b5e20;
}
.box-name {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 5px;
    word-break: break-all;
}
.box-id { font-size: 11px; color: #888; }

.map-area {
    flex: 1;
    position: relative;
}
#map {
    width: 100%;
    height: 100%;
    background: #e8e8e8;
}

.toggle-sidebar {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 24px;
    height: 60px;
    background: #fff;
    border: 1px solid #ddd;
    border-left: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #666;
    box-shadow: 2px 0 6px rgba(0,0,0,.08);
    z-index: 4;
    transition: left .3s;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.6; }

.loading {
    text-align: center;
    padding: 30px;
    color: #1a73e8;
}
.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #1a73e8;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.map-toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 4;
    display: flex;
    gap: 6px;
}
.map-tool-btn {
    padding: 8px 14px;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    color: #333;
    box-shadow: 0 2px 6px rgba(0,0,0,.1);
    transition: all .2s;
    user-select: none;
}
.map-tool-btn:hover { background: #f0f4ff; border-color: #1a73e8; color: #1a73e8; }
.map-tool-btn.active {
    background: #1a73e8;
    color: #fff;
    border-color: #1a73e8;
}

.map-tip {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    background: rgba(33, 33, 33, .92);
    color: #fff;
    padding: 8px 14px;
    border-radius: 22px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.map-tip button {
    background: rgba(255,255,255,.18);
    color: #fff;
    border: 0;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 12px;
    cursor: pointer;
}

.amap-info-window-content {
    font-family: -apple-system, 'Microsoft YaHei', sans-serif;
}
.iw-card { padding: 4px 2px; min-width: 240px; font-size: 13px; line-height: 1.7; }
.iw-card h3 { margin: 0 0 8px; color: #1a73e8; font-size: 16px; }
.iw-card.box-iw h3 { color: #2e7d32; }
.iw-card p { margin: 0; }
.iw-card .iw-tel {
    color: #e65100; font-weight: 700; font-size: 16px; text-decoration: none;
}
.iw-card .iw-tel:hover { text-decoration: underline; }
.iw-card .iw-coord {
    margin-top: 6px; padding-top: 6px;
    border-top: 1px solid #eee; font-size: 11px; color: #999;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }
