/* 基础样式和变量 */
:root {
  --primary-color: #00ccff;
  --secondary-color: #0066ff;
  --background-dark: #0a0a1a;
  --background-light: #151530;
  --card-bg: rgba(16, 18, 46, 0.7);
  --text-primary: #e0e0ff;
  --text-secondary: #a0a0ff;
  --success-color: #00ff88;
  --warning-color: #ffaa00;
  --error-color: #ff4444;
  --border-radius: 12px;
  --transition: all 0.3s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', 'Arial', sans-serif;
}

body {
  background: linear-gradient(135deg, var(--background-dark) 0%, var(--background-light) 50%, var(--background-dark) 100%);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* 背景效果 */
body::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 30%, rgba(0, 100, 255, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(0, 200, 255, 0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

.container {
  max-width: 1800px;
  margin: 0 auto;
  padding: 20px;
}

/* 头部样式 */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid rgba(0, 255, 255, 0.3);
  margin-bottom: 30px;
  position: relative;
}

header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
}

.logo {
  display: flex;
  align-items: center;
}

.logo-icon {
  font-size: 32px;
  margin-right: 15px;
  color: var(--primary-color);
  filter: drop-shadow(0 0 10px rgba(0, 200, 255, 0.7));
}

.logo h1 {
  font-size: 32px;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
  letter-spacing: 1px;
}

/* 状态面板 */
.status-panel {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid rgba(0, 150, 255, 0.3);
}

.status {
  display: flex;
  align-items: center;
  font-size: 16px;
  margin-right: 20px;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--error-color);
  margin-right: 8px;
  box-shadow: 0 0 10px var(--error-color);
  animation: pulse 2s infinite;
}

.status-indicator.connected {
  background-color: var(--success-color);
  box-shadow: 0 0 10px var(--success-color);
}

.sensor-count {
  display: flex;
  align-items: center;
  font-size: 16px;
}

.sensor-count i {
  margin-right: 8px;
  font-size: 20px;
  color: var(--primary-color);
}

/* 动画 */
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* 仪表板布局 */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  grid-gap: 20px;
  margin-bottom: 30px;
}

/* 卡片样式 */
.card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: 0 0 20px rgba(0, 150, 255, 0.1);
  border: 1px solid rgba(0, 150, 255, 0.2);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(5px);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 0 30px rgba(0, 150, 255, 0.3);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.sensor-name {
  font-size: 18px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
}

.sensor-name i {
  margin-right: 10px;
  color: var(--primary-color);
}

.location-id {
  font-size: 12px;
  color: #8080cc;
  background: rgba(0, 100, 255, 0.2);
  padding: 3px 8px;
  border-radius: 10px;
}

/* 数据显示 */
.data-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.data-value {
  font-size: 42px;
  font-weight: bold;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
}

.data-unit {
  font-size: 18px;
  color: var(--text-secondary);
  margin-left: 5px;
}

.data-icon {
  font-size: 46px;
  color: rgba(0, 200, 255, 0.7);
  filter: drop-shadow(0 0 5px rgba(0, 200, 255, 0.5));
}

.location-info {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

.location-info i {
  margin-right: 5px;
}

.last-update {
  font-size: 12px;
  color: #8080cc;
}

/* 图表容器 */
.charts-container {
  margin-top: 20px;
}

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 20px;
  margin-bottom: 20px;
}

.realtime-chart, .week-history, .data-history {
  height: 350px;
}

.realtime-chart canvas {
  height: 280px !important;
}

.history-chart {
  height: 280px;
}

/* WiFi信息样式 */
.wifi-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  position: absolute;
  bottom: 21px;
  right: 25px;
  max-width: 200px;
}

.wifi-name {
  font-size: 11px;
  color: #8888cc;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  order: 2;
}

.wifi-signal {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  height: 16px;
  order: 1;
}

.wifi-bar {
  width: 3px;
  background-color: #6666aa;
  border-radius: 1px;
  transition: var(--transition);
}

.wifi-bar:nth-child(1) { height: 4px; }
.wifi-bar:nth-child(2) { height: 6px; }
.wifi-bar:nth-child(3) { height: 8px; }
.wifi-bar:nth-child(4) { height: 10px; }

/* 信号强度样式 */
.wifi-signal[data-strength="1"] .wifi-bar:nth-child(1) { background-color: var(--success-color); }
.wifi-signal[data-strength="2"] .wifi-bar:nth-child(-n+2) { background-color: var(--success-color); }
.wifi-signal[data-strength="3"] .wifi-bar:nth-child(-n+3) { background-color: var(--success-color); }
.wifi-signal[data-strength="4"] .wifi-bar { background-color: var(--success-color); }

/* 警告样式 */
.card.data-timeout-warning {
  border: 3px solid var(--error-color) !important;
  box-shadow: 0 0 15px rgba(255, 68, 68, 0.6) !important;
  animation: pulse-warning 0.5s ease-in-out;
}

