:root {
  --navy: #0D47A1;
  --navy-dark: #0a3a85;
  --primary: #2196F3;
  --primary-deep: #1976D2;
  --surface-0: #F8FBFE;
  --surface-1: #FFFFFF;
  --highlight: #E3F2FD;
  --border: #DDEBFA;
  --line: #F1F5F9;
  --text: #071E27;
  --text-2: #5B6770;
  --success: #2E7D32;
  --success-bg: rgba(46, 125, 50, 0.10);
  --warning: #E65100;
  --warning-bg: rgba(230, 81, 0, 0.10);
  --error: #C62828;
  --error-bg: rgba(198, 40, 40, 0.10);
  --info: #1565C0;
  --info-bg: rgba(21, 101, 192, 0.10);
  --shadow: 0 4px 20px rgba(13, 71, 161, 0.08);
  --radius-sm: 4px;
  --radius-md: 8px;
  --font: "Inter", "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  --mono: "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--surface-0);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary-deep); text-decoration: none; }

.layout { display: flex; min-height: 100vh; }

/* 侧边导航 */
.sidebar {
  width: 240px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.12);
}
.brand-logo { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; }
.brand-name { font-size: 14px; font-weight: 600; line-height: 1.3; }
.brand-sub { font-size: 10px; opacity: 0.7; letter-spacing: 0.08em; }
.nav-group { padding: 10px 12px 2px; font-size: 11px; letter-spacing: 0.06em; opacity: 0.65; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; color: rgba(255,255,255,0.88); font-size: 13px; cursor: pointer;
  border-left: 4px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.active { background: rgba(255,255,255,0.10); border-left-color: var(--primary); color: #fff; }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }

/* 主区域 */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; color: var(--text-2); }
.content { padding: 20px 24px 40px; max-width: none; width: 100%; }

/* 卡片 */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* 统计卡 */
.stat-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; }
.stat-label { font-size: 12px; color: var(--text-2); letter-spacing: 0.03em; }
.stat-value { font-size: 24px; font-weight: 700; font-family: var(--mono); margin-top: 6px; }
.stat-sub { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.progress { height: 8px; background: #DCE6F0; border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-deep)); border-radius: 999px; }

/* 表格 */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table-wrap.table-fixed-head {
  max-height: calc(100vh - 340px);
  overflow: auto;
  width: auto;
  min-width: 320px;
  max-width: 100%;
  resize: horizontal;
}
.table-fixed-head table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table-fixed-head.freeze-cols table { width: auto; min-width: 1200px; }
.table-fixed-head thead {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #F0F7FF;
}
.table-fixed-head thead th {
  background: #F0F7FF;
  text-align: center;
  box-shadow: 0 1px 0 var(--border);
}
.freeze-cols th, .freeze-cols td { white-space: nowrap; }

/* 计量录入抽屉：备填表限高 + 表头吸顶 */
.ms-drawer-options .table-wrap {
  max-height: calc(100vh - 280px);
  overflow: auto;
}
.ms-drawer-options .table-wrap thead {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #F0F7FF;
}
.ms-drawer-options .table-wrap thead th {
  background: #F0F7FF;
  box-shadow: 0 1px 0 var(--border);
}
.ms-drawer-options table {
  table-layout: fixed;
  width: 100%;
}
.ms-drawer-options th, .ms-drawer-options td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ms-drawer-options th:nth-child(1), .ms-drawer-options td:nth-child(1) { width: 11%; }
.ms-drawer-options th:nth-child(2), .ms-drawer-options td:nth-child(2) { width: 16%; }
.ms-drawer-options th:nth-child(3), .ms-drawer-options td:nth-child(3) { width: 19%; }
.ms-drawer-options th:nth-child(4), .ms-drawer-options td:nth-child(4) { width: 10%; }
.ms-drawer-options th:nth-child(5), .ms-drawer-options td:nth-child(5) { width: 11%; }
.ms-drawer-options th:nth-child(6), .ms-drawer-options td:nth-child(6) { width: 14%; }
.ms-drawer-options th:nth-child(7), .ms-drawer-options td:nth-child(7) { width: 9%; }
.ms-drawer-options th:nth-child(8), .ms-drawer-options td:nth-child(8) { width: 10%; }
.ms-drawer-options th:nth-child(2), .ms-drawer-options td:nth-child(2),
.ms-drawer-options th:nth-child(3), .ms-drawer-options td:nth-child(3) {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-all;
}

/* 计量查询：各期计量台账表（吸顶 + 冻结前 2/3 列） */
.mq-table {
  max-height: calc(100vh - 320px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.mq-table table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 12px;
}
.mq-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #F0F7FF;
  box-shadow: 0 1px 0 var(--border);
  padding: 6px 10px;
  border: 1px solid var(--line);
  white-space: nowrap;
  text-align: center;
}
.mq-table td {
  padding: 5px 10px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.mq-f2 th:nth-child(1), .mq-f2 td:nth-child(1) { position: sticky; left: 0; z-index: 4; background: #fff; }
.mq-f2 th:nth-child(2), .mq-f2 td:nth-child(2) { position: sticky; left: 110px; z-index: 4; background: #fff; }
.mq-f3 th:nth-child(1), .mq-f3 td:nth-child(1) { position: sticky; left: 0; z-index: 4; background: #fff; }
.mq-f3 th:nth-child(2), .mq-f3 td:nth-child(2) { position: sticky; left: 110px; z-index: 4; background: #fff; }
.mq-f3 th:nth-child(3), .mq-f3 td:nth-child(3) { position: sticky; left: 250px; z-index: 4; background: #fff; }
.mq-f2 thead th:nth-child(-n+2), .mq-f3 thead th:nth-child(-n+3) { z-index: 6; background: #F0F7FF; }
.freeze-cols thead tr:first-child th:nth-child(-n+3),
.freeze-cols tbody td:nth-child(-n+3) {
  position: sticky;
  z-index: 2;
  background: #fff;
  box-shadow: 1px 0 0 var(--border);
}
.freeze-cols thead tr:first-child th:nth-child(1),
.freeze-cols tbody td:nth-child(1) { left: 0; width: 90px; min-width: 90px; max-width: 90px; }
.freeze-cols thead tr:first-child th:nth-child(2),
.freeze-cols tbody td:nth-child(2) { left: 90px; width: 220px; min-width: 220px; max-width: 220px; }
.freeze-cols thead tr:first-child th:nth-child(3),
.freeze-cols tbody td:nth-child(3) { left: 310px; width: 70px; min-width: 70px; max-width: 70px; }
.freeze-cols thead tr:first-child th:nth-child(-n+3) { z-index: 4; background: #F0F7FF; }
.freeze-cols tbody td:nth-child(-n+3) { z-index: 2; }
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  background: #F0F7FF; text-align: left; padding: 8px 12px; font-weight: 600;
  font-size: 11px; letter-spacing: 0.05em; color: var(--text-2); white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
tr:nth-child(5n) td { background: rgba(227, 242, 253, 0.25); }
tr:hover td { background: var(--highlight); }
.num { font-family: var(--mono); text-align: right; }
.right { text-align: right; }
.muted { color: var(--text-2); }
.empty { padding: 32px; text-align: center; color: var(--text-2); }

/* 徽章 */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 2px; font-size: 12px; font-weight: 500;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge-success { color: var(--success); background: var(--success-bg); }
.badge-warning { color: var(--warning); background: var(--warning-bg); }
.badge-error { color: var(--error); background: var(--error-bg); }
.badge-info { color: var(--info); background: var(--info-bg); }
.badge-muted { color: var(--text-2); background: rgba(91,103,112,0.10); }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text);
  transition: background 0.15s;
}
.btn:hover { background: var(--highlight); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-deep); }
.btn-danger { color: var(--error); border-color: #F4C7C3; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--highlight); color: var(--text); }
.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* 表单 */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; color: var(--text-2); }
input, select, textarea {
  border: 1px solid #C9D8EA; border-radius: var(--radius-sm); padding: 7px 10px;
  font-size: 13px; font-family: var(--font); background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}
.field input, .field select, .field textarea { min-width: 180px; }
.field .hint { font-size: 11px; color: var(--text-2); }

/* 模态框 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(7, 30, 39, 0.35);
  display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px;
  z-index: 100; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: var(--radius-md); box-shadow: var(--shadow);
  width: 100%; max-width: 640px; padding: 20px;
}
.modal.wide { max-width: 900px; }
.modal-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .form-grid .full { grid-column: 1 / -1; }

/* 提示 */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 10px 18px; z-index: 200; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.toast.ok::before { content: "✓"; color: var(--success); }
.toast.err::before { content: "✕"; color: var(--error); }

/* 过滤器 */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }

/* 登录页 */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0D47A1 0%, #1565C0 45%, #42A5F5 100%);
}
.login-card {
  background: #fff; border-radius: var(--radius-md); box-shadow: 0 16px 50px rgba(3, 26, 62, 0.35);
  width: 400px; padding: 36px 32px;
}
.login-card .brand { border: none; padding: 0 0 20px; justify-content: center; color: var(--text); }
.login-title { text-align: center; font-size: 18px; font-weight: 700; margin-bottom: 24px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; margin-top: 6px; }
.login-tip { text-align: center; margin-top: 16px; font-size: 12px; color: var(--text-2); }

/* 分页 */
.pager { display: flex; align-items: center; gap: 8px; margin-top: 12px; justify-content: flex-end; color: var(--text-2); font-size: 12px; }

.kbd { font-family: var(--mono); font-size: 12px; }
.row-actions { display: flex; gap: 6px; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tab { padding: 7px 14px; cursor: pointer; border-bottom: 2px solid transparent; font-size: 13px; color: var(--text-2); }
.tab.active { color: var(--primary-deep); border-bottom-color: var(--primary); font-weight: 600; }
.alert-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }

/* 项目树 */
.tree-node { padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 13px; margin-bottom: 2px; }
.tree-node:hover { background: var(--highlight); }
.tree-node.active { background: var(--highlight); color: var(--primary-deep); font-weight: 600; }
.tree-project { font-weight: 600; }
.tree-section { padding-left: 26px; color: var(--text-2); font-size: 12px; }
