:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --line: #e6eaf2;
  --text: #16202e;
  --muted: #7b8798;
  --brand: #2f6bff;
  --brand-dark: #1f4fd8;
  --ok: #12a870;
  --warn: #e08b1f;
  --danger: #dc4c4c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 64, .05), 0 8px 24px rgba(16, 32, 64, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.hidden { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 107, 255, .12);
}
textarea { resize: vertical; min-height: 84px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }

/* ---------- 登录 ---------- */
.auth-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px calc(24px + var(--safe-b));
  background: linear-gradient(170deg, #eef3ff 0%, #f7f9fc 45%, #f4f6fa 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 22px 26px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand-mark {
  width: 48px; height: 48px; flex: none;
  border-radius: 13px; overflow: hidden;
  box-shadow: 0 1px 4px rgba(16, 32, 64, .16);
}
.brand-mark img { width: 100%; height: 100%; display: block; object-fit: cover; }
.brand h1 { margin: 0; font-size: 19px; }
.brand-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.seg {
  display: flex; gap: 4px; padding: 4px;
  background: #f1f4fa; border-radius: 11px; margin-bottom: 4px;
}
.seg-btn {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 8px 4px; border-radius: 8px; font-size: 13.5px;
  cursor: pointer; transition: .15s;
}
.seg-btn.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(16,32,64,.1); }

