:root {
  --bg: #f8fafd;
  --surface: #ffffff;
  --surface-soft: #f1f3f4;
  --line: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --blue: #1a73e8;
  --green: #34a853;
  --yellow: #fbbc04;
  --red: #ea4335;
  --shadow: 0 1px 2px rgba(60, 64, 67, .16), 0 1px 3px rgba(60, 64, 67, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button, input, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: 64px 1fr;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: 220px 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #1a73e8 0%, #34a853 100%);
  font-weight: 700;
}

.search {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--surface-soft);
  border-radius: 22px;
  color: var(--muted);
  max-width: 720px;
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 15px;
  color: var(--text);
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.main {
  min-height: 0;
  display: grid;
  grid-template-columns: 86px 360px minmax(420px, 1fr) 390px;
  overflow: hidden;
}

.rail {
  padding: 16px 10px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.rail-item {
  width: 64px;
  height: 58px;
  display: grid;
  place-items: center;
  gap: 2px;
  border: 0;
  border-radius: 14px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.rail-item.active {
  color: var(--blue);
  background: #e8f0fe;
  font-weight: 600;
}

.icon {
  font-size: 20px;
  line-height: 1;
}

.list-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.pane-title {
  padding: 18px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pane-title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.new-btn {
  height: 36px;
  border: 0;
  border-radius: 18px;
  padding: 0 14px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
}

.filters {
  display: flex;
  gap: 8px;
  padding: 0 18px 12px;
  overflow: hidden;
}

.chip {
  height: 30px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.chip.active {
  color: var(--blue);
  border-color: #d2e3fc;
  background: #e8f0fe;
}

.threads {
  min-height: 0;
  overflow: auto;
  padding: 2px 8px 16px;
}

.thread {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 12px;
  padding: 14px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
}

.thread.active {
  background: #e8f0fe;
  border-color: #d2e3fc;
}

.risk-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  background: var(--yellow);
}

.risk-dot.high { background: var(--red); }
.risk-dot.low { background: var(--green); }
.risk-dot.mid { background: var(--yellow); }

.thread-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 5px;
}

.thread-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  max-height: 38px;
  overflow: hidden;
}

.thread-meta {
  text-align: right;
  color: var(--muted);
  font-size: 12px;
  min-width: 48px;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  margin-top: 8px;
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}

.content-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
}

.conversation-head {
  padding: 18px 24px;
  background: rgba(255,255,255,.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.person {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #dfe7fd;
  color: var(--blue);
  font-weight: 700;
  flex: none;
}

.ai-avatar {
  background: #e6f4ea;
  color: #137333;
}

.person h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.person p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.head-tags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge.warn {
  color: #9a6700;
  background: #fff8e1;
  border-color: #fde293;
}

.conversation {
  min-height: 0;
  overflow: auto;
  padding: 28px 32px;
}

.message {
  max-width: 760px;
  margin-bottom: 18px;
  display: flex;
  gap: 12px;
}

.bubble {
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  line-height: 1.65;
  font-size: 15px;
}

.bubble.ai {
  border: 1px solid #d2e3fc;
  background: #ffffff;
}

.bubble-title {
  margin-bottom: 6px;
  color: var(--blue);
  font-weight: 600;
  font-size: 13px;
}

.manual-test {
  max-width: 760px;
  margin-left: 54px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.manual-test label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

.manual-test textarea,
.config-form textarea,
.config-form input,
.config-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  line-height: 1.5;
  outline: none;
  background: #fff;
}

.manual-test textarea,
.config-form textarea {
  resize: vertical;
}

.manual-test button {
  margin-top: 10px;
}

.composer {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
}

.action {
  height: 38px;
  padding: 0 14px;
  border-radius: 19px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}

.action.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.action.danger {
  color: var(--red);
  border-color: #fad2cf;
  background: #fce8e6;
}

.action:disabled {
  opacity: .6;
  cursor: wait;
}

.drawer {
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.drawer-head {
  padding: 18px 18px 10px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
}

.tab {
  height: 34px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 17px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
}

.tab.active {
  color: var(--blue);
  background: #e8f0fe;
}

.drawer-body {
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.insight {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
  background: #fff;
}

.insight label,
.config-form label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.insight strong {
  font-size: 15px;
  font-weight: 600;
}

.muted-text {
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.task-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #edf0f2;
  color: var(--text);
  font-size: 14px;
}

.checkbox {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 2px solid var(--line);
  flex: none;
}

.config-form {
  display: grid;
  gap: 14px;
}

.config-form label {
  color: var(--text);
  font-weight: 600;
}

.config-form input,
.config-form textarea,
.config-form select {
  margin-top: 7px;
  color: var(--text);
  font-weight: 400;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.drawer-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.drawer-section-head strong {
  font-size: 16px;
}

.kb-form {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 9px;
  color: var(--text) !important;
  font-weight: 400 !important;
}

.check-row input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.kb-list {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.kb-count {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.kb-count.muted {
  margin-top: 12px;
}

.kb-item {
  width: 100%;
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: left;
  background: #fff;
  color: var(--text);
}

.kb-item.active {
  border-color: #d2e3fc;
  background: #e8f0fe;
}

.kb-item.inactive {
  opacity: .56;
}

.kb-title {
  font-size: 14px;
  font-weight: 600;
}

.kb-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.kb-used-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.kb-used {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid #d2e3fc;
  border-radius: 13px;
  color: var(--blue);
  background: #e8f0fe;
  font-size: 12px;
  line-height: 1.35;
}

.followup-form {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.followup-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 13px;
  color: #9a6700;
  background: #fff8e1;
  border: 1px solid #fde293;
  font-size: 12px;
  white-space: nowrap;
}

.status-chip.working {
  color: var(--blue);
  background: #e8f0fe;
  border-color: #d2e3fc;
}

.status-chip.waiting {
  color: #a14200;
  background: #fef7e0;
  border-color: #feefc3;
}

.status-chip.done {
  color: #137333;
  background: #e6f4ea;
  border-color: #ceead6;
}

.status-chip.archived {
  color: var(--muted);
  background: var(--surface-soft);
  border-color: var(--line);
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.reply-snapshot {
  border: 1px solid #edf0f2;
  border-radius: 12px;
  padding: 11px;
  color: var(--text);
  line-height: 1.55;
  font-size: 13px;
}

.reply-snapshot label {
  margin-bottom: 5px;
}

.followup-list {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.followup-item {
  width: 100%;
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: left;
  background: #fff;
  color: var(--text);
}

.followup-item.active {
  border-color: #d2e3fc;
  background: #e8f0fe;
}

.followup-title {
  font-size: 14px;
  font-weight: 600;
}

.followup-meta {
  color: var(--muted);
  font-size: 12px;
}

.followup-text {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  max-height: 36px;
  overflow: hidden;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 18px;
  background: #fff;
}

.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.empty-state.compact {
  padding: 12px;
}

@media (max-width: 1180px) {
  .main { grid-template-columns: 76px 320px minmax(360px, 1fr); }
  .drawer { display: none; }
}
