/* =========================================================
   台区线损采集系统 · 全局样式
   深蓝商务风 / 电力行业内部工具
   ========================================================= */
:root {
  --navy: #10233f;
  --navy-2: #183353;
  --primary: #2168d8;
  --primary-hover: #1855b5;
  --primary-soft: #edf4ff;
  --accent: #37d6c0;
  --bg: #f3f6fa;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-strong: #ccd6e2;
  --text: #182337;
  --text-2: #46566c;
  --muted: #6c7b90;
  --ok: #15824b;
  --ok-bg: #eaf7f0;
  --warn: #9a6700;
  --warn-bg: #fff6df;
  --bad: #c8323e;
  --bad-bg: #fff0f1;
  --shadow: 0 1px 2px rgba(16, 35, 63, .03), 0 8px 24px rgba(16, 35, 63, .045);
  --shadow-lg: 0 24px 64px rgba(5, 20, 40, .24);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-underline-offset: 3px; }
button, input, select { font: inherit; }
a, button, input, select { -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(33, 104, 216, .24);
  outline-offset: 2px;
}
::selection { background: #cfe1fb; color: var(--navy); }

/* ---------- 顶部导航 ---------- */
.topbar {
  background: var(--navy);
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 4px 18px rgba(8, 24, 45, .12);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  max-width: 1440px;
  min-height: 68px;
  margin: 0 auto;
  padding: 10px 28px;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 16px;
}
.topbar .brand {
  color: #fff;
  display: flex;
  align-items: center;
  gap: 11px;
  white-space: nowrap;
  text-decoration: none;
  flex: none;
}
.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #082d2a;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(255,255,255,.12), 0 5px 16px rgba(55,214,192,.16);
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.2; }
.brand-copy strong { font-size: 16px; letter-spacing: 1px; }
.brand-copy small { color: #91a4bd; font-size: 10px; letter-spacing: 2px; margin-top: 4px; }
.main-nav {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.main-nav::-webkit-scrollbar { display: none; }
.topbar .main-nav a, .topbar a.logout {
  color: #b6c4d6;
  text-decoration: none;
  font-size: 13px;
  padding: 8px 13px;
  border-radius: 7px;
  transition: background .16s ease, color .16s ease;
  white-space: nowrap;
  flex: none;
}
.topbar .main-nav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.topbar .main-nav a.active {
  color: #fff;
  background: rgba(255,255,255,.11);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
  font-weight: 600;
}
.topbar .main-nav a.active::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 2px;
}
.topbar a.logout {
  color: #c6d1df;
  margin-left: auto;
  padding-right: 13px;
}
.topbar a.logout:hover { color: #fff; background: rgba(255,255,255,.07); }

.container { max-width: 1440px; margin: 0 auto; padding: 0 28px 36px; }
.page-heading { margin: 30px 0 24px; }
.page-heading h1 { margin: 0; color: var(--navy); font-size: 26px; line-height: 1.3; letter-spacing: -.5px; }
.page-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 18px;
  padding: 0 0 15px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 16px;
  font-weight: 650;
  color: var(--navy);
  line-height: 1.4;
}
.card h2 span { color: var(--muted); font-size: 12px; font-weight: 400; }
.card h3 {
  margin: 28px 0 12px;
  font-size: 14px;
  color: var(--navy);
  font-weight: 650;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--border);
}
.card h3:first-child { margin-top: 0; }
.card > p { color: var(--text-2); }