.card.connection-warning {
  border: 2px solid var(--warning-color) !important;
  box-shadow: 0 0 10px rgba(255, 170, 0, 0.4) !important;
}

.card.server-warning {
  border: 2px solid var(--error-color) !important;
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.4) !important;
}

.card.fault-warning {
  border: 2px solid var(--warning-color) !important;
  animation: fault-pulse 1s infinite alternate !important;
  box-shadow: 0 0 15px rgba(255, 170, 0, 0.6) !important;
}

@keyframes pulse-warning {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes fault-pulse {
  0% {
    box-shadow: 0 0 5px rgba(255, 170, 0, 0.4);
    border-color: var(--warning-color);
  }
  100% {
    box-shadow: 0 0 20px rgba(255, 170, 0, 0.8);
    border-color: #ffcc00;
  }
}

/* 消息通知 */
.message {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 15px 20px;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 400px;
  transform: translateX(400px);
  opacity: 0;
  transition: var(--transition);
  border-left: 4px solid;
}

.message.show {
  transform: translateX(0);
  opacity: 1;
}

.message-success { border-left-color: var(--success-color); }
.message-error { border-left-color: var(--error-color); }
.message-warning { border-left-color: var(--warning-color); }
.message-info { border-left-color: var(--primary-color); }
.message-loading { border-left-color: #aa00ff; }

.message-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.message-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.4;
}

.message-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.message-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

/* 页脚和控件 */
.footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid rgba(0, 255, 255, 0.3);
  color: var(--text-secondary);
  font-size: 14px;
  position: relative;
}

.footer::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
}

.controls {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.control-btn {
  background: var(--card-bg);
  border: 1px solid rgba(0, 150, 255, 0.3);
  color: var(--text-secondary);
  padding: 8px 16px;
  margin: 0 5px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.control-btn:hover {
  background: rgba(0, 100, 255, 0.3);
  color: var(--primary-color);
}

.control-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 网格线背景 */
.grid-lines {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    linear-gradient(rgba(0, 150, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 150, 255, 0.05) 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
  z-index: -1;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .dashboard {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
  
  .chart-row {
    grid-template-columns: 1fr;
  }
  
  .realtime-chart, .week-history, .data-history {
    height: 300px;
  }
  
  .realtime-chart canvas,
  .history-chart {
    height: 230px !important;
  }
}

@media (max-width: 768px) {
  .dashboard {
    grid-template-columns: 1fr;
  }
  
  .chart-row {
    grid-template-columns: 1fr;
  }
  
  .realtime-chart, .week-history, .data-history {
    height: 280px;
  }
  
  .realtime-chart canvas,
  .history-chart {
    height: 210px !important;
  }
  
  header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .status-panel {
    margin-top: 15px;
    width: 100%;
    justify-content: space-between;
  }
  
  .data-value {
    font-size: 36px;
  }
}

/* 模态框样式 */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 10000;
  backdrop-filter: blur(5px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal.show {
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 1;
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  width: 90%;
  max-width: 1200px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(0, 150, 255, 0.3);
  border: 1px solid rgba(0, 150, 255, 0.3);
  position: relative;
  transform: translateY(-20px);
  transition: transform 0.3s ease;
}

.modal.show .modal-content {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid rgba(0, 150, 255, 0.3);
  background: rgba(16, 18, 46, 0.9);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  position: sticky;
  top: 0;
  z-index: 1;
}

.modal-header h2 {
  color: var(--text-primary);
  font-size: 24px;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 28px;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: var(--transition);
}

.modal-close:hover {
  background: rgba(255, 68, 68, 0.2);
  color: var(--error-color);
}

.modal-body {
  padding: 20px;
}

.sensor-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.info-section {
  background: rgba(0, 20, 40, 0.6);
  border-radius: 8px;
  padding: 15px;
  border: 1px solid rgba(0, 150, 255, 0.2);
}

.info-section h3 {
  color: var(--primary-color);
  font-size: 16px;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.info-row:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.info-label {
  color: var(--text-secondary);
  font-size: 14px;
}

.info-value {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  text-align: right;
  max-width: 60%;
  word-break: break-word;
}

.info-value small {
  color: var(--text-secondary);
  font-size: 12px;
}

.modal-chart {
  margin-top: 30px;
  background: rgba(0, 20, 40, 0.6);
  border-radius: 8px;
  padding: 15px;
  border: 1px solid rgba(0, 150, 255, 0.2);
}

.modal-chart h3 {
  color: var(--primary-color);
  font-size: 16px;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-chart-container {
  height: 200px;
  position: relative;
}

/* 卡片点击效果 */
.card {
  cursor: pointer;
  user-select: none;
}

.card:active {
  transform: translateY(-2px) scale(0.98);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .modal-content {
    width: 95%;
    max-height: 95vh;
  }
  
  .sensor-info-grid {
    grid-template-columns: 1fr;
  }
  
  .info-row {
    flex-direction: column;
    gap: 4px;
  }
  
  .info-value {
    max-width: 100%;
    text-align: left;
  }
}