:root {
  --bg: #f0f2f5; --panel: #ffffff; --panel-2: #f7f8fa; --line: #e3e6ea; --text: #111b21; --muted: #667781;
  --accent: #00a884; --accent-ink: #ffffff; --accent-soft: #d9fdd3; --chat-bg: #efeae2;
  --in: #ffffff; --out: #d9fdd3; --warn: #b42318; --warn-soft: #fee4e2; --amber: #93370d; --amber-soft: #fef0c7;
  --blue-soft: #e0f2fe; --blue: #075985; --note: #fff8c5;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.08);
  font-size: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a; --panel: #111b21; --panel-2: #1a252c; --line: #26333b; --text: #e9edef; --muted: #8696a0;
    --accent: #00a884; --accent-soft: #144d37; --chat-bg: #0b141a; --in: #202c33; --out: #005c4b;
    --warn: #fda29b; --warn-soft: #55160c; --amber: #fec84b; --amber-soft: #4e1d09; --blue-soft: #0c4a6e; --blue: #bae6fd;
    --note: #3d3514;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

#app { display: flex; height: 100vh; height: 100dvh; }
#view { flex: 1; min-width: 0; height: 100%; overflow: hidden; display: flex; flex-direction: column; }

/* ---------- navigation ---------- */
.nav { width: 96px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column;
  align-items: stretch; padding: 12px 0; gap: 2px; }
.brand { font-weight: 700; text-align: center; padding: 6px 0 14px; color: var(--accent); }
.brand span { color: var(--text); }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; text-decoration: none;
  font-size: 14px; color: var(--muted); border-left: 3px solid transparent; }
.nav a.on { color: var(--text); border-left-color: var(--accent); background: var(--panel-2); font-weight: 600; }
.nav .ico { font-size: 22px; }
.nav-foot { margin-top: auto; text-align: center; font-size: 13px; color: var(--muted); padding: 8px 4px; }
#who { word-break: break-all; margin-bottom: 4px; }

