.chat-page {
  min-height: 100vh;
}

.chat-main {
  padding: 0 0 70px;
}

.chat-intro {
  margin: 0 auto;
}

.chat-workspace {
  display: grid;
  grid-template-columns: minmax(350px, 0.86fr) minmax(430px, 1.14fr);
  align-items: stretch;
  gap: 18px;
}

.chat-setup-card,
.conversation-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px);
}

.chat-setup-card {
  padding: 27px;
}

.chat-card-heading,
.chat-setup-actions,
.conversation-header,
.conversation-identity,
.selected-persona {
  display: flex;
  align-items: center;
}

.chat-card-heading,
.conversation-header {
  justify-content: space-between;
}

.chat-card-heading {
  gap: 16px;
  margin-bottom: 20px;
}

.chat-card-heading h2,
.conversation-header h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 690;
  letter-spacing: -0.045em;
}

.setup-state {
  flex: none;
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--ink-faint);
  background: rgba(43, 39, 31, 0.045);
  font-size: 9px;
  font-weight: 760;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.setup-state.live {
  color: var(--violet-dark);
  background: var(--mint-soft);
}

.chat-source-switcher .mode-tab {
  min-height: 40px;
}

.chat-source-panel {
  position: relative;
  padding-top: 17px;
  animation: panel-in 260ms var(--ease) both;
}

.chat-source-panel.filter-menu-open,
.chat-setup-card.filter-menu-open {
  z-index: 200;
}

.chat-setup-card.filter-menu-open {
  position: relative;
  overflow: visible;
}

.chat-library-toolbar {
  gap: 10px;
  margin-bottom: 9px;
}

.chat-library-toolbar .search-field {
  height: 41px;
}

.chat-library-toolbar .library-count {
  max-width: 62px;
  text-align: right;
}

.chat-voice-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-height: 235px;
}

.chat-voice-grid .voice-card {
  grid-template-columns: 36px minmax(0, 1fr);
  min-height: 61px;
  gap: 8px;
  padding: 8px 40px 8px 8px;
}

.chat-voice-grid .voice-avatar {
  width: 36px;
  height: 36px;
}

.custom-voice-fields {
  display: grid;
  gap: 12px;
  min-height: 237px;
  align-content: center;
}

.chat-field {
  display: grid;
  gap: 7px;
}

