:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8f9fb;
  --ink: #17202c;
  --muted: #697386;
  --line: #e3e7ed;
  --line-strong: #d2d8e1;
  --navy: #0f1d2e;
  --navy-soft: #182a40;
  --gold: #d4a64f;
  --gold-soft: #fbf4e4;
  --blue: #3669a2;
  --blue-soft: #edf4fb;
  --green: #26725c;
  --green-soft: #eaf5f1;
  --red: #b64049;
  --red-soft: #fbecef;
  --shadow: 0 16px 48px rgba(15, 29, 46, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 72px;
  padding: 0 28px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.brand {
  width: fit-content;
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #132033;
  background: var(--gold);
  border-radius: 11px 4px 11px 4px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 21px;
  font-weight: 700;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: .1em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 9px; }

.primary-tabs {
  height: 100%;
  display: flex;
  align-items: stretch;
  gap: 10px;
}
.tab-button {
  min-width: 118px;
  padding: 0 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  font-weight: 700;
  transition: .16s ease;
}
.tab-button:hover { color: var(--ink); }
.tab-button.active { color: var(--ink); border-bottom-color: var(--gold); }
.tab-button small {
  padding: 3px 7px;
  color: #7d6840;
  background: var(--gold-soft);
  border-radius: 999px;
  font-size: 9px;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 9px;
}
.system-pill, .icon-button {
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 11px;
}
.account-button {
  min-height: 36px;
  padding: 0 10px 0 6px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}
.account-button:hover { border-color: #c9a75f; }
.account-avatar { width: 24px; height: 24px; display: grid; place-items: center; color: #765716; background: var(--gold-soft); border-radius: 50%; font-size: 10px; }
.system-pill:hover, .icon-button:hover { color: var(--ink); border-color: var(--line-strong); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.good { background: var(--green); box-shadow: 0 0 0 4px rgba(38,114,92,.12); }
.status-dot.warn { background: #c18b26; box-shadow: 0 0 0 4px rgba(193,139,38,.12); }
.status-dot.bad { background: var(--red); box-shadow: 0 0 0 4px rgba(182,64,73,.12); }
.status-dot.neutral { background: #98a1ae; box-shadow: 0 0 0 4px rgba(152,161,174,.12); }

main { min-width: 0; }
.tab-view { display: none; }
.tab-view.active { display: block; }
#candidatesView { width: min(1500px, 100%); margin: 0 auto; padding: 24px 34px 72px; }

.page-heading {
  margin-bottom: 25px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
}
.eyebrow, .section-kicker {
  margin: 0;
  color: #a17831;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .16em;
}
.page-heading h1 {
  margin: 6px 0 6px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 32px;
  font-weight: 650;
}
.page-heading p:not(.eyebrow), .studio-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.heading-actions { display: flex; gap: 9px; }

.button {
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 750;
  transition: .15s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button.primary { color: #17202c; background: var(--gold); border: 1px solid var(--gold); }
.button.secondary { color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); }
.button.dark { color: white; background: var(--navy); border: 1px solid var(--navy); }
.button.ghost { color: var(--blue); background: transparent; border: 1px solid #ccd9e6; }
.button.small { min-height: 34px; padding: 0 12px; }
.button.full { width: 100%; }
.account-modal-card { width: min(430px, calc(100vw - 32px)); }
.account-modal-body { padding: 4px 26px 26px; }
.auth-tabs { display: grid; grid-template-columns: repeat(2, 1fr); margin: 0 0 18px; padding: 3px; background: var(--surface-soft); border-radius: 10px; }
.auth-tabs button { min-height: 34px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-size: 12px; font-weight: 750; }
.auth-tabs button.active { color: var(--ink); background: var(--surface); box-shadow: 0 2px 8px rgba(15,29,46,.08); }
.account-form { display: grid; gap: 13px; }
.account-form label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.account-note { margin: -2px 0 3px; color: var(--muted); font-size: 10px; line-height: 1.6; }
.account-signed-in { padding: 12px; background: var(--green-soft); border: 1px solid #cce4db; border-radius: 10px; }
.account-signed-in strong { display: block; word-break: break-all; font-size: 13px; }
.account-signed-in p { margin: 7px 0 14px; color: #45675d; font-size: 11px; line-height: 1.6; }
.text-button {
  padding: 5px 6px;
  color: var(--blue);
  background: transparent;
  border: 0;
  font-size: 11px;
  font-weight: 700;
}
.text-button.muted { color: var(--muted); }

.freshness-banner {
  margin-bottom: 16px;
  padding: 13px 15px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--gold-soft);
  border: 1px solid #ead8b1;
  border-radius: 12px;
}
.freshness-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  color: #7b5d25;
  border: 1px solid #d8bb7c;
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 700;
}
.freshness-banner strong { display: block; font-size: 11px; }
.freshness-banner p { margin: 3px 0 0; color: #76694f; font-size: 10px; }
.freshness-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.auto-update-badge { padding: 5px 8px; border-radius: 999px; font-size: 8px; font-weight: 750; white-space: nowrap; }
.auto-update-badge.good { color: var(--green); background: var(--green-soft); }
.auto-update-badge.warning, .auto-update-badge.working { color: #7b5d25; background: #f6e9c9; }
.auto-update-badge.muted { color: var(--muted); background: rgba(255,255,255,.55); }

.metric-row {
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.metric-card {
  min-height: 106px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.metric-card span { color: var(--muted); font-size: 10px; }
.metric-card strong {
  display: block;
  margin: 9px 0 5px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 25px;
}
.metric-card strong.metric-date { font-size: 21px; }
.metric-card small { color: var(--muted); font-size: 9px; }

.dynamic-groups, .screening-studio, .candidate-panel {
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 5px 18px rgba(15,29,46,.025);
}
.screening-studio { padding: 23px; }
.dynamic-groups { padding: 22px 23px 16px; }
.dynamic-groups .studio-heading { margin-bottom: 14px; }
.group-panel-heading { margin-bottom: 17px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.group-panel-heading h2 { margin: 6px 0 5px; font-family: Georgia, "Songti SC", serif; font-size: 22px; }
.group-panel-heading p { margin: 0; color: var(--muted); font-size: 10px; }
.group-panel-actions { display: flex; align-items: center; gap: 8px; }
.dynamic-group-list { display: flex; flex-wrap: wrap; gap: 8px; }
.dynamic-group-card { position: relative; }
.dynamic-group {
  min-width: 144px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: left;
}
.delete-dynamic-group {
  position: absolute;
  top: -6px;
  right: -6px;
  z-index: 2;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: white;
  border: 1px solid var(--line);
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(15,29,46,.1);
  font-size: 12px;
}
.delete-dynamic-group:hover { color: var(--red); border-color: #e6bdc1; }
.dynamic-group:hover { border-color: #bdc6d2; background: #fff; }
.dynamic-group.active { color: #6d4b0b; background: var(--gold-soft); border-color: #d8b46a; }
.dynamic-group strong { font-size: 11px; }
.dynamic-group span, .dynamic-group small { color: var(--muted); font-size: 9px; }
.dynamic-group .group-count { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: inherit; font-family: Georgia, "Songti SC", serif; font-size: 20px; }
.dynamic-group-footer { margin-top: 13px; padding-top: 12px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-top: 1px solid var(--line); }
.dynamic-group-meta { margin: 0; color: var(--muted); font-size: 10px; }
.dynamic-group-footer > strong { font-family: Georgia, "Songti SC", serif; font-size: 16px; white-space: nowrap; }
.screening-hint { align-self: center; color: var(--muted); font-size: 10px; }
.studio-heading {
  margin-bottom: 19px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}
.studio-heading h2 {
  margin: 6px 0 6px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 19px;
}

input, select, textarea {
  width: 100%;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: none;
  transition: .15s ease;
}
input, select { min-height: 39px; padding: 0 11px; font-size: 11px; }
textarea { padding: 11px 12px; font-size: 12px; line-height: 1.6; resize: none; }
input:focus, select:focus, textarea:focus {
  border-color: #c59b4c;
  box-shadow: 0 0 0 3px rgba(212,166,79,.15);
}
.natural-query {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px;
}
.natural-query input { min-height: 46px; padding: 0 15px; background: var(--surface-soft); font-size: 12px; }
.natural-query .button { min-height: 46px; }

.condition-toolbar {
  margin: 18px 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.logic-switch {
  padding: 3px;
  display: inline-flex;
  background: #edf0f4;
  border-radius: 9px;
}
.logic-switch button {
  min-height: 31px;
  padding: 0 11px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-size: 10px;
  font-weight: 700;
}
.logic-switch button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(15,29,46,.08);
}
.condition-actions { display: flex; gap: 3px; }
.condition-list { display: grid; gap: 8px; }
.condition-empty {
  padding: 19px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  text-align: center;
  font-size: 10px;
}
.condition-row {
  padding: 9px;
  display: grid;
  grid-template-columns: minmax(160px, 1.25fr) minmax(120px, .85fr) minmax(100px, .7fr) minmax(100px, .7fr) auto;
  gap: 8px;
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
}
.condition-row .remove-condition {
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 18px;
}
.condition-row .remove-condition:hover { color: var(--red); background: var(--red-soft); }

.screen-footer {
  margin-top: 14px;
  padding-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  border-top: 1px solid var(--line);
}
.sort-controls { display: flex; gap: 10px; }
.sort-controls label {
  min-width: 124px;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 9px;
}
.sort-controls label:last-child { min-width: 78px; }
.screen-warning {
  margin-top: 12px;
  padding: 10px 12px;
  color: #7b5a1e;
  background: var(--gold-soft);
  border-radius: 9px;
  font-size: 10px;
}

.candidate-panel { overflow: hidden; }
.table-toolbar {
  min-height: 65px;
  padding: 12px 17px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  border-bottom: 1px solid var(--line);
}
.table-search { display: flex; gap: 8px; }
.table-search input { width: 230px; }
.table-search select { width: 112px; }
.stock-list-caption { align-self: center; color: var(--muted); font-size: 9px; white-space: nowrap; }
.table-actions { display: flex; align-items: center; gap: 10px; }
.selection-actions { display: flex; align-items: center; gap: 9px; }
.selection-actions > span { color: var(--muted); font-size: 10px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 10px; }
th {
  padding: 11px 10px;
  color: var(--muted);
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-weight: 650;
  white-space: nowrap;
}
td { padding: 12px 10px; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
tbody tr { transition: .12s ease; }
tbody tr:hover { background: #fbfcfd; }
tbody tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { width: 42px; padding-left: 17px; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.stock-button {
  min-width: 105px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  text-align: left;
}
.stock-button strong, .stock-button span { display: block; }
.stock-button strong { font-size: 11px; }
.stock-button span { margin-top: 3px; color: var(--muted); font-size: 9px; }
.score-value { font-size: 14px; font-weight: 800; }
.metric-move.positive { color: var(--red); }
.metric-move.negative { color: var(--green); }
.tag {
  display: inline-flex;
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 8px;
  font-weight: 800;
  white-space: nowrap;
}
.tag.core { color: #8a5f12; background: var(--gold-soft); }
.tag.watch { color: var(--blue); background: var(--blue-soft); }
.tag.unpooled { color: #687386; background: #edf0f4; }
.tag.new { margin-left: 4px; color: var(--green); background: var(--green-soft); }
.reason-cell { min-width: 250px; max-width: 390px; color: #4f5a69; line-height: 1.55; }
.date-cell { color: var(--muted); white-space: nowrap; }

.empty-state { padding: 70px 20px; text-align: center; }
.empty-state.hidden { display: none; }
.empty-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  color: #8a6b2f;
  background: var(--gold-soft);
  border-radius: 16px 5px 16px 5px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 21px;
}
.empty-state h3 { margin: 0 0 7px; font-family: Georgia, "Songti SC", serif; font-size: 17px; }
.empty-state p { margin: 0 0 16px; color: var(--muted); font-size: 10px; }

/* Chat */
#chatView { height: calc(100vh - 72px); height: calc(100dvh - 72px); min-height: 0; overflow: hidden; }
.chat-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 290px;
  background: var(--surface);
  overflow: hidden;
}
.conversation-sidebar, .context-panel { min-width: 0; min-height: 0; background: var(--surface-soft); }
.conversation-sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line); overflow: hidden; }
.conversation-header {
  min-height: 86px;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}
.conversation-header h2 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 18px; }
.new-chat-button {
  min-height: 34px;
  padding: 0 11px;
  color: white;
  background: var(--navy);
  border: 0;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 750;
}
.conversation-list { min-height: 0; flex: 1; padding: 10px; overflow-y: auto; }
.conversation-empty { padding: 28px 14px; color: var(--muted); text-align: center; font-size: 10px; line-height: 1.6; }
.conversation-item {
  width: 100%;
  margin-bottom: 5px;
  padding: 11px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 9px;
  align-items: center;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  text-align: left;
}
.conversation-item:hover { background: white; border-color: var(--line); }
.conversation-item.active { background: white; border-color: #d8c59f; box-shadow: 0 4px 12px rgba(15,29,46,.04); }
.conversation-item .conversation-avatar { width: 27px; height: 27px; font-size: 8px; }
.conversation-copy { min-width: 0; }
.conversation-copy strong, .conversation-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy strong { font-size: 10px; }
.conversation-copy small { margin-top: 4px; color: var(--muted); font-size: 8px; }
.delete-conversation {
  width: 25px;
  height: 25px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
}
.delete-conversation:hover { color: var(--red); background: var(--red-soft); }
.conversation-footnote { padding: 14px 18px; color: var(--muted); border-top: 1px solid var(--line); font-size: 9px; line-height: 1.5; }

.chat-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); overflow: hidden; }
.chat-header {
  min-height: 72px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}
.chat-model-control, .chat-group-control {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}
.chat-group-control { margin-left: 0; }
.chat-model-control select, .chat-group-control select {
  width: min(220px, 24vw);
  min-height: 34px;
  padding: 0 9px;
  background: var(--surface-soft);
  font-size: 9px;
}
.active-agent { display: flex; align-items: center; gap: 10px; }
.active-agent strong, .active-agent small { display: block; }
.active-agent strong { font-size: 11px; }
.active-agent small { margin-top: 4px; color: var(--muted); font-size: 9px; }
.agent-avatar, .conversation-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: white;
  border-radius: 10px;
  font-size: 9px;
  font-weight: 850;
}
.agent-avatar.blue, .conversation-avatar.blue { background: var(--blue); }
.agent-avatar.gold, .conversation-avatar.gold { color: #2d2414; background: var(--gold); }
.agent-avatar.green, .conversation-avatar.green { background: var(--green); }
.agent-avatar.neutral, .conversation-avatar.neutral { background: #8792a0; }
.context-button, .mobile-conversations {
  min-height: 34px;
  padding: 0 11px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 10px;
}
.context-button span {
  margin-left: 5px;
  padding: 2px 6px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 999px;
}
.mobile-conversations { display: none; }
.chat-scroll { min-height: 0; flex: 1 1 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.agent-picker {
  min-height: 100%;
  padding: 54px 34px;
  display: grid;
  align-content: center;
}
.agent-picker-heading { max-width: 640px; margin: 0 auto 27px; text-align: center; }
.agent-picker-heading h1 { margin: 7px 0 8px; font-family: Georgia, "Songti SC", serif; font-size: 29px; }
.agent-picker-heading p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 11px; }
.agent-grid { width: min(850px, 100%); margin: 0 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.agent-card {
  min-height: 180px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 15px;
  text-align: left;
  transition: .16s ease;
}
.agent-card:hover { transform: translateY(-2px); border-color: #d7bd8c; box-shadow: var(--shadow); }
.agent-card .agent-avatar { margin-bottom: 21px; }
.agent-card strong { font-size: 13px; }
.agent-card p { margin: 8px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.agent-card small { margin-top: auto; padding-top: 14px; color: var(--blue); font-size: 9px; font-weight: 750; }

.message-list { width: min(820px, 100%); margin: 0 auto; padding: 28px 24px 50px; }
.message { margin-bottom: 20px; display: flex; gap: 11px; }
.message.user { flex-direction: row-reverse; }
.message-badge {
  width: 29px;
  height: 29px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: white;
  background: var(--navy);
  border-radius: 9px;
  font-size: 8px;
  font-weight: 800;
}
.message.user .message-badge { color: #493715; background: var(--gold); }
.message-content { max-width: 82%; }
.message-bubble {
  padding: 13px 15px;
  color: #303b49;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 5px 14px 14px 14px;
  font-size: 11px;
  line-height: 1.75;
  white-space: pre-wrap;
}
.message-bubble.markdown { white-space: normal; }
.message-bubble.markdown h1, .message-bubble.markdown h2, .message-bubble.markdown h3 {
  margin: 15px 0 7px;
  color: var(--ink);
  line-height: 1.35;
}
.message-bubble.markdown h1:first-child, .message-bubble.markdown h2:first-child, .message-bubble.markdown h3:first-child { margin-top: 0; }
.message-bubble.markdown h1 { font-size: 15px; }
.message-bubble.markdown h2 { font-size: 13px; }
.message-bubble.markdown h3 { font-size: 12px; }
.message-bubble.markdown p { margin: 0 0 9px; }
.message-bubble.markdown p:last-child { margin-bottom: 0; }
.message-bubble.markdown ul, .message-bubble.markdown ol { margin: 7px 0 10px; padding-left: 19px; }
.message-bubble.markdown li + li { margin-top: 4px; }
.message-bubble.markdown code { padding: 1px 4px; background: #e8edf2; border-radius: 4px; font-size: .92em; }
.message-bubble.markdown blockquote { margin: 9px 0; padding: 7px 10px; color: var(--muted); border-left: 3px solid var(--gold); background: white; }
.markdown-table-wrap { max-width: 100%; margin: 9px 0 12px; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.message-bubble.markdown table { min-width: 420px; background: white; font-size: 9px; }
.message-bubble.markdown th, .message-bubble.markdown td { padding: 7px 9px; }
.message.user .message-bubble { color: white; background: var(--navy); border-color: var(--navy); border-radius: 14px 5px 14px 14px; }
.message-meta { margin-top: 5px; color: var(--muted); font-size: 8px; }
.message.user .message-meta { text-align: right; }
.message-sources { margin-top: 8px; padding: 10px 12px; background: var(--blue-soft); border-radius: 9px; }
.message-sources strong { display: block; margin-bottom: 5px; color: #436481; font-size: 8px; }
.message-sources a { display: block; padding: 3px 0; color: var(--blue); font-size: 9px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-sources a:hover { text-decoration: underline; }
.typing .message-bubble { color: var(--muted); }
.typing-dots span { display: inline-block; animation: pulse 1s infinite alternate; }
.typing-dots span:nth-child(2) { animation-delay: .18s; }
.typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }

.chat-composer {
  flex: 0 0 auto;
  padding: 12px 22px 15px;
  background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line);
}
.chat-composer > small { width: min(820px, 100%); margin: 7px auto 0; display: block; color: var(--muted); font-size: 8px; text-align: center; }
.context-chips { width: min(820px, 100%); margin: 0 auto 7px; display: flex; gap: 5px; overflow-x: auto; }
.context-chip {
  padding: 4px 8px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 999px;
  font-size: 8px;
  white-space: nowrap;
}
.composer-row {
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 5px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  box-shadow: 0 8px 24px rgba(15,29,46,.05);
}
.composer-row:focus-within { border-color: #c59b4c; box-shadow: 0 0 0 3px rgba(212,166,79,.12); }
.composer-row textarea { max-height: 130px; border: 0; box-shadow: none; }
.send-button {
  min-width: 62px;
  color: white;
  background: var(--navy);
  border: 0;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 750;
}

.context-panel { border-left: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.context-heading {
  min-height: 72px;
  padding: 16px 17px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.context-heading h3 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 16px; }
.close-panel {
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  font-size: 20px;
}
.close-panel:hover { color: var(--ink); background: #edf0f4; }
.context-status { padding: 15px 17px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.context-status-row { display: flex; justify-content: space-between; gap: 10px; font-size: 9px; }
.context-status-row span { color: var(--muted); }
.context-status-row strong { text-align: right; }
.context-section { padding: 16px 17px; }
.context-section-title { display: flex; align-items: center; justify-content: space-between; font-size: 10px; }
.context-stock-list { margin-top: 10px; display: grid; gap: 7px; }
.context-stock {
  padding: 9px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.context-stock strong, .context-stock span { display: block; }
.context-stock strong { font-size: 10px; }
.context-stock span { margin-top: 3px; color: var(--muted); font-size: 8px; }
.context-stock button { color: var(--muted); background: transparent; border: 0; }
.context-stock-empty { padding: 22px 8px; color: var(--muted); text-align: center; font-size: 9px; line-height: 1.6; }

/* Drawers and modal */
.drawer { position: fixed; inset: 0; z-index: 60; min-height: 0; display: grid; grid-template-columns: 1fr minmax(420px, 590px); overflow: hidden; }
.drawer-backdrop { background: rgba(9,17,27,.42); backdrop-filter: blur(2px); }
.drawer-panel { min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; background: var(--surface); box-shadow: -18px 0 50px rgba(15,29,46,.16); animation: slide .2s ease; }
.drawer-panel.compact { max-width: 470px; }
@keyframes slide { from { transform: translateX(24px); opacity: .7; } to { transform: none; opacity: 1; } }
.drawer-header {
  padding: 22px 24px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}
.drawer-header h2 { margin: 6px 0 5px; font-family: Georgia, "Songti SC", serif; font-size: 22px; }
.drawer-header p { margin: 0; color: var(--muted); font-size: 10px; }
.drawer-content { min-height: 0; flex: 1; padding: 22px 24px; overflow-y: auto; }
.drawer-footer { padding: 14px 24px; display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); }
.detail-score-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 7px; }
.detail-score {
  padding: 11px 8px;
  background: var(--surface-soft);
  border-radius: 9px;
  text-align: center;
}
.detail-score span, .detail-score strong { display: block; }
.detail-score span { color: var(--muted); font-size: 8px; }
.detail-score strong { margin-top: 5px; font-family: Georgia, serif; font-size: 17px; }
.detail-section { margin-top: 21px; }
.detail-section h3 { margin: 0 0 10px; font-size: 11px; }
.reason-list, .risk-list { display: grid; gap: 7px; }
.reason-item, .risk-item { padding: 10px 11px; border-radius: 9px; font-size: 10px; }
.reason-item { color: var(--green); background: var(--green-soft); }
.risk-item { color: var(--red); background: var(--red-soft); }
.metric-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); border-top: 1px solid var(--line); }
.metric-detail {
  padding: 10px 4px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 9px;
}
.metric-detail:nth-child(odd) { padding-right: 14px; border-right: 1px solid var(--line); }
.metric-detail:nth-child(even) { padding-left: 14px; }
.metric-detail span { color: var(--muted); }
.settings-status { display: grid; gap: 8px; }
.settings-card { padding: 12px; display: flex; justify-content: space-between; align-items: center; background: var(--surface-soft); border-radius: 9px; font-size: 10px; }
.settings-card span { color: var(--muted); }
.settings-section { margin-top: 24px; }
.settings-section h3 { margin: 0 0 6px; font-size: 12px; }
.settings-section p { margin: 0 0 12px; color: var(--muted); font-size: 10px; line-height: 1.6; }
.settings-section ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 10px; line-height: 1.8; }
.stacked-actions { display: grid; gap: 8px; }
.settings-label { margin-top: 12px; display: grid; gap: 6px; }
.settings-label > span { color: var(--muted); font-size: 9px; font-weight: 700; }
.model-config-heading { margin-top: 19px; display: flex; align-items: center; justify-content: space-between; font-size: 10px; }
.model-config-list { margin-top: 9px; display: grid; gap: 9px; }
.model-config-empty { padding: 13px; color: var(--muted); background: var(--surface-soft); border: 1px dashed var(--line-strong); border-radius: 9px; font-size: 10px; line-height: 1.55; }
.model-config-row { padding: 12px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 10px; }
.model-config-row .settings-label { margin-top: 9px; }
.model-config-topline { display: flex; align-items: center; justify-content: space-between; font-size: 10px; }
.model-config-grid { display: grid; grid-template-columns: 1fr 1.2fr; gap: 8px; }
.settings-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 8px; }
.auto-update-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.auto-update-heading h3 { margin-bottom: 4px; }
.auto-update-heading p { margin-bottom: 0; }
.toggle-control { padding-top: 1px; display: flex; align-items: center; gap: 7px; cursor: pointer; }
.toggle-control input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-control > span { position: relative; width: 34px; height: 19px; background: #cbd2dc; border-radius: 999px; transition: .16s ease; }
.toggle-control > span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; background: white; border-radius: 50%; box-shadow: 0 1px 4px rgba(15,29,46,.2); transition: .16s ease; }
.toggle-control input:checked + span { background: var(--green); }
.toggle-control input:checked + span::after { transform: translateX(15px); }
.toggle-control input:focus-visible + span { outline: 3px solid rgba(212,166,79,.3); }
.toggle-control b { font-size: 9px; }
.auto-update-card { margin-top: 10px; padding: 12px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border: 1px solid var(--line); border-radius: 10px; }
.auto-update-card > div { min-width: 0; }
.auto-update-card strong, .auto-update-card small { display: block; }
.auto-update-card strong { font-size: 10px; }
.auto-update-card small { margin-top: 4px; color: var(--muted); font-size: 8px; line-height: 1.45; }
.auto-update-card.good { background: var(--green-soft); border-color: #cfe6dd; }
.auto-update-card.warning { background: var(--gold-soft); border-color: #ead8b1; }
.auto-update-card.working { background: var(--blue-soft); border-color: #cfdeec; }
.auto-update-card.muted { background: var(--surface-soft); }
.privacy-note { margin-top: 8px !important; font-size: 8px !important; }

.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; background: rgba(9,17,27,.5); backdrop-filter: blur(3px); }
.modal-card { width: min(420px, 100%); padding: 23px; background: var(--surface); border-radius: 15px; box-shadow: var(--shadow); }
.modal-card h2 { margin: 0 0 7px; font-family: Georgia, "Songti SC", serif; font-size: 20px; }
.modal-card p { margin: 0 0 18px; color: var(--muted); font-size: 10px; }
.modal-card label { display: grid; gap: 7px; font-size: 10px; font-weight: 700; }
.modal-actions { margin-top: 18px; display: flex; justify-content: flex-end; gap: 8px; }
.group-editor-modal { width: min(820px, 100%); max-height: min(820px, calc(100vh - 40px)); padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.group-editor-header { padding: 20px 22px 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.group-editor-header h2 { margin: 5px 0 5px; }
.group-editor-header p { margin: 0; }
.group-editor-body { min-height: 0; padding: 18px 22px; overflow-y: auto; }
.group-name-field { margin-bottom: 12px; }
.group-name-field > span { color: var(--muted); font-size: 9px; }
.natural-query.compact input, .natural-query.compact .button { min-height: 40px; }
.metric-support-panel { margin: 12px 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.metric-support-panel summary { padding: 11px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; list-style: none; font-size: 9px; }
.metric-support-panel summary::-webkit-details-marker { display: none; }
.metric-support-panel summary strong { font-size: 10px; }
.metric-support-panel summary span { color: var(--blue); }
.metric-support-panel summary::after { content: "＋"; color: var(--muted); font-size: 13px; }
.metric-support-panel[open] summary::after { content: "−"; }
.metric-support-content { padding: 0 12px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; border-top: 1px solid var(--line); }
.metric-support-content section { padding-top: 12px; }
.metric-support-content h3 { margin: 0 0 8px; font-size: 10px; }
.metric-support-content > p { grid-column: 1 / -1; margin: 0; padding: 9px 10px; background: var(--gold-soft); border-radius: 8px; font-size: 8px; line-height: 1.55; }
.metric-support-groups, .unsupported-metric-groups { display: grid; gap: 7px; }
.metric-support-group, .unsupported-metric-group { padding: 8px 9px; background: white; border: 1px solid var(--line); border-radius: 8px; }
.metric-support-group strong, .unsupported-metric-group strong { display: block; font-size: 9px; }
.metric-support-group p, .unsupported-metric-group p { margin: 4px 0 0; font-size: 8px; line-height: 1.5; }
.unsupported-metric-group strong span { margin-left: 5px; padding: 2px 5px; color: var(--red); background: var(--red-soft); border-radius: 999px; font-size: 7px; }
.unsupported-metric-group small { display: block; margin-top: 4px; color: var(--muted); font-size: 7px; line-height: 1.5; }
.group-preview { margin-top: 12px; padding: 10px 12px; color: var(--blue); background: var(--blue-soft); border-radius: 9px; font-size: 9px; }
.group-editor-actions { margin: 0; padding: 13px 22px; border-top: 1px solid var(--line); }

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  max-width: 380px;
  padding: 12px 15px;
  color: white;
  background: var(--navy);
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .18s ease;
  font-size: 10px;
}
#toast.show { opacity: 1; transform: none; }
#toast.error { background: var(--red); }

@media (max-width: 1180px) {
  .chat-layout { grid-template-columns: 240px minmax(0,1fr); }
  .context-panel {
    position: fixed;
    top: 72px;
    right: -310px;
    bottom: 0;
    z-index: 45;
    width: 290px;
    box-shadow: var(--shadow);
    transition: .2s ease;
  }
  .context-panel.open { right: 0; }
}

@media (max-width: 900px) {
  .app-header { padding: 0 16px; grid-template-columns: auto 1fr auto; }
  .brand > span:last-child { display: none; }
  .tab-button { min-width: 98px; padding: 0 11px; }
  #candidatesView { padding: 28px 18px 60px; }
  .group-panel-heading { flex-direction: column; }
  .group-panel-actions { width: 100%; flex-wrap: wrap; }
  .metric-row { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .condition-row { grid-template-columns: 1fr 1fr 1fr auto; }
  .condition-row .condition-value2 { grid-column: 3; }
  .screen-footer { align-items: stretch; flex-direction: column; }
  .screen-footer .button { align-self: flex-end; }
  .group-editor-modal { max-height: calc(100vh - 24px); }
  .metric-support-content { grid-template-columns: 1fr; }
  .metric-support-content > p { grid-column: auto; }
  .chat-layout { grid-template-columns: 1fr; }
  .conversation-sidebar {
    position: fixed;
    top: 72px;
    left: -280px;
    bottom: 0;
    z-index: 46;
    width: 268px;
    box-shadow: var(--shadow);
    transition: .2s ease;
  }
  .conversation-sidebar.open { left: 0; }
  .mobile-conversations { display: inline-flex; }
  .chat-header { padding: 0 14px; gap: 8px; }
  .active-agent small, .chat-model-control span, .chat-group-control span { display: none; }
  .chat-model-control select, .chat-group-control select { width: min(150px, 21vw); }
  .agent-grid { grid-template-columns: 1fr; }
  .agent-card { min-height: 135px; }
  .agent-card .agent-avatar { margin-bottom: 13px; }
}

@media (max-width: 640px) {
  .app-header { height: 64px; }
  .brand-mark { width: 34px; height: 34px; }
  .tab-button { min-width: 83px; font-size: 11px; }
  .tab-button small { display: none; }
  .system-pill { width: 36px; padding: 0; justify-content: center; }
  .system-pill > span:last-child { display: none; }
  .icon-button { padding: 0 9px; }
  #candidatesView { padding: 22px 12px 48px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading h1 { font-size: 27px; }
  .heading-actions { width: 100%; }
  .heading-actions .button { flex: 1; }
  .freshness-banner { grid-template-columns: auto 1fr; }
  .freshness-banner .text-button { grid-column: 2; justify-self: flex-start; padding-left: 0; }
  .freshness-actions { grid-column: 2; justify-content: flex-start; flex-wrap: wrap; }
  .metric-row { gap: 8px; }
  .metric-card { min-height: 94px; padding: 14px; }
  .metric-card strong { font-size: 21px; }
  .dynamic-groups, .screening-studio { padding: 16px; }
  .group-panel-actions .auto-update-badge { order: 4; }
  .group-panel-actions .button { flex: 1; padding: 0 10px; }
  .dynamic-group { min-width: 132px; }
  .dynamic-group-footer { align-items: flex-start; flex-direction: column; }
  .studio-heading { display: grid; }
  .screening-hint { align-self: start; }
  .natural-query { grid-template-columns: 1fr; }
  .condition-toolbar { align-items: flex-start; flex-direction: column; }
  .condition-row { grid-template-columns: 1fr 1fr; }
  .condition-row .remove-condition { grid-column: 2; justify-self: end; }
  .sort-controls { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .sort-controls label { min-width: 0; }
  .screen-footer .button { width: 100%; }
  .table-toolbar { align-items: stretch; flex-direction: column; }
  .table-search { display: grid; grid-template-columns: 1fr; }
  .table-search input { width: auto; }
  .table-actions { justify-content: space-between; }
  .selection-actions { justify-content: space-between; }
  .drawer { grid-template-columns: 1fr; }
  .drawer-backdrop { display: none; }
  .drawer-panel, .drawer-panel.compact { width: 100%; max-width: none; }
  #chatView { height: calc(100vh - 64px); height: calc(100dvh - 64px); }
  .conversation-sidebar, .context-panel { top: 64px; }
  .chat-header { padding: 0 12px; }
  .active-agent small { display: none; }
  .chat-model-control span { display: none; }
  .chat-group-control span { display: none; }
  .chat-model-control select, .chat-group-control select { width: 112px; }
  .context-button { padding: 0 9px; font-size: 0; }
  .context-button::before { content: "上下文"; font-size: 10px; }
  .agent-picker { padding: 34px 16px; }
  .agent-picker-heading h1 { font-size: 25px; }
  .message-list { padding: 22px 12px 35px; }
  .message-content { max-width: 88%; }
  .chat-composer { padding: 9px 10px 12px; }
  .detail-score-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .model-config-grid { grid-template-columns: 1fr; gap: 0; }
  .settings-actions .button { flex: 1; padding: 0 10px; }
}
