:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --panel: #f5f6f7;
  --line: #e7e8eb;
  --text: #191f25;
  --muted: #858b96;
  --primary: #07c160;
  --primary-dark: #06a954;
  --accent: #fa9d3b;
  --danger: #d94343;
  --shadow: 0 18px 58px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(90deg, rgba(7, 193, 96, 0.08) 0 1px, transparent 1px 100%),
    linear-gradient(180deg, rgba(7, 193, 96, 0.06) 0 1px, transparent 1px 100%),
    #edf1f4;
  background-size: 36px 36px;
  color: var(--text);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.workspace {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(260px, 308px) 1fr;
  gap: 20px;
  padding: 14px 18px;
  overflow: hidden;
}

.side-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr;
  gap: 10px;
  overflow: hidden;
}

.panel-section {
  min-width: 0;
  padding: 14px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(231, 232, 235, 0.96);
  border-radius: 14px;
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.08);
}

.sessions-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  align-content: start;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.section-title h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: 0;
}

.title-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.state-pill,
.count-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #64748b;
  font-size: 12px;
}

.state-pill.saved {
  background: rgba(7, 193, 96, 0.12);
  color: var(--primary-dark);
}

.side-actions {
  display: grid;
  margin-bottom: 8px;
}

.config-form,
.new-session-form {
  display: grid;
  gap: 8px;
}

.config-form label,
.new-session-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.config-form input,
.config-form textarea,
.config-form select,
.new-session-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  background: #f7f8fa;
  color: var(--text);
  font-size: 12px;
}

.secret-field {
  position: relative;
  display: block;
}

.secret-field input {
  padding-right: 48px;
}

.secret-toggle {
  position: absolute;
  top: 50%;
  right: 7px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  border-radius: 50%;
  background: transparent;
  color: #7b8492;
  line-height: 1;
}

.secret-toggle:hover,
.secret-toggle.visible {
  background: #eef0f2;
  color: var(--primary-dark);
}

.eye-icon {
  position: relative;
  width: 18px;
  height: 12px;
  display: block;
  border: 1.8px solid currentColor;
  border-radius: 999px 999px 999px 999px / 80% 80% 80% 80%;
}

.eye-icon::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: currentColor;
}

.secret-toggle.visible .eye-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: -2px;
  width: 22px;
  height: 1.8px;
  transform: rotate(-38deg);
  border-radius: 999px;
  background: currentColor;
}

.config-form input,
.config-form select,
.new-session-form input {
  height: 38px;
  padding: 0 11px;
}

.config-form textarea {
  resize: vertical;
  min-height: 52px;
  max-height: 58px;
  padding: 7px 9px;
}

.config-form input:focus,
.config-form textarea:focus,
.config-form select:focus,
.new-session-form input:focus {
  border-color: rgba(7, 193, 96, 0.58);
  box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.1);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle-line {
  align-self: end;
  height: 32px;
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 8px !important;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f8fa;
}

.toggle-line input {
  width: 16px;
  height: 16px;
}

.primary-button,
.secondary-button {
  height: 44px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  transition:
    transform 0.16s ease,
    background-color 0.16s ease;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.secondary-button {
  background: #f1f2f5;
  color: #1f2937;
}

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

.secondary-button:hover {
  background: #e9ebef;
}

.primary-button:active,
.secondary-button:active,
.session-item:active,
.icon-button:active,
.tool-button:active,
.send-button:active,
.quick-replies button:active {
  transform: scale(0.97);
}

.session-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  margin-top: 12px;
  scrollbar-width: none;
}

.session-list::-webkit-scrollbar,
.messages::-webkit-scrollbar {
  display: none;
}

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

.session-item.active {
  border-color: rgba(7, 193, 96, 0.46);
  background: #f3fff8;
  box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.1);
}