/* ---------- KPI 汇总卡片 ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  padding: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.kpi {
  background: var(--card);
  padding: 21px 24px 19px;
  position: relative;
  min-width: 0;
}
.kpi::before {
  content: "";
  position: absolute;
  left: 24px;
  top: 20px;
  width: 24px;
  height: 3px;
  border-radius: 3px;
  background: var(--primary);
}
.kpi.kpi-ok::before { background: var(--ok); }
.kpi.kpi-warn::before { background: #d59a19; }
.kpi.kpi-bad::before  { background: var(--bad); }
.kpi .kpi-label { font-size: 12px; color: var(--text-2); margin: 12px 0 7px; font-weight: 500; }
.kpi .kpi-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.8px;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.kpi .kpi-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.kpi .kpi-sub { font-size: 11px; color: var(--muted); margin-top: 7px; }

/* ---------- 表格 ---------- */
.tw {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 9px;
  scrollbar-color: #bdc9d8 transparent;
  scrollbar-width: thin;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: #f6f8fb;
  color: var(--text-2);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .2px;
  border-bottom: 1px solid var(--border-strong);
}
td { color: #2b394d; height: 48px; }
td a[href^="/stations"] { text-decoration: none; }
td a[href^="/stations"]:hover { text-decoration: underline; }
tbody tr { transition: background .14s ease; }
tbody tr:hover td { background: #f5f8fd; }
tbody tr:last-child td { border-bottom: none; }

/* 数字右对齐 + 等宽数字 */
th.num, td.num, .num { text-align: right; font-variant-numeric: tabular-nums; }

/* 空状态 */
tr.empty td {
  text-align: center;
  color: var(--muted);
  padding: 30px 12px;
  background: #fff !important;
}
tr.empty td::before { content: "○ "; color: var(--border-strong); }

/* ---------- 徽标 ---------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 18px;
  font-weight: 500;
  white-space: nowrap;
}
.badge.ok   { background: var(--ok-bg);   color: var(--ok);   border: 1px solid #bfe8d0; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f3e0ac; }
.badge.bad  { background: var(--bad-bg);  color: var(--bad);  border: 1px solid #f5c6c6; }
.badge.muted{ background: #f0f2f5;       color: var(--muted); border: 1px solid #e4e7ec; }
.badge.info { background: var(--primary-soft); color: var(--primary); border: 1px solid #c8ddf9; }
/* 带状态点的徽标 */
.badge.dot::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 6px;
  vertical-align: 1px;
}

/* ---------- 线损率颜色 ---------- */
.rate { font-weight: 700; font-variant-numeric: tabular-nums; }
.rate.ok   { color: var(--ok); }
.rate.warn { color: var(--warn); }
.rate.bad  { color: var(--bad); }
.rate-tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.rate-tag.ok   { background: var(--ok-bg);   color: var(--ok); }
.rate-tag.warn { background: var(--warn-bg); color: var(--warn); }
.rate-tag.bad  { background: var(--bad-bg);  color: var(--bad); }

/* ---------- 进度条 ---------- */
.progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  vertical-align: middle;
}
.progress .bar {
  width: 96px;
  height: 6px;
  background: #e8ecf2;
  border-radius: 99px;
  overflow: hidden;
  flex: none;
}
.progress .bar > i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #2f7ef0, #58a6ff);
}
.progress.done .bar > i { background: linear-gradient(90deg, #1a9e55, #3fc27a); }
.progress .txt { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 15px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: #9cb9e5; color: var(--primary); background: var(--primary-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 5px rgba(33,104,216,.18);
}
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; box-shadow: 0 3px 8px rgba(33,104,216,.24); }
.btn.danger {
  background: #fff;
  color: var(--bad);
  border-color: #efc2c6;
}
.btn.danger:hover { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { min-height: 30px; padding: 4px 11px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

form.inline { display: inline-block; margin: 0; }

/* 集中器 IMEI 编辑区独立成行，窄屏时表格横向滚动，避免跨列重叠 */
.device-table { min-width: 1180px; }
.device-imei-form { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; }
.device-imei-form input[type="text"] { width: 190px; min-width: 190px; }
.device-imei-meta { display: block; line-height: 18px; }

/* 抄表计划批量管理 */
.bulk-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
.bulk-bar label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.bulk-bar select { width: 170px; }
.check-cell { width: 38px; text-align: center; }
.check-cell input[type="checkbox"] { width: auto; min-height: 0; }
.plan-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- 统计块 ---------- */
.stat {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat .item {
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  min-width: 120px;
}
.stat .num {
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  text-align: left;
}
.stat .label { font-size: 13px; color: var(--muted); margin-top: 2px; text-align: left; }

/* ---------- 表单 ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
  align-items: end;
}
.form-grid label {
  font-size: 13px;
  color: var(--text-2);
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
}
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
input[type="file"] { width: 100%; color: var(--text-2); font-size: 13px; }
input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text-2);
  cursor: pointer;
}
input:hover, select:hover { border-color: #9faec0; }
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(33,104,216,.13);
}
input::placeholder { color: #98a5b5; }

/* 表单分组（archive 密集表单） */
.form-section {
  background: #f8fafd;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px 6px;
  margin: 0 0 18px;
}
.form-section .form-grid:last-child { margin-bottom: 8px; }

/* ---------- 标签页（保留兼容） ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs a {
  padding: 6px 14px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- 提示条 ---------- */
.notice {
  background: var(--primary-soft);
  border: 1px solid #c8ddf9;
  color: #14509e;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
}
.notice a { font-weight: 600; }

/* ---------- 图表 ---------- */
.chart-wrap {
  position: relative;
  height: 320px;
  background: #fbfcfe;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1000px 500px at 80% -10%, rgba(59,130,246,.25), transparent 60%),
    radial-gradient(800px 400px at 10% 110%, rgba(29,111,224,.20), transparent 60%),
    linear-gradient(135deg, #0b2545 0%, #10336b 55%, #0d2b57 100%);
  position: relative;
  overflow: hidden;
}
.login-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
}
.login-box {
  background: #fff;
  padding: 40px 40px 34px;
  border-radius: 14px;
  width: 380px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}
.login-logo {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  box-shadow: 0 8px 20px rgba(16,35,63,.22);
}
.login-logo svg { width: 29px; height: 29px; }
.login-box h1 { margin: 0 0 4px; font-size: 21px; text-align: center; color: var(--navy); letter-spacing: 1px; }
.login-slogan {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 26px;
}
.login-box .form-grid { grid-template-columns: 1fr; gap: 16px; }
.login-box label { font-size: 13px; }
.login-box input { padding: 10px 12px; }
.login-box .btn { padding: 11px 16px; font-size: 15px; letter-spacing: 6px; text-indent: 6px; }
.login-foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 18px;
}
.error {
  color: var(--bad);
  background: var(--bad-bg);
  border: 1px solid #f5c6c6;
  font-size: 13px;
  margin-bottom: 16px;
  padding: 9px 12px;
  border-radius: 6px;
}

/* ---------- 继电器控制 ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 18px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #f8fafd;
}
.filter-field { display: flex; flex-direction: column; gap: 5px; flex: 1 1 300px; min-width: 0; }
.filter-field label { color: var(--text-2); font-size: 12px; font-weight: 600; }
.filter-field select { max-width: 100%; }
.relay-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}
.relay-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  background: #fafcff;
}
.relay-device { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.device-sn { color: var(--navy); font-family: Consolas, "SFMono-Regular", monospace; font-size: 14px; font-weight: 700; }
.relay-station { color: var(--muted); font-size: 12px; margin: 4px 0 16px; }
.relay-channel { border-top: 1px solid var(--border); padding-top: 15px; }
.relay-channel + .relay-channel { margin-top: 16px; }
.relay-channel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.relay-name { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; font-weight: 650; }
.relay-name i {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-style: normal;
}
.relay-meta { color: var(--muted); font-size: 11px; line-height: 1.6; margin-bottom: 10px; }
.relay-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.relay-timer {
  display: flex !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.duration-group {
  display: flex;
  align-items: center;
  flex: none;
  gap: 9px;
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
}
.duration-group label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}
.duration-group label span { order: 2; margin-left: 1px; }
.duration-group input {
  width: 32px;
  min-height: 24px;
  padding: 2px 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: none;
  font-size: 12px;
  text-align: center;
  order: 1;
}
.duration-group input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 2px var(--primary-soft); }
.duration-group em { color: var(--muted); font-size: 11px; font-style: normal; white-space: nowrap; }

/* ---------- 页面标题（详情页头部） ---------- */
.page-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.page-head .code {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1200px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .topbar-inner { gap: 10px; padding: 10px 18px; }
}

@media (max-width: 780px) {
  .topbar-inner { min-height: 0; padding: 9px 12px; gap: 8px; }
  .topbar a.logout { padding: 7px 4px; }
  .topbar .main-nav a { padding: 7px 9px; font-size: 12px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 8px; }
  .brand-mark svg { width: 18px; height: 18px; }
  .brand-copy strong { font-size: 14px; }
  .brand-copy small { font-size: 9px; margin-top: 3px; }
  .container { padding: 0 14px 24px; }
  .page-heading { margin: 22px 0 18px; }
  .page-heading h1 { font-size: 23px; }
  .page-heading p { font-size: 12px; }
  .card { padding: 18px 15px; border-radius: 10px; margin-bottom: 14px; }
  .card h2 { padding-bottom: 12px; margin-bottom: 14px; }
  .kpi-row { margin-bottom: 14px; }
  .kpi { padding: 17px 18px 15px; }
  .kpi::before { left: 18px; top: 16px; }
  .kpi .kpi-label { margin-top: 10px; }
  .kpi .kpi-value { font-size: 25px; }
  .kpi .kpi-sub { font-size: 10px; }
  th, td { padding: 10px 12px; }
  .relay-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .chart-wrap { height: 280px; }
  .login-box { width: calc(100vw - 32px); padding: 30px 24px 26px; }
}

@media (max-width: 420px) {
  .kpi { padding-left: 14px; padding-right: 12px; }
  .kpi::before { left: 14px; }
  .kpi .kpi-value { font-size: 23px; }
  .kpi .kpi-sub { min-height: 30px; }
  .relay-card { padding: 14px; }
  .relay-timer { flex-wrap: wrap; }
  .duration-field { flex: 1 1 150px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
