:root {
  --brand-primary: #2cbdec;
  --brand-primary-hover: #1fa9d6;
  --brand-primary-soft: #e6f7fc;
  --brand-accent: #ffc12c;
  --brand-dark: #1a2124;
  --brand-neutral: #83959d;
  --bg: #eef3f5;
  --surface: #ffffff;
  --surface-alt: #f7f9fa;
  --surface-soft: #fbfdfe;
  --border: #e5eaec;
  --text: #1a2124;
  --muted: #63757d;
  --danger: #c9353b;
  --shadow: 0 20px 56px rgba(26, 33, 36, 0.14);
  --chat-bg: linear-gradient(180deg, #ffffff 0%, #f7fbfc 100%);
  --hover: rgba(26, 33, 36, 0.07);
  --scroll-thumb: rgba(26, 33, 36, 0.24);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101719;
    --surface: #182124;
    --surface-alt: #11191c;
    --surface-soft: #1e2a2e;
    --border: #2b3b40;
    --text: #edf5f7;
    --muted: #a7b7bd;
    --brand-primary-soft: #123640;
    --brand-primary-hover: #6ad1ef;
    --shadow: 0 24px 64px rgba(0, 0, 0, 0.38);
    --chat-bg: linear-gradient(180deg, #182124 0%, #121b1e 100%);
    --hover: rgba(255, 255, 255, 0.08);
    --scroll-thumb: rgba(237, 245, 247, 0.28);
  }
}

:root[data-theme="light"] {
  --bg: #eef3f5;
  --surface: #ffffff;
  --surface-alt: #f7f9fa;
  --surface-soft: #fbfdfe;
  --border: #e5eaec;
  --text: #1a2124;
  --muted: #63757d;
  --brand-primary-soft: #e6f7fc;
  --brand-primary-hover: #1fa9d6;
  --shadow: 0 20px 56px rgba(26, 33, 36, 0.14);
  --chat-bg: linear-gradient(180deg, #ffffff 0%, #f7fbfc 100%);
  --hover: rgba(26, 33, 36, 0.07);
  --scroll-thumb: rgba(26, 33, 36, 0.24);
}

:root[data-theme="dark"] {
  --bg: #101719;
  --surface: #182124;
  --surface-alt: #11191c;
  --surface-soft: #1e2a2e;
  --border: #2b3b40;
  --text: #edf5f7;
  --muted: #a7b7bd;
  --brand-primary-soft: #123640;
  --brand-primary-hover: #6ad1ef;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.38);
  --chat-bg: linear-gradient(180deg, #182124 0%, #121b1e 100%);
  --hover: rgba(255, 255, 255, 0.08);
  --scroll-thumb: rgba(237, 245, 247, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 16% 12%, rgba(44, 189, 236, 0.12), transparent 34%),
    linear-gradient(135deg, var(--bg), var(--surface-alt));
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body[data-page="chat"] {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 36px 20px;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: var(--brand-primary-hover);
}

.start-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.start-panel {
  width: min(100%, 460px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  padding: 28px;
  box-shadow: var(--shadow);
}

body[data-widget="true"][data-page="start"] {
  background: var(--surface-alt);
}

body[data-widget="true"][data-page="start"] .start-shell {
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: clamp(20px, 5vh, 44px);
}

body[data-widget="true"][data-page="start"] .start-panel {
  width: min(100%, 440px);
  margin-top: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.brand-row,
.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.agent-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: var(--brand-primary-soft);
  color: #0e7795;
  font-size: 22px;
  font-weight: 700;
}

.agent-avatar {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--brand-primary-soft);
  object-fit: cover;
  image-rendering: auto;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

.lead {
  margin: 22px 0 24px;
  color: var(--muted);
  font-size: 15px;
}

.lead-secondary {
  margin-top: -10px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

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

.start-form label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-weight: 600;
}

.field-caption {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

.start-form .consent-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
}

.start-form .consent-row input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--brand-primary);
}

.start-form .consent-row a {
  font-weight: 600;
}

.start-form input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  outline: none;
  touch-action: manipulation;
  transition:
    border-color 120ms ease-out,
    box-shadow 120ms ease-out;
}

.start-form input {
  height: 44px;
  padding: 0 12px;
}

.start-form .consent-row input {
  width: 18px;
  height: 18px;
  padding: 0;
}

.start-form input:focus,
.composer textarea:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(44, 189, 236, 0.18);
}

.primary-button,
.send-button {
  border: 0;
  border-radius: var(--radius);
  background: var(--brand-primary);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  transition:
    background 120ms ease-out,
    opacity 120ms ease-out;
}

.primary-button {
  height: 44px;
  margin-top: 4px;
}

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

.primary-button:disabled,
.send-button:disabled {
  cursor: default;
  opacity: 0.6;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  width: min(100%, 960px);
  height: 80vh;
  min-height: 620px;
  max-height: 860px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  flex: 0 0 auto;
  min-height: 76px;
  border-bottom: 1px solid var(--border);
  padding: 12px 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
}

.chat-title {
  min-width: 0;
  flex: 1;
}

.chat-title h1 {
  font-size: 18px;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle,
.mode-toggle {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  padding: 2px;
}

.header-icon-button {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition:
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.header-icon-button:hover {
  background: var(--hover);
}

.header-icon-button:active {
  transform: scale(0.96);
}

.theme-toggle .header-icon-button[aria-pressed="true"],
.mode-toggle .header-icon-button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--brand-primary-hover);
  box-shadow: 0 1px 5px rgba(26, 33, 36, 0.12);
}

.header-icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.has-tooltip::after {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 20;
  width: max-content;
  max-width: 180px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 24px rgba(10, 20, 24, 0.18);
  color: var(--text);
  content: attr(data-tooltip);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  opacity: 0;
  padding: 8px 10px;
  pointer-events: none;
  transform: translate(-50%, -4px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
  white-space: nowrap;
}

.has-tooltip:hover::after,
.has-tooltip:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.has-tooltip::after {
  display: none;
}

.tooltip-layer {
  position: fixed;
  z-index: 9999;
  width: max-content;
  max-width: min(220px, calc(100vw - 16px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(10, 20, 24, 0.22);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  padding: 8px 10px;
  pointer-events: none;
  white-space: nowrap;
}

.tooltip-layer[hidden] {
  display: none;
}

.session-warning {
  flex: 0 0 auto;
  margin: 12px 18px 0;
  border: 1px solid #f4d1d3;
  border-radius: var(--radius);
  background: #fff7f7;
  color: var(--danger);
  padding: 10px 12px;
}

.scenario-status {
  display: none;
}

.messages-panel {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--chat-bg);
}

.chat-empty-hint {
  position: absolute;
  left: 50%;
  top: 43%;
  z-index: 0;
  max-width: min(430px, calc(100% - 40px));
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  padding: 10px 14px;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -50%);
}

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

.audio-call-panel {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--brand-primary) 14%, transparent), transparent 34%),
    color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(12px);
}

