/* Chat Page Styles */

.chat-page-layout {
  display: flex;
  /* dvh tracks the visible viewport on iOS Safari as the URL bar expands/
     collapses; vh fallback for older browsers. */
  height: calc(100vh - 20px);
  height: calc(100dvh - 20px);
  gap: 0;
  padding: 10px;
  position: relative;
  box-sizing: border-box;
}

/* Force full width through the parent chain */
.app-content main:has(.chat-page-layout),
.app-content .user-container:has(.chat-page-layout) {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: none !important;
  padding: 0 !important;
  margin: 0 !important;
  width: 100%;
}

.user-container:has(.chat-page-layout) .chat-page-layout {
  flex: 1;
  width: 100%;
}

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 998;
}

.sidebar-overlay.active {
  display: block;
}

/* Client sidebar */
.client-sidebar {
  width: 280px;
  min-width: 220px;
  background: var(--card-bg, #fff);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999;
}

.client-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
}

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

.client-sidebar-header h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-primary, #333);
}

.client-sidebar-subtitle {
  margin: 4px 0 0 0;
  font-size: 0.75rem;
  color: var(--text-secondary, #666);
  line-height: 1.3;
}

.client-sidebar-actions {
  display: flex;
  gap: 4px;
}

.sidebar-close-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text-secondary, #666);
}

.client-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.client-list-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary, #888);
  font-size: 0.9rem;
}

.client-list-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary, #888);
  font-size: 0.9rem;
}

.client-list-empty p {
  margin: 0 0 8px 0;
}

.client-list-empty a {
  color: #3F8CFF;
  text-decoration: underline;
}