.chat-field > span {
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-field > span small {
  margin-left: 5px;
  color: var(--ink-faint);
  font-size: 9px;
  font-weight: 620;
  letter-spacing: 0;
  text-transform: none;
}

.chat-field input,
.chat-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.chat-field input {
  height: 43px;
  padding: 0 13px;
  border-radius: 11px;
}

.chat-field textarea {
  min-height: 94px;
  padding: 12px 13px;
  resize: vertical;
  border-radius: 13px;
  font-size: 12px;
  line-height: 1.55;
}

.chat-field input:focus,
.chat-field textarea:focus {
  border-color: rgba(10, 169, 156, 0.42);
  background: white;
  box-shadow: 0 0 0 3px rgba(10, 169, 156, 0.08);
}

.chat-field input:disabled,
.chat-field textarea:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.chat-upload-zone {
  display: flex;
  min-height: 93px;
  align-items: center;
  gap: 13px;
  padding: 15px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 14px;
  background: rgba(247, 244, 237, 0.55);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.chat-upload-zone:hover {
  border-color: rgba(10, 169, 156, 0.5);
  background: var(--violet-soft);
}

.chat-upload-icon {
  display: grid;
  width: 42px;
  height: 42px;
  flex: none;
  place-items: center;
  border-radius: 12px;
  color: var(--violet);
  background: var(--violet-soft);
}

.chat-upload-icon svg,
.composer button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-upload-zone strong,
.chat-upload-zone small {
  display: block;
}

.chat-upload-zone strong {
  font-size: 12px;
}

.chat-upload-zone small {
  margin-top: 3px;
  color: var(--ink-faint);
  font-size: 10px;
}

.selected-persona {
  gap: 11px;
  margin-top: 17px;
  padding: 10px;
  border: 1px solid rgba(10, 169, 156, 0.2);
  border-radius: 14px;
  background: rgba(221, 244, 240, 0.5);
}

.selected-persona-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  flex: none;
  place-items: center;
  overflow: hidden;
  border-radius: 12px;
  color: var(--violet-dark);
  background: var(--violet-soft);
  font-size: 11px;
  font-weight: 780;
}

.selected-persona-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.selected-persona small,
.selected-persona strong {
  display: block;
}

.selected-persona small {
  color: var(--ink-faint);
  font-size: 9px;
  font-weight: 740;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.selected-persona strong {
  margin-top: 1px;
  font-size: 13px;
}

.brief-field {
  margin-top: 17px;
}

.chat-setup-actions {
  justify-content: space-between;
  gap: 12px;
  margin-top: 17px;
}

.chat-start-control {
  display: grid;
  flex: none;
  justify-items: end;
  gap: 6px;
}

.chat-option-toggles {
  display: grid;
  align-content: center;
  gap: 10px;
}

.chat-language {
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-language select {
  min-width: 122px;
}

.chat-language select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.chat-toggle-with-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-credit-message {
  max-width: 220px;
  color: var(--danger);
  font-size: 10px;
  font-weight: 650;
  line-height: 1.35;
  text-align: right;
}

.chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 10px;
  font-weight: 650;
}

.chat-toggle[hidden] {
  display: none;
}

.chat-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chat-toggle > span {
  position: relative;
  width: 31px;
  height: 18px;
  flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(43, 39, 31, 0.08);
  transition: background 160ms ease;
}

.chat-toggle > span::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(9, 38, 34, 0.18);
  content: "";
  transition: transform 160ms var(--ease);
}

.chat-toggle input:checked + span {
  background: var(--violet);
}

.chat-toggle input:checked + span::after {
  transform: translateX(13px);
}

.chat-start-button {
  display: inline-flex;
  min-height: 43px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 17px;
  border: 0;
  border-radius: 12px;
  color: white;
  background: var(--ink);
  box-shadow: 0 8px 20px rgba(9, 38, 34, 0.15);
  cursor: pointer;
  font-size: 11px;
  font-weight: 720;
  transition: background 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.chat-start-button:hover:not(:disabled) {
  background: var(--violet-dark);
}

.chat-start-button:active:not(:disabled) {
  transform: scale(0.98);
}

.chat-start-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.chat-start-button.connected {
  color: var(--danger);
  background: #fff4f2;
  box-shadow: none;
}

.start-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #62c6a7;
  box-shadow: 0 0 0 4px rgba(98, 198, 167, 0.14);
}

.chat-start-button.connected .start-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(189, 77, 69, 0.1);
}

.conversation-card {
  --bot-level: 0;
  --user-level: 0;
  --voice-level: 0;
  position: relative;
  display: flex;
  height: 690px;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.chat-connecting {
  position: absolute;
  inset: 87px 0 0;
  z-index: 3;
  display: grid;
  padding: 24px;
  place-items: center;
  background: rgba(247, 250, 248, 0.8);
  backdrop-filter: blur(9px);
  animation: fade-in 180ms ease both;
}

.chat-connecting[hidden] {
  display: none;
}

.chat-connecting-card {
  text-align: center;
}

.chat-connecting .processing-orb {
  width: 72px;
  height: 72px;
  margin-bottom: 20px;
}

.chat-connecting strong,
.chat-connecting small {
  display: block;
}

.chat-connecting strong {
  font-size: 17px;
  letter-spacing: -0.02em;
}

.chat-connecting small {
  margin-top: 6px;
  color: var(--ink-faint);
  font-size: 10px;
}

.conversation-header {
  min-height: 87px;
  flex: none;
  gap: 15px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.conversation-identity {
  gap: 13px;
}

.conversation-header-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.conversation-text-toggle {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--violet-dark);
  background: rgba(255, 255, 255, 0.72);
  font-size: 9px;
  font-weight: 760;
  cursor: pointer;
}

.conversation-text-toggle:hover {
  border-color: rgba(10, 169, 156, 0.35);
  background: white;
}

.conversation-text-toggle[hidden],
.conversation-content[hidden],
.voice-stage[hidden] {
  display: none;
}

.voice-orb {
  position: relative;
  display: grid;
  width: 48px;
  height: 48px;
  flex: none;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 33% 28%, #effffc 0 5%, #a9e2da 24%, #16ad9f 64%, #08736c 100%);
  box-shadow:
    0 6px 18px rgba(7, 118, 109, 0.2),
    0 0 0 calc(var(--user-level) * 7px) rgba(10, 169, 156, 0.11),
    inset -6px -7px 14px rgba(4, 61, 56, 0.18);
  transform: scale(calc(1 + var(--voice-level) * 0.16));
  transition: transform 80ms linear, box-shadow 100ms linear;
}

.voice-orb span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 calc(5px + var(--bot-level) * 12px) rgba(255, 255, 255, 0.9);
}

