/**
 * 平面图查看器样式
 * @version 1.0.0
 * @date 2025-11-29
 */

/* ========================
   主容器布局
   ======================== */
.floor-plan-viewer-container {
    display: flex;
    /* 使用 flex: 1 填充父容器（父容器是 display: flex） */
    flex: 1;
    min-height: 0;
    gap: 16px;
    background: #f5f5f5;
    padding: 16px;
    border-radius: 8px;
}

/* ========================
   左侧位置树面板（已弃用，保留兼容）
   ======================== */
.floor-plan-location-panel {
    width: 260px;
    flex-shrink: 0;
    background: #fff;
    border-radius: 8px;
    padding: 16px;
    overflow-y: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* 无侧边栏模式：左侧面板隐藏，主面板全宽 */
.floor-plan-viewer-container--no-sidebar {
    gap: 0;
}

.floor-plan-viewer-container--no-sidebar .floor-plan-location-panel {
    display: none;
}

.floor-plan-location-tree {
    background: transparent;
}

.floor-plan-location-tree .equipment-count {
    color: #999;
    font-size: 12px;
    margin-left: 4px;
}

.floor-plan-location-tree .ant-tree-node-content-wrapper {
    transition: background-color 0.2s;
}

.floor-plan-location-tree .ant-tree-node-content-wrapper:hover {
    background-color: #e6f7ff !important;
}

/* ========================
   中间主面板
   ======================== */
.floor-plan-main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* 工具栏 */
.floor-plan-toolbar {
    padding: 12px 16px;
    background: linear-gradient(135deg, #fafafa 0%, #f5f5f5 100%);
    border-bottom: 1px solid #e8e8e8;
    flex-shrink: 0;
}

.floor-plan-stats {
    color: #666;
    font-size: 13px;
    padding: 4px 12px;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #e8e8e8;
}

/* 画布区域 */
.floor-plan-canvas-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: 
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    min-height: 400px;
}

/* 确保 ant-spin 组件填满容器 */
.floor-plan-canvas-wrapper .ant-spin-nested-loading,
.floor-plan-canvas-wrapper .ant-spin-container {
    height: 100%;
    width: 100%;
}

.floor-plan-canvas {
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: grab;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.floor-plan-canvas.is-panning {
    cursor: grabbing;
}

.floor-plan-canvas.edit-mode {
    cursor: crosshair;
}

.floor-plan-transform-layer {
    position: relative;
    transform-origin: center center;
    transition: transform 0.1s ease-out;
}

/* 图片和标记的容器 */
.floor-plan-image-wrapper {
    position: relative;
    display: inline-block;
}

.floor-plan-image {
    display: block;
    max-width: 100%;
    /* 使用 100vh / zoom 来补偿响应式 zoom 缩放的影响 */
    max-height: calc(100vh / var(--dynamic-zoom, 0.85) - 300px);
    object-fit: contain;
    user-select: none;
    pointer-events: none;
    transition: opacity 0.3s;
}

/* 背景淡化样式 */
.floor-plan-image.faded {
    opacity: 0.3;
}

/* 标记覆盖层 - 与图片完全重叠 */
.floor-plan-markers-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.floor-plan-markers-overlay .equipment-marker {
    pointer-events: auto;
}

/* 空状态 */
.floor-plan-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: #fafafa;
}

/* ========================
   设备标记样式
   ======================== */
.equipment-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    cursor: pointer;
    z-index: 10;
    transition: transform 0.2s, box-shadow 0.2s;
}

.equipment-marker:hover {
    z-index: 20;
}

