/* ==========================================================================
   本地跨境投流 CRM — 设计系统
   风格锚点：深墨绿侧栏 + 暖白内容区 + 单一琥珀金强调色
   刻意回避：紫色渐变 / 圆角卡片+左侧彩色描边 / emoji 图标 / 大圆角浮夸阴影
   ========================================================================== */

:root {
  --ink:        #17201b;
  --ink-2:      #4d554f;
  --ink-3:      #838b85;
  --ink-4:      #a8afa9;

  --bg:         #f6f5f2;
  --panel:      #ffffff;
  --panel-2:    #fbfaf8;
  --line:       #e5e3dd;
  --line-2:     #efece6;

  --rail:       #141b17;
  --rail-2:     #1d2620;
  --rail-ink:   #c8cec9;
  --rail-ink-2: #7f8a82;

  --accent:      #b45309;
  --accent-2:    #92400e;
  --accent-soft: #fdf3e7;

  --green:  #15803d;
  --green-soft: #eaf5ee;
  --blue:   #1d4ed8;
  --blue-soft: #eaeffc;
  --cyan:   #0e7490;
  --amber:  #a16207;
  --amber-soft: #fbf4e3;
  --red:    #b91c1c;
  --red-soft: #fdeded;
  --slate:  #57534e;
  --slate-soft: #f1efec;

  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(20, 27, 23, .06), 0 4px 12px -6px rgba(20, 27, 23, .10);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
          "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", sans-serif;
  --mono: "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* 数字统一等宽，表格纵向对齐 —— 数据产品的细节签名 */
.num, td.num, .kpi-value, .tnum { font-variant-numeric: tabular-nums; }

/* ============================ 登录页 ============================ */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(1100px 520px at 12% -10%, #20302a 0%, transparent 62%),
    linear-gradient(160deg, #151d18 0%, #0e1411 100%);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border-radius: 10px; padding: 36px 34px 30px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.55);
  border-top: 3px solid var(--accent);
}
.login-brand { font-size: 12px; letter-spacing: .22em; color: var(--accent); font-weight: 600; text-transform: uppercase; }
.login-title { font-size: 22px; font-weight: 650; margin: 10px 0 4px; letter-spacing: -.01em; }
.login-sub { color: var(--ink-3); font-size: 12.5px; margin-bottom: 26px; }
.login-foot { margin-top: 20px; font-size: 11.5px; color: var(--ink-4); text-align: center; }

/* ============================ 布局 ============================ */
.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }

.rail { background: var(--rail); color: var(--rail-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.rail-brand { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.07); }
.rail-brand .mark { font-size: 11px; letter-spacing: .2em; color: var(--accent); font-weight: 700; }
.rail-brand .name { font-size: 15px; font-weight: 620; color: #eef2ef; margin-top: 5px; letter-spacing: -.01em; }
.rail-nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.rail-group { font-size: 10.5px; letter-spacing: .14em; color: var(--rail-ink-2); padding: 14px 10px 6px; text-transform: uppercase; }
.rail-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--rail-ink); font-size: 13px; margin-bottom: 1px; border-left: 2px solid transparent;
}
.rail-item:hover { background: var(--rail-2); color: #fff; }
.rail-item.active { background: var(--rail-2); color: #fff; border-left-color: var(--accent); font-weight: 560; }
.rail-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .45; flex: none; }
.rail-user { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12px; }
.rail-user .who { color: #e8ece9; font-weight: 560; }
.rail-user .role { color: var(--rail-ink-2); font-size: 11px; }
.rail-user .acts { margin-top: 8px; display: flex; gap: 12px; }
.rail-user .acts span { cursor: pointer; color: var(--rail-ink-2); font-size: 11.5px; }
.rail-user .acts span:hover { color: var(--accent); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 14px 24px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 16px; font-weight: 640; margin: 0; letter-spacing: -.01em; }
.topbar .sub { color: var(--ink-3); font-size: 12px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.content { padding: 22px 24px 60px; }

/* ============================ 通用控件 ============================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-size: 12.5px; color: var(--ink-2);
  transition: background .12s, border-color .12s, color .12s; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: var(--ink-4); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 560; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-danger { color: var(--red); border-color: #f0d5d5; }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 5px; font-weight: 520; }
.field .hint { font-size: 11.5px; color: var(--ink-4); margin-top: 4px; line-height: 1.5; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=email], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 14px; }

/* ============================ 面板 / 卡片 ============================ */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head {
  padding: 12px 16px; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 10px;
}
.panel-head h2 { font-size: 13.5px; font-weight: 620; margin: 0; }
.panel-head .tail { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.panel-body { padding: 16px; min-width: 0; }
.panel-body.tight { padding: 0; overflow-x: auto; }

/* KPI */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 11.5px; color: var(--ink-3); letter-spacing: .04em; margin-bottom: 6px; }
.kpi-value { font-size: 23px; font-weight: 620; letter-spacing: -.02em; line-height: 1.15; }
.kpi-value small { font-size: 12px; font-weight: 500; color: var(--ink-3); margin-left: 3px; }
.kpi-foot { font-size: 11.5px; color: var(--ink-4); margin-top: 5px; }
.kpi.accent-line { border-top: 2px solid var(--accent); }

/* ============================ 表格 ============================ */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 12.8px; }
table.data th {
  text-align: left; font-weight: 580; color: var(--ink-2); font-size: 11.5px; letter-spacing: .03em;
  padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2);
  white-space: nowrap; position: sticky; top: 0;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tbody tr:hover { background: #fcfbf9; }
table.data tbody tr.clickable { cursor: pointer; }
table.data .muted { color: var(--ink-3); }
table.data .strong { font-weight: 580; }
.empty { padding: 44px 16px; text-align: center; color: var(--ink-4); font-size: 13px; }

/* 徽标 */
.tag {
  display: inline-block; padding: 2px 7px; border-radius: 3px; font-size: 11.5px;
  background: var(--slate-soft); color: var(--slate); white-space: nowrap; font-weight: 520;
}
.tag-blue { background: var(--blue-soft); color: var(--blue); }
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-amber { background: var(--amber-soft); color: var(--amber); }
.tag-red { background: var(--red-soft); color: var(--red); }
.tag-cyan { background: #e3f2f4; color: var(--cyan); }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.dot-a { background: var(--red); }
.dot-b { background: var(--amber); }
.dot-c { background: var(--ink-4); }

/* 工具条 */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar input[type=text], .toolbar select { width: auto; min-width: 130px; padding: 6px 9px; }
.toolbar input[type=date] { width: auto; padding: 6px 9px; }

/* ============================ 抽屉 / 弹窗 ============================ */
.mask { position: fixed; inset: 0; background: rgba(20,27,23,.42); z-index: 100; display: none; }
.mask.show { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 94vw); background: var(--panel);
  z-index: 101; transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column;
  box-shadow: -12px 0 40px -16px rgba(0,0,0,.35);
}
.drawer.show { transform: none; }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.drawer-head h2 { font-size: 15px; margin: 0; font-weight: 620; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px; }
.drawer-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: var(--panel-2); }

.modal { position: fixed; z-index: 101; background: var(--panel); border-radius: 8px;
  top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(680px, 94vw); max-height: 88vh;
  display: none; flex-direction: column; box-shadow: 0 30px 70px -24px rgba(0,0,0,.45); }
.modal.show { display: flex; }
.modal-head { padding: 15px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h2 { font-size: 15px; margin: 0; font-weight: 620; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: var(--panel-2); }
.close-x { margin-left: auto; cursor: pointer; color: var(--ink-3); font-size: 18px; line-height: 1; background: none; border: none; padding: 4px; }
.close-x:hover { color: var(--ink); }

/* 详情块 */
.dl { display: grid; grid-template-columns: 84px 1fr; gap: 8px 12px; font-size: 12.8px; }
.dl dt { color: var(--ink-3); font-size: 12px; }
.dl dd { margin: 0; }
.section-title { font-size: 12px; letter-spacing: .1em; color: var(--ink-3); text-transform: uppercase;
  margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line-2); }
.section-title:first-child { margin-top: 0; }

/* 时间轴 */
.tl { position: relative; padding-left: 16px; }
.tl::before { content: ''; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
.tl-item { position: relative; padding-bottom: 16px; }
.tl-item::before { content: ''; position: absolute; left: -16px; top: 5px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); }
.tl-meta { font-size: 11.5px; color: var(--ink-4); margin-bottom: 3px; }
.tl-body { font-size: 12.8px; white-space: pre-wrap; }

/* 漏斗 */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: 76px 1fr 58px; align-items: center; gap: 12px; font-size: 12.5px; }
.funnel-bar { height: 20px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; }
.funnel-bar i { display: block; height: 100%; background: var(--accent); opacity: .82; }
.funnel-count { text-align: right; color: var(--ink-2); }

/* 提示 */
.toast-wrap { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 9px 16px; border-radius: var(--radius-sm); font-size: 12.8px; box-shadow: var(--shadow);
  background: var(--ink); color: #fff; animation: drop .2s ease; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }

.banner { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 12.5px; line-height: 1.6;
  background: var(--accent-soft); color: var(--accent-2); border: 1px solid #f2e0c9; margin-bottom: 14px; }
.banner.info { background: var(--blue-soft); color: var(--blue); border-color: #d8e0f8; }
.banner.warn { background: var(--amber-soft); color: var(--amber); border-color: #efe0c2; }
.mono { font-family: var(--mono); font-size: 12px; }
.code-block { background: #1b231e; color: #d6ddd8; border-radius: var(--radius-sm); padding: 12px 14px;
  font-family: var(--mono); font-size: 11.6px; line-height: 1.65; overflow-x: auto; white-space: pre; }
.hr { height: 1px; background: var(--line-2); margin: 18px 0; }
.flex { display: flex; align-items: center; gap: 8px; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb8 { margin-bottom: 8px; } .mb16 { margin-bottom: 16px; }
.two-col { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; align-items: start; }
.two-col > * { min-width: 0; }
@media (max-width: 1080px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; min-width: 0; }
  .rail-nav { display: flex; overflow-x: auto; gap: 4px; min-width: 0; }
  .rail-item { flex: none; white-space: nowrap; }
  .rail-group { display: none; }
  .main, .content, .panel, .table-wrap { min-width: 0; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .content { padding: 16px 14px 48px; }
  .toolbar input[type=text], .toolbar select { min-width: 0; flex: 1 1 130px; }
}

/* ============================ WhatsApp 消息中心 ============================ */
.wa-layout {
  display: grid; grid-template-columns: 300px 1fr; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  height: calc(100vh - 268px); min-height: 460px;
}
.wa-side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.wa-side-head { padding: 10px 12px; border-bottom: 1px solid var(--line-2); }
.wa-side-head input { font-size: 12.5px; padding: 6px 9px; }
.wa-filters { display: flex; gap: 6px; margin-top: 8px; }
.wa-filter.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.wa-chat-list { flex: 1; overflow-y: auto; }
.wa-item { padding: 10px 12px; border-bottom: 1px solid var(--line-2); cursor: pointer; position: relative; }
.wa-item:hover { background: var(--panel-2); }
.wa-item.active { background: var(--accent-soft); }
.wa-item-top { display: flex; align-items: center; gap: 6px; }
.wa-item-name { font-weight: 560; font-size: 12.8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.wa-badge { background: var(--accent); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; line-height: 16px; flex: none; }
.wa-item-bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 3px; }
.wa-item-last { color: var(--ink-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-item-time { color: var(--ink-4); font-size: 11px; flex: none; }
.wa-item-tag { position: absolute; right: 12px; top: 30px; font-size: 10.5px; color: var(--ink-4); }
.wa-main-panel { display: flex; flex-direction: column; min-width: 0; }
.wa-main-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.wa-thread { flex: 1; overflow-y: auto; padding: 16px; background: var(--panel-2); }
.wa-msg { margin-bottom: 12px; display: flex; flex-direction: column; }
.wa-msg.out { align-items: flex-end; }
.wa-msg.in { align-items: flex-start; }
.wa-bubble { max-width: 76%; padding: 8px 11px; border-radius: 8px; font-size: 12.9px; line-height: 1.6; word-break: break-word; }
.wa-msg.in .wa-bubble { background: #fff; border: 1px solid var(--line); }
.wa-msg.out .wa-bubble { background: var(--accent-soft); border: 1px solid #f0dfc8; }
.wa-meta { font-size: 11px; color: var(--ink-4); margin-top: 4px; }
.wa-compose { padding: 12px 16px; border-top: 1px solid var(--line); }
.wa-compose textarea { min-height: 46px; }
@media (max-width: 900px) {
  .wa-layout { grid-template-columns: 1fr; height: auto; }
  .wa-side { border-right: none; border-bottom: 1px solid var(--line); max-height: 240px; }
  .wa-thread { max-height: 50vh; }
}

/* 登录页与主界面切换 */
.hidden { display: none !important; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
