/* =================================
   1. 全局与基础样式 (Global & Base Styles)
   ================================= */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 20px;
    background-image: url('https://andyarno.top/usr/uploads/背景图/su57.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    min-height: 100vh; /* Changed from height to min-height */
    /* overflow: hidden; Removed */
    transition: background-image 1s ease-in-out;
}

.container {
    max-width: 2500px;
    margin: 0 auto;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    padding: 14px;
    
    /* 新增的 Grid 布局 */
    display: grid;
    grid-template-columns: repeat(6, 1fr); /* 创建一个6列的网格 */
    grid-template-rows: auto 1fr; /* Changed first row to auto, second to 1fr to allow content to dictate height */
    gap: 14px; /* 网格项之间的间距 */
    
    /* Allow container to grow with content and scroll */
    /* height: calc(100vh - 40px); Removed */
    /* overflow: hidden; Removed */
}

h1, h2, h3 {
    color: #333;
}

h1 {
    display: none;
}

/* =================================
   11. 坐标显示 (Coordinate Display)
   ================================= */
.coordinate-display {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 14px;
    pointer-events: none;
    z-index: 1001;
}

.coordinate-display p {
    margin: 2px 0;
}

/* =================================
   12. 背景控制按钮 (Background Control Buttons)
   ================================= */
.bg-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.8);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.bg-control-btn {
    padding: 8px 12px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.bg-control-btn:hover {
    background-color: #45a049;
}

.bg-control-btn:active {
    background-color: #3d8b40;
}

.bg-control-btn.active {
    background-color: #f44336;
}

.bg-control-btn.active:hover {
    background-color: #d32f2f;
}

.panel {
    min-width: 300px;
    background-color: rgba(249, 249, 249, 0.7);
    border-radius: 8px;
    padding: 11px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    flex: 1;
}

.panel h3 {
    margin-top: 0;
    color: #4CAF50;
    border-bottom: 1px solid #eee;
    padding-bottom: 7px;
}

/* =================================
   3. 键盘与地图控制按钮 (Keyboard & Map Control Buttons)
   ================================= */
.keyboard-control-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 52px;
}

.keyboard-toggle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.advanced-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 5px;
    font-size: 14px;
    color: #333;
    text-align: center;
}

.advanced-controls span {
    display: block;
    width: 100%;
    text-align: center;
}

.keyboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 36px);
    gap: 7px;
}

