:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #1b1d24;
  --muted: #6b7280;
  --line: #e6e8ee;
  --primary: #fe2c55;
  --primary-dark: #e01f46;
  --dark: #161823;
  --blue: #2f6fed;
  --green: #10b981;
  --amber: #f59e0b;
  --purple: #8b5cf6;
  --red: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 6px 20px rgba(20, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* 手机上最关键的一条：禁止整页横向滚动。
   侧边菜单和客户详情抽屉是用 translateX 挪到屏幕外的固定定位元素，
   部分手机浏览器的「视觉视口」会因此变宽，一旦页面被聚焦的输入框带着往右滚，
   整页内容就会左右错位（表现为左边的字被切掉）。这道防护让这种情况物理上不可能发生。 */
html, body { overflow-x: hidden; max-width: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--blue); }

/* ---------------- 登录 ---------------- */
.login-wrap {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, #2b2f45 0%, #161823 55%, #0f1119 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 18px; padding: 32px 28px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35); text-align: center;
}
.login-logo { font-size: 40px; line-height: 1; }
.login-card h1 { font-size: 20px; margin: 10px 0 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-hint { color: #9aa1ae; font-size: 12px; margin: 16px 0 0; }
.login-error { color: var(--red); font-size: 13px; min-height: 20px; text-align: left; }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; min-width: 0; max-width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fbfbfd; outline: none; transition: border-color .15s, box-shadow .15s; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(254, 44, 85, .12);
}
.field textarea { resize: vertical; min-height: 66px; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  background: #eef0f5; color: var(--text); font-weight: 500; transition: all .15s; white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-dark { background: var(--dark); color: #fff; }
.btn-line { background: #fff; border-color: var(--line); }
.btn-ghost { background: transparent; color: inherit; }
.btn-danger { background: #fdecef; color: var(--red); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }

/* ---------------- 布局 ---------------- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 208px; flex: 0 0 208px; background: var(--dark); color: #cfd3e0;
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { color: #fff; font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; padding: 4px 8px 18px; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px rgba(254, 44, 85, .18); }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer;
  color: #cfd3e0; border: 0; background: transparent; text-align: left; width: 100%; font-size: 14px;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; }
.nav-item .pill { margin-left: auto; background: #fff; color: var(--dark); border-radius: 20px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.nav-item.active .pill { background: #fff; color: var(--primary); }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .1); padding-top: 12px; margin-top: 8px; }
.who { font-size: 12px; color: #98a0b3; padding: 0 8px 8px; }
.who b { color: #fff; display: block; font-size: 14px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 58px; flex: 0 0 58px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; padding: 0 18px;
}
.topbar h2 { font-size: 17px; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #c9ccd6; }
.live.on i { background: var(--green); box-shadow: 0 0 0 3px rgba(16, 185, 129, .18); }
.live.off i { background: var(--red); }
/* overflow-x: hidden 是兜底：万一以后又有元素超出宽度，只裁掉那一个，
   而不是把整个页面撑宽（手机上会表现为整页左右被切掉）。
   表格自己的横向滚动在 .table-wrap 里，不受影响。 */
.view { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 18px; -webkit-overflow-scrolling: touch; }

/* ---------------- 通用块 ---------------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; max-width: 100%; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 15px; flex: 1; }
.panel-body { padding: 16px; }
.panel-body.tight { padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.spacer { flex: 1; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 5px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; line-height: 1.2; }
.stat .v small { font-size: 13px; font-weight: 500; color: var(--muted); }
.stat.hl { background: linear-gradient(135deg, #2b2f45, #161823); border-color: transparent; }
.stat.hl .k { color: #b9c0d4; }
.stat.hl .v { color: #fff; }
.stat.warn .v { color: var(--amber); }
.stat.ok .v { color: var(--green); }
.stat.hot .v { color: var(--primary); }

/* 买房 / 卖房 对比卡里的小指标 */
.minis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.mini { text-align: center; }
.mini b { display: block; font-size: 17px; font-weight: 700; line-height: 1.3; }
.mini span { font-size: 11.5px; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; line-height: 18px; white-space: nowrap; }
.badge-待分配 { background: #fff4e5; color: #b45309; }
.badge-待联系 { background: #e8f0fe; color: #1d4ed8; }
.badge-跟进中 { background: #f1ebfe; color: #6d28d9; }
.badge-已成交 { background: #e6f8f1; color: #047857; }
.badge-已流失 { background: #f1f2f5; color: #6b7280; }
.badge-无效 { background: #fdecef; color: #b91c1c; }
.badge-A { background: #fdecef; color: #be123c; font-weight: 700; }
.badge-B { background: #fff4e5; color: #b45309; }
.badge-C { background: #f1f2f5; color: #6b7280; }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }
table.tb { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tb th, table.tb td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tb th { background: #fafbfd; color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; z-index: 1; }
table.tb tbody tr:hover { background: #fafbfd; }
table.tb td.wrap { white-space: normal; min-width: 160px; }
table.tb input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 32px; display: block; margin-bottom: 8px; }

/* ---------------- 客户卡片 ---------------- */
.ccards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 12px; }
.ccard { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); cursor: pointer; transition: all .15s; }
.ccard:hover { border-color: #cfd5e4; transform: translateY(-1px); }
.ccard .top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ccard .name { font-weight: 700; font-size: 15px; }
.ccard .meta { color: var(--muted); font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }
.ccard .foot { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.tag-due { color: var(--red); font-weight: 600; }
.tag-soon { color: var(--amber); font-weight: 600; }

/* ---------------- 筛选栏 ---------------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.toolbar input, .toolbar select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none;
  max-width: 100%; min-width: 0;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--primary); }
.toolbar .grow { flex: 1; min-width: 120px; }
.seg { display: flex; background: #eef0f5; border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 13px; }
.seg button.on { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }

/* ---------------- 时间线 ---------------- */
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 16px; }
.tl-item::before { content: ""; position: absolute; left: -20px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px #fff; }
.tl-item .tl-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tl-item .tl-time { color: var(--muted); font-size: 12px; }
.tl-item .tl-body { color: #3d4353; margin-top: 4px; white-space: pre-wrap; }
.tl-item .tl-next { color: var(--amber); font-size: 12px; margin-top: 4px; }

/* ---------------- 抽屉 ---------------- */
.drawer-mask { position: fixed; inset: 0; background: rgba(12, 14, 22, .45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.drawer-mask.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 520px; max-width: 100%; background: var(--bg);
  box-shadow: -12px 0 40px rgba(0, 0, 0, .18); transform: translateX(102%); transition: transform .24s ease;
  z-index: 41; display: flex; flex-direction: column;
}
.drawer.on { transform: none; }
.drawer-head { background: #fff; border-bottom: 1px solid var(--line); padding: 14px 18px; display: flex; align-items: center; gap: 10px; }
.drawer-head h3 { margin: 0; font-size: 16px; flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.drawer-foot { background: #fff; border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 8px; }

/* ---------------- 弹窗 ---------------- */
.modal-root { position: fixed; inset: 0; z-index: 60; display: none; }
.modal-root.on { display: block; }
.modal-mask { position: absolute; inset: 0; background: rgba(12, 14, 22, .45); }
.modal {
  position: relative; margin: 6vh auto 0; width: 560px; max-width: calc(100% - 28px); max-height: 88vh;
  background: #fff; border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, .3); display: flex; flex-direction: column;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------- 提示 ---------------- */
.toast-root { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #161823; color: #fff; padding: 10px 18px; border-radius: 24px; font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); animation: tin .25s ease; max-width: 86vw;
}
.toast.ok { background: #0f7a5a; }
.toast.err { background: #b3261e; }
.toast.info { background: #23305c; }
@keyframes tin { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

.banner { background: #fff8e6; border: 1px solid #f6dfae; color: #8a5a00; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner > span:first-child { flex: 1; min-width: 180px; }
.banner-info { background: #eef4ff; border-color: #cddcff; color: #234a9c; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 14px; }
.checkline { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; background: #fff; }
.checkline:hover { border-color: #cfd5e4; }
.checkline.on { border-color: var(--primary); background: #fff5f7; }
.checkline input { width: 16px; height: 16px; }
.kv { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 6px 10px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
.copy-mini { cursor: pointer; border-bottom: 1px dashed #b9bfcc; }
pre.code {
  background: #f7f8fb; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px;
  font: 12px/1.6 Consolas, "Courier New", monospace; white-space: pre-wrap; word-break: break-all;
  max-height: 240px; overflow: auto; margin: 0; color: #38405a;
}

/* 直播指标：详情里的指标网格 + 表单里的分组折叠 */
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 9px; }
.mitem { background: #fafbfd; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.mitem .l { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.mitem .v { font-size: 16px; font-weight: 700; margin-top: 2px; }
.mitem.zero { background: #fcfcfd; }
.mitem.zero .v { color: #c3c8d4; font-weight: 500; }
.mgroup-title { font-size: 13px; font-weight: 700; margin: 16px 0 8px; display: flex; gap: 8px; align-items: baseline; }
.mgroup-title:first-child { margin-top: 0; }
details.mgroup { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: #fcfcfe; }
details.mgroup > summary { cursor: pointer; font-weight: 600; font-size: 13px; display: flex; gap: 6px; align-items: baseline; list-style: none; }
details.mgroup > summary::-webkit-details-marker { display: none; }
details.mgroup > summary::before { content: "▸"; color: var(--muted); font-size: 11px; }
details.mgroup[open] > summary::before { content: "▾"; }
details.mgroup .field { margin-bottom: 10px; }
details.mgroup .field input { padding: 7px 9px; }
.mgroup summary span { margin-left: auto; }
.only-mobile { display: none; }
.tabbar { display: none; }

/* 手机端侧边菜单的遮罩：点空白处就能关掉菜单（桌面端不显示） */
.sidebar-mask { display: none; }

/* ---------------- 手机底部导航 ---------------- */
@media (max-width: 900px) {
  .sidebar-mask {
    display: block; position: fixed; inset: 0; z-index: 45;
    background: rgba(12, 14, 22, .45); opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .sidebar-mask.on { opacity: 1; pointer-events: auto; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(255, 255, 255, .97); backdrop-filter: blur(8px);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar button {
    flex: 1; border: 0; background: transparent; padding: 7px 2px 8px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px; color: #9aa1ae; font-size: 10.5px;
  }
  .tabbar button .ico { font-size: 19px; line-height: 1; }
  .tabbar button.active { color: var(--primary); font-weight: 600; }
  .tabbar button .dot {
    position: absolute; margin-left: 22px; margin-top: -2px; min-width: 15px; height: 15px; border-radius: 8px;
    background: var(--primary); color: #fff; font-size: 10px; line-height: 15px; text-align: center; padding: 0 3px;
  }
  .view { padding-bottom: 76px; }
}

/* ---------------- 手机适配 ---------------- */
@media (max-width: 900px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: 232px; flex-basis: 232px;
    transform: translateX(-104%); transition: transform .22s ease;
  }
  .sidebar.on { transform: none; }
  /* 注意：这里的 padding-bottom 必须留出底部导航栏的高度，否则内容会被挡住 */
  .view { padding: 12px; padding-bottom: 84px; }
  .topbar { padding: 0 10px; height: 54px; flex-basis: 54px; }
  .topbar h2 { font-size: 16px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat { padding: 11px 12px; }
  .stat .v { font-size: 21px; }
  .ccards { grid-template-columns: minmax(0, 1fr); }
  /* 表单在手机上保留两列，不然 39 个指标那个表单会长到没法用 */
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .drawer { width: 100%; }
  .modal { margin: 0; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
  .modal-foot { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .toolbar { padding: 10px 12px; }
  .panel-head { padding: 11px 12px; }
  .panel-body { padding: 12px; }
  /* 提示条要浮在底部导航栏上方 */
  .toast-root { top: auto; bottom: 84px; }
  table.tb th, table.tb td { padding: 9px 10px; }
  .hide-sm { display: none; }

  /* 宽表格很多列，手机上横向滚动时把第一列固定住，不然不知道在看哪一行 */
  .table-wrap { position: relative; }
  table.tb th:first-child, table.tb td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: #fff; box-shadow: 1px 0 0 var(--line);
  }
  table.tb th:first-child { background: #fafbfd; z-index: 3; }
  table.tb tbody tr:hover td:first-child { background: #fafbfd; }

  /* 手机上的点击目标放大一点，手指点得准 */
  .btn-sm { padding: 8px 13px; font-size: 13px; }
  .toolbar input, .toolbar select { padding: 9px 11px; }
  .field input, .field select, .field textarea { padding: 11px 12px; }
  details.mgroup .field input { padding: 10px 11px; }
}

/* 很窄的手机（<=560px）上，两列表单会把字段标签挤成竖排甚至截断，
   这里让 grid-3 / grid-4 退回单列，标签在上、输入框在下完整显示，避免横向溢出 */
@media (max-width: 560px) {
  .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); gap: 9px; }
}
