:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e4e8ee;
  --text: #1f2733;
  --text-sub: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #16a34a;
  --green-bg: #ecfdf5;
  --yellow: #d97706;
  --yellow-bg: #fffbeb;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --orange: #ea580c;
  --orange-bg: #fff7ed;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ===== 登录页 ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .2);
  text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { font-size: 22px; margin: 10px 0 6px; }
.login-sub { color: var(--text-sub); font-size: 13px; margin-bottom: 26px; }
.login-card form { text-align: left; }
.login-card label { display: block; margin: 12px 0 6px; font-size: 13px; color: var(--text-sub); }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.login-card .btn { margin-top: 20px; }
.login-hint { margin-top: 18px; font-size: 12px; color: #9ca3af; }

/* ===== 顶部栏 ===== */
.topbar {
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { font-weight: 700; font-size: 16px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-chip {
  background: #eef2ff; color: #3730a3; padding: 5px 10px; border-radius: 20px; font-size: 13px;
}
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; display: inline-block; }
.conn-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, .15); }
.conn-dot.offline { background: var(--red); }

/* ===== 布局 ===== */
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: 200px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  flex-shrink: 0;
}
.nav-item {
  display: block;
  width: 100%;
  padding: 11px 14px;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 4px;
  text-decoration: none;
  font-size: 14px;
  text-align: left;
  border: none;
  background: transparent;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.active { background: #eef2ff; color: var(--primary); font-weight: 600; }
.content { flex: 1; padding: 20px; min-width: 0; }

/* ===== 视图 ===== */
.view-title { font-size: 20px; margin-bottom: 16px; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.view-head .view-title { margin-bottom: 0; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== 卡片 ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card .label { color: var(--text-sub); font-size: 13px; }
.card .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.card .value.money { font-family: "SF Mono", Consolas, monospace; }
.card.red .value { color: var(--red); }
.card.green .value { color: var(--green); }
.card.yellow .value { color: var(--yellow); }

/* ===== 面板 ===== */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.panel.narrow { max-width: 460px; }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel-head h3 { font-size: 15px; }
.panel-body { padding: 16px; }

/* ===== 工具栏 ===== */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff;
}
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--primary); }
.toolbar input[type="search"] { min-width: 240px; flex: 1; max-width: 360px; }

/* ===== 表格 ===== */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; overflow-y: auto; max-height: calc(100vh - 200px); }
/* 固定在视口底部的横向滚动条：表格超宽时一直可见 */
.h-scrollbar { position: fixed; bottom: 0; left: 220px; right: 0; height: 16px; overflow-x: auto; overflow-y: hidden; background: #f9fafb; border-top: 1px solid var(--border); z-index: 50; display: none; }
.h-scrollbar.visible { display: block; }
.h-scrollbar > div { height: 1px; pointer-events: none; }
@media (max-width: 768px) { .h-scrollbar { left: 0; } }
.data-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.data-table th, .data-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th { background: #f9fafb; color: var(--text-sub); font-weight: 600; font-size: 13px; }
/* 表头行固定：上下滚动时表头不动（兼作列宽拖拽手柄的定位上下文） */
.data-table thead th { position: sticky; top: 0; z-index: 4; }
.data-table th .col-resizer {
  position: absolute; top: 0; right: -3px; width: 7px; height: 100%;
  cursor: col-resize; user-select: none; z-index: 6;
}
.data-table th .col-resizer:hover, .data-table th .col-resizer.active { background: var(--primary); opacity: 0.5; }
/* 表头筛选图标 */
.data-table th .filter-btn { margin-left: 3px; cursor: pointer; color: #b0b7c3; font-size: 11px; display: inline-block; vertical-align: middle; user-select: none; }
.data-table th .filter-btn:hover { color: var(--primary); }
.data-table th .filter-btn.active { color: var(--primary); }
/* 表头筛选下拉面板 */
.col-filter-panel { position: fixed; z-index: 200; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.15); min-width: 190px; max-height: 340px; display: flex; flex-direction: column; }
.col-filter-panel .cf-list { overflow-y: auto; flex: 1; min-height: 40px; }
.col-filter-panel .cf-item { display: flex; align-items: center; gap: 7px; padding: 6px 12px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.col-filter-panel .cf-item:hover { background: #f3f6fb; }
.col-filter-panel .cf-item input { cursor: pointer; }
.col-filter-panel .cf-foot { display: flex; justify-content: space-between; align-items: center; padding: 7px 12px; border-top: 1px solid var(--border); }
.col-filter-panel .cf-foot button { border: none; background: none; color: var(--primary); cursor: pointer; font-size: 13px; padding: 3px 6px; border-radius: 4px; }
.col-filter-panel .cf-foot button:hover { background: #eef4ff; }
.data-table tbody tr:hover { background: #f8fafc; }
/* 首列冻结：经销商名称列水平滚动时一直可见 */
.data-table .sticky-col {
  position: -webkit-sticky;
  position: sticky;
  left: 0;
  z-index: 2;
  background: #ffffff;
  box-shadow: 2px 0 4px rgba(0,0,0,0.06);
  min-width: 120px;
  max-width: 180px;
  white-space: normal;
  word-break: break-all;
}
.data-table .sticky-col.head { z-index: 5; background: #f9fafb; }
.data-table td.name-col .dealer-code {
  color: #9ca3af;
  font-size: 12px;
  line-height: 1.3;
}
.data-table td.num { text-align: right; font-family: "SF Mono", Consolas, monospace; }
.data-table .empty { text-align: center; color: #9ca3af; padding: 30px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.gray { background: #f3f4f6; color: var(--text-sub); }

/* ===== 按钮 ===== */
.btn { display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; font-size: 14px; font-weight: 500; text-align: center; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 18px; color: var(--text-sub); padding: 6px; border-radius: 6px; }
.icon-btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== 表单 ===== */
.field label { display: block; margin-bottom: 5px; font-size: 13px; color: var(--text-sub); }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.field input:disabled, .field select:disabled, .field textarea:disabled { background: #f3f4f6; color: #9ca3af; cursor: not-allowed; }
.req { color: var(--red); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-full { grid-column: 1 / -1; }
.error-text { color: var(--red); font-size: 13px; margin-top: 8px; }

/* ===== 模态框 ===== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 620px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 68px; right: 20px; background: #111827; color: #fff; padding: 12px 18px;
  border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 200;
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== 响应式 ===== */
#menu-toggle { display: none; }
.sidebar-mask { display: none; }
@media (max-width: 768px) {
  #menu-toggle { display: inline-block; flex-shrink: 0; }
  .brand { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .topbar-right { gap: 6px; flex-shrink: 0; }
  .user-chip { font-size: 12px; padding: 4px 8px; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar {
    position: fixed; left: 0; top: 56px; bottom: 0; z-index: 60;
    width: 220px; max-width: 82vw;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask {
    display: block;
    position: fixed; inset: 56px 0 0 0;
    background: rgba(15, 23, 42, .45);
    z-index: 55;
  }
  .content { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
  .form-grid { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card .value { font-size: 18px; }
  .view-title { font-size: 17px; }
  .view-actions { gap: 6px; }
  .view-actions .btn { padding: 7px 10px; font-size: 13px; }
  .toolbar input[type="search"] { min-width: 100%; max-width: none; }
  .toast { left: 16px; right: 16px; top: auto; bottom: calc(20px + env(safe-area-inset-bottom)); text-align: center; }
  /* 手机端表格：统一字号 + 收紧内边距，让更多列可见 */
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 6px 6px; }
  .data-table th { font-size: 12px; }
  /* 首列（单位名称）锁定 + 限宽换行，长名称不撑宽 */
  .data-table .sticky-col {
    min-width: 96px;
    max-width: 132px;
    white-space: normal;
    word-break: break-all;
  }
  .data-table .sticky-col.head { white-space: normal; }
  .data-table td.name-col .dealer-code { font-size: 11px; }
}