.audio-call-panel[hidden] {
  display: none;
}

.call-avatar-wrap {
  position: relative;
  display: grid;
  width: 126px;
  height: 126px;
  place-items: center;
}

.call-ring {
  position: absolute;
  inset: 10px;
  border: 1px solid color-mix(in srgb, var(--brand-primary) 45%, transparent);
  border-radius: 50%;
  opacity: 0.55;
  animation: call-ring 2.4s infinite ease-out;
}

.call-ring.ring-two {
  animation-delay: 700ms;
}

.call-avatar {
  position: relative;
  z-index: 1;
  width: 86px;
  height: 86px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 12px 34px rgba(26, 33, 36, 0.16);
  object-fit: cover;
}

.call-state {
  display: grid;
  gap: 4px;
  max-width: 460px;
  text-align: center;
}

.call-title {
  font-size: 20px;
  font-weight: 800;
}

.call-status {
  color: var(--muted);
  font-size: 14px;
}

.audio-call-panel[data-call-state="ready"] .call-status,
.audio-call-panel[data-call-state="preview"] .call-status {
  color: var(--text);
  font-weight: 650;
}

.call-wave {
  display: flex;
  height: 42px;
  align-items: center;
  gap: 5px;
}

.call-wave i {
  width: 5px;
  height: 22%;
  min-height: 8px;
  border-radius: 999px;
  background: var(--brand-primary);
  opacity: 0.35;
  transition:
    height 180ms ease,
    opacity 180ms ease;
}