/* ---------- common ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 9px 14px; cursor: pointer; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ai { background: linear-gradient(135deg, #7c3aed, #2563eb); border: 0; color: #fff; font-weight: 600; }
.btn.small { padding: 5px 10px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=datetime-local], select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 9px 11px; width: 100%; }
textarea { resize: vertical; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.pill { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--line); white-space: nowrap; }
.pill.stage { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.pill.ok { background: var(--accent-soft); border-color: transparent; }
.page { padding: 20px 24px; overflow: auto; height: 100%; }
.page h1 { font-size: 24px; margin: 0 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111b21; color: #fff;
  padding: 12px 18px; border-radius: 10px; z-index: 50; max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.bad { background: #b42318; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { margin: auto; width: min(380px, 92vw); }
.login h1 { color: var(--accent); }
.login label { display: block; margin: 12px 0 4px; font-weight: 600; }

/* ---------- inbox ---------- */
.inbox { display: flex; height: 100%; min-height: 0; }
.list-pane { width: 380px; min-width: 300px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.list-head { padding: 12px 12px 6px; display: flex; gap: 8px; align-items: center; }
.chips { display: flex; gap: 6px; padding: 4px 12px 10px; overflow-x: auto; scrollbar-width: none; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 11px; font-size: 14px;
  cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip b { font-weight: 700; margin-left: 3px; }
.chip.hot-count b { color: var(--warn); }
.chip.on b { color: #fff; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; border-top: 1px solid var(--line); }
.chat-item { display: flex; gap: 12px; padding: 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.on { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: #c7d2da; color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 18px; flex: none; }
.ci-main { flex: 1; min-width: 0; }
.ci-top { display: flex; gap: 6px; align-items: baseline; }
.ci-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-time { font-size: 13px; color: var(--muted); flex: none; }
.ci-time.late { color: var(--warn); font-weight: 600; }
.ci-last { color: var(--muted); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 2px 0 5px; }
.ci-tags { display: flex; gap: 4px; flex-wrap: wrap; font-size: 13px; }

.conv-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); }
.conv-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.conv-title { flex: 1; min-width: 160px; }
.conv-title .name { font-weight: 700; font-size: 18px; }
.conv-head select { width: auto; padding: 6px 8px; }
.back { display: none; }
.banner { padding: 8px 14px; font-size: 15px; }
.banner.lock { background: var(--amber-soft); color: var(--amber); }
.msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 13px; padding: 3px 10px; border-radius: 8px; margin: 10px 0 6px; box-shadow: var(--shadow); }
.bubble { max-width: min(560px, 80%); padding: 7px 10px 5px; border-radius: 8px; box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.bubble.in { background: var(--in); align-self: flex-start; }
.bubble.out { background: var(--out); align-self: flex-end; }
.bubble .meta { font-size: 12px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble .media { font-style: italic; color: var(--muted); }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-box { border-radius: 8px; padding: 10px 12px; font-size: 15px; }
.ai-box.check { background: var(--amber-soft); color: var(--amber); }
.ai-box.next { background: var(--blue-soft); color: var(--blue); }
.send-row { display: flex; gap: 8px; align-items: flex-end; }
.send-row textarea { min-height: 48px; max-height: 40vh; }
.conv-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }

.info-pane { width: 360px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
.info-sec { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.info-sec h3 { margin: 0 0 10px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.info-sec h3 .grow { flex: 1; }
.ai-card { background: linear-gradient(135deg, rgba(124,58,237,.08), rgba(37,99,235,.08)); border-radius: 10px; padding: 12px; }
.ai-card .sum { white-space: pre-wrap; line-height: 1.55; }
.fields { display: grid; grid-template-columns: 76px 1fr; gap: 6px 8px; align-items: center; font-size: 15px; }
.fields label { color: var(--muted); }
.fields input, .fields select { padding: 6px 8px; }
.flag-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.flag { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 10px; font-size: 14px; cursor: pointer; }
.flag.on { background: var(--amber-soft); color: var(--amber); border-color: transparent; font-weight: 600; }
.task { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; font-size: 15px; }
.task.overdue .when { color: var(--warn); font-weight: 600; }
.task.done { opacity: .5; text-decoration: line-through; }
.note { background: var(--note); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 15px; white-space: pre-wrap; }
.note .by { font-size: 12px; color: var(--muted); margin-top: 3px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 10px 6px; font-size: 15px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .when { font-size: 12px; color: var(--muted); }

/* ---------- contacts ---------- */
.big-search { font-size: 18px; padding: 12px 14px; }
.results { margin-top: 12px; display: grid; gap: 8px; }
.result { display: flex; gap: 12px; align-items: center; padding: 12px; cursor: pointer; }
.result:hover { background: var(--panel-2); }

/* ---------- pipeline ---------- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; height: calc(100% - 60px); align-items: flex-start; }
.col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); width: 250px; flex: none; max-height: 100%; display: flex; flex-direction: column; }
.col.drop { outline: 2px dashed var(--accent); }
.col-head { padding: 10px 12px; font-weight: 700; display: flex; justify-content: space-between; }
.col-body { padding: 0 8px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: grab; box-shadow: var(--shadow); }
.pcard .nm { font-weight: 600; }
.pcard select { margin-top: 6px; padding: 4px 6px; font-size: 13px; }

/* ---------- follow-ups / settings ---------- */
.fu-group { margin-bottom: 18px; }
.fu-group h2 { font-size: 18px; margin: 0 0 8px; }
.fu-row { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.fu-row:last-child { border-bottom: 0; }
.settings-grid { display: grid; gap: 16px; max-width: 860px; }
.user-row { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.user-row select { width: auto; }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .info-pane { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: -4px 0 20px rgba(0,0,0,.2); max-width: 92vw; }
  .info-pane.closed { display: none; }
}
@media (min-width: 1101px) { .info-toggle { display: none; } .info-close { display: none; } }
@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  .nav { width: 100%; height: 62px; flex-direction: row; padding: 0; border-right: 0; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); }
  .nav a { flex: 1; border-left: 0; border-top: 3px solid transparent; font-size: 12px; padding: 6px 2px; }
  .nav a.on { border-top-color: var(--accent); }
  .nav .ico { font-size: 20px; }
  .brand, .nav-foot { display: none; }
  #view { height: calc(100% - 62px); }
  .list-pane { width: 100%; min-width: 0; border-right: 0; }
  .inbox.open .list-pane { display: none; }
  .inbox:not(.open) .conv-pane { display: none; }
  .back { display: inline-block; }
  .msgs { padding: 12px 10px; }
  .bubble { max-width: 88%; }
  .page { padding: 14px 16px; }
  .conv-head select { font-size: 14px; }
}