.auth-form { margin-top: 4px; }
.row-input { display: flex; gap: 8px; }
.row-input input { flex: 1; min-width: 0; }
.row-input .btn-ghost { flex: none; white-space: nowrap; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.grid2 input, .grid3 input, .grid2 select, .grid3 select { min-width: 0; }
.grid3 select { padding: 11px 6px; font-size: 13.5px; }

.btn-primary {
  width: 100%; margin-top: 18px; padding: 12px;
  border: 0; border-radius: 11px;
  background: var(--brand); color: #fff;
  font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .55; cursor: default; }

.btn-ghost {
  padding: 11px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--brand);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.btn-ghost:disabled { opacity: .5; cursor: default; }

.btn-danger { background: #fff; border: 1px solid #f2c9c9; color: var(--danger); font-weight: 600; padding: 10px 14px; border-radius: 10px; cursor: pointer; width: 100%; }
.btn-line { background: #fff; border: 1px solid var(--line); color: var(--text); font-weight: 600; padding: 10px 14px; border-radius: 10px; cursor: pointer; width: 100%; }

.link { border: 0; background: transparent; color: var(--brand); font-size: 13px; padding: 0; cursor: pointer; }
.row-between { display: flex; justify-content: flex-end; margin-top: 10px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }

.msg { min-height: 18px; margin: 12px 0 0; font-size: 13px; color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ---------- 主应用 ---------- */
.app-wrap { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 16px;
  background: rgba(244, 246, 250, .88);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 17px; }
.topbar-left { display: flex; align-items: center; gap: 9px; min-width: 0; }
.topbar-logo { width: 27px; height: 27px; flex: none; border-radius: 8px; box-shadow: 0 1px 3px rgba(16, 32, 64, .14); }
.icon-btn {
  width: 34px; height: 34px; flex: none;
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  color: var(--muted); cursor: pointer; font-size: 15px;
}

.page {
  flex: 1;
  padding: 14px 16px calc(84px + var(--safe-b));
  max-width: 780px; width: 100%; margin: 0 auto;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: rgba(255, 255, 255, .95);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; font-size: 11.5px; color: var(--muted); cursor: pointer;
}
.tabbar button span { font-size: 17px; line-height: 1; }
.tabbar button.active { color: var(--brand); font-weight: 600; }

/* ---------- 卡片 / 通用 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-title { margin: 0 0 12px; font-size: 14.5px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title .sub { font-size: 12px; color: var(--muted); font-weight: 400; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px; box-shadow: var(--shadow);
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.4px; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat.accent .v { color: var(--brand); }
.stat.ok .v { color: var(--ok); }
.stat.warn .v { color: var(--warn); }

.section-gap { margin-top: 14px; }

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
  cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%;
}
.item:last-child { border-bottom: 0; }
.item .avatar {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  display: grid; place-items: center;
  background: #eef3ff; color: var(--brand);
  font-weight: 700; font-size: 14px;
}
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .right { flex: none; text-align: right; font-size: 12px; color: var(--muted); }

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11.5px; background: #f1f4fa; color: var(--muted); margin-right: 4px;
}
.tag.intent-A { background: #e3f5ec; color: #0e7a52; font-weight: 600; }
.tag.intent-B { background: #e7efff; color: #2554c7; font-weight: 600; }
.tag.intent-C { background: #fff4e2; color: #b9761a; font-weight: 600; }
.tag.intent-D { background: #f1f2f5; color: #8b94a3; font-weight: 600; }
.tag.type { background: #f0ecfd; color: #6b4fc4; }
.tag.nature { background: #e9f4fd; color: #1f6fa8; }
.tag.level-A { background: #fdecec; color: #c0392b; }
.tag.level-B { background: #fff4e2; color: #b9761a; }
.tag.level-C { background: #eef1f6; color: #6b7788; }
.tag.overdue { background: #fdecec; color: #c0392b; }
.tag.soon { background: #e8f6ef; color: #12805a; }

.empty { text-align: center; color: var(--muted); font-size: 13.5px; padding: 26px 10px; }
.empty .big { display: block; font-size: 26px; margin-bottom: 8px; opacity: .5; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input { flex: 1; }
.toolbar .btn-ghost { flex: none; }

.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }

/* 管道看板 */
.pipeline { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.col { flex: 0 0 200px; }
.col-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 8px; font-size: 13px; font-weight: 600; }
.col-head .num { color: var(--muted); font-weight: 500; font-size: 12px; }
.deal { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 11px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; }
.deal .dt { font-weight: 600; font-size: 13.5px; }
.deal .dc { font-size: 12px; color: var(--muted); margin-top: 3px; }
.deal .da { font-size: 13px; color: var(--brand); font-weight: 700; margin-top: 6px; }

.bar-row { display: flex; align-items: center; gap: 8px; margin: 7px 0; font-size: 12.5px; }
.bar-row .bl { width: 46px; flex: none; color: var(--muted); }
.bar-row .bt { flex: 1; height: 7px; background: #eef1f6; border-radius: 999px; overflow: hidden; }
.bar-row .bf { height: 100%; background: var(--brand); border-radius: 999px; }
.bar-row .bn { width: 42px; text-align: right; flex: none; color: var(--muted); }

/* 模态 */
.modal-mask {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(14, 22, 38, .42);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(20px + var(--safe-b));
  animation: rise .2s cubic-bezier(.2,.8,.3,1);
}
@keyframes rise { from { transform: translateY(18px); opacity: .6 } to { transform: none; opacity: 1 } }
.modal h2 { margin: 0 0 4px; font-size: 17px; }
.modal .modal-sub { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn-primary { margin-top: 0; flex: 1; }
.modal-actions .btn-line { flex: 1; width: auto; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 13px; cursor: pointer; color: var(--muted);
}
.chip.active { border-color: var(--brand); background: #eef3ff; color: var(--brand); font-weight: 600; }

/* 详情页 */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.back-btn { border: 0; background: transparent; color: var(--brand); font-size: 13.5px; padding: 0; cursor: pointer; font-weight: 600; }
.kv { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: 0; }
.kv .k { width: 66px; flex: none; color: var(--muted); }
.kv .v { flex: 1; word-break: break-all; }
.kv .v a { color: var(--brand); text-decoration: none; }

.timeline { position: relative; padding-left: 16px; }
.timeline::before { content: ""; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 16px 6px; }
.tl-item::before { content: ""; position: absolute; left: -16px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: #fff; border: 2px solid var(--brand); }
.tl-item:last-child { padding-bottom: 2px; }
.tl-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.tl-body { font-size: 14px; margin-top: 3px; white-space: pre-wrap; }
.tl-next { margin-top: 6px; font-size: 12.5px; background: #f5f8ff; border-left: 2px solid var(--brand); padding: 6px 9px; border-radius: 0 8px 8px 0; color: #35507f; }

/* AI */
.ai-out { white-space: pre-wrap; font-size: 14px; line-height: 1.68; }
.ai-out:empty::before { content: "点上面的按钮，让 AI 读一遍你的客户和机会数据，给出本周该做的事。"; color: var(--muted); font-size: 13.5px; }
.ai-status { font-size: 12px; color: var(--muted); margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b));
  transform: translateX(-50%);
  background: rgba(22, 32, 46, .93); color: #fff;
  padding: 9px 16px; border-radius: 999px; font-size: 13.5px;
  z-index: 90; max-width: 88vw; text-align: center;
}

/* 装到手机桌面步骤 */
.steps { display: flex; flex-direction: column; gap: 8px; }
.step { font-size: 13px; line-height: 1.6; color: var(--text); background: #f7f9fc; border-radius: 10px; padding: 8px 11px; }
.step b { display: block; font-size: 12.5px; color: var(--brand); margin-bottom: 2px; }