.audio-call-panel.is-recording .call-wave i,
.audio-call-panel.is-sending .call-wave i,
.audio-call-panel.is-speaking .call-wave i {
  animation: call-wave 900ms infinite ease-in-out;
  opacity: 0.86;
}

.audio-call-panel.is-recording .call-wave i:nth-child(2n),
.audio-call-panel.is-sending .call-wave i:nth-child(2n),
.audio-call-panel.is-speaking .call-wave i:nth-child(2n) {
  animation-delay: 120ms;
}

.audio-call-panel.is-recording .call-wave i:nth-child(3n),
.audio-call-panel.is-sending .call-wave i:nth-child(3n),
.audio-call-panel.is-speaking .call-wave i:nth-child(3n) {
  animation-delay: 240ms;
}

.call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.call-control {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.call-control:hover {
  background: var(--hover);
}

.call-control:active {
  transform: scale(0.96);
}

.call-control:disabled {
  cursor: default;
  opacity: 0.58;
}

.call-control.primary,
.call-control.send {
  border-color: transparent;
  background: var(--brand-primary);
  color: #fff;
}

.call-control.pulse-attention {
  animation: mic-attention 1.6s infinite ease-in-out;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand-primary) 34%, transparent);
}

.audio-call-panel.is-preview .call-control.send {
  transform: scale(1.06);
}

.audio-call-panel.is-recording .call-control.send {
  background: var(--surface);
  color: var(--brand-primary-hover);
  border-color: color-mix(in srgb, var(--brand-primary) 42%, var(--border));
}

@keyframes mic-attention {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand-primary) 28%, transparent);
  }
  50% {
    box-shadow: 0 0 0 10px color-mix(in srgb, var(--brand-primary) 0%, transparent);
  }
}

.call-control.danger {
  border-color: transparent;
  background: #fff1f1;
  color: var(--danger);
}

:root[data-theme="dark"] .call-control.danger {
  background: rgba(201, 53, 59, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .call-control.danger {
    background: rgba(201, 53, 59, 0.14);
  }
}

.call-control svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

body[data-chat-mode="call"] .messages,
body[data-chat-mode="call"] .typing,
body[data-chat-mode="call"] .chat-empty-hint {
  display: none;
}

@keyframes call-ring {
  0% {
    opacity: 0.62;
    transform: scale(0.82);
  }
  100% {
    opacity: 0;
    transform: scale(1.42);
  }
}

@keyframes call-wave {
  0%,
  100% {
    height: 22%;
  }
  50% {
    height: 92%;
  }
}

.messages {
  display: flex;
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 12px 10px 18px;
  scroll-behavior: smooth;
  scrollbar-color: transparent transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.messages::before {
  content: "";
  margin-top: auto;
}

.messages:hover,
.messages:focus-within {
  scrollbar-color: var(--scroll-thumb) transparent;
}

.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: transparent;
  transition: background 180ms ease;
}

.messages:hover::-webkit-scrollbar-thumb,
.messages:focus-within::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
}

.message {
  display: grid;
  max-width: min(82%, 700px);
  gap: 4px;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  grid-template-columns: 34px minmax(0, 1fr);
  align-self: flex-start;
  align-items: end;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  object-fit: cover;
}

.message-body {
  min-width: 0;
  max-width: 100%;
}