.equipment-marker:hover .marker-label {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 标记点 - 显示编号 */
.marker-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--status-color, #1890ff);
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.equipment-marker:hover .marker-dot {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* 编辑模式下的标记 */
.equipment-marker.editable {
    cursor: move;
}

.equipment-marker.editable .marker-dot {
    animation: marker-pulse 2s infinite;
}

.equipment-marker.is-dragging {
    z-index: 100;
    pointer-events: none;
}

.equipment-marker.is-dragging .marker-dot {
    transform: scale(1.3);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

/* 脉冲动画 */
@keyframes marker-pulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 0 0 rgba(24, 144, 255, 0.4);
    }
    50% {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 0 8px rgba(24, 144, 255, 0);
    }
}

/* ========================
   右侧待定位设备面板
   ======================== */
.floor-plan-unpositioned-panel {
    width: 240px;
    flex-shrink: 0;
    background: #fff;
    border-radius: 8px;
    padding: 16px;
    overflow-y: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 2px dashed #91d5ff;
    animation: panel-glow 2s infinite;
}

@keyframes panel-glow {
    0%, 100% {
        border-color: #91d5ff;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    }
    50% {
        border-color: #1890ff;
        box-shadow: 0 2px 8px rgba(24, 144, 255, 0.2);
    }
}

.floor-plan-unpositioned-panel .panel-header {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.floor-plan-unpositioned-panel .panel-header h4 {
    margin: 0 0 4px 0;
    color: #262626;
    font-size: 14px;
    font-weight: 500;
}

.floor-plan-unpositioned-panel .panel-header .hint {
    margin: 0;
    color: #999;
    font-size: 12px;
}

.unpositioned-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.unpositioned-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fafafa;
    border: 1px solid #f0f0f0;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s;
}

.unpositioned-item:hover {
    background: #e6f7ff;
    border-color: #91d5ff;
    transform: translateX(-2px);
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.1);
}

.unpositioned-item:active {
    cursor: grabbing;
}

.unpositioned-item .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.unpositioned-item .item-info {
    flex: 1;
    min-width: 0;
}

.unpositioned-item .item-name {
    font-size: 13px;
    color: #262626;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.unpositioned-item .item-type {
    font-size: 11px;
    color: #999;
}

/* ========================
   编辑模式提示
   ======================== */
.floor-plan-canvas.edit-mode::before {
    content: '编辑模式 - 拖拽设备标记或从右侧拖入设备';
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(24, 144, 255, 0.9);
    color: #fff;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 13px;
    z-index: 100;
    animation: hint-bounce 0.5s ease-out;
}

@keyframes hint-bounce {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ========================
   响应式设计
   ======================== */
@media (max-width: 1200px) {
    .floor-plan-viewer-container {
        flex-wrap: wrap;
    }
    
    .floor-plan-location-panel {
        width: 100%;
        max-height: 200px;
    }
    
    .floor-plan-main-panel {
        width: 100%;
        min-height: 400px;
    }
    
    .floor-plan-unpositioned-panel {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .floor-plan-viewer-container {
        height: auto;
        padding: 8px;
    }
    
    .floor-plan-toolbar {
        padding: 8px;
    }
    
    .floor-plan-toolbar .ant-space {
        flex-wrap: wrap;
    }
    
    .floor-plan-stats {
        display: none;
    }
}

/* ========================
   暗色模式支持
   ======================== */
@media (prefers-color-scheme: dark) {
    .floor-plan-viewer-container {
        background: #1f1f1f;
    }
    
    .floor-plan-location-panel,
    .floor-plan-main-panel,
    .floor-plan-unpositioned-panel {
        background: #262626;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
    
    .floor-plan-toolbar {
        background: linear-gradient(135deg, #2a2a2a 0%, #1f1f1f 100%);
        border-bottom-color: #434343;
    }
    
    .floor-plan-stats {
        background: #1f1f1f;
        border-color: #434343;
        color: #a6a6a6;
    }
    
    .floor-plan-canvas-wrapper {
        background-color: #1a1a1a;
    }
    
    .floor-plan-empty {
        background: #1a1a1a;
    }
    
    .unpositioned-item {
        background: #1f1f1f;
        border-color: #434343;
    }
    
    .unpositioned-item:hover {
        background: #2a2a2a;
        border-color: #1890ff;
    }
    
    .unpositioned-item .item-name {
        color: #e8e8e8;
    }
    
    .marker-label {
        background: rgba(255, 255, 255, 0.9);
        color: #262626;
    }
    
    .marker-label::before {
        border-color: transparent transparent rgba(255, 255, 255, 0.9) transparent;
    }
}

/* ========================
   打印样式
   ======================== */
@media print {
    .floor-plan-viewer-container {
        height: auto;
        page-break-inside: avoid;
    }
    
    .floor-plan-toolbar,
    .floor-plan-location-panel,
    .floor-plan-unpositioned-panel {
        display: none;
    }
    
    .floor-plan-main-panel {
        box-shadow: none;
        border: 1px solid #e8e8e8;
    }
    
    .floor-plan-canvas {
        cursor: default;
    }
}

/* ========================
   设备图例面板
   ======================== */
.floor-plan-legend-panel {
    position: absolute;
    top: 60px;  /* 在工具栏下方，避免遮挡按钮 */
    right: 16px;
    width: 240px;
    max-height: calc(100% - 76px);  /* 留出上下边距 */
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    z-index: 50;
    display: flex;
    flex-direction: column;
    transition: max-height 0.3s ease;
}

.floor-plan-legend-panel.is-collapsed {
    max-height: 48px;
}

.floor-plan-legend-panel .panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.floor-plan-legend-panel .panel-header.legend-drag-handle {
    cursor: move;
}

.floor-plan-legend-panel.is-collapsed .panel-header {
    border-bottom: none;
}

.floor-plan-legend-panel .panel-header h4 {
    margin: 0;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.legend-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-header-actions .ant-btn {
    color: #666;
}

.legend-header-actions .ant-btn:hover {
    color: #1890ff;
}

.legend-list {
    overflow-y: auto;
    max-height: 400px;
    padding: 8px 0;
}

.legend-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    gap: 10px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.legend-item:hover {
    background-color: #e6f7ff;
}

.legend-index {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    /* 背景色通过内联样式设置，与设备状态颜色一致 */
}

.legend-info {
    flex: 1;
    min-width: 0;
}

.legend-name {
    font-size: 13px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.legend-status {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
}

/* 图例为空时的提示 */
.legend-empty {
    padding: 24px 16px;
    text-align: center;
    color: #999;
    font-size: 13px;
}