.voice-stage {
  display: grid;
  min-height: 0;
  flex: 1;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(221, 244, 240, 0.58), transparent 42%),
    rgba(247, 250, 248, 0.45);
}

.voice-stage-orb {
  width: 156px;
  height: 156px;
  box-shadow:
    0 18px 45px rgba(7, 118, 109, 0.2),
    0 0 0 calc(var(--user-level) * 55px) rgba(10, 169, 156, 0.09),
    0 0 calc(28px + var(--bot-level) * 55px) rgba(10, 169, 156, 0.2),
    inset -18px -20px 34px rgba(4, 61, 56, 0.18);
  transform: scale(calc(1 + var(--voice-level) * 0.3));
}

.voice-stage-orb span {
  width: 18px;
  height: 18px;
  box-shadow: 0 0 calc(12px + var(--bot-level) * 26px) rgba(255, 255, 255, 0.95);
}

.conversation-card[data-turn-phase="listening"] .voice-orb {
  background: radial-gradient(circle at 33% 28%, #effffc 0 5%, #a9e2da 24%, #16ad9f 64%, #08736c 100%);
}

.conversation-card[data-turn-phase="listening"] .voice-stage {
  background:
    radial-gradient(circle at center, rgba(193, 241, 232, 0.72), transparent 43%),
    rgba(247, 250, 248, 0.45);
}

.conversation-card[data-turn-phase="thinking"] .voice-orb {
  background: radial-gradient(circle at 33% 28%, #fff9e8 0 5%, #f4d58a 24%, #d89a2b 64%, #855713 100%);
  box-shadow:
    0 8px 24px rgba(157, 103, 23, 0.2),
    0 0 0 12px rgba(216, 154, 43, 0.08),
    inset -6px -7px 14px rgba(89, 55, 5, 0.17);
  animation: turn-thinking-pulse 1.15s ease-in-out infinite alternate;
}

.conversation-card[data-turn-phase="thinking"] .voice-stage {
  background:
    radial-gradient(circle at center, rgba(250, 225, 169, 0.65), transparent 43%),
    rgba(250, 248, 242, 0.48);
}

@keyframes turn-thinking-pulse {
  to { filter: brightness(1.1) saturate(1.08); }
}

.conversation-card[data-turn-phase="speaking"] .voice-orb {
  background: radial-gradient(circle at 33% 28%, #fbf7ff 0 5%, #d9c8f2 24%, #8f67c7 64%, #51337e 100%);
  box-shadow:
    0 8px 24px rgba(81, 51, 126, 0.22),
    0 0 0 calc(var(--bot-level) * 28px) rgba(143, 103, 199, 0.1),
    0 0 calc(26px + var(--bot-level) * 55px) rgba(143, 103, 199, 0.2),
    inset -7px -8px 16px rgba(55, 31, 91, 0.2);
}

.conversation-card[data-turn-phase="speaking"] .voice-stage {
  background:
    radial-gradient(circle at center, rgba(222, 207, 244, 0.7), transparent 43%),
    rgba(248, 246, 250, 0.48);
}

.conversation-card.text-hidden .conversation-header .voice-orb {
  display: none;
}

.conversation-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-faint);
  font-size: 10px;
  font-weight: 700;
}

.conversation-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aaa59c;
}