.bubble {
  position: relative;
  box-sizing: border-box;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 13px;
  box-shadow: 0 4px 12px rgba(26, 33, 36, 0.04);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble-voice {
  min-width: 238px;
  padding: 8px 10px;
  white-space: normal;
}

.bubble-image {
  width: min(360px, 72vw);
  overflow: hidden;
  padding: 4px;
  white-space: normal;
}

.image-bubble {
  display: grid;
  gap: 7px;
}

.image-bubble-media,
.image-bubble-placeholder {
  display: block;
  width: 100%;
  max-height: 360px;
  border-radius: 13px;
  background: var(--surface-alt);
}

.image-bubble-media {
  object-fit: cover;
}

.image-bubble-placeholder {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  font-weight: 600;
}

.image-bubble-caption {
  padding: 2px 6px 5px;
  color: var(--text);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.user .bubble {
  border-color: #bfeaf7;
  background: var(--brand-primary-soft);
}

.message.assistant .bubble {
  background: var(--surface);
}

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

.message.pending {
  opacity: 0.72;
}

.voice-bubble {
  display: grid;
  grid-template-columns: 38px minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.voice-play {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--brand-primary);
  color: #fff;
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.voice-play:hover {
  background: var(--brand-primary-hover);
}

.voice-play:active {
  transform: scale(0.96);
}

.voice-play:disabled {
  cursor: wait;
  opacity: 0.68;
}

.voice-play svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.voice-pause-icon,
.voice-bubble.is-playing .voice-play-icon {
  display: none;
}

.voice-bubble.is-playing .voice-pause-icon {
  display: block;
}

.voice-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.voice-wave {
  display: flex;
  height: 24px;
  align-items: center;
  gap: 3px;
}

.voice-wave i {
  width: 3px;
  height: var(--h);
  min-height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-primary-hover) 62%, var(--muted));
  opacity: 0.78;
}

.voice-bubble.is-pending .voice-wave i {
  animation: voice-wave 900ms infinite ease-in-out;
}

.voice-bubble.is-pending .voice-wave i:nth-child(2n) {
  animation-delay: 120ms;
}

.voice-bubble.is-pending .voice-wave i:nth-child(3n) {
  animation-delay: 240ms;
}

@keyframes voice-wave {
  0%,
  100% {
    transform: scaleY(0.72);
    opacity: 0.5;
  }
  50% {
    transform: scaleY(1.12);
    opacity: 0.95;
  }
}

.voice-progress {
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 20%, transparent);
}

.voice-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand-primary);
  transition: width 120ms linear;
}

.voice-duration {
  min-width: 42px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

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

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

.typing {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 0 18px 12px;
  color: var(--muted);
  font-size: 13px;
}

.typing[hidden] {
  display: none;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  padding: 9px 12px;
  box-shadow: 0 4px 12px rgba(26, 33, 36, 0.04);
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.typing-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.38;
  animation: typing-dot 1.15s infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
  animation-delay: 140ms;
}

.typing-dots i:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes typing-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.34;
  }
  40% {
    transform: translateY(-3px);
    opacity: 0.9;
  }
}

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  background: var(--surface-alt);
}

.image-preview {
  margin-bottom: 10px;
}