.client-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.client-item:hover {
  background: var(--bg-secondary, #f5f5f5);
}

.client-item.selected {
  background: rgba(63, 140, 255, 0.1);
  border: 1px solid rgba(63, 140, 255, 0.3);
}

.client-item.offline {
  opacity: 0.6;
}

.client-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.client-status-dot.online {
  background: #51cf66;
}

.client-status-dot.offline {
  background: #adb5bd;
}

.client-info {
  flex: 1;
  min-width: 0;
}

.client-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary, #333);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-meta {
  font-size: 0.75rem;
  color: var(--text-secondary, #888);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-clear-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.client-item:hover .client-clear-btn,
.client-item.selected .client-clear-btn {
  opacity: 0.6;
}

.client-clear-btn:hover {
  opacity: 1 !important;
}

/* Chat main area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

.chat-header-card {
  background: var(--card-bg, #fff);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.chat-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.chat-header-content {
  flex: 1;
}

.chat-header-card h2 {
  margin: 0 0 8px 0;
  font-size: 1.25rem;
  color: var(--text-primary, #333);
}

.chat-header-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary, #666);
}

.mobile-sidebar-toggle {
  display: none;
  background: #3F8CFF;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.mobile-sidebar-toggle:hover {
  background: #e03e00;
}

.chat-connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color, #e0e0e0);
}

.clear-chat-btn {
  background: transparent;
  border: 1px solid rgba(63, 140, 255, 0.3);
  color: #3F8CFF;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1;
}

.clear-chat-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.clear-chat-modal .modal-content {
  max-width: 420px;
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ccc;
}

.connection-dot.connected {
  background: #51cf66;
}

.connection-dot.connecting {
  background: #fcc419;
  animation: pulse 1s infinite;
}

.connection-dot.disconnected {
  background: #ff6b6b;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.connection-text {
  font-size: 0.85rem;
  color: var(--text-secondary, #666);
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card-bg, #fff);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow: hidden;
  min-height: 300px;
  position: relative;
}

.scroll-to-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 16px;
  z-index: 10;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-secondary, #999);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease;
  pointer-events: none;
  padding: 0;
}

.scroll-to-bottom-btn.visible {
  opacity: 0.7;
  transform: translateY(0);
  pointer-events: auto;
}

.scroll-to-bottom-btn:hover {
  opacity: 1;
  color: var(--text-primary, #333);
}

.chat-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-secondary, #fafafa);
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  font-size: 0.85rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.chat-message.user {
  align-self: flex-end;
  background: linear-gradient(180deg, #4F97FF 0%, #3578E5 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.08),
    0 1px 2px rgba(53, 120, 229, 0.18),
    0 4px 12px rgba(53, 120, 229, 0.22);
}

.chat-message.assistant {
  align-self: flex-start;
  background: #ffffff;
  color: var(--text-primary, #333);
  border-bottom-left-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.04),
    0 2px 4px rgba(15, 23, 42, 0.04),
    0 8px 16px -4px rgba(15, 23, 42, 0.10),
    0 20px 32px -12px rgba(15, 23, 42, 0.06);
}

.chat-message.system {
  align-self: center;
  background: transparent;
  color: var(--text-secondary, #888);
  font-size: 0.85rem;
  font-style: italic;
}

.chat-message.error {
  align-self: center;
  background: #fff5f5;
  color: #c92a2a;
  border: 1px solid #ffc9c9;
}

.chat-message.agent-thinking {
  align-self: flex-start;
  background: transparent;
  color: var(--text-secondary, #888);
  font-size: 0.85rem;
  font-style: italic;
  padding: 6px 12px;
}

.chat-message.agent-thinking .thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chat-message.agent-thinking strong {
  font-style: normal;
  color: var(--text-primary, #333);
}

.chat-message pre {
  background: rgba(0,0,0,0.1);
  padding: 8px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.85rem;
}

.chat-message.assistant pre {
  background: rgba(0,0,0,0.05);
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
}

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

.message-meta {
  font-size: 0.7rem;
  text-transform: none;
  font-weight: 500;
  opacity: 0.7;
}

.message-summary {
  font-size: 0.9rem;
  line-height: 1.4;
  margin-bottom: 6px;
  white-space: pre-line;
}

/* Markdown-rendered assistant messages */
.message-summary.markdown-body {
  white-space: normal;
}

.message-summary.markdown-body h1,
.message-summary.markdown-body h2,
.message-summary.markdown-body h3,
.message-summary.markdown-body h4 {
  margin: 0.6em 0 0.3em;
  line-height: 1.3;
}

.message-summary.markdown-body h1 { font-size: 1.2em; }
.message-summary.markdown-body h2 { font-size: 1.1em; }
.message-summary.markdown-body h3 { font-size: 1.0em; }

.message-summary.markdown-body p {
  margin: 0.4em 0;
}

.message-summary.markdown-body ul,
.message-summary.markdown-body ol {
  margin: 0.4em 0;
  padding-left: 1.5em;
}

.message-summary.markdown-body li {
  margin: 0.2em 0;
}

.message-summary.markdown-body code {
  background: rgba(0, 0, 0, 0.08);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.88em;
}

.message-summary.markdown-body pre {
  background: rgba(0, 0, 0, 0.06);
  padding: 10px 14px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.5em 0;
}

.message-summary.markdown-body pre code {
  background: transparent;
  padding: 0;
}

.message-summary.markdown-body blockquote {
  border-left: 3px solid rgba(0, 0, 0, 0.2);
  margin: 0.5em 0;
  padding: 0.2em 0.8em;
  color: inherit;
  opacity: 0.85;
}

.message-summary.markdown-body table {
  border-collapse: collapse;
  margin: 0.5em 0;
  width: 100%;
}

.message-summary.markdown-body th,
.message-summary.markdown-body td {
  border: 1px solid rgba(0, 0, 0, 0.15);
  padding: 6px 10px;
  text-align: left;
}

.message-summary.markdown-body th {
  font-weight: 600;
  background: rgba(0, 0, 0, 0.04);
}

.message-summary.markdown-body > *:first-child {
  margin-top: 0;
}

.message-summary.markdown-body > *:last-child {
  margin-bottom: 0;
}

.message-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-success {
  background: rgba(81, 207, 102, 0.15);
  color: #2f9e44;
}

.badge-failure {
  background: rgba(255, 107, 107, 0.2);
  color: #c92a2a;
}

.json-toggle {
  background: none;
  border: none;
  color: #8a8886;
  padding: 2px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.15s;
  vertical-align: middle;
}

.json-toggle:hover {
  color: #3F8CFF;
  background: rgba(63, 140, 255, 0.08);
}

.chat-message.user .json-toggle {
  color: rgba(255, 255, 255, 0.6);
}

.chat-message.user .json-toggle:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

.json-toggle.open {
  color: #3F8CFF;
}

.json-content {
  margin-top: 8px;
}

.json-content.hidden {
  display: none;
}

/* Tool list styles */
.tools-list {
  white-space: pre-line;
}

.tools-section {
  margin-bottom: 8px;
}

.tools-section:last-child {
  margin-bottom: 0;
}

.tool-item {
  margin: 2px 0;
}

.tool-link {
  color: #2196F3;
  background: rgba(33, 150, 243, 0.1);
  padding: 1px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tool-link:hover {
  background: rgba(33, 150, 243, 0.25);
  color: #1565C0;
}

.chat-message.event-bubble {
  padding: 8px 12px;
  font-size: 0.85rem;
  border-radius: 10px;
}

.chat-message.script-log-line {
  align-self: flex-start;
  background: none;
  border: none;
  padding: 2px 8px;
  margin: 1px 0;
  font-size: 0.8rem;
  color: #aaa;
  cursor: pointer;
  border-radius: 4px;
  max-width: 100%;
  transition: color 0.15s;
}

.chat-message.script-log-line:hover {
  color: #666;
}

.chat-message.script-log-line .script-log-text {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-message.script-log-line .json-content {
  margin-top: 4px;
  font-size: 0.75rem;
  color: #888;
}

.chat-message.result-compact {
  padding: 8px 12px;
  font-size: 0.88rem;
}

.chat-message.result-compact .message-header {
  margin-bottom: 2px;
  font-size: 0.72rem;
}

.chat-message.result-compact .message-summary {
  margin-bottom: 4px;
}

.chat-input-wrapper {
  position: relative;
  border-top: 1px solid var(--border-color, #e0e0e0);
  background: var(--bg-secondary, #fafafa);
}

.running-script-indicator {
  position: absolute;
  bottom: 100%;
  left: 16px;
  background: #3F8CFF;
  color: white;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 6px 6px 0 0;
  display: none;
  white-space: nowrap;
  gap: 6px;
  align-items: center;
}

.running-script-indicator .stop-script-btn {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  /* Bottom padding extends with the iPhone home-indicator safe area so the
     send button never sits underneath it. */
  padding: 16px 20px max(16px, env(safe-area-inset-bottom));
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border-color, #ddd);
  border-radius: 8px;
  font-size: 0.95rem;
  resize: none;
  min-height: 44px;
  max-height: 68px;
  font-family: inherit;
  overflow-y: auto;
}

.chat-input:focus {
  outline: none;
  border-color: #3F8CFF;
  box-shadow: 0 0 0 2px rgba(63, 140, 255, 0.1);
}

.platform-page .chat-send-btn {
  padding: 0;
  background: #3F8CFF;
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.chat-send-btn:hover:not(:disabled) {
  opacity: 0.85;
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Send button with icon (no text) */
.chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.chat-send-btn svg {
  display: block;
}

/* Speaking state — stop button */
.chat-send-btn #sendBtnStop {
  fill: white;
}

/* Recording state — send button pulses red */
.chat-send-btn.recording {
  background: #e53935;
  animation: recording-pulse 1s ease-in-out infinite;
}

.chat-send-btn.recording svg {
  stroke: white;
}

/* Processing state — the mic icon stays visible and gently "breathes" while
   we wait for the AI. The in-chat thinking indicator carries the real
   progress feedback; the button just rests, non-interactive. */
.chat-send-btn.processing {
  pointer-events: none;
}
.chat-send-btn.processing #sendBtnMic {
  animation: send-btn-mic-pulse 1.4s ease-in-out infinite;
}
@keyframes send-btn-mic-pulse {
  0%, 100% { opacity: 1;    transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.92); }
}

/* Recording state — textarea subtle red pulse */
.chat-input.recording {
  animation: textarea-recording-pulse 1.5s ease-in-out infinite;
}

@keyframes textarea-recording-pulse {
  0%, 100% {
    border-color: rgba(229, 57, 53, 0.3);
    box-shadow: 0 0 0 1px rgba(229, 57, 53, 0.08);
  }
  50% {
    border-color: rgba(229, 57, 53, 0.6);
    box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.12);
  }
}

@keyframes recording-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Attach button */
.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid var(--border-color, #ddd);
  border-radius: 8px;
  color: var(--text-secondary, #888);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s, border-color 0.2s;
}
.attach-btn:hover {
  color: #3F8CFF;
  border-color: #3F8CFF;
}

/* Attachment preview strip */
.attachment-preview {
  display: flex;
  gap: 8px;
  padding: 8px 20px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  background: var(--bg-secondary, #fafafa);
}
.attachment-preview-item {
  position: relative;
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #ddd);
  overflow: hidden;
  background: var(--bg-primary, #fff);
  display: flex;
  align-items: center;
  justify-content: center;
}
.attachment-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.attachment-preview-item .pdf-icon {
  font-size: 0.7rem;
  color: var(--text-secondary, #888);
  text-align: center;
  padding: 4px;
  word-break: break-all;
  line-height: 1.2;
}
.attachment-preview-item .pdf-icon-label {
  display: block;
  font-size: 1.2rem;
  margin-bottom: 2px;
}
.attachment-remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Attachment thumbnails in sent messages */
.message-attachments {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.message-attachment-thumb {
  width: 80px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.2);
  cursor: pointer;
}
.message-attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.message-attachment-pdf {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.12);
  color: inherit;
  text-decoration: none;
  font-size: 0.85rem;
  line-height: 1.2;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.message-attachment-pdf:hover,
.message-attachment-pdf:focus-visible {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.4);
  text-decoration: none;
  color: inherit;
}
.message-attachment-pdf:visited,
.message-attachment-pdf:active {
  color: inherit;
}
.message-attachment-pdf .attachment-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  opacity: 0.85;
}
.message-attachment-pdf .attachment-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.message-attachment-pdf .attachment-size {
  font-size: 0.75rem;
  opacity: 0.7;
  white-space: nowrap;
  flex: 0 0 auto;
}
.chat-message.assistant .message-attachment-thumb {
  border-color: var(--border-color, #ddd);
}
.chat-message.assistant .message-attachment-pdf {
  background: rgba(0,0,0,0.05);
  border-color: rgba(0,0,0,0.12);
}
.chat-message.assistant .message-attachment-pdf:hover,
.chat-message.assistant .message-attachment-pdf:focus-visible {
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.18);
}

/* Drag-and-drop overlay */
.chat-container.drag-over::after {
  content: 'Drop files here';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(63, 140, 255, 0.15);
  border: 2px dashed #3F8CFF;
  border-radius: 12px;
  color: #3F8CFF;
  font-size: 1.1rem;
  font-weight: 600;
  z-index: 10;
  pointer-events: none;
}

/* Voice message styles */
.voice-message-container {
  border-radius: 8px;
  padding: 0;
  max-width: 240px;
}

.voice-audio {
  width: 100%;
  height: 24px;
  margin-bottom: 0;
  background: #ffd2bf;
  border: 1px solid #ff9a73;
  border-radius: 6px;
  accent-color: #ff9a73;
}

.voice-audio::-webkit-media-controls-panel {
  background: #ffd2bf;
}

.voice-transcription {
  font-size: 0.85rem;
  color: #fff;
  line-height: 1.4;
  padding: 0;
  background: #3F8CFF;
  border-radius: 6px;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary, #888);
  text-align: center;
  padding: 40px;
}

.chat-empty h3 {
  margin: 0 0 8px 0;
  font-size: 1.1rem;
  color: var(--text-primary, #555);
}

.chat-empty p {
  margin: 0;
  font-size: 0.9rem;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #888;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Chat-specific mobile nav toggle in status bar (hidden on desktop) */
.chat-mobile-nav-toggle {
  display: none;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
  .chat-mobile-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none !important;
    border: none !important;
    box-shadow: none;
    cursor: pointer;
    color: var(--text-secondary, #666);
    padding: 2px;
    margin-right: 4px;
    flex-shrink: 0;
    border-radius: 0;
  }

  .chat-mobile-nav-toggle:hover {
    color: var(--text-primary, #333);
    border: none !important;
    background: none !important;
  }
  .chat-page-layout {
    padding: 0;
    gap: 0;
    height: 100vh;
    height: 100dvh;
  }

  .client-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }

  .client-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: block;
  }

  .mobile-sidebar-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 8px;
  }

  .chat-main {
    width: 100%;
  }

  .chat-header-card {
    padding: 12px 16px;
    margin-bottom: 0;
    border-radius: 0;
  }

  .chat-header-card h2 {
    font-size: 1.1rem;
  }

  .chat-header-card p {
    font-size: 0.85rem;
  }

  .chat-header-card > p {
    display: none;
  }

  .chat-container {
    border-radius: 0;
    box-shadow: none;
  }

  .chat-messages {
    padding: 8px;
    gap: 8px;
  }

  .chat-message {
    max-width: 100%;
    padding: 10px 12px;
    font-size: 0.9rem;
    border-radius: 8px;
  }

  .chat-message.user {
    border-bottom-right-radius: 4px;
  }

  .chat-message.assistant {
    border-bottom-left-radius: 4px;
  }

  .chat-input-area {
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  .chat-input {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .chat-send-btn {
    padding: 10px 16px;
    font-size: 0.9rem;
  }

  .chat-empty {
    padding: 20px;
  }

  .chat-empty h3 {
    font-size: 1rem;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .chat-header-row {
    flex-direction: column;
    gap: 8px;
  }

  .mobile-sidebar-toggle {
    width: 100%;
    justify-content: center;
  }

  .chat-messages {
    padding: 6px;
  }

  .chat-message {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .chat-send-btn {
    padding: 10px 12px;
  }

  .chat-input-area {
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
  }
}

/* ========================================
   Voice Mode Styles
   ======================================== */

/* Mode toggle buttons */
.chat-mode-toggle {
  display: flex;
  gap: 2px;
  margin-left: auto;
  background: none;
  padding: 0;
}

.platform-page .mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  border: none;
  background: none;
  border-radius: 4px;
  cursor: pointer;
  color: #8a8886;
  padding: 4px;
  transition: color 0.15s;
}

.mode-btn:hover {
  color: #3F8CFF;
  background: none;
}

.mode-btn.active {
  color: #3F8CFF;
  background: none;
  box-shadow: none;
}

/* Voice input area */
.voice-input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  gap: 16px;
  min-height: 160px;
}

/* Voice visualization orb */
.voice-visualization {
  position: relative;
  width: 80px;
  height: 80px;
}

.voice-orb {
  position: relative;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  outline: none;
}

.orb-inner {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #3F8CFF 0%, #6B5BFF 100%);
  border-radius: 50%;
  transition: transform 0.3s, box-shadow 0.3s;
  box-shadow: 0 0 0 3px rgba(63, 140, 255, 0.2);
}

.voice-orb:hover .orb-inner {
  box-shadow: 0 0 0 3px rgba(63, 140, 255, 0.4);
  transform: scale(1.05);
}

.voice-orb:active .orb-inner {
  transform: scale(0.95);
  box-shadow: 0 0 0 3px rgba(63, 140, 255, 0.6), 0 0 15px rgba(63, 140, 255, 0.3);
}

.voice-orb.disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.voice-orb.disabled .orb-inner {
  box-shadow: 0 0 0 3px rgba(128, 128, 128, 0.2);
}

.voice-orb.disabled:hover .orb-inner {
  transform: none;
  box-shadow: 0 0 0 3px rgba(128, 128, 128, 0.2);
}

.orb-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(63, 140, 255, 0.3);
  opacity: 0;
  transition: opacity 0.3s;
}

.ring-1 { width: 50px; height: 50px; }
.ring-2 { width: 62px; height: 62px; }
.ring-3 { width: 76px; height: 76px; }

/* Listening state - user is speaking */
.voice-orb.listening .orb-inner {
  transform: scale(1.1);
  box-shadow: 0 0 20px rgba(63, 140, 255, 0.5);
}

.voice-orb.listening .orb-ring {
  opacity: 1;
  animation: pulse-ring 1.5s ease-out infinite;
}

.voice-orb.listening .ring-2 {
  animation-delay: 0.2s;
}

.voice-orb.listening .ring-3 {
  animation-delay: 0.4s;
}

@keyframes pulse-ring {
  0% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0;
  }
}

/* Speaking state - AI is talking */
.voice-orb.speaking .orb-inner {
  background: linear-gradient(135deg, #51cf66 0%, #20c997 100%);
  animation: speaking-pulse 0.8s ease-in-out infinite;
}

.voice-orb.speaking .orb-ring {
  border-color: rgba(81, 207, 102, 0.3);
  opacity: 1;
  animation: speaking-ring 1.2s ease-in-out infinite;
}

.voice-orb.speaking .ring-2 {
  animation-delay: 0.15s;
}

.voice-orb.speaking .ring-3 {
  animation-delay: 0.3s;
}

@keyframes speaking-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 10px rgba(81, 207, 102, 0.3);
  }
  50% {
    transform: scale(1.15);
    box-shadow: 0 0 25px rgba(81, 207, 102, 0.5);
  }
}

@keyframes speaking-ring {
  0%, 100% {
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0.5;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.05);
    opacity: 1;
  }
}

/* Interrupt hint - shown when AI is speaking */
.orb-interrupt-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 18px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.orb-interrupt-hint span {
  color: rgba(0, 0, 0, 0.6);
  font-size: 10px;
  line-height: 1;
}

.voice-orb.speaking .orb-interrupt-hint {
  opacity: 1;
  animation: interrupt-hint-pulse 1.5s ease-in-out infinite;
}

@keyframes interrupt-hint-pulse {
  0%, 100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

/* Processing state */
.voice-orb.processing .orb-inner {
  background: linear-gradient(135deg, #fcc419 0%, #fab005 100%);
  animation: processing-spin 2s linear infinite;
}

@keyframes processing-spin {
  0% {
    transform: scale(1) rotate(0deg);
  }
  50% {
    transform: scale(1.05) rotate(180deg);
  }
  100% {
    transform: scale(1) rotate(360deg);
  }
}

/* Voice status text */
.voice-status {
  font-size: 0.9rem;
  color: var(--text-secondary, #666);
  text-align: center;
  min-height: 1.4em;
}

.voice-status.error {
  color: #e03131;
}

/* Hide text input area in voice mode */
.chat-input-wrapper.voice-mode .chat-input-area {
  display: none;
}

.chat-input-wrapper.voice-mode .voice-input-area {
  display: flex;
}

/* Mobile responsive for voice mode */
@media (max-width: 768px) {
  .voice-input-area {
    padding: 16px;
    min-height: 140px;
  }

  .voice-visualization {
    width: 60px;
    height: 60px;
  }

  .voice-orb {
    width: 60px;
    height: 60px;
  }

  .orb-inner {
    width: 30px;
    height: 30px;
  }

  .ring-1 { width: 38px; height: 38px; }
  .ring-2 { width: 48px; height: 48px; }
  .ring-3 { width: 58px; height: 58px; }

  .orb-interrupt-hint {
    width: 14px;
    height: 14px;
  }

  .orb-interrupt-hint span {
    font-size: 8px;
  }
}
