:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef6f4;
  --text: #18201f;
  --muted: #65706d;
  --line: #dce3e1;
  --accent: #147d68;
  --accent-dark: #0c5d4d;
  --warn: #9b5b00;
  --warn-bg: #fff4dc;
  --danger: #a43131;
  --shadow: 0 14px 36px rgba(23, 38, 35, 0.08);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 16px;
  align-items: start;
}

.quote-panel,
.result-panel,
.tabs-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.quote-panel,
.result-panel {
  padding: 18px;
}

.section-heading,
.summary-row,
.action-row,
.toolbar,
.tabs {
  display: flex;
  align-items: center;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 11px 12px;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 125, 104, 0.14);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.quick-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 16px;
}

.quick-examples button,
.tab,
.icon-button,
.secondary,
.primary {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

.quick-examples button {
  min-height: 32px;
  color: var(--muted);
  font-size: 13px;
}

.action-row {
  gap: 10px;
}

.primary {
  flex: 1;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary:hover,
.icon-button:hover,
.quick-examples button:hover,
.tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.empty-state {
  min-height: 285px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fafcfb;
  color: var(--muted);
  padding: 22px;
  text-align: center;
  line-height: 1.6;
}

.answer-box {
  border: 1px solid #bfddd5;
  border-radius: 8px;
  background: #f4fbf9;
  padding: 14px;
  margin-bottom: 14px;
}

.answer-label {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 9px;
}

.answer-body {
  color: var(--text);
  line-height: 1.65;
  font-size: 14px;
  white-space: pre-wrap;
}

.answer-body ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.hidden {
  display: none !important;
}

.summary-row {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.summary-row > div {
  width: 50%;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.summary-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.summary-row strong {
  font-size: 22px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  background: #f1f5f4;
  color: #35413e;
  font-size: 12px;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.amount {
  font-weight: 800;
  white-space: nowrap;
}

.notes {
  display: grid;
  gap: 8px;
}

.note {
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.45;
}

.note.danger {
  background: #fff0f0;
  color: var(--danger);
}

.tabs-section {
  margin-top: 16px;
  padding: 14px;
}

.tabs {
  gap: 8px;
  margin-bottom: 14px;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.toolbar {
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar input {
  flex: 1;
}

.toolbar select {
  width: min(310px, 42%);
}

.compact {
  max-height: 430px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.learning-list,
.handoff-list {
  display: grid;
  gap: 12px;
}

.learning-item,
.handoff-item {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.learning-head,
.handoff-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.learning-head strong,
.handoff-head strong {
  display: block;
  margin-bottom: 5px;
}

.learning-head span,
.handoff-head span {
  color: var(--muted);
  font-size: 12px;
}

.learning-status {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #eef6f4;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 8px;
}

.learning-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.handoff-messages {
  border-radius: 6px;
  background: #fafcfb;
  border: 1px solid var(--line);
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  max-height: 180px;
  overflow: auto;
}

.learning-answer {
  min-height: 72px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.history-item strong {
  display: block;
  margin-bottom: 5px;
}

.history-item p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.maintain-panel {
  border: 1px solid #bfddd5;
  border-radius: 8px;
  background: #f4fbf9;
  padding: 14px;
  margin-bottom: 12px;
}

.maintain-panel p {
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.maintain-panel code {
  color: #173d35;
  font-family: "SFMono-Regular", Consolas, monospace;
}

.maintain-panel pre {
  overflow: auto;
  border-radius: 6px;
  background: #17201e;
  color: #fff;
  padding: 11px 12px;
  margin: 10px 0;
}

.rule-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fafcfb;
}

.rule-grid p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  background: #17201e;
  color: #fff;
  padding: 11px 14px;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  z-index: 5;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.voice-config {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.28);
  padding: 20px;
}

.voice-config[hidden] {
  display: none;
}

.voice-config-panel {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.18);
}

.voice-config-panel strong {
  font-size: 16px;
}

.voice-config-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.voice-config-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.voice-config-actions button:first-child {
  border-color: #07c160;
  background: #07c160;
  color: #fff;
  font-weight: 700;
}

.client-shell {
  width: min(760px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.client-header {
  padding: 18px 0 22px;
}

.client-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.client-answer {
  display: grid;
  gap: 12px;
  min-height: 260px;
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  padding: 14px;
  margin-top: 16px;
}

.client-message {
  display: grid;
  gap: 5px;
  max-width: 86%;
}

.client-message.user {
  justify-self: end;
}

.client-message.assistant {
  justify-self: start;
}

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

.client-message.user .message-meta {
  text-align: right;
}

.message-bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
}

.client-message.user .message-bubble {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.message-bubble .table-wrap {
  margin: 10px 0 0;
  background: #fff;
}

.message-bubble table {
  min-width: 520px;
}

.client-actions {
  margin-top: 14px;
}

.wechat-shell {
  width: min(720px, 100%);
  height: 100vh;
  min-height: 620px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: 58px 1fr auto;
  background: #ededed;
  border-left: 1px solid #d7dcda;
  border-right: 1px solid #d7dcda;
}

.wechat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: #f7f7f7;
  border-bottom: 1px solid #dcdcdc;
}

.wechat-title {
  display: grid;
  gap: 2px;
}

.wechat-title strong {
  color: #111;
  font-size: 17px;
  line-height: 1.2;
}

.wechat-title span {
  color: #2f9b68;
  font-size: 12px;
}

.wechat-clear {
  min-height: 34px;
  border: 1px solid #d2d8d6;
  border-radius: 6px;
  background: #fff;
  color: #57605e;
  padding: 0 10px;
}

.wechat-chat {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #ededed;
}

.wechat-examples {
  padding: 8px 10px 3px;
  margin: 0;
  background: #ededed;
  gap: 6px;
}

.wechat-examples button {
  border-color: #d4d9d7;
  background: #fff;
  min-height: 28px;
  padding: 0 9px;
  font-size: 13px;
}

.wechat-shell .client-answer {
  min-height: 0;
  max-height: none;
  height: auto;
  align-content: start;
  gap: 8px;
  border: none;
  border-radius: 0;
  background: #ededed;
  padding: 8px 12px 12px;
  margin: 0;
}

.wechat-shell .empty-state {
  min-height: 180px;
  border: none;
  background: transparent;
  color: #7c8582;
}

.wechat-shell .client-message {
  max-width: min(76%, 560px);
  gap: 3px;
}

.wechat-shell .message-meta {
  font-size: 11px;
  color: #8b9491;
  padding: 0 4px;
}

.wechat-shell .message-bubble {
  position: relative;
  border: none;
  border-radius: 6px;
  background: #fff;
  padding: 8px 10px;
  line-height: 1.45;
  width: auto;
  max-width: 100%;
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}

.wechat-shell .client-message.user .message-bubble {
  justify-self: end;
}

.wechat-shell .client-message.assistant .message-bubble::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 12px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 6px solid #fff;
}

.wechat-shell .client-message.user .message-bubble {
  background: #95ec69;
  color: #111;
}

.wechat-shell .client-message.user .message-bubble::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 12px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid #95ec69;
}

.wechat-shell .message-bubble .table-wrap {
  border-color: #d9dfdd;
  max-width: 100%;
  overflow-x: auto;
}

.wechat-shell .message-bubble table {
  min-width: 420px;
}

.selectable-list {
  display: grid;
  gap: 7px;
}

.selectable-title {
  font-weight: 700;
}

.selectable-option {
  width: 100%;
  min-height: 34px;
  border: 1px solid #dce3e1;
  border-radius: 6px;
  background: #f8fbfa;
  color: #18201f;
  text-align: left;
  padding: 6px 9px;
}

.selectable-option:active {
  background: #e7f7ef;
}

.chat-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  color: #4e5754;
  font-size: 13px;
  line-height: 1.5;
}

.wechat-inputbar {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 7px;
  align-items: center;
  padding: 6px 10px calc(24px + env(safe-area-inset-bottom));
  background: #fafafa;
  border-top: 1px solid #dcdcdc;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.wechat-composer {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  min-height: 40px;
  margin-bottom: 14px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #eeeeee;
}

.wechat-inputbar textarea {
  min-height: 38px;
  max-height: 120px;
  border: none;
  border-radius: 6px;
  background: transparent;
  padding: 9px 6px 9px 10px;
  line-height: 1.45;
  box-shadow: none;
}

.wechat-inputbar button {
  min-width: 40px;
  min-height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #111;
  font-weight: 700;
}

.wechat-inputbar .voice-button,
.wechat-inputbar .more-button {
  position: relative;
  width: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: transparent;
  color: #111;
  border: none;
  font-size: 28px;
  line-height: 1;
  padding: 0;
}

.wechat-icon {
  display: block;
  width: 26px;
  height: 26px;
  margin: auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wechat-icon .fill-shape {
  fill: currentColor;
  stroke: none;
}

.wechat-inputbar .voice-button {
  grid-column: 1;
  grid-row: 1;
  margin-bottom: 14px;
  border: 2px solid #111;
}

.keyboard-mic-button {
  position: relative;
  grid-column: 2;
  width: 34px;
  min-width: 34px;
  min-height: 34px;
}

.keyboard-mic-button .wechat-icon {
  width: 23px;
  height: 23px;
  color: #8d9693;
  stroke-width: 2.1;
}

.wechat-inputbar .more-button {
  grid-column: 3;
  grid-row: 1;
  margin-bottom: 14px;
  border: 2px solid #111;
  font-size: 32px;
  font-weight: 400;
}

.wechat-inputbar #askBtn {
  grid-column: 3;
  grid-row: 1;
  display: none;
  min-width: 56px;
  min-height: 36px;
  margin-bottom: 14px;
  border-radius: 6px;
  background: #07c160;
  color: #fff;
  padding: 0 12px;
}

.wechat-inputbar.has-text .more-button {
  display: none;
}

.wechat-inputbar.has-text #askBtn {
  display: block;
}

.wechat-inputbar .voice-button.active,
.wechat-inputbar .more-button.active {
  background: #e8f4ef;
  border-color: #07c160;
  color: #07a653;
}

.voice-hold-button {
  display: none;
  grid-column: 1 / -1;
  width: 100%;
  border: none;
  border-radius: 6px;
  background: #fff !important;
  color: #26302d !important;
  font-weight: 700;
  letter-spacing: 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.wechat-inputbar.voice-mode textarea {
  display: none;
}

.wechat-inputbar.voice-mode .keyboard-mic-button {
  display: none;
}

.wechat-inputbar.voice-mode .voice-hold-button {
  display: block;
}

.image-input {
  display: none;
}

.wechat-action-panel {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 72px));
  gap: 12px;
  padding: 10px 0 2px;
}

.wechat-action-panel[hidden] {
  display: none;
}

.wechat-action-panel .action-tile {
  display: grid;
  place-items: center;
  gap: 6px;
  width: 62px;
  min-width: 62px;
  min-height: 62px;
  border: 1px solid #d9dfdd;
  border-radius: 8px;
  background: #fff;
  color: #26302d;
  padding: 0;
}

.wechat-action-panel .action-tile span {
  font-size: 12px;
  color: #596360;
}

.wechat-action-panel .image-button::before,
.wechat-action-panel .audio-button::before,
.wechat-action-panel .handoff-button::before {
  content: "";
  display: block;
  width: 24px;
  height: 20px;
  border: 2px solid #7b8582;
  border-radius: 4px;
}

.wechat-action-panel .audio-button::before {
  width: 18px;
  height: 24px;
  border-radius: 12px;
}

.wechat-action-panel .image-button::after {
  content: "";
  position: absolute;
}

.wechat-action-panel .handoff-button::before {
  width: 24px;
  height: 18px;
  border-radius: 12px;
}

.wechat-inputbar .voice-button.listening {
  background: #e6fff1;
  color: #07a653;
  border-color: #07c160;
}

.wechat-inputbar.recording .voice-hold-button {
  background: #e6fff1 !important;
  color: #07a653 !important;
}

.wechat-inputbar.voice-upload-mode .voice-hold-button {
  background: #fff !important;
  color: #111 !important;
}

.chat-image-wrap {
  display: grid;
  gap: 5px;
  margin-bottom: 6px;
}

.chat-image-wrap img {
  display: block;
  width: min(220px, 100%);
  max-height: 260px;
  object-fit: cover;
  border-radius: 6px;
  background: #f3f3f3;
}

.chat-image-name {
  max-width: 220px;
  color: #68716e;
  font-size: 11px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-audio-wrap {
  display: grid;
  gap: 5px;
  min-width: min(230px, 100%);
  margin-bottom: 4px;
}

.chat-audio-wrap audio {
  width: 100%;
  max-width: 230px;
  height: 32px;
}

.chat-audio-wrap span {
  color: #5b6662;
  font-size: 12px;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    padding-top: 10px;
  }

  .topbar,
  .workspace,
  .form-grid,
  .summary-row,
  .toolbar,
  .rule-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .workspace {
    gap: 12px;
  }

  .summary-row > div,
  .toolbar select {
    width: 100%;
  }

  .quote-panel,
  .result-panel,
  .client-card,
  .tabs-section {
    padding: 14px;
  }

  h1 {
    font-size: 24px;
  }

  table {
    min-width: 560px;
  }

  .wechat-shell {
    width: 100%;
    min-height: 100vh;
    border: none;
  }

  .wechat-shell .client-message {
    max-width: 84%;
  }

  .wechat-inputbar {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
  }
}
