
/* ========== 基础 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --brand: #009688;
  --blue: #1E9FFF;
  --red: #f56c6c;
  --orange: #ffb800;
  --green: #16b777;
  --dark: #20222A;
  --bg: #f2f2f2;
  --border: #e6e6e6;
  --text: #333;
  --text-2: #666;
  --text-3: #999;
}
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  overflow: hidden;
}
button { font-family: inherit; }
a { text-decoration: none; color: var(--blue); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 3px; }
.num { font-variant-numeric: tabular-nums; }

/* ========== 布局 ========== */
.topbar {
  height: 50px; background: var(--dark);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: relative; z-index: 10;
}
.topbar .logo { color: #fff; font-size: 17px; font-weight: bold; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.topbar .logo .logo-mark {
  width: 26px; height: 26px; border-radius: 6px;
  background: linear-gradient(135deg, var(--brand), var(--blue));
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px;
}
.topbar .logo .ver { font-size: 12px; color: #888; font-weight: normal; }

/* ========== 登录层（左右分栏：左品牌区 + 右表单；body.authed 控制显隐） ========== */
#login_layer { position: fixed; inset: 0; z-index: 9999; display: flex; background: #fff; }
.login-brand {
  flex: 1.4; background: linear-gradient(160deg, #1e3a8a, #2563eb); color: #fff;
  display: flex; flex-direction: column; justify-content: center; padding: 48px 60px;
}
.login-brand-name { font-size: 50px; font-weight: bold; letter-spacing: 2px; }
.login-brand-slogan { margin-top: 18px; font-size: 15px; opacity: .8; letter-spacing: 1px; }
.login-brand-ver { margin-top: 40px; font-size: 13px; opacity: .5; }
.login-form { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 48px; background: #fff; }
.login-form h2 { font-size: 20px; margin-bottom: 24px; color: #333; }
.login-form input {
  width: 100%; max-width: 320px; box-sizing: border-box; margin-bottom: 14px;
  padding: 10px 12px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; outline: none;
}
.login-form input:focus { border-color: var(--brand); }
.login-tip { margin-top: 18px; font-size: 12px; color: #999; }
.top-user { margin-left: 12px; position: relative; display: inline-flex; align-items: center; }
.user-menu-btn { cursor: pointer; user-select: none; white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.user-menu-btn:hover { color: var(--blue); }
.user-menu-caret { font-size: 10px; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 110px; z-index: 50;
  display: flex; flex-direction: column; overflow: hidden;
}
.user-dropdown[hidden] { display: none; }
.user-dropdown a { padding: 8px 14px; font-size: 13px; color: var(--text); white-space: nowrap; cursor: pointer; }
.user-dropdown a:hover { background: #f0f9f7; color: var(--brand); }
body:not(.authed) .topbar, body:not(.authed) .layout { display: none; }
body.authed #login_layer { display: none; }
@media (max-width: 900px) {
  .login-brand { display: none; }
  .login-form { padding: 32px; }
}

.top-info { display: flex; align-items: center; gap: 22px; color: #ccc; font-size: 13px; }
.top-info .ws { font-weight: bold; font-size: 12px; }
.ws.on { color: var(--brand); }
.ws.off { color: var(--red); }
.top-info a { color: #7cc5ff; }
.top-info a:hover { text-decoration: underline; }
.alarm-badge { color: var(--red); font-weight: bold; }
.alarm-link { cursor: pointer; }
.alarm-link:hover { text-decoration: underline; }

.layout { display: flex; height: calc(100% - 50px); }
.sidebar { width: 184px; min-width: 184px; background: var(--dark); overflow-y: auto; padding: 10px 0; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  height: 44px; padding: 0 20px; color: #ccc; font-size: 14px;
  border-left: 3px solid transparent;
  transition: background-color .15s ease, color .15s ease;
}
.sidebar nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.sidebar nav a.active { color: #fff; background: var(--brand); border-left-color: #7fd4cd; }
.sidebar nav a .ico { width: 18px; text-align: center; font-size: 15px; }
.sidebar .group-label { color: #666; font-size: 11px; padding: 14px 20px 4px; letter-spacing: 1px; }

.content { flex: 1; overflow-y: auto; padding: 0; }
.page { display: none; padding: 16px; }
.page.active { display: block; }

/* ========== 通用组件 ========== */
.card { background: #fff; border-radius: 5px; box-shadow: 0 1px 4px rgba(0,0,0,.06); padding: 16px; margin-bottom: 14px; }
.card h3 { font-size: 15px; padding-bottom: 10px; margin-bottom: 14px; border-bottom: 2px solid var(--brand); display: flex; align-items: center; gap: 8px; }
.card h3 .hint { font-size: 12px; color: var(--text-3); font-weight: normal; }

.btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid transparent; border-radius: 4px;
  padding: 7px 16px; font-size: 13px; cursor: pointer;
  background: #fff; color: var(--text-2); border-color: #d9d9d9;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #01877a; color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.blue:hover { background: #1890e8; color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { background: #e45050; color: #fff; }
.btn.warn { background: #ffb800; border-color: #ffb800; color: #fff; }
.btn.sm { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { padding: 9px 12px; text-align: left; border-bottom: 1px solid #f0f0f0; }
table.tbl th { background: #fafafa; color: var(--text-2); font-weight: 600; white-space: nowrap; }
table.tbl tr:hover td { background: #f8fbff; }
table.tbl td .num, table.tbl th.num { font-variant-numeric: tabular-nums; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 10px; font-size: 12px; font-weight: bold; }
.tag.green { background: #f0fff4; color: var(--green); }
.tag.red { background: #fff1f0; color: var(--red); }
.tag.orange { background: #fff7e6; color: #faad14; }
.tag.gray { background: #f5f5f5; color: #999; }
.tag.blue { background: #e8f4ff; color: var(--blue); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot.ok { background: var(--green); box-shadow: 0 0 5px rgba(22,183,119,.5); }
.dot.err { background: var(--red); box-shadow: 0 0 5px rgba(245,108,108,.5); }
.dot.warn { background: var(--orange); box-shadow: 0 0 5px rgba(255,184,0,.5); }

/* Tab */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid #e8e8e8; margin-bottom: 16px; }
.tabs button {
  border: none; background: none; padding: 10px 22px; font-size: 14px; cursor: pointer;
  color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color .15s ease, border-color .15s ease;
}
.tabs button:hover { color: var(--blue); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: bold; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 24px; }
.form-item { display: flex; align-items: center; }
.form-item > label { width: 110px; color: var(--text-2); font-size: 13px; flex-shrink: 0; }
.form-item input[type=text], .form-item input[type=password], .form-item input[type=number], .form-item select {
  flex: 1; height: 34px; border: 1px solid #d9d9d9; border-radius: 4px; padding: 0 10px; font-size: 13px; background: #fff;
}
.form-item input:focus, .form-item select:focus { border-color: var(--blue); outline: none; }
.form-item .range-input { flex: 1; display: flex; align-items: center; gap: 6px; }
.form-item .range-input input { padding: 0 6px; flex: 1;min-width: 0px;width:0; }
.form-item .range-input span { flex-shrink: 0; color: var(--text-3); font-size: 13px; }
.search-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.search-bar .field { display: flex; flex-direction: column; gap: 4px; }
.search-bar .field label { font-size: 12px; color: var(--text-2); }
.search-bar input, .search-bar select { height: 32px; border: 1px solid #d9d9d9; border-radius: 4px; padding: 0 8px; font-size: 13px; min-width: 130px; }

/* 开关 */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #ccc; border-radius: 22px; cursor: pointer; transition: background-color .2s ease; }
.switch .slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .2s ease; }
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* ========== 实时监控页 ========== */
.mon-toolbar { background: #fff; border-bottom: 1px solid var(--border); height: 46px; display: flex; align-items: center; padding: 0 15px; gap: 12px; margin: -16px -16px 0; }
.mon-toolbar .dev-name { font-weight: bold; }
.mon-toolbar .temp { color: var(--brand); font-size: 13px; }
.ch-section { background: #f8f8f8; border-bottom: 1px solid var(--border); padding: 8px 15px; margin: 0 -16px; }
.ch-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ch-label { font-size: 12px; color: var(--text-3); min-width: 44px; }
.ch-tag {
  border: 1px solid #d2d2d2; background: #fff; border-radius: 3px; padding: 4px 12px;
  font-size: 12px; color: var(--text-2); cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background-color .15s ease;
}
.ch-tag:hover { border-color: var(--blue); color: var(--blue); }
.ch-tag.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.ch-tag .cnt { opacity: .8; margin-left: 2px; }
.sensor-row { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 15px; background: #fff; border-bottom: 1px solid var(--border); margin: 0 -16px 10px; }
.sensor-tag { border: 1px solid #e0e0e0; background: #fafafa; border-radius: 3px; padding: 3px 10px; font-size: 12px; color: var(--text-2); cursor: pointer; }
.sensor-tag:hover { border-color: var(--blue); color: var(--blue); }
.sensor-tag.active { background: #5FB878; color: #fff; border-color: #5FB878; }

.mon-body { display: flex; flex-direction: column; gap: 8px; height: calc(100vh - 210px); }
.wf-panel { background: #16213e; border-radius: 5px; height: 240px; flex-shrink: 0; display: flex; flex-direction: column; }
.wf-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 14px; color: var(--blue); font-weight: bold; font-size: 13px; }
.wf-head .wf-time { color: #999; font-weight: normal; font-size: 11px; margin-left: 8px; }
.wf-head a { color: var(--blue); font-size: 12px; cursor: pointer; }
.wf-canvas { flex: 1; margin: 0 10px 10px; border-radius: 3px;
  background: repeating-linear-gradient(90deg, rgba(30,159,255,.05) 0 2px, transparent 2px 24px),
             linear-gradient(180deg, #0f0f23, #1a1a3e);
  position: relative; overflow: hidden;
}
.wf-canvas::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse 30% 60% at 30% 40%, rgba(255,120,80,.55), transparent 70%),
              radial-gradient(ellipse 25% 50% at 65% 60%, rgba(255,200,60,.45), transparent 70%),
              radial-gradient(ellipse 20% 40% at 85% 30%, rgba(255,90,90,.4), transparent 70%);
}
.chart-grid { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-height: 0; overflow-y: auto; grid-auto-rows: minmax(160px, 1fr); }
.chart-cell { background: #fff; border: 1px solid var(--border); border-radius: 4px; position: relative; overflow: hidden; }
.chart-cell .chart-title { position: absolute; top: 6px; left: 10px; font-size: 12px; color: var(--text-2); background: rgba(255,255,255,.85); padding: 2px 6px; border-radius: 3px; z-index: 2; }
.chart-cell svg { width: 100%; height: 100%; }
.chart-cell.empty { display: flex; align-items: center; justify-content: center; }
.chart-cell.empty span { color: var(--text-3); font-size: 13px; }
#mon_sensor_tags { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }

/* ========== 台账页 ========== */
.source-bar { display: flex; align-items: center; gap: 14px; background: #fff8e1; border: 1px solid #ffe082; border-radius: 5px; padding: 10px 14px; margin-bottom: 14px; color: #8d6e00; font-size: 13px; flex-wrap: wrap; }
.channel-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.channel-item { display: flex; align-items: center; gap: 6px; background: #f9f9f9; border-radius: 4px; padding: 8px 10px; font-size: 12px; flex-wrap: wrap; }
.channel-item.off { opacity: .5; }
.channel-item label { font-weight: bold; white-space: nowrap; }
.channel-item input, .channel-item select { height: 28px; border: 1px solid #d9d9d9; border-radius: 3px; font-size: 12px; padding: 0 4px; }
.channel-item .w { width: 84px; }
.channel-item .s { width: 78px; }
.channel-item .n { width: 52px; }

/* ========== 系统维护 ========== */
.summary-bar { background: #f0f5ff; border: 1px solid #adc6ff; border-radius: 5px; padding: 10px 15px; margin-bottom: 14px; font-size: 13px; color: #1d39c4; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.ver-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 6px; }
.ver-card { text-align: center; padding: 14px; background: #f8f9fa; border-radius: 8px; }
.ver-card .l { color: var(--text-3); font-size: 12px; margin-bottom: 6px; }
.ver-card .v { font-size: 19px; font-weight: bold; }
.ver-card .v.cur { color: var(--green); }
.ver-card .v.bak { color: var(--blue); }
.progress { height: 8px; background: #f0f0f0; border-radius: 4px; width: 90px; display: inline-block; vertical-align: middle; margin-right: 8px; overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: 4px; }

.upload-area { border: 2px dashed #d9d9d9; border-radius: 8px; padding: 34px; text-align: center; cursor: pointer; background: #fafafa; margin-bottom: 14px; transition: border-color .2s ease, background-color .2s ease; }
.upload-area:hover { border-color: var(--blue); background: #f0f7ff; }
.upload-area .up-ico { font-size: 40px; color: #bbb; margin-bottom: 8px; }
.upload-area .tip { color: var(--text-3); font-size: 12px; margin-top: 6px; }
.step-list { list-style: none; margin: 14px 0; }
.step-list li { display: flex; align-items: center; gap: 10px; padding: 8px 14px; margin-bottom: 5px; border-radius: 4px; font-size: 13px; background: #f5f5f5; color: var(--text-3); }
.step-list li.done { background: #f0fff4; color: var(--green); }
.step-list li.active { background: #fff7e6; color: #faad14; font-weight: bold; }
.banner { display: flex; align-items: center; gap: 10px; background: #fff3e0; border: 1px solid #ff9800; border-radius: 5px; padding: 10px 14px; margin-bottom: 14px; color: #e65100; font-size: 13px; }
.banner button { margin-left: auto; }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.note { color: var(--text-3); font-size: 12px; line-height: 1.8; }
.breadcrumb-tag { font-size: 12px; color: var(--text-3); margin-bottom: 12px; }
.breadcrumb-tag b { color: var(--brand); }

/* ========== 曲线图图例 ========== */
.chart-cell .chart-legend { position: absolute; top: 7px; right: 10px; z-index: 2; background: rgba(255,255,255,.85); padding: 2px 6px; border-radius: 3px; display: flex; gap: 12px; font-size: 11px; color: var(--text-2); }
.chart-legend span { display: flex; align-items: center; gap: 4px; }
.chart-legend .ln { width: 16px; border-top: 2px solid; display: inline-block; }
.chart-legend .ln.dash { border-top-style: dashed; }
.chart-legend.plain { position: static; background: none; padding: 0; margin-top: 6px; }

/* ========== 告警记录分页 ========== */
.pager { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--text-2); flex-wrap: wrap; justify-content: flex-end; }
.pager label { display: flex; align-items: center; gap: 6px; }
.pager select { height: 28px; border: 1px solid #d9d9d9; border-radius: 4px; padding: 0 6px; font-size: 13px; background: #fff; }
.pager input { width: 44px; height: 28px; border: 1px solid #d9d9d9; border-radius: 4px; padding: 0 6px; font-size: 13px; text-align: center; }

/* ========== 告警数据图弹窗 ========== */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-mask[hidden] { display: none; }
.modal-box { width: min(860px, 92vw); max-height: 88vh; overflow-y: auto; background: #fff; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.25); padding: 16px 18px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding-bottom: 10px; border-bottom: 2px solid var(--brand); margin-bottom: 14px; }
.modal-head b { font-size: 15px; }
.modal-head .hint { font-size: 12px; color: var(--text-3); }
.modal-head .btn { margin-left: auto; }
.modal-chart { margin-bottom: 16px; }
.modal-chart h4 { font-size: 13px; margin-bottom: 8px; color: var(--text-2); }
.modal-chart svg { width: 100%; height: 160px; border: 1px solid var(--border); border-radius: 4px; background: #fff; }
.alarm-media { display: flex; gap: 16px; margin-top: 4px; }
.alarm-media .media-item { flex: 1; min-width: 0; }
.alarm-media .media-title { display: flex; align-items: center; justify-content: space-between; font-size: 13px; margin-bottom: 8px; color: var(--text-2); }
.alarm-media img { width: 100%; height: 150px; object-fit: cover; border: 1px solid var(--border); border-radius: 4px; background: #f5f5f5; }
.alarm-media video { width: 100%; height: 150px; border: 1px solid var(--border); border-radius: 4px; background: #000; }

/* ========== 测试工具页：左执行台 + 右用例/记录两栏 ========== */
.test-layout { display: flex; gap: 16px; align-items: flex-start; }
.test-layout .test-console { flex: 11; min-width: 0; }
.test-side { flex: 9; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.test-result { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fafbfc; font-size: 13px; line-height: 1.8; }

/* ========== 系统配置页：3 处开关宽度调整为 50px（中台模式/瀑布图推送/MQTT模式） ========== */
main#main_content > section.page:nth-child(5) > div.card:nth-child(5) > div.form-grid > div.form-item:nth-child(1) > label.switch > span.slider,
main#main_content > section.page:nth-child(5) > div.card:nth-child(5) > div.form-grid > div.form-item:nth-child(5) > label.switch > span.slider,
main#main_content > section.page:nth-child(5) > div.card:nth-child(7) > div.form-grid > div.form-item:nth-child(1) > label.switch > span.slider {
  width: 50px;
}

/* ========== 台账配置页：中台自动同步开启后整页置灰只读（开关在置灰状态下仍可点击） ========== */
.page[data-page="book"] { position: relative; }
.config-readonly-mask { display: none; position: absolute; inset: 0; z-index: 50; background: rgba(200,200,200,.5); align-items: flex-start; justify-content: center; }
.page[data-page="book"].readonly .config-readonly-mask { display: flex; }
.config-readonly-mask .rm-tip { margin-top: 18px; background: #fff; border: 1px solid #ff9800; color: #e65100; border-radius: 5px; padding: 10px 16px; font-size: 13px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.page[data-page="book"] .source-bar .switch { position: relative; z-index: 60; }

/* ========== 光谱查看弹窗（多通道同图对比） ========== */
.spec-ch-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.spec-ch { display: inline-flex; align-items: center; gap: 5px; border: 1px solid #d2d2d2; border-radius: 3px; padding: 4px 10px; font-size: 12px; color: var(--text-2); cursor: pointer; user-select: none; }
.spec-ch i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.spec-ch.on { border-color: var(--blue); background: #e8f4ff; color: var(--blue); font-weight: bold; }
.spec-legend { font-size: 12px; color: var(--text-2); margin-bottom: 8px; min-height: 16px; }
#spec_svg { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 4px; background: #fff; }

/* ========== Toast 提示 ========== */
.toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: rgba(32,34,42,.9); color: #fff; padding: 8px 18px; border-radius: 4px; font-size: 13px; z-index: 200; }
