:root {
  --primary: #1565c0;
  --primary-light: #e3f2fd;
  --success: #2e7d32;
  --warning: #f9a825;
  --danger: #c62828;
  --bg: #eceff1;
  --card: #fff;
  --border: #cfd8dc;
  --text: #263238;
  --text2: #546e7a;
  --radius: 6px;
}

/* ========== 顶部菜单栏 ========== */
.topbar {
  display: flex;
  align-items: center;
  position: relative;
  background:#fff;
  padding: 0 16px;
  height: 42px;
  color: #fff;
}
.topbar-left { display: flex; gap: 0; align-items: center; }
.topbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-right:20px;
  padding-left: 12px;
}
.topbar-right span { font-size: 12px; color:#fff;background:var(--primary); border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,.08);padding:5px 10px;}
.topbar-btn {
  padding: 8px 14px;
  border: none;
  background: none;
  color:var(--text2);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: background .15s;
  white-space: nowrap;
  border-bottom:3px solid transparent;
  line-height:1.5em;
}
.topbar-btn:hover { color:var(--primary); background:var(--primary-light); }
.topbar-btn.on { color:var(--primary); border-bottom-color:var(--primary); }

/* 下拉菜单 */
.dropdown { position: static; }
.dropdown-menu {
  display: none;
  position: fixed;
  top: 116px;
  left: 20px;
  background: #fff;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  z-index: 100;
  min-width: 140px;
  overflow: hidden;
}
.dropdown-menu.open { display: block; }
.dropdown-menu a {
  display: block;
  padding: 10px 18px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  transition: background .1s;
}
.dropdown-menu a:hover { background: var(--primary-light); color: var(--primary); }



/* 主容器 */
.wrap { max-width: 1600px; margin: 0 auto; padding: 16px; }
.pane { display: none; }
.pane.on { display: block; }

/* 卡片 */
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,.08); padding:2px 10px 10px 10px; margin-bottom: 14px; }
.card h2 { font-size: 14px; font-weight: 600; margin-bottom: 10px; color: var(--text); border-left: 3px solid var(--primary); padding-left: 10px; }

/* 表单 */
.row { display: flex; gap: 14px; margin-bottom: 10px; align-items: flex-start; flex-wrap: wrap; }
.grp { display: flex; flex-direction: column; gap: 3px; min-width: 180px; flex: 1; }
.grp label { font-size: 12px; color: var(--text2); font-weight: 500; }
.grp input, .grp select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; outline: none; }
.grp input:focus, .grp select:focus { border-color: var(--primary); }
.grp .tip { font-size: 11px; color: var(--text2); line-height: 1.3; }

