/* ============ 全局重置 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, "Microsoft YaHei", "Segoe UI", sans-serif; background: #f0f2f5; color: #333; }

/* ============ 布局 ============ */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    width: 360px;
    min-width: 360px;
    background: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 12px rgba(0,0,0,0.08);
    z-index: 10;
    overflow: hidden;
}

.sidebar-header {
    padding: 18px 20px 12px;
    background: linear-gradient(135deg, #1a73e8, #0d47a1);
    color: #fff;
}
.sidebar-header h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 1px;
}

/* Tab 栏 */
.tab-bar {
    display: flex;
    background: #f5f7fa;
    border-bottom: 1px solid #e0e4ea;
}
.tab-btn {
    flex: 1;
    padding: 10px 0;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: #1a73e8; }
.tab-btn.active {
    color: #1a73e8;
    border-bottom-color: #1a73e8;
    background: #fff;
}

/* Tab 面板 */
.tab-panel {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 0;
}
.tab-panel.active { display: flex; flex-direction: column; }

.panel-section {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}
.panel-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ============ 上传区 ============ */
.upload-zone {
    border: 2px dashed #c0c8d4;
    border-radius: 8px;
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
    background: #fafbfc;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: #1a73e8;
    background: #e8f0fe;
}
.upload-zone p { font-size: 14px; color: #555; margin-bottom: 4px; }
.upload-hint { font-size: 12px; color: #999; }

.progress-bar {
    height: 4px;
    background: #e0e4ea;
    border-radius: 2px;
    margin-top: 10px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #1a73e8, #42a5f5);
    border-radius: 2px;
    width: 0;
    transition: width 0.3s;
    animation: progressPulse 1.5s infinite;
}
@keyframes progressPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ============ 表单 ============ */
.form-group { margin-bottom: 12px; }
.form-group label {
    display: block;
    font-size: 13px;
    color: #555;
    margin-bottom: 4px;
    font-weight: 500;
}
.required { color: #e53935; }

.form-group select, .search-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    transition: border-color 0.2s;
}
.form-group select:focus, .search-input:focus {
    outline: none;
    border-color: #1a73e8;
    box-shadow: 0 0 0 2px rgba(26,115,232,0.15);
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* ============ 预览表格 ============ */
.preview-table-wrap {
    max-height: 180px;
    overflow: auto;
    margin: 10px 0;
    border: 1px solid #e0e4ea;
    border-radius: 6px;
}
.preview-table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.preview-table-wrap th {
    background: #f5f7fa;
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 0;
    white-space: nowrap;
}
.preview-table-wrap td {
    padding: 5px 8px;
    border-top: 1px solid #eee;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============ 统计卡片 ============ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}
.stat-card {
    text-align: center;
    padding: 12px 6px;
    background: #f5f7fa;
    border-radius: 8px;
}
.stat-card.highlight {
    background: linear-gradient(135deg, #e8f0fe, #d0e3ff);
}
.stat-num {
    font-size: 22px;
    font-weight: 700;
    color: #1a73e8;
}
.stat-label {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}

/* ============ 按钮 ============ */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #1a73e8; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1557b0; }
.btn-secondary { background: #e0e4ea; color: #333; }
.btn-secondary:hover:not(:disabled) { background: #d0d5dd; }
.btn-danger { background: #e53935; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c62828; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

.btn-icon {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.btn-icon:hover { background: #f0f0f0; color: #e53935; }

/* ============ 列表项 ============ */
.item-list {
    max-height: 400px;
    overflow-y: auto;
}
.list-item {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.list-item:hover { background: #f5f7fa; }
.list-item.mini { padding: 6px 10px; }

.list-item-title {
    font-size: 13px;
    font-weight: 500;
    color: #333;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.list-item-meta {
    font-size: 11px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-badge {
    display: inline-block;
    background: #e8f0fe;
    color: #1a73e8;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.addr-text {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
}
.abnormal-badge {
    display: inline-block;
    background: #e53935;
    color: #fff;
    padding: 0 5px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    vertical-align: middle;
}
.failed-badge {
    display: inline-block;
    background: #bbb;
    color: #fff;
    padding: 0 5px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    vertical-align: middle;
}
.filter-row label {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.badge {
    display: inline-block;
    background: #e0e4ea;
    color: #555;
    padding: 0 7px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

/* ============ 区域列表 ============ */
.area-item {
    display: flex;
    align-items: center;
    gap: 10px;
}
.area-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}
.area-info { flex: 1; min-width: 0; cursor: pointer; }

/* ============ 绘制面板 ============ */
.draw-toolbar {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.save-area-form {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.color-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #555;
}
.color-row input[type="color"] {
    width: 36px;
    height: 28px;
    border: 1px solid #d0d5dd;
    border-radius: 4px;
    padding: 2px;
    cursor: pointer;
}

.hint-text {
    font-size: 12px;
    color: #888;
    line-height: 1.6;
    margin-bottom: 8px;
}

/* ============ 地图区域 ============ */
.map-wrap {
    flex: 1;
    position: relative;
    background: #e0e0e0;
}
#map { width: 100%; height: 100%; }

/* 地图类型切换 */
.map-type-switch {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 100;
    display: flex;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    overflow: hidden;
}
.map-type-btn {
    padding: 6px 14px;
    border: none;
    background: #fff;
    font-size: 12px;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
    border-right: 1px solid #eee;
}
.map-type-btn:last-child { border-right: none; }
.map-type-btn:hover { background: #f5f7fa; }
.map-type-btn.active {
    background: #1a73e8;
    color: #fff;
}

/* Toast 提示 */
.map-toast {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.78);
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 13px;
    z-index: 200;
    pointer-events: none;
    white-space: nowrap;
    animation: toastIn 0.3s;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============ 滚动条 ============ */
.item-list::-webkit-scrollbar, .tab-panel::-webkit-scrollbar,
.grid-checkboxes::-webkit-scrollbar, .color-list::-webkit-scrollbar { width: 6px; }
.item-list::-webkit-scrollbar-thumb, .tab-panel::-webkit-scrollbar-thumb,
.grid-checkboxes::-webkit-scrollbar-thumb, .color-list::-webkit-scrollbar-thumb {
    background: #c0c8d4; border-radius: 3px;
}
.item-list::-webkit-scrollbar-thumb:hover, .grid-checkboxes::-webkit-scrollbar-thumb:hover,
.color-list::-webkit-scrollbar-thumb:hover { background: #90a0b5; }
.item-list::-webkit-scrollbar-track, .tab-panel::-webkit-scrollbar-track,
.grid-checkboxes::-webkit-scrollbar-track, .color-list::-webkit-scrollbar-track {
    background: transparent;
}

/* ============ 原网格筛选 (UI优化) ============ */
.grid-filter-wrap {
    margin: 10px 0 !important;
    font-size: 12px;
    flex-direction: column;
    align-items: stretch !important;
    gap: 6px;
}
.grid-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #444;
    padding: 0 2px;
}
.grid-filter-title { font-size: 12px; }
.hint-inline { color: #999; font-weight: 400; font-size: 11px; }
.grid-filter-actions { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.grid-filter-actions .sep { color: #ddd; }
.link-btn {
    color: #1a73e8;
    text-decoration: none;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background 0.15s;
}
.link-btn:hover { background: #e8f0fe; }

.grid-checkboxes {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid #e4e8f0;
    padding: 6px 8px;
    border-radius: 8px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #fafbfd;
}
.grid-cb-label {
    display: flex;
    align-items: center;
    line-height: 1.4;
    cursor: pointer;
    padding: 5px 6px;
    border-radius: 5px;
    transition: background 0.15s;
    gap: 4px;
}
.grid-cb-label:hover { background: #eef3fc; }
.grid-cb-label input[type="checkbox"] {
    margin: 0 2px 0 0;
    accent-color: #1a73e8;
    cursor: pointer;
}
.grid-cb-label .cb-color-dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 4px;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
}
.grid-cb-label .cb-text {
    word-break: break-all;
    font-size: 12.5px;
    color: #333;
}

/* 小区列表的网格 tag (带颜色边框) */
.list-item .grid-tag {
    display: inline-block;
    font-size: 10.5px;
    margin-left: 6px;
    padding: 1px 5px;
    border: 1px solid currentColor;
    border-radius: 3px;
    font-weight: 600;
    vertical-align: middle;
    opacity: 0.9;
}
/* 现在网格 tag (用实心填充区分) */
.list-item .grid-tag.curr {
    color: #fff !important;
    border: 1px solid transparent;
    margin-left: 4px;
}
/* 已调整标识 */
.list-item .changed-flag {
    display: inline-block;
    font-size: 10px;
    margin-left: 4px;
    padding: 0 4px;
    background: #e91e63;
    color: #fff;
    border-radius: 3px;
    font-weight: 700;
    vertical-align: middle;
    letter-spacing: 0.5px;
}
.list-item .arrow-flag {
    display: inline-block;
    font-size: 10px;
    color: #e91e63;
    margin: 0 2px;
    font-weight: 900;
}

/* ============ 双栏筛选汇总条 ============ */
.filter-summary-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    margin: 8px 0;
    background: linear-gradient(135deg, #e3f2fd, #f3e5f5);
    border-radius: 8px;
    border: 1px solid #bbdefb;
    font-size: 12px;
    color: #555;
}
.filter-summary-bar .fs-label { color: #555; font-weight: 500; }
.filter-summary-bar .fs-num {
    font-size: 17px;
    font-weight: 800;
    color: #1a73e8;
    margin: 0 2px;
    font-variant-numeric: tabular-nums;
}
.filter-summary-bar .fs-num.fs-user { color: #e53935; }
.filter-summary-bar .fs-num.fs-changed { color: #e91e63; }
.filter-summary-bar .fs-unit { font-size: 11px; color: #888; margin-right: 2px; }
.filter-summary-bar .fs-sep { color: #c0c8d4; margin: 0 4px; }
.filter-summary-bar .fs-tail { margin-left: auto; }
.filter-summary-bar .fs-changed-seg { display: inline-flex; align-items: center; }

/* ============ 按网格自动生成区域 ============ */
.auto-gen-box {
    margin: 10px 0;
    padding: 12px;
    background: linear-gradient(135deg, #fff8e1, #fff3e0);
    border: 1px solid #ffe0b2;
    border-radius: 10px;
}
.auto-gen-title {
    font-size: 13px;
    font-weight: 700;
    color: #e65100;
    margin-bottom: 4px;
}
.auto-gen-box .btn-primary {
    background: linear-gradient(135deg, #fb8c00, #ef6c00);
}
.auto-gen-box .btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #ef6c00, #e65100);
    box-shadow: 0 2px 6px rgba(230,81,0,0.35);
}

/* ============ 对比模式筛选 ============ */
.diff-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 6px 0 8px;
    padding: 6px 8px;
    background: #fafbfd;
    border-radius: 6px;
    font-size: 12px;
    border: 1px dashed #d0d8e4;
}
.diff-filter .diff-label { color: #555; font-weight: 600; margin-right: 2px; }
.diff-filter label { cursor: pointer; display: inline-flex; align-items: center; gap: 3px; }
.diff-filter .diff-changed { color: #e91e63; font-weight: 600; }
.diff-filter .diff-same { color: #43a047; }

/* 双栏标题色点 */
.grid-tab-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}
.grid-tab-dot.orig-dot {
    background: #1a73e8;
    box-shadow: 0 0 0 1px #fff, 0 0 0 2px #1a73e8;
}
.grid-tab-dot.curr-dot {
    background: #fff;
    border: 2px solid #e91e63;
    box-sizing: border-box;
}

/* checkbox 户数后缀 */
.grid-cb-label .cb-count {
    margin-left: auto;
    font-size: 10.5px;
    color: #1565c0;
    background: #e8f0fe;
    padding: 0 5px;
    border-radius: 8px;
    font-weight: 600;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.grid-cb-label .cb-text {
    flex: 1;
    min-width: 0;
}

/* 双圆 checkbox 色点 (内填充+外环) — 现在网格用 */
.grid-cb-label .cb-color-dot.ring {
    background: transparent !important;
    border: 2px solid var(--ring-color, #888);
    box-shadow: none !important;
    box-sizing: border-box;
}

/* ============ 弹窗通用 ============ */
.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    animation: modalFadeIn 0.18s ease-out;
}
@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.modal-card {
    background: #fff;
    width: 480px;
    max-width: 92vw;
    max-height: 86vh;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideIn 0.22s ease-out;
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
    padding: 14px 20px;
    background: linear-gradient(135deg, #1a73e8, #0d47a1);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.modal-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
    transition: background 0.15s;
}
.modal-close:hover { background: rgba(255,255,255,0.2); }
.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fafbfc;
}

/* ============ 配色面板专用 ============ */
.color-section {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px dashed #e5e8ec;
}
.color-section:last-child { border-bottom: none; margin-bottom: 0; }
.color-section-title {
    font-size: 13px;
    font-weight: 700;
    color: #333;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.color-search { margin-bottom: 8px; }
.color-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.color-list.scrollable {
    max-height: 280px;
    overflow-y: auto;
    padding-right: 2px;
}
.color-row-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: #f7f9fc;
    border-radius: 8px;
    transition: background 0.15s;
}
.color-row-item:hover { background: #eef3fc; }
.color-row-item.is-custom {
    background: #fff8e1;
    border: 1px solid #ffe082;
}
.color-row-item .color-preview {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0,0,0,0.12);
}
.color-row-item .color-name {
    flex: 1;
    font-size: 13px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.color-row-item .color-name .custom-flag {
    background: #ff9800;
    color: #fff;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 4px;
    font-weight: 600;
}
.color-row-item .color-picker {
    width: 36px;
    height: 28px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    padding: 2px;
    cursor: pointer;
    background: #fff;
}
.color-row-item .btn-reset-one {
    width: 28px;
    height: 28px;
    border: 1px solid #ffab91;
    background: #fff;
    color: #e64a19;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s;
}
.color-row-item .btn-reset-one:hover {
    background: #ffccbc;
}
.empty-hint {
    padding: 24px;
    text-align: center;
    color: #999;
    font-size: 12px;
    background: #f7f9fc;
    border-radius: 8px;
}

/* ============ 按钮微调 (UI优化) ============ */
.btn {
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.btn-primary {
    background: linear-gradient(135deg, #1a73e8, #1557b0);
}
.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #1557b0, #0d47a1);
    box-shadow: 0 2px 6px rgba(26,115,232,0.35);
}
.btn-danger {
    background: linear-gradient(135deg, #e53935, #c62828);
}
.btn-danger:hover:not(:disabled) {
    background: linear-gradient(135deg, #c62828, #b71c1c);
    box-shadow: 0 2px 6px rgba(229,57,53,0.35);
}
