:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f7f8fa;
  --surface-strong: #eef1f5;
  --border: #dfe3e8;
  --border-strong: #c9d0d8;
  --text: #16191d;
  --muted: #68717d;
  --blue: #135fc4;
  --blue-dark: #0d4794;
  --blue-soft: #eaf2fd;
  --green: #147a4d;
  --green-soft: #eaf7f0;
  --amber: #a45d08;
  --amber-soft: #fff5df;
  --red: #b42318;
  --red-soft: #fff0ee;
  --shadow: 0 12px 32px rgba(19, 31, 47, 0.12);
  font-family:
    "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  letter-spacing: 0;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(19, 95, 196, 0.24);
  outline-offset: 2px;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.brand-code {
  color: var(--blue);
  font-size: 23px;
  line-height: 1;
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  line-height: 1.2;
  font-weight: 650;
  white-space: nowrap;
}

.topbar-actions,
.voice-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 98px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  background: #fff;
}

.status-indicator[data-state="connecting"] {
  color: var(--amber);
}

.status-indicator[data-state="connecting"] .status-dot {
  border-color: var(--amber);
  animation: status-pulse 1.3s ease-in-out infinite;
}

.status-indicator[data-state="connected"] {
  color: var(--green);
}

.status-indicator[data-state="connected"] .status-dot {
  border-color: var(--green);
  background: var(--green);
}

.status-indicator[data-state="error"] {
  color: var(--red);
}

.status-indicator[data-state="error"] .status-dot {
  border-color: var(--red);
  background: var(--red);
}

@keyframes status-pulse {
  50% {
    opacity: 0.35;
  }
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: #4b5562;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  color: var(--blue);
  border-color: #9bbce7;
  background: var(--blue-soft);
}

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

.app-shell {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  background: var(--bg);
}

.conversation-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-right: 1px solid var(--border);
}

.pane-header {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

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

.pane-header h1 {
  font-size: 18px;
  line-height: 1.35;
  font-weight: 700;
}

.turn-status {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px max(24px, calc((100% - 820px) / 2));
  scroll-behavior: smooth;
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  color: var(--muted);
  text-align: center;
}

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

.empty-state strong {
  color: #3d4650;
  font-size: 15px;
}

.empty-state span {
  max-width: 280px;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 4px;
  fill: none;
  stroke: #788391;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.message {
  width: min(76%, 640px);
  margin-bottom: 22px;
}

.message[data-role="user"] {
  margin-left: auto;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.message[data-role="user"] .message-meta {
  justify-content: flex-end;
}

.message-meta .icon {
  width: 15px;
  height: 15px;
}

.message-bubble {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message[data-role="assistant"] .message-bubble {
  border-color: #c8d9ef;
  background: var(--blue-soft);
}

.message[data-role="user"] .message-bubble {
  border-color: #badfca;
  background: var(--green-soft);
}

.message[data-pending="true"] .message-bubble::after {
  display: inline-block;
  width: 5px;
  height: 16px;
  margin-left: 4px;
  vertical-align: -3px;
  background: currentColor;
  content: "";
  animation: cursor-blink 0.8s steps(1) infinite;
}

@keyframes cursor-blink {
  50% {
    opacity: 0;
  }
}

.interaction-dock {
  padding:
    10px max(20px, calc((100% - 820px) / 2))
    max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: #fff;
}

.waveform {
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-bottom: 8px;
  overflow: hidden;
}

.waveform span {
  width: 3px;
  height: 4px;
  border-radius: 1px;
  background: #b8c0ca;
  transform: scaleY(var(--wave-scale, 1));
  transition:
    transform 90ms linear,
    background-color 180ms ease;
}

.waveform[data-active="true"] span {
  background: var(--blue);
}

.voice-controls {
  justify-content: center;
  margin-bottom: 10px;
}

.call-button {
  min-width: 150px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 18px;
  color: #fff;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  font-weight: 650;
  cursor: pointer;
}

.call-button:hover:not(:disabled) {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
}

.call-button[data-active="true"] {
  border-color: var(--red);
  background: var(--red);
}

.call-button:disabled {
  cursor: wait;
  opacity: 0.66;
}

.call-button .icon-stop,
.call-button[data-active="true"] .icon-start {
  display: none;
}

.call-button[data-active="true"] .icon-stop {
  display: block;
}

.control-button[aria-pressed="true"] {
  color: var(--red);
  border-color: #e9aaa4;
  background: var(--red-soft);
}

.control-button .icon-off,
.control-button[aria-pressed="true"] .icon-on {
  display: none;
}

.control-button[aria-pressed="true"] .icon-off {
  display: block;
}

.composer {
  height: 46px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
}

.composer:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(19, 95, 196, 0.1);
}

.composer input {
  min-width: 0;
  height: 100%;
  padding: 0 14px;
  color: var(--text);
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
}

.composer input::placeholder {
  color: #929aa4;
}

.send-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #fff;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  cursor: pointer;
}

.send-button:disabled {
  color: #98a0aa;
  background: var(--surface-strong);
  cursor: not-allowed;
}

.diagnostics-pane {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  background: var(--surface);
}

.diagnostics-header,
.event-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.diagnostics-header h2 {
  font-size: 16px;
}

.diagnostics-close,
.diagnostics-toggle {
  display: none;
}

.diagnostics-list {
  margin: 20px 0 26px;
}

.diagnostics-list > div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.diagnostics-list dt {
  color: var(--muted);
  font-size: 12px;
}

.diagnostics-list dd {
  min-width: 0;
  margin: 0;
  color: #303841;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.event-log-header h3 {
  font-size: 14px;
}

.event-log {
  max-height: 360px;
  margin: 12px 0 0;
  padding: 0;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  list-style: none;
}

.event-log li {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  color: #4f5965;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 11px;
  line-height: 1.4;
}

.event-log li span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.event-log time {
  color: #8a929c;
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: grid;
  gap: 10px;
  pointer-events: none;
}

.toast {
  width: min(380px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  padding: 13px 14px;
  color: #5b231d;
  border: 1px solid #efb6b0;
  border-radius: 8px;
  background: var(--red-soft);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.5;
  pointer-events: auto;
}

.toast .icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.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: 900px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .conversation-pane {
    border-right: 0;
  }

  .diagnostics-toggle,
  .diagnostics-close {
    display: inline-grid;
  }

  .diagnostics-pane {
    position: fixed;
    top: 68px;
    right: 0;
    bottom: 0;
    z-index: 30;
    width: min(360px, 92vw);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(105%);
    transition: transform 220ms ease;
  }

  body[data-diagnostics-open="true"] .diagnostics-pane {
    transform: translateX(0);
  }
}

@media (max-width: 600px) {
  .app {
    grid-template-rows: 60px minmax(0, 1fr);
  }

  .topbar {
    padding: 0 14px;
  }

  .brand {
    gap: 8px;
  }

  .brand-code {
    font-size: 20px;
  }

  .brand-title {
    font-size: 15px;
  }

  .status-indicator {
    min-width: auto;
    font-size: 12px;
  }

  .diagnostics-pane {
    top: 60px;
  }

  .pane-header {
    min-height: 64px;
    padding: 11px 14px;
  }

  .pane-header h1 {
    font-size: 16px;
  }

  .messages {
    padding: 20px 14px;
  }

  .message {
    width: 88%;
  }

  .message-bubble {
    font-size: 14px;
  }

  .interaction-dock {
    padding:
      8px 12px
      max(12px, env(safe-area-inset-bottom));
  }

  .waveform {
    height: 26px;
    margin-bottom: 6px;
  }

  .call-button {
    min-width: 134px;
  }

  .voice-controls {
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
