/* ===== 基本样式 ===== */
body {
  margin: 0;
  padding: 16px;
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont;
  background-color: #f4f6f8;
  color: #333;
}

h1 {
  text-align: center;
  margin-bottom: 24px;
}
/* ================= 顶部固定摄像头区域 ================= */

.top-cameras {
  margin-bottom: 2rem;
}

/* 三列摄像头网格 */
.top-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

/* 摄像头卡片 */
.top-grid .camera-card {
  background: #fff;
  border-radius: 10px;
  padding: 0.5rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 放大层 */
.camera-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}
.camera-modal.hidden { display: none; }

.camera-modal-content img {
  max-width: 90vw;
  max-height: 90vh;
}

/* 离线摄像头 */
.camera-offline {
  opacity: 0.4;
  filter: grayscale(1);
}

/* 标题 */
.top-grid .camera-title {
  font-weight: bold;
  margin-bottom: 0.5rem;
}

/* 关键：限制摄像头尺寸 */
.top-grid img {
  width: 100%;
  max-height: 220px;     /* ⭐ 控制“不会太大” */
  object-fit: contain;  /* 等比缩放，不裁剪 */
  background: #000;
  border-radius: 6px;
}

/* ===== 摄像头区域 ===== */
.camera-section {
  background: #fff;
  padding: 1rem;
  border-radius: 10px;
  margin-bottom: 2rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}


.position-bar {
  width: 100%;
  height: 14px;
  background: #ddd;
  border-radius: 7px;
  overflow: hidden;
}

.position-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg,#4caf50,#8bc34a);
  transition: width 0.3s linear;
}

/* ===== 摄像头网格 ===== */
.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.camera-grid.single {
  grid-template-columns: 1fr;
  justify-items: center;
}

/* ===== 摄像头卡片 ===== */
.camera-card {
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.camera-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

/* ===== 摄像头标题 / 状态 ===== */
.camera-title {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,.6);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .85rem;
}

/* ===== 添加摄像头表单 ===== */
.camera-add {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px dashed #ddd;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 768px) {
  .form-row {
    grid-template-columns: 1fr 2fr;
  }
}


/* ===== 页面主容器 ===== */
.container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

/* ===== 三块区域整体作为“卡片网格” ===== */
.three-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* 卡片通用样式 */
.air,
.soil,
.relay,
.new,
.calculation,
.auto-control {
  background: #ffffff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  min-width: 0;
}
.cam-del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 0, 0, 0.75);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-weight: bold;
  line-height: 26px;
}

.cam-del-btn:hover {
  background: rgba(255, 0, 0, 0.95);
}


/* ===== 平板及以上：两列 ===== */
@media (min-width: 768px) {
  .three-columns {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===== 电脑端：三列 ===== */
@media (min-width: 1200px) {
  .three-columns {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ===== 表单样式 ===== */
.device-card label {
  display: block;
  margin-bottom: 16px;
}

.label-text {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  box-sizing: border-box;
  border: 1px solid #ccc;
  border-radius: 6px;
}

/* ===== 按钮组 ===== */
.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  padding: 8px 16px;
  border: none;
  background-color: #2563eb;
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

button:hover {
  background-color: #1d4ed8;
}

/* ===== 摄像头区域：始终独占一行 ===== */
.camera-container {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 16px;
}

.camera-container img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  border: 2px solid #ddd;
}

/* 摄像头添加框 */
#newCamId,
#newCamUrl {
  padding: 8px;
  margin-bottom: 8px;
  border: 1px solid #bbb;
  border-radius: 6px;
  width: 100%;
}

/* ===== 在线状态 ===== */
.online {
  color: #16a34a;
  background-color: #ecfdf5;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #16a34a;
  font-weight: 600;
}

.offline {
  color: #dc2626;
  background-color: #fef2f2;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #dc2626;
  font-weight: 600;
}

.device-card {
  border: 1px solid #ccc;
  padding: 10px;
  margin: 10px 0;
  background-color: #f9f9f9;
  border-radius: 5px;
}

.device-card .online {
  color: green;
}

.device-card .offline {
  color: red;
}

#calculatedData {
  margin-top: 20px;
  font-weight: bold;
  color: #333;
}


#photo-result {
  margin-top: 16px;
}

@media (max-width: 768px) {
  .top-grid {
    grid-template-columns: 1fr;
  }

  .top-grid img {
    max-height: 200px;
  }
}
