* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Microsoft YaHei", sans-serif;
  background: #f4f6f8;
  color: #222;
  line-height: 1.5;
  padding-bottom: 40px;
}

/* 登录框 */
.login-box {
  max-width: 360px;
  margin: 80px auto 0;
  padding: 32px 24px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  text-align: center;
}
.login-box h1 {
  font-size: 20px;
  margin-bottom: 20px;
  color: #2c3e50;
}
.login-box input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 14px;
}
.login-box input:focus {
  outline: none;
  border-color: #2c3e50;
}
.login-box button {
  width: 100%;
  padding: 10px;
  background: #2c3e50;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
}
.login-box button:hover { background: #34495e; }
.login-error {
  margin-top: 12px;
  color: #e74c3c;
  font-size: 13px;
}

header {
  background: #2c3e50;
  color: #fff;
  padding: 16px 20px;
}

header h1 { font-size: 18px; margin-bottom: 4px; }
.logout-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
}
.logout-btn:hover { background: rgba(255,255,255,0.25); }
header { position: relative; }
#device-meta { font-size: 13px; opacity: 0.85; }
#device-meta span { margin-right: 12px; }
/* 设了别名时，设备编号退到标题下方一行：编号是权威标识（别名可能重名），必须还在 */
.header-sub { font-size: 12px; opacity: 0.8; font-family: monospace; margin-bottom: 4px; }

main {
  max-width: 720px;
  margin: 20px auto;
  padding: 0 16px;
}

.card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.card h2 {
  font-size: 15px;
  margin-bottom: 12px;
  color: #34495e;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.metric {
  display: flex;
  flex-direction: column;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 6px;
}