.image-preview-card {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 10px;
  width: min(100%, 520px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  padding: 8px;
  box-shadow: 0 10px 28px rgba(26, 33, 36, 0.08);
}

.image-preview-card img {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
}

.image-preview-main {
  min-width: 0;
}

.image-preview-title {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.image-preview-clear {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.image-preview-clear:hover {
  background: var(--hover);
  color: var(--text);
}

.image-preview-clear svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.text-composer,
.voice-composer {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: end;
  gap: 8px;
}

.text-composer[hidden],
.voice-composer[hidden] {
  display: none;
}

.composer textarea {
  max-height: 140px;
  min-height: 40px;
  overflow-y: hidden;
  resize: none;
  border-radius: 20px;
  padding: 9px 13px;
  background: var(--surface);
  scrollbar-color: transparent transparent;
  scrollbar-width: thin;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    scrollbar-color 220ms ease;
}

.composer textarea:hover,
.composer textarea:focus {
  overflow-y: auto;
  scrollbar-color: var(--scroll-thumb) transparent;
}

.composer textarea::-webkit-scrollbar {
  width: 0;
  transition: width 220ms ease;
}

.composer textarea:hover::-webkit-scrollbar,
.composer textarea:focus::-webkit-scrollbar {
  width: 7px;
}

.composer textarea::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--scroll-thumb);
  background-clip: content-box;
}

.icon-button,
.send-button {
  display: grid;
  width: 40px;
  min-width: 40px;
  align-self: end;
  height: 40px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.icon-button {
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  background: var(--hover);
  color: var(--text);
}

.icon-button.recording {
  background: #fff1f1;
  color: var(--danger);
}

.voice-composer {
  grid-template-columns: auto 1fr auto;
}

.voice-recording-status {
  display: flex;
  min-width: 0;
  height: 40px;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  padding: 0 12px;
  color: var(--text);
}

.recording-pulse {
  position: relative;
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--danger);
}

.recording-pulse::after {
  position: absolute;
  inset: -5px;
  border-radius: inherit;
  background: var(--danger);
  content: "";
  opacity: 0.18;
  animation: record-pulse 1.2s infinite ease-out;
}

@keyframes record-pulse {
  from {
    transform: scale(0.7);
    opacity: 0.28;
  }
  to {
    transform: scale(1.7);
    opacity: 0;
  }
}

#voice-timer {
  min-width: 40px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.voice-recording-label {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

@media (max-width: 640px) {
  body[data-page="chat"] {
    display: block;
    padding: 0;
  }

  .start-shell {
    align-items: start;
    padding: 14px;
  }

  .start-panel {
    margin-top: 24px;
    padding: 20px;
  }

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

  .chat-header {
    min-height: 64px;
    padding: 10px 12px;
  }

  .agent-mark {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    font-size: 20px;
  }

  .agent-avatar {
    width: 42px;
    height: 42px;
    border-radius: 13px;
  }

  .chat-title h1 {
    font-size: 16px;
  }

  .chat-actions {
    gap: 6px;
  }

  .theme-toggle,
  .mode-toggle {
    gap: 0;
  }

  .header-icon-button {
    width: 34px;
    height: 34px;
  }

  .has-tooltip::after {
    display: none;
  }

  .ghost-link {
    padding: 6px 8px;
    font-size: 12px;
  }

  .messages {
    gap: 10px;
    padding: 14px 8px 14px 10px;
  }

  .chat-empty-hint {
    top: 42%;
    max-width: calc(100% - 28px);
    border-radius: 14px;
    font-size: 12px;
    padding: 9px 12px;
  }

  .audio-call-panel {
    gap: 14px;
    padding: 20px 16px;
  }

  .call-avatar-wrap {
    width: 108px;
    height: 108px;
  }

  .call-avatar {
    width: 76px;
    height: 76px;
    border-radius: 22px;
  }

  .call-title {
    font-size: 18px;
  }

  .call-status {
    font-size: 13px;
  }

  .call-control {
    width: 44px;
    height: 44px;
  }

  .message {
    max-width: 88%;
  }

  .message.assistant {
    max-width: 86%;
  }

  .message.assistant .message-body {
    width: calc(100vw - 92px);
  }

  .bubble-voice {
    min-width: min(238px, 76vw);
  }

  .voice-bubble {
    grid-template-columns: 36px minmax(84px, 1fr) auto;
    gap: 8px;
  }

  .message.assistant {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .message-avatar {
    width: 28px;
    height: 28px;
  }

  .composer {
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  }

  .text-composer,
  .voice-composer {
    grid-template-columns: auto 1fr auto auto;
  }

  .voice-composer {
    grid-template-columns: auto 1fr auto;
  }

  .bubble-image {
    width: min(300px, 78vw);
  }

  .image-bubble-media,
  .image-bubble-placeholder {
    max-height: 280px;
  }

  .composer textarea {
    max-height: 112px;
    min-height: 38px;
    padding: 8px 12px;
  }

  .icon-button,
  .send-button {
    width: 38px;
    min-width: 38px;
    height: 38px;
  }

  .send-button {
    width: 38px;
  }
}

@media (min-width: 641px) and (max-height: 760px) {
  body[data-page="chat"] {
    padding: 18px;
  }

  .chat-shell {
    height: 86vh;
    min-height: 0;
  }
}

body[data-widget="true"][data-page="chat"] {
  display: block;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
  background: var(--surface-alt);
}

body[data-widget="true"][data-page="chat"] .chat-shell {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--surface-alt);
  box-shadow: none;
}