.session-title {
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-id,
.session-preview {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.chat-app {
  width: min(100%, 480px);
  height: calc(100vh - 24px);
  height: calc(100dvh - 24px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  overflow: hidden;
  background: linear-gradient(180deg, #f4f7fb 0%, #f8fafc 52%, #f4f6f8 100%);
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 2px;
  box-shadow: var(--shadow);
}

.mini-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 42px;
  background: #fff;
  color: #080b0f;
  font-size: 17px;
  font-weight: 700;
}

.phone-indicators {
  display: flex;
  align-items: center;
}

.phone-indicators img {
  width: 106px;
  height: auto;
  display: block;
  object-fit: contain;
}

.chat-header {
  display: grid;
  grid-template-columns: 56px 1fr 112px;
  align-items: start;
  gap: 0;
  min-height: 120px;
  padding: 18px 28px 18px;
  background: #fff;
  border-bottom: 0;
}

.agent {
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: start;
  gap: 0;
}

.agent-copy {
  min-width: 0;
}

.agent-copy h1 {
  margin: 0 0 11px;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-copy p {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: none;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.header-actions > .icon-button {
  display: none;
}

.mini-capsule {
  width: 104px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border: 1px solid #eceef2;
  border-radius: 999px;
  background: #fff;
  color: #111827;
  font-size: 18px;
  line-height: 1;
}

.mini-capsule span:last-child {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  border: 5px solid #111827;
}

.icon-button,
.tool-button,
.send-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  transition:
    transform 0.16s ease,
    background-color 0.16s ease;
}

.icon-button {
  width: 42px;
  height: 42px;
  background: transparent;
  color: #243144;
  font-size: 44px;
  line-height: 1;
}

#backButton span {
  width: 17px;
  height: 17px;
  display: block;
  overflow: hidden;
  text-indent: -999px;
  border-left: 3px solid #111827;
  border-bottom: 3px solid #111827;
  transform: rotate(45deg);
}

.icon-button:hover,
.tool-button:hover {
  background: #eaf0f6;
}

.time-chip {
  width: fit-content;
  margin: 0 auto 20px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(223, 228, 235, 0.74);
  color: #9ca3af;
  font-size: 15px;
  line-height: 1.2;
}

.messages {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px 18px 14px;
  scroll-behavior: smooth;
  scrollbar-width: none;
}

.empty-state {
  margin: auto;
  width: fit-content;
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(23, 33, 47, 0.08);
  color: #718096;
  font-size: 13px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin: 18px 0;
}

.agent-row {
  justify-content: flex-start;
}

.user-row {
  justify-content: flex-end;
}

.bubble {
  max-width: min(74%, 310px);
  padding: 14px 16px 9px;
  font-size: 16px;
  line-height: 1.55;
  word-break: break-word;
  box-shadow: none;
}

.agent-bubble {
  border-radius: 0 16px 16px 16px;
  background: #fff;
  border: 0;
  box-shadow: 0 12px 34px rgba(31, 41, 55, 0.06);
}

.user-bubble {
  border-radius: 16px 16px 0 16px;
  background: linear-gradient(135deg, #3f8cff 0%, #2f73ff 100%);
  color: #fff;
  box-shadow: 0 14px 30px rgba(47, 115, 255, 0.2);
}

.bubble-text {
  white-space: pre-wrap;
}

.bubble-meta {
  margin-top: 6px;
  color: #9aa1ad;
  font-size: 12px;
  text-align: left;
}

.message-detail-button {
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef3f8;
  color: #334155;
  font-size: 12px;
  line-height: 1.4;
}

.chat-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  box-shadow: 0 8px 22px rgba(31, 41, 55, 0.1);
}

.agent-avatar {
  background:
    radial-gradient(circle at 50% 33%, #f7d6c4 0 21%, transparent 22%),
    radial-gradient(circle at 50% 43%, #222 0 29%, transparent 30%),
    radial-gradient(circle at 50% 30%, #f9dccb 0 28%, transparent 29%),
    linear-gradient(135deg, #fdf2f8, #dbeafe);
}

.user-avatar {
  background:
    radial-gradient(circle at 50% 36%, #2d3748 0 20%, transparent 21%),
    radial-gradient(circle at 50% 30%, #f2c7a7 0 19%, transparent 20%),
    linear-gradient(135deg, #93c5fd, #dbeafe 52%, #86efac);
}

.message-detail-button:hover {
  background: #e2eaf3;
}

.option-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.option-card {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #edf0f5;
  border-radius: 12px;
  background: #f8fafc;
  color: #374151;
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background-color 0.16s ease;
}

.option-card:hover {
  border-color: rgba(7, 193, 96, 0.45);
  background: #f0faf4;
  color: var(--primary-dark);
}

.option-card:active {
  transform: scale(0.98);
}

.option-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.option-card.selected {
  border-color: var(--primary);
  background: rgba(7, 193, 96, 0.08);
  color: var(--primary-dark);
  opacity: 1;
}

.modal {
  width: min(92vw, 720px);
  max-height: min(86vh, 760px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--text);
}

.detail-modal {
  width: min(calc(92dvh * 1.34), calc(100vw - 128px));
  height: min(92dvh, calc((100vw - 128px) / 1.34));
  max-width: calc(100vw - 128px);
  max-height: 92dvh;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(2px);
}

.modal-panel {
  max-height: min(86vh, 760px);
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: 18px;
  background: #fff;
  border: 1px solid rgba(231, 232, 235, 0.92);
  border-radius: 16px;
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.18);
  scrollbar-width: none;
}

.modal-panel::-webkit-scrollbar {
  display: none;
}

.detail-modal .modal-panel {
  height: 100%;
  max-height: 100%;
  min-height: 0;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr;
  align-items: stretch;
  overflow: hidden;
}

.detail-modal .modal-header {
  grid-column: 1 / -1;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: 0;
}

.modal-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f1f2f5;
  color: #1f2937;
  font-size: 20px;
  line-height: 1;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.detail-action-button {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: #f1f2f5;
  color: #263241;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.detail-action-button:hover {
  background: #e5e9ef;
}

.detail-block {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.detail-block h3 {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.3;
  letter-spacing: 0;
}

.json-viewer {
  max-height: none;
  min-height: 0;
  height: 100%;
  margin: 0;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  color: #e5e7eb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  word-break: break-word;
}

.json-raw {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.json-raw-key {
  color: #93c5fd;
}

.json-raw-string {
  color: #86efac;
}

.json-raw-number {
  color: #fbbf24;
}

.json-raw-boolean {
  color: #f472b6;
}

.json-raw-null {
  color: #9ca3af;
}

.json-node {
  min-width: 0;
  padding: 1px 0;
}

.json-node summary {
  width: fit-content;
  max-width: 100%;
  cursor: pointer;
  list-style: none;
  outline: 0;
  white-space: nowrap;
}

.json-node summary::-webkit-details-marker {
  display: none;
}

.json-node summary::before {
  content: "▸";
  display: inline-block;
  width: 14px;
  color: #9ca3af;
}

.json-node details[open] > summary::before {
  content: "▾";
}

.json-children {
  margin-left: 18px;
  padding-left: 10px;
  border-left: 1px solid rgba(148, 163, 184, 0.25);
}

.json-key {
  color: #93c5fd;
}

.json-meta {
  color: #c4b5fd;
}

.json-value-string {
  color: #86efac;
}

.json-value-number {
  color: #fbbf24;
}

.json-value-boolean {
  color: #f472b6;
}

.json-value-null {
  color: #9ca3af;
}

.user-bubble .bubble-meta {
  color: rgba(255, 255, 255, 0.78);
  text-align: right;
}

.quick-replies {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  padding: 12px 16px;
  background: transparent;
  border-top: 0;
  scrollbar-width: none;
}

.quick-replies::-webkit-scrollbar {
  display: none;
}

.quick-replies button {
  flex: 0 0 auto;
  width: auto;
  max-width: 132px;
  height: 34px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid #edf0f5;
  border-radius: 999px;
  background: #fff;
  color: #374151;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 8px 22px rgba(31, 41, 55, 0.05);
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease;
}

.quick-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  display: inline-block;
  border-radius: 50%;
  background: rgba(7, 193, 96, 0.16);
  position: relative;
}

.quick-icon::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--primary);
}

.quick-replies button:hover {
  border-color: rgba(7, 193, 96, 0.45);
  color: var(--primary-dark);
}

.composer {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 34px 42px 0;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 32px;
  background: #fff;
  border-top: 1px solid #f0f1f3;
}

.tool-button,
.voice-button,
.emoji-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: transparent;
  color: #667180;
  font-size: 26px;
}

.voice-button {
  width: 42px;
  justify-self: start;
}

.voice-button svg,
.emoji-button svg,
.tool-button svg {
  width: 22px;
  height: 22px;
  color: #667180;
  transition: color 0.16s ease;
}

.voice-button:hover svg,
.emoji-button:hover svg,
.tool-button:hover svg {
  color: var(--primary-dark);
}

.tool-button {
  background: transparent;
}

.input-wrap {
  min-width: 0;
}

.input-wrap input {
  width: 100%;
  height: 42px;
  border: 1px solid #dfe3e8;
  border-radius: 999px;
  outline: 0;
  padding: 0 16px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

.input-wrap input:focus {
  border-color: rgba(7, 193, 96, 0.58);
  box-shadow: 0 0 0 4px rgba(7, 193, 96, 0.11);
}

.send-button {
  width: 0;
  height: 0;
  overflow: hidden;
  padding: 0;
  pointer-events: none;
  background: var(--primary);
  color: #fff;
  font-size: 22px;
  box-shadow: 0 8px 18px rgba(7, 193, 96, 0.24);
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 860px) {
  html,
  body {
    overflow: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .side-panel {
    min-height: 0;
    grid-template-rows: auto auto;
    overflow: visible;
  }

  .chat-app {
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
  }

  .detail-modal {
    width: calc(100vw - 24px);
    height: calc(100dvh - 24px);
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
  }

  .detail-modal .modal-panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr);
  }
}

@media (max-width: 520px) {
  body {
    background: var(--panel);
  }

  .workspace {
    padding: 0;
    gap: 0;
  }

  .side-panel {
    display: block;
    padding: 10px;
  }

  .panel-section {
    margin-bottom: 10px;
  }

  .session-list {
    max-height: 210px;
  }

  .chat-app {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .bubble {
    max-width: 82%;
  }
}

@media (max-width: 360px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .chat-header {
    grid-template-columns: 32px 1fr auto;
    gap: 6px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .avatar {
    width: 34px;
    height: 34px;
    border-radius: 12px;
  }

  .header-actions {
    gap: 2px;
  }

  .icon-button {
    width: 30px;
    height: 30px;
  }

  .composer {
    grid-template-columns: 38px minmax(0, 1fr) 32px 38px 0;
    gap: 7px;
    padding-left: 10px;
    padding-right: 10px;
  }
}