/* 按钮 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 7px 14px; border: none; border-radius: 4px; font-size: 13px; cursor: pointer; font-weight: 500; transition: all .15s; }
.btn-pri { background: var(--primary); color: #fff; }
.btn-pri:hover { background: #115293; }
.btn-ok { background: var(--success); color: #fff; }
.btn-ok:hover { background: #1b5e20; }
.btn-warn { background: var(--warning); color: #333; }
.btn-err { background: var(--danger); color: #fff; }
.btn-err:hover { background: #b71c1c; }
.btn-out { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-out:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btns { display: flex; gap: 7px; flex-wrap: wrap; }

/* 表格 */
.tbl-wrap { overflow: auto; max-height: 550px; margin-top: 6px; border: 1px solid var(--border); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 6px 8px; border: 1px solid var(--border); min-width: 50px; }
th { background: #f5f5f5; font-weight: 600; position: sticky; top: 0; z-index: 1; text-align: center; }
tr:hover td { background: var(--primary-light); }
td.edit { cursor: cell; }
td.edit:focus { outline: 2px solid var(--primary); outline-offset: -2px; }
td.err { color: var(--danger); }

/* 消息 */
.log { padding: 10px 14px; border-radius: 4px; margin-bottom: 10px; font-size: 12px; }
.log.on { display: flex; align-items: center; gap: 6px; }
.log.i { background: #e3f2fd; color: #1565c0; }
.log.ok { background: #e8f5e9; color: #2e7d32; }
.log.e { background: #ffebee; color: #c62828; }
.log.w { background: #fff8e1; color: #f57f17; }

/* 执行日志 */
.exec-log { max-height: 100px; overflow-y: auto; font-size: 11px; font-family: monospace; background: #263238; color: #b0bec5; padding: 10px; position: fixed; bottom: 36px; right: 20px; width: 460px; z-index: 99; box-shadow: 0 2px 12px rgba(0,0,0,.3); }
.exec-log .t { color: #78909c; }
.exec-log .ok { color: #81c784; }
.exec-log .e { color: #ef5350; }

/* ========== 主程序-两栏布局 ========== */
.main-layout { display: flex; gap: 16px; }
.main-left { width: 280px; min-width: 240px; flex-shrink: 0; }
.main-right { flex: 1; min-width: 0; }
.right-top-row { display: flex; gap: 12px; }
.card-peitui { flex: 1; min-width: 0; }
.card-preview { flex: 1; min-width: 0; }
.card-legend { margin-top: 12px; }

/* DWG上传区 */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.upload-area:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-area.drag-over { border-color: var(--success); background: #e8f5e9; }
.upload-icon { font-size: 28px; color: var(--text2); line-height: 1; }
.upload-text { font-size: 13px; color: var(--text); margin-top: 6px; font-weight: 500; }
.upload-tip { font-size: 11px; color: var(--text2); margin-top: 4px; }

/* 塔基列表 */
.tower-list { display: flex; flex-direction: column; gap: 0; margin-top: 8px; max-height: 440px; overflow-y: auto; }
.tower-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: all .15s;
  font-size: 12px;
}
.tower-item:hover { border-color: var(--primary); background: var(--primary-light); }
.tower-item.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.tower-item.on .btn-sm { color: #fff; border-color: rgba(255,255,255,.5); }
.tower-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tower-item .btn-sm {
  padding: 2px 5px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: none;
  border-radius: 3px;
  cursor: pointer;
  color: var(--primary);
  margin-left: 6px;
  white-space: nowrap;
  transition: all .15s;
}
.tower-item .btn-sm:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.tower-item.on .btn-sm:hover { background: rgba(255,255,255,.2); border-color: #fff; }
.tower-item .tower-item-btns { display: flex; gap: 2px; flex-shrink: 0; }
.tower-item .btn-sm-del { color: var(--danger); border-color: var(--danger); }
.tower-item .btn-sm-del:hover { background: var(--danger); color: #fff; }
.tower-item.on .btn-sm-del { color: #fff; border-color: rgba(255,255,255,.5); }
.tower-item.on .btn-sm-del:hover { background: rgba(255,255,255,.2); border-color: #fff; }
.tower-item .status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}
.tower-item .status-dot.done { background: #4CAF50; }
.tower-item .status-dot.hasdata { background: #FF9800; }
.tower-item .status-dot.needjiangji { background: #2196F3; }
.tower-item .status-dot.notfound { background: #f44336; }
.tower-item .status-dot.pending { background: #9E9E9E; }
.tower-item .status-dot.reading { background: #FF9800; animation: blink 1s infinite; }
.tower-item .status-dot.error { background: #f44336; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ========== 配腿专区 ========== */
.peitui-empty { text-align: center; padding: 40px 20px; color: var(--text2); font-size: 14px; }

/* 配腿信息摘要表格 */
.peitui-summary { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: 13px; border: 2px solid #333; }
.peitui-summary th { background: #e8eaf6; font-weight: 600; padding: 4px 8px; text-align: center; border: 1px solid #999; }
.peitui-summary td { padding: 4px 8px; text-align: center; border: 1px solid #666; font-weight: 600; }

.peitui-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  border: 2px solid #333;
}
.peitui-table th {
  background: #e8eaf6;
  font-weight: 600;
  padding: 8px 10px;
  text-align: center;
  border: 1px solid #999;
  position: static;
}
.peitui-table td {
  padding: 6px 10px;
  border: 1px solid #999;
  text-align: center;
}
.peitui-table .lbl-cell {
  background: #f5f5f5;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}
.peitui-table .val-cell {
  text-align: center;
}
.peitui-table .merged-info {
  text-align: center;
  vertical-align: middle;
  font-weight: 600;
}
.peitui-table .highlight-ok { background: #e8f5e9; }
.peitui-table .highlight-warn { background: #fff8e1; }
.peitui-table .highlight-danger { background: #ffebee; }
.peitui-table .highlight-info { background: #e3f2fd; }

/* 图例说明 */
.legend-box { display: flex; flex-wrap: wrap; gap: 12px; padding: 8px 0; }
.legend-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text2); }
.legend-color { display: inline-block; width: 14px; height: 14px; border-radius: 3px; }

/* 对话框 */
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.5); z-index: 200; justify-content: center; align-items: center; }
.modal.on { display: flex; }
.mdl { background: #fff; border-radius: var(--radius); max-width: 850px; width: 92%; max-height: 88vh; overflow-y: auto; padding: 22px; }

/* 工程列表项 */
.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all .15s;
}
.project-item:hover { border-color: var(--primary); background: var(--primary-light); }
.project-item .pj-name { font-weight: 500; font-size: 14px; }
.project-item .pj-time { font-size: 11px; color: var(--text2); }
.project-item .pj-del {
  color: var(--danger);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
}

/* 响应式 */
@media(max-width: 900px) {
  .main-layout { flex-direction: column; }
  .main-left { width: 100%; }
  .row { flex-direction: column; }
  .grp { min-width: 100%; }
  /* 配腿+预览改为单列 */
  .right-top-row { flex-direction: column; }
  /* 菜单栏横向滚动 */
  .topbar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topbar-left { flex-shrink: 0; }
  .topbar-right { flex-shrink: 0; margin-right: 8px; }
  /* topbar-btn 缩小间距 */
  .topbar-btn { padding: 8px 10px; font-size: 12px; }
  .wrap { padding: 8px; }
  .card { padding: 2px 6px 6px 6px; }
  /* 塔基列表高度调整 */
  .tower-list { max-height: 300px; }
  /* 隐藏upload-tip详情 */
  .upload-tip div:nth-child(n+2) { display: none; }
  .upload-area { padding: 8px; }
  .upload-icon { font-size: 22px; }
  /* 表格缩小字体 */
  table { font-size: 11px; }
  th, td { padding: 4px 5px; }
  /* 执行日志全宽 */
  .exec-log { width: calc(100% - 16px); left: 8px; right: 8px; bottom: 28px; }
  /* 配腿表格缩小 */
  .peitui-table, .peitui-summary { font-size: 12px; }
  .peitui-table th, .peitui-table td { padding: 4px 6px; }
}

@media(max-width: 480px) {
  .topbar { padding: 0 6px; height: 38px; }
  .topbar-btn { padding: 6px 8px; font-size: 11px; }
  .topbar-right span { font-size: 11px; padding: 3px 6px; }
  .btn { padding: 5px 10px; font-size: 12px; }
  .card h2 { font-size: 13px; }
  .peitui-table, .peitui-summary { font-size: 11px; }
  .peitui-table th, .peitui-table td { padding: 3px 4px; }
}

/* 可编辑单元格样式 */
.val-cell.edit {
  background: rgba(59, 130, 246, 0.08);
  cursor: text;
  color: #2563eb;
  font-weight: 500;
}
.val-cell.edit:hover {
  background: rgba(59, 130, 246, 0.15);
}
.val-cell.edit:focus {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
  background: #fff;
}
/* 未找到标记 */
.not-found {
  color: #ef4444;
  font-style: italic;
  font-size: 11px;
}
/* ===== 塔基预览卡片 ===== */
.preview-container { position:relative; min-height:220px; }
.preview-empty { display:flex; align-items:center; justify-content:center; height:220px; color:var(--text3); font-size:13px; }
#preview-canvas { background:#ffffff; border:1px solid var(--border); cursor:crosshair; }
.preview-legend { display:flex; gap:14px; margin-top:6px; font-size:11px; color:var(--text2); flex-wrap:wrap; padding:4px 0; }
.preview-legend-item { display:flex; align-items:center; gap:5px; }
/* 预览操作提示 */
.preview-tips { display:flex; gap:12px; margin-top:6px; font-size:11px; color:#888; flex-wrap:wrap; padding:4px 0; border-top:1px solid #eee; }
.tip-item { white-space:nowrap; }

.preview-legend-dot { width:10px; height:10px; border-radius:2px; flex-shrink:0; }
/* 塔基预览按钮组 */
.preview-btns { margin-left: 12px; display: inline-flex; gap: 6px; vertical-align: middle; }
.preview-btns .btn-sm { font-size: 12px; padding: 0 10px; height: 30px; line-height: 30px; min-width: auto; box-sizing: border-box; }