:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text2: #6b7280;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { text-decoration: none; color: var(--primary); }

/* ---------- 认证页 ---------- */
.auth-bg { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #2563eb 100%); }
.auth-card { width: 400px; background: #fff; border-radius: 12px; padding: 36px 32px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth-title { text-align: center; font-size: 22px; font-weight: 600; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--text2); font-size: 13px; margin-bottom: 24px; }
.auth-tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.auth-tabs .tab { flex: 1; text-align: center; padding: 10px; cursor: pointer; color: var(--text2); }
.auth-tabs .tab.on { color: var(--primary); border-bottom: 2px solid var(--primary); font-weight: 600; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; height: 40px; border: 1px solid var(--border); border-radius: 8px; padding: 0 12px;
  font-size: 14px; outline: none; background: #fff; color: var(--text); }
.field input:focus, .field select:focus { border-color: var(--primary); }
.field textarea { height: 72px; padding: 8px 12px; }
.sms-row { display: flex; gap: 8px; }
.sms-row input { flex: 1; }
.btn { display: inline-block; border: none; cursor: pointer; border-radius: 8px; font-size: 14px;
  height: 40px; padding: 0 18px; background: var(--primary); color: #fff; transition: .15s;
  line-height: 40px; text-decoration: none; }
a.btn { display: inline-flex; align-items: center; justify-content: center; }
.btn.sm { line-height: 30px; }
.btn:hover { background: var(--primary-dark); }
.btn.block { display: block; width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.code-btn { height: 40px; white-space: nowrap; min-width: 108px; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 10; }
.logo { height: 60px; display: flex; align-items: center; gap: 10px; padding: 0 18px; color: #fff; font-size: 16px; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); box-shadow: 0 0 8px var(--success); }
.menu { flex: 1; padding: 12px 0; overflow-y: auto; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 12px 20px; cursor: pointer; color: var(--sidebar-text); font-size: 14px; border-left: 3px solid transparent; }
.menu-item:hover { color: #fff; background: rgba(255,255,255,.05); }
.menu-item.on { color: #fff; background: rgba(37,99,235,.25); border-left-color: var(--primary); }
.menu-item .ico { width: 18px; text-align: center; }
/* 「数据大屏」可展开子菜单 */
.menu-item .caret { margin-left: auto; font-size: 11px; opacity: .75; }
.sub-menu { background: rgba(0,0,0,.18); padding: 4px 0 6px; }
.sub-item { display: flex; align-items: center; gap: 8px; padding: 9px 20px 9px 42px; cursor: pointer; font-size: 13px; color: var(--sidebar-text); border-left: 3px solid transparent; }
.sub-item:hover { color: #fff; background: rgba(255,255,255,.05); }
.sub-item.on { color: #fff; background: rgba(37,99,235,.2); border-left-color: var(--primary); }
.sub-item .ico { width: 16px; text-align: center; font-size: 12px; }
.sub-empty { padding: 8px 20px 8px 42px; font-size: 12px; color: #64748b; line-height: 1.5; }
.sidebar-foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #64748b; }
.main { flex: 1; margin-left: 220px; display: flex; flex-direction: column; }
.topbar { height: 60px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 5; }
.topbar .title { font-size: 17px; font-weight: 600; }
.user-box { display: flex; align-items: center; gap: 12px; color: var(--text2); }
.user-box .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.content { padding: 20px 24px; flex: 1; }

/* ---------- 通用组件 ---------- */
.card { background: var(--card); border-radius: 10px; padding: 18px; border: 1px solid var(--border); margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.grid { display: grid; gap: 16px; }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
.stat-num { font-size: 30px; font-weight: 700; margin: 6px 0; }
.stat-label { color: var(--text2); font-size: 13px; }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.stat-row { display: flex; align-items: center; gap: 14px; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--text2); font-weight: 500; padding: 10px 12px; background: #f9fafb; border-bottom: 1px solid var(--border); }
.tbl td { padding: 12px; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.tbl tr:hover td { background: #f8fafc; }

.tag { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; }
.tag.on { background: #d1fae5; color: #065f46; }
.tag.off { background: #fee2e2; color: #991b1b; }
.tag.blue { background: #dbeafe; color: #1e40af; }
.tag.gray { background: #f1f5f9; color: #475569; }
.tag.warn { background: #fef3c7; color: #92400e; }

.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 12px; padding: 24px; width: 520px; max-width: 94vw; max-height: 88vh; overflow-y: auto; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 999; padding: 10px 22px; border-radius: 8px; color: #fff; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.ok { background: var(--success); }
.toast.err { background: var(--danger); }

.empty { text-align: center; color: var(--text2); padding: 40px 0; }
.chart { width: 100%; height: 300px; }
.chart.sm { height: 220px; }

/* ---------- 物联网大屏 / 组态 深色 ---------- */
.screen-dark { background: #0a1120; color: #e2e8f0; min-height: 100vh; }
.screen-header { height: 70px; display: flex; align-items: center; justify-content: center; position: relative;
  background: linear-gradient(180deg, rgba(37,99,235,.25), transparent); border-bottom: 1px solid rgba(59,130,246,.3); }
.screen-header h1 { font-size: 26px; letter-spacing: 6px; background: linear-gradient(90deg,#60a5fa,#a5f3fc); -webkit-background-clip: text; background-clip: text; color: transparent; }
.screen-clock { position: absolute; right: 24px; color: #7dd3fc; font-size: 14px; }
.screen-back { position: absolute; left: 20px; color: #93c5fd; cursor: pointer; font-size: 14px; }
.screen-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 16px 20px; }
.dark-card { background: rgba(15,23,42,.75); border: 1px solid rgba(59,130,246,.25); border-radius: 10px; padding: 16px; }
.dark-card .ct { font-size: 14px; color: #93c5fd; margin-bottom: 10px; border-left: 3px solid #3b82f6; padding-left: 8px; }
.dark-num { font-size: 34px; font-weight: 700; color: #fff; text-align: center; }
.dark-num small { font-size: 14px; color: #94a3b8; margin-left: 4px; }
.scroll-list { max-height: 260px; overflow: hidden; }
.scroll-item { display: flex; justify-content: space-between; padding: 7px 4px; font-size: 13px; border-bottom: 1px dashed rgba(148,163,184,.15); }
.gauge-wrap { height: 220px; }

/* 组态编辑器 */
.scada-canvas { position: relative; min-height: 480px; background: #0f172a; border: 1px dashed rgba(59,130,246,.4); border-radius: 10px; overflow: hidden; }
.widget { position: absolute; background: rgba(15,23,42,.9); border: 1px solid rgba(59,130,246,.35); border-radius: 8px; padding: 10px; color: #e2e8f0; cursor: move; user-select: none; }
.widget.selected { border-color: #f59e0b; box-shadow: 0 0 10px rgba(245,158,11,.4); }
.widget .w-title { font-size: 12px; color: #93c5fd; margin-bottom: 4px; }
.widget .w-value { font-size: 22px; font-weight: 700; }
.widget .w-value small { font-size: 12px; color: #94a3b8; }
.scada-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

.pager { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; align-items: center; color: var(--text2); }
.kv { display: flex; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.kv .k { color: var(--text2); width: 90px; text-align: right; }
.code-box { background: #0f172a; color: #a5f3fc; font-family: Consolas, monospace; font-size: 12px; padding: 10px 12px; border-radius: 8px; word-break: break-all; }
@media (max-width: 1100px) { .grid.c4 { grid-template-columns: repeat(2, 1fr); } .screen-grid { grid-template-columns: 1fr; } }

/* ===== 设备详情-采集：属性标签块 ===== */
.pv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 12px; }
.pv-box { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; min-height: 98px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.pv-box:hover { border-color: var(--primary); }
.pv-name { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-val { font-size: 22px; font-weight: 600; color: var(--text); margin: 4px 0 8px; line-height: 1.2; word-break: break-all; }
.pv-unit { font-size: 12px; font-weight: 400; color: var(--text2); margin-left: 4px; }
.pv-foot { margin-top: auto; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.pv-time { font-size: 11px; color: var(--text2); white-space: nowrap; }
.pv-btn { font-size: 11px; padding: 3px 9px; border-radius: 6px; border: 1px solid var(--border); background: transparent; color: var(--text2); cursor: pointer; }
.pv-btn:hover { color: #fff; border-color: var(--primary); background: var(--primary); }
.pv-btn:disabled { opacity: .55; cursor: not-allowed; }
/* 趋势图图例（点位勾选） */
.pv-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 6px; }
.pv-legend-item { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }

/* ===== 设备调试：网络调试助手风格 ===== */
.dbg-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.dbg-toolbar .seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.dbg-toolbar .seg button { border: none; background: transparent; color: var(--text2); padding: 4px 14px; cursor: pointer; font-size: 12px; }
.dbg-toolbar .seg button.on { background: var(--primary); color: #fff; }
.dbg-chk { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text2); cursor: pointer; user-select: none; }
.dbg-chk input { margin: 0; cursor: pointer; }
.dbg-console { background: #0b1220; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; height: 360px; overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace; font-size: 12px; line-height: 1.7; color: #cbd5e1; }
.dbg-line { display: flex; gap: 8px; white-space: pre-wrap; word-break: break-all; padding: 1px 0; }
.dbg-line:hover { background: rgba(148,163,184,.06); }
.dbg-ts { color: #64748b; flex: 0 0 auto; }
.dbg-dir { flex: 0 0 58px; font-weight: 700; letter-spacing: .5px; }
.dbg-dir.rx { color: #34d399; }
.dbg-dir.tx { color: #fbbf24; }
.dbg-data { flex: 1 1 auto; color: #e2e8f0; }

/* ===== 采集看板：开关量滑动开关 ===== */
.pv-box-sw { min-height: 112px; }
.pv-sw-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sw-track { position: relative; flex: none; width: 54px; height: 30px; border-radius: 15px; cursor: pointer;
  background: #475569; box-shadow: inset 0 1px 3px rgba(0,0,0,.45); transition: background .22s; }
.sw-track .sw-knob { position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: transform .22s; }
.sw-track.on { background: #16a34a; }
.sw-track.on .sw-knob { transform: translateX(24px); }
.sw-track.ro { cursor: not-allowed; opacity: .75; }
.sw-track.busy { opacity: .6; cursor: wait; }
.sw-txt { font-size: 14px; font-weight: 600; color: var(--text2); }
.sw-txt.on { color: #4ade80; }
.pv-tag { font-size: 10px; padding: 1px 6px; border-radius: 4px; border: 1px solid; line-height: 1.6; }
.pv-tag.out { color: #fbbf24; border-color: rgba(251,191,36,.4); background: rgba(251,191,36,.10); }
.pv-tag.in  { color: #7dd3fc; border-color: rgba(125,211,252,.4); background: rgba(125,211,252,.10); }