.metric .label { font-size: 12px; color: #7f8c8d; }
.metric .value { font-size: 15px; font-weight: 500; margin-top: 2px; }
.metric .value a { color: #3498db; text-decoration: none; }
.metric .value a:hover { text-decoration: underline; }

.loading, .empty, .error {
  color: #95a5a6;
  font-size: 14px;
  padding: 8px 0;
}

.error { color: #e74c3c; }

.actuator-list, .task-list { list-style: none; }

.task-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #ecf0f1;
}

/* 执行器行：三列网格（名称 | 状态 | 操作）。
   原来是 flex + space-between：空闲空间被均分到两个间隙，状态徽标与按钮的横向位置
   会随名称长度漂移，行与行对不齐；改成固定列后名称列自适应、后两列各自成列。 */
.actuator-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #ecf0f1;
}

.actuator-list li:last-child,
.task-list li:last-child { border-bottom: none; }

.actuator-name { font-weight: 500; min-width: 0; }

.actuator-status {
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 4px;
  min-width: 2.4em;          /* 开/关 等宽，跨行形成一列 */
  text-align: center;
}

.status-on  { background: #d4edda; color: #155724; }
.status-off { background: #f8d7da; color: #721c24; }

.actuator-actions {
  display: inline-flex;
  gap: 6px;
  justify-content: flex-end;
}

/* 下发中：设备最长要等一个上报周期（5 分钟）才取走意图，这段空窗里不给可点按钮，
   否则会堆重复意图。文案与"指令记录"的状态用词保持一致。 */
.actuator-pending {
  font-size: 12px;
  color: #7f8c8d;
  background: #f4f6f7;
  border-radius: 4px;
  padding: 3px 8px;
  white-space: nowrap;
}

.actuator-actions button {
  border: none;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: #fff;
}

.btn-on  { background: #27ae60; }
.btn-off { background: #e74c3c; }

.btn-on:disabled, .btn-off:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.task-meta { color: #7f8c8d; font-size: 13px; }

.del-task-btn {
  border: none;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  background: #ecf0f1;
  color: #e74c3c;
}
.del-task-btn:hover { background: #f8d7da; }

.alias-form { display: flex; gap: 8px; }

.alias-form input {
  flex: 1;
  padding: 8px;
  border: 1px solid #bdc3c7;
  border-radius: 4px;
  font-size: 14px;
}

.alias-form button {
  padding: 8px 16px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.alias-form button:disabled { opacity: 0.5; cursor: not-allowed; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(44, 62, 80, 0.92);
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.show { opacity: 1; }

/* 登录页底部链接 */
.login-footer {
  margin-top: 16px;
  font-size: 13px;
  color: #7f8c8d;
}
.login-footer a {
  color: #3498db;
  text-decoration: none;
}
.login-footer a:hover { text-decoration: underline; }

/* 注册表单分隔 */
.form-section-title {
  font-size: 13px;
  color: #7f8c8d;
  margin: 8px 0 4px;
  text-align: left;
}
.login-box hr {
  border: none;
  border-top: 1px solid #ecf0f1;
  margin: 12px 0 8px;
}

/* header 操作按钮 */
.header-actions {
  position: absolute;
  top: 16px;
  right: 20px;
  display: flex;
  gap: 8px;
}
.header-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.header-btn:hover { background: rgba(255,255,255,0.25); }

/* 设备卡片网格 */
.device-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.device-card {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
  position: relative;
  text-decoration: none;
  color: inherit;
  display: block;
}

.device-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

.device-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.device-card-name {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
}

.device-card-id {
  font-size: 12px;
  color: #95a5a6;
  margin-top: 2px;
  font-family: monospace;
}

.device-card-status {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 10px;
  white-space: nowrap;
}

.device-card-status.online {
  background: #d4edda;
  color: #155724;
}

.device-card-status.offline {
  background: #f8d7da;
  color: #721c24;
}

.device-card-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: #7f8c8d;
}

.device-card-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.device-card-meta .meta-value {
  color: #34495e;
  font-weight: 500;
}

/* 加号卡片 */
.device-card.add-card {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #d0d5dd;
  background: #fafbfc;
  min-height: 120px;
  box-shadow: none;
}

.device-card.add-card:hover {
  border-color: #3498db;
  background: #eef7fd;
  box-shadow: none;
}

.add-card-icon {
  font-size: 36px;
  color: #bdc3c7;
  line-height: 1;
  transition: color 0.2s;
}

.device-card.add-card:hover .add-card-icon {
  color: #3498db;
}

/* 弹窗 */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-content {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  width: 320px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.modal-content h3 {
  font-size: 16px;
  margin-bottom: 16px;
}
.modal-content input {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 10px;
  border: 1px solid #d0d5dd;
  border-radius: 4px;
  font-size: 14px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}
.modal-actions button {
  padding: 6px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
.btn-cancel { background: #ecf0f1; color: #333; }
#pwd-submit { background: #3498db; color: #fff; }
#bind-submit { background: #27ae60; color: #fff; }

/* 备案号 */
.site-footer {
  text-align: center;
  padding: 16px 0;
  font-size: 12px;
}
.site-footer a {
  color: #95a5a6;
  text-decoration: none;
}
.site-footer a:hover { color: #7f8c8d; }

@media (max-width: 480px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  /* 窄屏下执行器行**保持**三列同行（名称 / 状态 / 开关）：
     名称列 minmax(0,1fr) 自己收缩、长名字在列内折行，状态徽标与开关始终并排。
     2026-10 现场：这里曾把操作列设成整行跨列，结果按钮被挤到第二行、和状态徽标
     分了家（反馈"状态和开关换行了"）。所以这一行**不要**在窄屏里改列数、
     也**不要**加 row-gap —— 那等于把开关挪走。 */
  .device-grid { grid-template-columns: 1fr; }
}

/* ==================== v2 页面补充样式 ==================== */
.header-user { font-size: 13px; opacity: 0.9; margin-right: 8px; }

/* 顶部提示条（场景 / 告警） */
.banner {
  padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 14px;
  background: #eaf4fd; color: #21618c; border-left: 4px solid #3498db;
}
.banner-alert { background: #fdecea; color: #a93226; border-left-color: #e74c3c; }

/* 数据新鲜度 / 图表说明 */
.freshness { font-size: 12px; font-weight: 400; color: #95a5a6; margin-left: 6px; }

/* 趋势图：ECharts 自托管渲染，容器只负责尺寸（高度必须显式给，否则 auto 高度取不到值） */
.trend-chart {
  width: 100%; height: 260px; background: #fbfdff;
  border: 1px solid #eef2f5; border-radius: 6px;
}
.trend-box { display: block; }
/* 图表脚注：时间范围与最新/平均同一行，省一行提示 */
.chart-legend {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
  font-size: 12px; color: #95a5a6; margin-top: 6px;
}
.chart-legend span:empty { display: none; }

/* 超时保护徽标 */
.badge-timeout {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 8px;
  font-size: 11px; background: #fff3cd; color: #8a6d3b;
}

/* 弹窗/区块内的说明文字 */
.modal-hint { font-size: 12px; color: #7f8c8d; line-height: 1.6; margin: 6px 0; }
.modal-hint code { background: #f4f6f7; padding: 1px 4px; border-radius: 3px; }
