* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; }
body { display: flex; flex-direction: column; background: #f1f5f9; color: #0f172a; }

/* 顶栏 */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #1d4ed8; color: #fff; padding: 6px 10px;
    padding-top: calc(6px + env(safe-area-inset-top));
    z-index: 1000; box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar .title { font-size: 16px; font-weight: 600; white-space: nowrap; }
.topbar .title small { font-size: 11px; opacity: .8; margin-left: 3px; }
.topbar .actions { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.btn-icon {
    background: rgba(255,255,255,.15); border: none; color: #fff;
    width: 34px; height: 34px; border-radius: 10px; font-size: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.btn-icon:active { background: rgba(255,255,255,.3); }
.btn-icon-small {
    background: rgba(0,0,0,.06); border: none; color: #475569;
    width: 28px; height: 28px; border-radius: 7px; font-size: 14px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.btn-primary {
    background: #fff; color: #1d4ed8; border: none; font-weight: 600;
    height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; cursor: pointer;
    white-space: nowrap;
}
.btn-primary:disabled { opacity: .5; }

/* 地图 */
#map { flex: 1; width: 100%; }

/* 设施标记 */
.fac-icon { background: none; border: none; }
.fac-dot {
    width: 34px; height: 34px; border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg); display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,.35); border: 2px solid #fff; cursor: pointer;
}
.fac-dot.draggable { cursor: grab; }
.fac-dot.draggable:active { cursor: grabbing; }
.fac-dot { font-size: 16px; line-height: 1; }

/* 弹窗 */
.popup { max-width: 260px; font-size: 13px; }
.pop-cat { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.pop-name { font-weight: 600; margin-bottom: 2px; }
.pop-note { color: #475569; margin-bottom: 4px; white-space: pre-wrap; }
.pop-street { font-size: 11px; color: #1d4ed8; margin-bottom: 2px; background: #eff6ff; padding: 2px 6px; border-radius: 4px; display: inline-block; }
.pop-dir { font-size: 12px; color: #6d28d9; margin-bottom: 2px; margin-left: 4px; }
.pop-photo { width: 100%; border-radius: 8px; margin: 4px 0; }
.pop-meta { color: #94a3b8; font-size: 11px; }
.pop-actions { display: flex; gap: 8px; margin-top: 8px; }
.pop-nav {
    flex: 1; text-align: center; background: #1d4ed8; color: #fff;
    text-decoration: none; padding: 6px 0; border-radius: 8px; font-weight: 600; font-size: 12px;
}
.pop-del {
    background: #fee2e2; color: #dc2626; border: none; padding: 6px 12px;
    border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 12px;
}
.pop-edit {
    background: #e0e7ff; color: #4338ca; border: none; padding: 6px 10px;
    border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 12px;
}

/* Toast */
.toast {
    position: fixed; left: 50%; top: 80px; transform: translateX(-50%) translateY(-10px);
    background: rgba(15,23,42,.9); color: #fff; padding: 10px 16px; border-radius: 20px;
    font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 2000;
    max-width: 80%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========== 绘制工具栏 ========== */
.draw-toolbar {
    position: fixed; top: 60px; right: 8px; width: calc(100% - 16px); max-width: 300px;
    background: #fff; border-radius: 14px; z-index: 1500;
    box-shadow: 0 4px 20px rgba(0,0,0,.2); padding: 0;
}
.draw-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-bottom: 1px solid #e2e8f0;
    font-weight: 600; font-size: 14px;
}
.draw-options { padding: 12px 14px 6px; }
.draw-opt-row {
    display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
    font-size: 12px; color: #475569; flex-wrap: wrap;
}
.draw-label { font-weight: 500; min-width: 32px; }
.draw-select {
    flex:1; min-width: 80px; padding: 5px 8px; border: 1px solid #cbd5e1;
    border-radius: 6px; font-size: 12px; background: #fff;
}
.draw-color { width: 32px; height: 28px; border: 1px solid #e2e8f0; border-radius: 4px; padding: 2px; cursor: pointer; }
.draw-range { flex: 1; min-width: 60px; accent-color: #1d4ed8; }
.draw-input {
    flex: 1; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 12px;
}
.draw-actions {
    display: flex; gap: 6px; padding: 8px 14px 12px; flex-wrap: wrap;
}
.draw-btn {
    flex: 1; padding: 8px 10px; border: none; border-radius: 8px; font-size: 12px; font-weight: 600;
    cursor: pointer; white-space: nowrap; min-width: 60px;
}
.draw-btn-start { background: #1d4ed8; color: #fff; }
.draw-btn-save { background: #16a34a; color: #fff; }
.draw-btn-cancel { background: #f1f5f9; color: #475569; }
.draw-btn-danger { background: #fee2e2; color: #dc2626; }
.draw-btn:disabled { opacity: .4; cursor: not-allowed; }

/* 绘制提示浮动元素 */
.draw-tip {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
    background: rgba(29,78,216,.9); color: #fff; padding: 8px 16px;
    border-radius: 20px; font-size: 13px; z-index: 2000; pointer-events: none;
    animation: drawPulse 1s ease-out;
}
@keyframes drawPulse { from { opacity: 0; transform: translate(-50%,-50%) scale(.9); } to { opacity: 1; transform: translate(-50%,-50%) scale(1); } }

/* ========== 街路面板 ========== */
.streets-panel {
    position: fixed; bottom: 0; left: 0; right: 0;
    max-height: 55vh; background: #fff; z-index: 1500;
    border-radius: 18px 18px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.2);
    display: flex; flex-direction: column;
}
.streets-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid #e2e8f0;
}
.streets-head h3 { margin: 0; font-size: 15px; }
.streets-filter {
    display: flex; gap: 6px; padding: 10px 14px; flex-wrap: wrap;
    border-bottom: 1px solid #f1f5f9;
}
.filter-select, .filter-search {
    padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 8px;
    font-size: 11px; background: #fff;
}
.filter-select { min-width: 70px; }
.filter-search { flex: 1; min-width: 100px; }
.streets-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.street-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 16px; border-bottom: 1px solid #f8fafc; cursor: pointer;
    transition: background .15s; gap: 10px;
}
.street-item:active, .street-item:hover { background: #f0f4ff; }
.street-item-name { font-size: 13px; font-weight: 600; color: #1e293b; flex: 1; }
.street-item-type {
    font-size: 10px; padding: 2px 6px; border-radius: 6px; font-weight: 500;
    white-space: nowrap;
}
.street-type-main { background: #fef3c7; color: #b45309; }
.street-type-secondary { background: #e0e7ff; color: #4338ca; }
.street-type-branch { background: #f1f5f9; color: #64748b; }
.street-item-dir { font-size: 10px; color: #94a3b8; white-space: nowrap; }
.street-item-count {
    font-size: 11px; background: #1d4ed8; color: #fff; border-radius: 10px;
    padding: 1px 7px; min-width: 20px; text-align: center;
}
.street-empty { padding: 30px; text-align: center; color: #94a3b8; font-size: 13px; }

/* ========== 方位选择 ========== */
.dir-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.dir-btn {
    padding: 10px 4px; border: 2px solid #e2e8f0; border-radius: 10px;
    background: #f8fafc; font-size: 14px; font-weight: 600; color: #475569;
    cursor: pointer; text-align: center; transition: all .15s;
}
.dir-btn.active { border-color: #1d4ed8; background: #eff6ff; color: #1d4ed8; }

/* ========== 街路匹配 ========== */
.street-match {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 10px 12px; background: #f0f9ff; border: 1px solid #bae6fd;
    border-radius: 10px;
}
.street-match-name { font-size: 14px; font-weight: 600; color: #0369a1; }
.street-match-dist { font-size: 11px; color: #64748b; background: #e2e8f0; padding: 1px 5px; border-radius: 4px; }
.street-match-tag { font-size: 10px; padding: 2px 6px; background: #dbeafe; color: #1d4ed8; border-radius: 4px; }
.street-nearby { width: 100%; font-size: 11px; color: #94a3b8; margin-top: 2px; }
.street-nearby span { margin-right: 8px; }

/* 遮罩 + 底部面板 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1500; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; background: #fff;
    border-radius: 18px 18px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    z-index: 1600; box-shadow: 0 -4px 20px rgba(0,0,0,.2); max-height: 88vh; overflow-y: auto;
}
.sheet-grip { width: 40px; height: 4px; background: #cbd5e1; border-radius: 2px; margin: 0 auto 10px; }
.sheet h3 { margin: 0 0 4px; font-size: 16px; }
.sheet .hint { margin: 0 0 12px; color: #64748b; font-size: 12px; word-break: break-all; }

.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.cat-btn {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    background: #f8fafc; border: 2px solid transparent; border-radius: 12px;
    padding: 10px 4px; font-size: 12px; color: #334155; cursor: pointer;
}
.cat-btn.active { border-color: #1d4ed8; background: #eff6ff; }
.cat-ico {
    width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 17px; color: #fff;
}

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: #475569; margin-bottom: 4px; }
.field input[type=text], .field textarea {
    width: 100%; border: 1px solid #cbd5e1; border-radius: 10px; padding: 10px;
    font-size: 14px; font-family: inherit; resize: vertical;
}
.field input[type=file] { font-size: 13px; }

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn-ghost {
    flex: 1; background: #f1f5f9; color: #475569; border: none; padding: 12px;
    border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.sheet-actions .btn-primary { flex: 2; }

/* 列表面板 */
.list-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: 88%; max-width: 380px;
    background: #fff; z-index: 1700; box-shadow: -4px 0 20px rgba(0,0,0,.2);
    display: flex; flex-direction: column;
}
.list-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid #e2e8f0;
}
.list-head h3 { margin: 0; font-size: 16px; }
.badge { background: #1d4ed8; color: #fff; border-radius: 10px; font-size: 12px; padding: 1px 8px; margin-left: 4px; }
.list-tabs { display: flex; border-bottom: 1px solid #e2e8f0; }
.list-tab {
    flex: 1; padding: 10px; border: none; background: none; font-size: 12px; font-weight: 600;
    color: #64748b; cursor: pointer; border-bottom: 2px solid transparent;
    transition: all .15s;
}
.list-tab.active { color: #1d4ed8; border-bottom-color: #1d4ed8; }
.list-body { flex: 1; overflow-y: auto; }
.list-item {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9; cursor: pointer;
}
.list-item:active { background: #f8fafc; }
.li-icon {
    width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center;
    justify-content: center; font-size: 18px; color: #fff; flex-shrink: 0;
}
.li-info { flex: 1; min-width: 0; }
.li-cat { font-size: 12px; color: #64748b; }
.li-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-street { font-size: 11px; color: #1d4ed8; margin-top: 1px; }
.li-dir { font-size: 10px; color: #6d28d9; margin-left: 3px; }
.li-time { font-size: 11px; color: #94a3b8; flex-shrink: 0; }
.empty { padding: 40px 20px; text-align: center; color: #94a3b8; font-size: 14px; }

/* 街路分组视图 */
.street-group { margin-bottom: 4px; }
.street-group-header {
    padding: 10px 16px; background: #f0f4ff; font-size: 13px; font-weight: 700;
    color: #1d4ed8; border-bottom: 1px solid #e0e7ff; display: flex; align-items: center; gap: 8px;
}
.street-group-count { font-size: 11px; background: #1d4ed8; color: #fff; border-radius: 10px; padding: 1px 7px; }

.hidden { display: none !important; }

/* ========== 设施详情弹窗 ========== */
.detail-modal { position: fixed; inset: 0; z-index: 1800; display: flex; align-items: center; justify-content: center; }
.detail-mask { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.detail-card {
    position: relative; background: #fff; border-radius: 16px; padding: 20px;
    width: 90%; max-width: 360px; max-height: 80vh; overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.detail-card .close-detail {
    position: absolute; top: 10px; right: 10px; width: 30px; height: 30px;
    border-radius: 50%; border: none; background: #f1f5f9; font-size: 16px;
    cursor: pointer; color: #64748b;
}
.detail-card img { width: 100%; border-radius: 10px; margin: 8px 0; }
.detail-card .detail-cat { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.detail-card .detail-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.detail-card .detail-note { color: #475569; margin-bottom: 8px; }
.detail-card .detail-street { font-size: 13px; color: #1d4ed8; margin-bottom: 4px; }
.detail-card .detail-dir { font-size: 13px; color: #6d28d9; margin-bottom: 4px; }
.detail-card .detail-meta { font-size: 11px; color: #94a3b8; margin-bottom: 12px; }
.detail-card .detail-actions { display: flex; gap: 8px; }

/* ========== 行政区界标注 ========== */
.boundary-label {
    background: none !important; border: none !important; box-shadow: none !important;
    font-size: 13px; font-weight: 700; color: #1d4ed8;
    text-shadow:
        -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff,
        0 0 6px rgba(255,255,255,.9), 0 0 10px rgba(255,255,255,.9);
    white-space: nowrap; pointer-events: none;
    padding: 2px 4px !important;
}

/* ========== 响应式适配 ========== */
@media (max-width: 480px) {
    .topbar { padding: 4px 6px; padding-top: calc(4px + env(safe-area-inset-top)); }
    .topbar .title { font-size: 14px; }
    .btn-icon { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
    .btn-primary { height: 30px; font-size: 12px; padding: 0 10px; }
    .draw-toolbar { top: 50px; max-width: calc(100% - 12px); }
    .draw-opt-row { gap: 4px; font-size: 11px; }
    .streets-filter { gap: 4px; padding: 8px 10px; }
    .filter-select { min-width: 60px; font-size: 10px; }
    .filter-search { font-size: 10px; }
    .street-item { padding: 10px 12px; }
    .street-item-name { font-size: 12px; }
    .dir-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .dir-btn { padding: 8px 2px; font-size: 13px; }
    .cat-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .cat-btn { padding: 8px 3px; font-size: 11px; }
    .list-panel { width: 92%; max-width: 100%; }
    .detail-card { width: 94%; padding: 16px; }
}