.map-controls {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.control-btn {
    padding: 11px;
    font-size: 13px;
    font-weight: bold;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.control-btn:hover {
    background-color: #45a049;
}

.control-btn:active {
    background-color: #3d8b40;
}

.stop-mode {
    background-color: #f44336 !important; /* 红色背景 */
    color: white !important;
}

.stop-mode:hover {
    background-color: #d32f2f !important;
}

.stop-mode:active {
    background-color: #b71c1c !important;
}

.control-btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

.control-btn.active {
    background-color: #28a745;
    color: white;
    border-color: #28a745;
}

/* =================================
   4. 状态显示 (Status Display)
   ================================= */
.status-item {
    margin: 7px 0;
    padding: 7px;
    background-color: #e8f5e9;
    border-radius: 5px;
    border-left: 4px solid #4CAF50;
}

.status-value {
    font-weight: bold;
    color: #2e7d32;
}

/* =================================
   5. 数据切换按钮 (Data Toggle Buttons)
   ================================= */
.toggle-btn {
    padding: 10px 20px;
    margin: 5px;
    font-size: 16px;
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.toggle-btn:hover {
    background-color: #1976D2;
}

.toggle-btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

.toggle-btn.active {
    background-color: #f44336;
}

.toggle-btn.active:hover {
    background-color: #d32f2f;
}

/* =================================
   6. 可视化区域 (Visualization Area)
   ================================= */

.map-container {
    position: relative;
    text-align: center;
}


#map-canvas {
    border: 2px solid #ddd;
    border-radius: 5px;
    background-color: #f0f0f0;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
}

.traffic-light-controls {
    display: flex;
    justify-content: center;
    margin-top: 15px;
    gap: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-item input[type="checkbox"] {
    margin-right: 5px; /* 在复选框和颜色块之间添加一些空间 */
}

.color-box {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

/* =================================
   7. 控制面板布局 (Control Panel Layout)
   ================================= */

/* =================================
   8. 响应式设计 (Responsive Design)
   ================================= */
@media (max-width: 768px) {
    .control-panel {
        flex-direction: column;
    }
    
    .panel {
        min-width: 100%;
    }
    
    .keyboard-grid {
        max-width: 100%;
    }
}

/* =================================
   8. 通知系统 (Notification System)
   ================================= */
#notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    background-color: #f44336; /* 红色背景表示错误 */
    color: white;
    padding: 15px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    opacity: 1;
    transition: opacity 0.5s, transform 0.5s;
    transform: translateX(0);
}

.notification.fade-out {
    opacity: 0;
    transform: translateX(100%);
}

/* =================================
   9. 终端日志 (Terminal Log)
   ================================= */
div.panel.log-panel {
    background-color: #0c0c0c; /* 强制设置父容器背景色为黑色 */
    padding: 15px;
    border: 1px solid #444; /* 添加一个深色边框以更好地融合 */
}

.log-panel h3 {
    color: #4CAF50; /* 保持标题颜色一致 */
    border-bottom: 1px solid #444; /* 匹配深色主题 */
}

.log-container {
    height: 280px;
    overflow-y: auto;
    padding: 0; /* 移除内边距，因为父容器已经有了 */
    background-color: #0c0c0c;
    color: #c0c0c0;
    font-family: 'Consolas', 'Courier New', Courier, monospace;
    font-size: 14px;
    line-height: 1.6;
}

.log-container p {
    margin: 0;
    padding: 1px 0;
    border-bottom: none; /* 移除分隔线以获得更简洁的外观 */
}

/* =================================
   10. 性能监控面板 (Performance Panel)
   ================================= */
.performance-panel {
    background: rgba(255, 255, 255, 0.9);
    padding: 10px;
    border-radius: 5px;
    font-size: 12px;
    margin-top: 10px;
}

.performance-panel h4 {
    margin: 0 0 8px 0;
    color: #333;
}

#performance-stats p {
    margin: 2px 0;
    color: #666;
}

/* =================================
   11. 坐标显示 (Coordinate Display)
   ================================= */
.coordinate-display {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 14px;
    pointer-events: none;
    z-index: 1001;
}

.coordinate-display p {
    margin: 2px 0;
}

/* --- Grid Layout Definitions --- */

/* Row 1 */
#keyboard-panel {
    grid-column: 1 / span 2; /* Starts at column 1, spans 2 columns */
    grid-row: 1;
}

#status-panel {
    grid-column: 3 / span 2; /* Starts at column 3, spans 2 columns */
    grid-row: 1;
}

#log-panel {
    grid-column: 5 / span 2; /* Starts at column 5, spans 2 columns */
    grid-row: 1;
}

/* Row 2 */
#camera-panel {
    grid-column: 1 / span 3; /* Starts at column 1, spans 3 columns */
    grid-row: 2;
}

#map-panel {
    grid-column: 4 / span 3; /* Starts at column 4, spans 3 columns */
    grid-row: 2;
}


/* --- Panel Content Height Constraints --- */

/* Make second-row panels flexible columns and prevent overflow */
#camera-panel, #map-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Allow camera container to grow */
.camera-container {
    flex-grow: 1;
    min-height: 0; /* Flexbox overflow fix */
    display: flex;
}

/* Allow map/performance area to grow */
.map-and-performance-container {
    flex-grow: 1;
    min-height: 0; /* Flexbox overflow fix */
    display: flex;
    gap: 20px;
}

.map-and-performance-container .map-container {
    flex: 3;
    display: flex;
    min-width: 0; /* Flexbox overflow fix */
}

.map-and-performance-container .performance-panel {
    flex: 1;
    overflow-y: auto; /* Allow performance stats to scroll */
}

/* Make canvases responsive within their containers */
#camera-canvas, #map-canvas {
    width: 100%;
    height: 100%;
}