.conversation-status.live {
  color: var(--violet-dark);
}

.conversation-status.live i {
  background: #50a582;
  box-shadow: 0 0 0 4px rgba(80, 165, 130, 0.11);
}

.conversation-status.error {
  color: var(--danger);
}

.conversation-status.error i {
  background: var(--danger);
}

.conversation-content {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.transcript-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 11px;
  padding: 23px;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-color: rgba(10, 169, 156, 0.22) transparent;
  scrollbar-width: thin;
}

.transcript-empty {
  display: grid;
  max-width: 280px;
  margin: auto;
  place-items: center;
  color: var(--ink-faint);
  text-align: center;
}

.empty-spark {
  display: grid;
  width: 45px;
  height: 45px;
  margin-bottom: 13px;
  place-items: center;
  border: 1px solid rgba(10, 169, 156, 0.15);
  border-radius: 15px;
  color: var(--violet);
  background: var(--violet-soft);
  font-size: 18px;
}

.transcript-empty strong {
  color: var(--ink-soft);
  font-size: 13px;
}

.transcript-empty small {
  margin-top: 5px;
  font-size: 10px;
  line-height: 1.55;
}

.message {
  max-width: 82%;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: message-in 220ms var(--ease) both;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(5px); }
}

.message.user {
  align-self: flex-end;
  border-color: rgba(10, 169, 156, 0.2);
  border-bottom-right-radius: 4px;
  color: #075e57;
  background: var(--violet-soft);
}

.message.bot {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
}

.message.streaming::after {
  display: inline-block;
  margin-left: 2px;
  color: var(--violet);
  content: "▍";
  animation: chat-caret 900ms steps(2) infinite;
}

@keyframes chat-caret {
  50% { opacity: 0; }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: rgba(247, 250, 248, 0.75);
}

.composer textarea {
  min-height: 44px;
  max-height: 130px;
  flex: 1;
  padding: 11px 13px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  line-height: 1.5;
  transition: border-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.composer textarea:focus {
  border-color: rgba(10, 169, 156, 0.42);
  box-shadow: 0 0 0 3px rgba(10, 169, 156, 0.08);
}

.composer textarea:disabled {
  opacity: 0.56;
  cursor: not-allowed;
}

.composer button {
  display: grid;
  width: 44px;
  height: 44px;
  flex: none;
  place-items: center;
  border: 0;
  border-radius: 13px;
  color: white;
  background: var(--violet-dark);
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.composer button:hover:not(:disabled) {
  background: var(--violet);
}

.composer button:active:not(:disabled) {
  transform: scale(0.96);
}

.composer button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

#bot-audio {
  display: none;
}

@media (max-width: 960px) {
  .chat-workspace {
    grid-template-columns: 1fr;
  }

  .conversation-card {
    height: 620px;
  }
}

@media (max-width: 760px) {
  .chat-setup-card {
    padding: 22px 18px;
    border-radius: 23px;
  }

  .conversation-card {
    height: 570px;
    border-radius: 23px;
  }

  .chat-library-toolbar {
    flex-direction: row;
  }
}

@media (max-width: 520px) {
  .chat-voice-grid {
    grid-template-columns: 1fr;
  }

  .chat-setup-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-start-button {
    width: 100%;
  }

  .chat-start-control {
    width: 100%;
  }

  .chat-credit-message {
    max-width: none;
    text-align: center;
  }

  .conversation-header {
    padding-inline: 17px;
  }

  .conversation-header-controls {
    align-items: flex-end;
    flex-direction: column;
    gap: 5px;
  }

  .voice-stage-orb {
    width: 132px;
    height: 132px;
  }

  .transcript-list {
    padding: 17px;
  }

  .message {
    max-width: 90%;
  }
}
