/* ============================================
   Chat Redesign - Telegram-style Components
   Version: 1.0
   Date: 2026-01-10
   ============================================ */

/* ========================================
   CSS Variables for Chat
   ======================================== */
:root {
  /* Message bubbles - STRICT TELEGRAM STYLE */
  /* User bubble (LEFT side) - Light blue tint like Telegram incoming */
  --chat-bubble-user-bg: rgba(70, 130, 180, 0.18);
  --chat-bubble-user-border: rgba(70, 130, 180, 0.35);
  
  /* Bot bubble (RIGHT side) - Dark gray like Telegram outgoing */
  --chat-bubble-bot-bg: rgba(255, 255, 255, 0.10);
  --chat-bubble-bot-border: rgba(255, 255, 255, 0.18);
  
  /* Text colors - High contrast for readability */
  --chat-text-primary: rgba(255, 255, 255, 0.96);
  --chat-text-secondary: rgba(255, 255, 255, 0.70);
  --chat-text-timestamp: rgba(255, 255, 255, 0.50);
  
  /* Chat list */
  --chat-list-item-bg: rgba(255, 255, 255, 0.05);
  --chat-list-item-hover-bg: rgba(255, 255, 255, 0.10);
  --chat-list-item-active-bg: rgba(47, 107, 255, 0.12);
  --chat-list-item-border: rgba(255, 255, 255, 0.08);
  
  /* Unread badge */
  --chat-badge-bg: rgba(34, 211, 238, 1);
  --chat-badge-text: rgba(0, 0, 0, 0.9);
  
  /* Header */
  --chat-header-bg: rgba(255, 255, 255, 0.10);
  --chat-header-border: rgba(255, 255, 255, 0.15);
  
  /* Input bar */
  --chat-input-bg: rgba(255, 255, 255, 0.10);
  --chat-input-border: rgba(255, 255, 255, 0.25);
  --chat-input-focus-border: rgba(47, 107, 255, 0.6);
  
  /* Context menu */
  --chat-menu-bg: rgba(20, 25, 35, 0.95);
  --chat-menu-border: rgba(255, 255, 255, 0.2);
  --chat-menu-item-hover: rgba(255, 255, 255, 0.15);
  
  /* Dimensions */
  --chat-avatar-size: 40px;
  --chat-avatar-size-sm: 36px;
  --chat-header-height: 56px;
  --chat-input-height: 50px;
  --chat-bubble-padding-x: 14px;
  --chat-bubble-padding-y: 10px;
  --chat-bubble-radius: 18px;
  --chat-bubble-max-width: 75%;
  --chat-bubble-shadow-incoming: 0 10px 24px rgba(7, 13, 28, 0.22);
  --chat-bubble-shadow-outgoing: 0 14px 26px rgba(14, 36, 90, 0.20);
  
  /* Spacing - TELEGRAM STYLE: More vertical air */
  --chat-message-gap: 10px;
  --chat-message-same-sender-gap: 6px;
  --chat-list-item-gap: 4px;

  /* Floating back button positioning */
  --bottom-nav-height: 0px;
  --chat-floating-nav-clearance: 12px;
  --chat-floating-offset-bottom-base: 80px;
  --chat-floating-offset-bottom: calc(var(--chat-floating-offset-bottom-base) + env(safe-area-inset-bottom, 0px));
}

/* ========================================
   Chat Container
   ======================================== */
.chat-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100dvh;
  height: var(--app-viewport-height, var(--tg-viewport-stable-height, 100dvh));
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: transparent;
  overflow: hidden;
  z-index: 10;
}

.chat-container--embedded {
  position: relative;
  inset: auto;
  height: auto;
  max-width: 100%;
  margin: 0;
  z-index: auto;
  --chat-floating-offset-bottom-base: 24px;
  --chat-floating-offset-bottom: calc(var(--chat-floating-offset-bottom-base) + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 767.98px) {
  .chat-container--embedded {
    width: 100%;
    max-width: none;
  }
}

@media (min-width: 768px) {
  .chat-container {
    max-width: var(--layout-max-width);
  }
}

/* ========================================
   Chat List View
   ======================================== */
.chat-list-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-list-view.is-hidden {
  display: none;
}

.chat-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--chat-header-height);
  padding: 0 var(--space-lg);
  background: var(--chat-header-bg);
  backdrop-filter: blur(var(--blur-nav));
  border-bottom: 1px solid var(--chat-header-border);
  flex-shrink: 0;
}

.chat-list-header h1 {
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--chat-text-primary);
}

.chat-list-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Chat List Item */
.chat-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--chat-list-item-bg);
  border-bottom: 1px solid var(--chat-list-item-border);
  cursor: pointer;
  transition: background 180ms ease;
  -webkit-user-select: none;
  user-select: none;
}

.chat-list-item:hover {
  background: var(--chat-list-item-hover-bg);
}

.chat-list-item:active {
  background: var(--chat-list-item-active-bg);
}

.chat-list-item.is-active {
  background: var(--chat-list-item-active-bg);
}

/* Avatar */
.chat-avatar {
  width: var(--chat-avatar-size);
  height: var(--chat-avatar-size);
  border-radius: 50%;
  background: var(--glass-card-bg);
  border: 1px solid var(--glass-card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: var(--color-accent-cyan);
  flex-shrink: 0;
  overflow: hidden;
}

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

.chat-avatar-sm {
  width: var(--chat-avatar-size-sm);
  height: var(--chat-avatar-size-sm);
  font-size: 14px;
}

/* Chat List Item Info */
.chat-list-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-list-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.chat-list-item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--chat-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list-item-time {
  font-size: 13px;
  color: var(--chat-text-timestamp);
  flex-shrink: 0;
}

.chat-list-item-preview {
  font-size: 14px;
  color: var(--chat-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.chat-list-item-preview.is-unread {
  font-weight: 500;
  color: var(--chat-text-primary);
}

/* Unread Badge */
.chat-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--chat-badge-bg);
  color: var(--chat-badge-text);
  font-size: 12px;
  font-weight: 700;
  border-radius: 10px;
  flex-shrink: 0;
}

/* ========================================
   Chat Dialog View
   ======================================== */
.chat-dialog-view {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  --chat-bottom-controls-height: calc(var(--chat-input-height) + (var(--space-md) * 2) + 8px);
  --chat-floating-offset-bottom-base: max(
    var(--chat-bottom-controls-height),
    calc(var(--bottom-nav-height) + var(--chat-floating-nav-clearance))
  );
  --chat-floating-offset-bottom: calc(var(--chat-floating-offset-bottom-base) + env(safe-area-inset-bottom, 0px));
}

.chat-dialog-view:has(.ai-reply-panel:not(.is-hidden)) {
  --chat-bottom-controls-height: calc(var(--chat-input-height) + (var(--space-md) * 2) + 190px);
}

.chat-dialog-view.is-hidden {
  display: none;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  height: var(--chat-header-height);
  padding: 0 var(--space-lg);
  background: var(--chat-header-bg);
  backdrop-filter: blur(var(--blur-nav));
  border-bottom: 1px solid var(--chat-header-border);
  flex-shrink: 0;
  z-index: 10;
}

/* Reusable back button with ⬅️ icon */
.chat-back-btn,
.chat-header-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--color-accent-cyan);
  cursor: pointer;
  transition: background 180ms ease;
  flex-shrink: 0;
}

.chat-back-btn svg,
.chat-header-back svg {
  width: 20px;
  height: 20px;
}

.chat-back-btn:hover,
.chat-header-back:hover {
  background: rgba(255, 255, 255, 0.08);
}

.chat-back-btn:active,
.chat-header-back:active {
  background: rgba(255, 255, 255, 0.12);
}

.chat-back-btn.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.chat-back-btn.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Username displayed ONLY in header */
.chat-username,
.chat-header-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--chat-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Online status */
.chat-status,
.chat-header-status {
  font-size: 13px;
  color: var(--chat-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-status.is-online,
.chat-header-status.is-online {
  color: #4CAF50;
}

/* Messages Container */
.chat-messages-container,
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Message Wrapper */
.message {
  display: flex;
  gap: var(--space-sm);
  animation: messageSlideIn 280ms ease-out;
  position: relative;
  margin-top: var(--chat-message-gap);
}

.chat-messages-container > .message:first-child,
.chat-messages > .message:first-child {
  margin-top: 0;
}

.message.message-user + .message.message-user,
.message.message-bot + .message.message-bot,
.message.is-user + .message.is-user,
.message.is-bot + .message.is-bot {
  margin-top: var(--chat-message-same-sender-gap);
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .message {
    animation: none;
  }
}

/* STRICT TELEGRAM STYLE: User on LEFT, Bot on RIGHT */
.message-user {
  flex-direction: row;
  justify-content: flex-start;
}

.message-bot {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

/* Keep old class names for backwards compatibility but mark as deprecated */
.message.is-user {
  flex-direction: row;
  justify-content: flex-start;
}

.message.is-bot {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

/* Message Avatar */
.message-avatar {
  flex-shrink: 0;
  align-self: flex-end;
}

/* Message Bubble */
.message-bubble {
  max-width: var(--chat-bubble-max-width);
  min-width: min(210px, var(--chat-bubble-max-width));
  padding: 12px 14px 10px;
  border-radius: var(--chat-bubble-radius);
  backdrop-filter: blur(var(--blur-sm));
  word-wrap: break-word;
  overflow-wrap: break-word;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-user-select: text;
  user-select: text;
  position: relative;
  box-shadow: var(--chat-bubble-shadow-incoming);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.message-content {
  font-size: 15px;
  line-height: 1.45;
  color: var(--chat-text-primary);
  margin-bottom: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  min-height: 16px;
  gap: 4px 10px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--chat-text-timestamp);
}

.message-footer > span {
  flex: 0 1 auto;
  min-width: 0;
}

.message-footer__analysis,
.message-footer__sender {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.message-footer__analysis {
  opacity: 0.72;
  font-weight: 400;
}

.message-timestamp,
.message-meta {
  font-size: 11px;
  line-height: 1.3;
  color: var(--chat-text-timestamp);
}

.message-user .message-footer,
.message.is-user .message-footer {
  text-align: left;
  justify-content: flex-start;
}

.message-bot .message-footer,
.message.is-bot .message-footer {
  text-align: right;
  justify-content: flex-end;
}

.message-bubble--user {
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.17), rgba(255, 255, 255, 0.09));
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-left-radius: 6px;
}

.message-bubble--manager {
  background: linear-gradient(150deg, rgba(47, 107, 255, 0.28), rgba(47, 107, 255, 0.14));
  border: 1px solid rgba(47, 107, 255, 0.40);
  border-bottom-right-radius: 6px;
  box-shadow: var(--chat-bubble-shadow-outgoing);
}

.message-bubble--bot {
  background: linear-gradient(150deg, rgba(34, 211, 238, 0.22), rgba(34, 211, 238, 0.11));
  border: 1px solid rgba(34, 211, 238, 0.36);
  border-bottom-right-radius: 6px;
  box-shadow: var(--chat-bubble-shadow-outgoing);
}

/* Context menu button (⋯) for user messages - shown on hover */
.message-menu-btn {
  position: relative;
  top: 0;
  right: auto;
  align-self: flex-start;
  margin-top: 6px;
  margin-left: 6px;
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--chat-text-secondary);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: all 180ms ease;
  backdrop-filter: blur(8px);
}

.message-bot .message-menu-btn,
.message.is-bot .message-menu-btn {
  margin-left: 0;
  margin-right: 6px;
}

.message:hover .message-menu-btn {
  opacity: 1;
}

.message-menu-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--chat-text-primary);
}

.message-menu-btn:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.95);
}

@media (max-width: 480px) {
  .message-menu-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }
}

/* Message context menu */
.message-context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 160px;
  padding: 8px;
  background: rgba(30, 35, 45, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  backdrop-filter: blur(20px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  animation: menuFadeIn 150ms ease-out;
}

@keyframes menuFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.message-context-menu .menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--chat-text-primary);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease;
}

.message-context-menu .menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.message-context-menu .menu-item:active {
  background: rgba(255, 255, 255, 0.15);
}

/* ========================================
   Input Bar
   ======================================== */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--chat-header-bg);
  backdrop-filter: blur(var(--blur-nav));
  border-top: 1px solid var(--chat-header-border);
  flex-shrink: 0;
  z-index: 10;
}

.chat-input-wrapper {
  flex: 1;
  position: relative;
}

.chat-input-textarea,
.chat-input-field {
  width: 100%;
  min-height: var(--chat-input-height);
  padding: 12px 16px;
  background: var(--chat-input-bg);
  border: 1px solid var(--chat-input-border);
  border-radius: 24px;
  color: var(--chat-text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.4;
  transition: border-color 180ms ease;
  -webkit-user-select: text;
  user-select: text;
}

.chat-input-textarea {
  min-height: calc(1em * 1.4 + 24px + 2px);
  resize: none;
  overflow-y: hidden;
}

.chat-input-textarea::placeholder,
.chat-input-field::placeholder {
  color: var(--chat-text-secondary);
}

.chat-input-textarea:focus,
.chat-input-field:focus {
  outline: none;
  border-color: var(--chat-input-focus-border);
}

.chat-input-send,
.chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-accent-blue);
  border: none;
  color: white;
  cursor: pointer;
  transition: all 180ms ease;
  flex-shrink: 0;
}

.chat-input-send svg,
.chat-send-btn svg {
  width: 20px;
  height: 20px;
}

.chat-input-send:hover,
.chat-send-btn:hover {
  background: rgba(47, 107, 255, 0.9);
  transform: scale(1.05);
}

.chat-input-send:active,
.chat-send-btn:active {
  transform: scale(0.95);
}

.chat-input-send:disabled,
.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: scale(1);
}

/* ========================================
   Context Menu
   ======================================== */
.chat-context-menu {
  position: absolute;
  z-index: 1000;
  min-width: 160px;
  padding: var(--space-sm);
  background: var(--chat-menu-bg);
  border: 1px solid var(--chat-menu-border);
  border-radius: var(--radius-action);
  backdrop-filter: blur(var(--blur-panel));
  box-shadow: var(--shadow-glass);
  animation: menuFadeIn 150ms ease-out;
}

@keyframes menuFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.chat-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--chat-text-primary);
  cursor: pointer;
  transition: background 120ms ease;
  -webkit-user-select: none;
  user-select: none;
}

.chat-menu-item:hover {
  background: var(--chat-menu-item-hover);
}

.chat-menu-item:active {
  background: rgba(255, 255, 255, 0.2);
}

.chat-menu-item.is-danger {
  color: rgba(239, 68, 68, 1);
}

.chat-menu-item.is-danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* ========================================
   AI Assistant Integration
   ======================================== */

/* AI suggestion hint */
.live-response-hint {
  font-size: 13px;
  color: var(--chat-text-secondary);
  margin-bottom: 8px;
  padding: 8px 12px;
  background: rgba(124, 92, 255, 0.1);
  border-left: 3px solid rgba(124, 92, 255, 0.5);
  border-radius: 8px;
  line-height: 1.4;
}

.live-response-hint::before {
  content: '✨ ';
}

/* Response textarea - Telegram style */
.live-response-input {
  width: 100%;
  min-height: 60px;
  max-height: 150px;
  padding: var(--chat-bubble-padding-y) var(--chat-bubble-padding-x);
  background: var(--chat-input-bg);
  border: 1px solid var(--chat-input-border);
  border-radius: 16px;
  color: var(--chat-text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.4;
  resize: vertical;
  transition: border-color 180ms ease;
  -webkit-user-select: text;
  user-select: text;
}

.live-response-input::placeholder {
  color: var(--chat-text-secondary);
}

.live-response-input:focus {
  outline: none;
  border-color: var(--chat-input-focus-border);
}

.live-response-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Response form */
.live-response-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
  padding: var(--space-md);
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-action);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.live-response-form button[type="submit"] {
  align-self: flex-end;
  min-width: 120px;
}

/* Chat response container */
.live-chat-response {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ========================================
   Scroll to Bottom Button
   ======================================== */
.chat-scroll-to-bottom {
  position: absolute;
  bottom: 80px;
  right: var(--space-lg);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--glass-card-bg);
  backdrop-filter: blur(var(--blur-button));
  border: 1px solid var(--glass-card-border);
  box-shadow: var(--shadow-button);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-accent-cyan);
  cursor: pointer;
  transition: all 180ms ease;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
}

.chat-scroll-to-bottom svg {
  width: 20px;
  height: 20px;
}

.chat-scroll-to-bottom.is-visible,
.chat-scroll-to-bottom.chat-visible {
  opacity: 1;
  pointer-events: auto;
}

.chat-scroll-to-bottom:hover {
  background: var(--glass-button-hover-bg);
  transform: scale(1.05);
}

.chat-scroll-to-bottom:active {
  transform: scale(0.95);
}

.live-training-chat {
  min-height: 0;
  height: 100%;
  --live-training-chat-composer-bottom-offset: calc(var(--bottom-nav-height, 72px) + var(--safe-area-bottom));
  --live-training-chat-composer-shell-height: 0px;
  --live-training-chat-composer-effective-height: var(--live-training-chat-composer-shell-height);
  --live-training-chat-scroll-button-clearance: var(--space-lg);
}

.live-training-chat--open-surface {
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.live-training-chat--open-surface .live-training-chat-layout {
  padding-top: 18px;
}

.live-training-chat--open-surface .live-training-chat__messages {
  padding-top: 18px;
  padding-bottom: calc(
    var(--live-training-chat-composer-effective-height)
    + 18px
  );
}

.live-training-composer-shell {
  position: sticky;
  left: auto;
  right: auto;
  bottom: calc(var(--bottom-nav-height, 72px) + var(--safe-area-bottom));
  width: 100%;
  max-width: none;
  margin: 0;
  box-sizing: border-box;
  z-index: 40;
  padding: var(--space-sm) var(--space-lg) env(safe-area-inset-bottom, 0px);
  background: transparent;
}

.live-training-chat__composer {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  max-width: none;
  margin: 0;
  box-sizing: border-box;
  z-index: auto;
  padding: 0;
  border-top: 0;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.live-training-chat__composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.live-training-chat__ai-improve-btn {
  border-radius: 999px;
  font-size: 12px;
  padding: 6px 12px;
  min-height: 32px;
}

.live-training-chat__ai-apply-btn {
  border-radius: 999px;
  font-size: 12px;
  padding: 6px 12px;
  min-height: 32px;
}

.live-training-chat__suggested-reply-preview {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--color-border-glass-card) 72%, transparent);
  background: color-mix(in srgb, var(--color-surface-glass-card) 55%, transparent);
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.4;
  max-height: 140px;
  overflow-y: auto;
}

.live-training-chat .chat-scroll-to-bottom {
  bottom: calc(
    var(--live-training-chat-composer-effective-height)
    + var(--live-training-chat-scroll-button-clearance)
    + var(--bottom-nav-height)
    + env(safe-area-inset-bottom, 0px)
  );
}

.live-training-chat__header-shell {
  position: static;
  z-index: auto;
  margin: 0 0 var(--space-md);
  padding: 0;
  background: transparent;
  border-bottom: 1px solid var(--chat-header-border);
}

.live-training-chat__header {
  align-items: center;
  min-height: 64px;
  padding: 10px 12px;
  gap: 10px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--chat-header-bg) 78%, rgba(13, 18, 31, 0.35));
  border: 1px solid color-mix(in srgb, var(--chat-header-border) 85%, transparent);
  backdrop-filter: blur(var(--blur-nav));
  border-bottom: 0;
}

.live-training-chat__back-btn {
  margin-left: 0;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  color: var(--chat-text-primary);
  border: 1px solid color-mix(in srgb, var(--chat-header-border) 65%, transparent);
  background: color-mix(in srgb, rgba(255, 255, 255, 0.14) 60%, transparent);
}

.live-training-chat__header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, rgba(255, 255, 255, 0.42) 78%, transparent);
  box-shadow: 0 8px 24px rgba(2, 8, 24, 0.28);
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.live-training-chat__header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.live-training-chat__header-avatar-initials {
  color: rgba(255, 255, 255, 0.98);
  font-size: 13px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.live-training-chat__header-main {
  gap: 2px;
}

.live-training-chat__title {
  margin-top: 0;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.live-training-chat__subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--chat-text-secondary);
  letter-spacing: 0.01em;
}

.live-training-chat__toolbar {
  margin-bottom: var(--space-sm);
}

.live-training-chat__toolbar-title {
  font-weight: 600;
}

.live-training-session-subtabs {
  display: inline-flex;
  gap: 6px;
  margin-bottom: var(--space-md);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--color-glass-border);
  background: rgba(255, 255, 255, 0.04);
}

.live-training-session-subtab {
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--color-text-secondary);
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.2;
}

.live-training-session-subtab--active {
  background: rgba(92, 111, 255, 0.2);
  border-color: rgba(92, 111, 255, 0.55);
  color: var(--color-text-primary);
  font-weight: 600;
}

.live-training-chat__analysis-controls {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0;
}

.live-training-chat__header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.live-training-chat__analyze-chat-btn {
  white-space: nowrap;
}

.live-training-chat__analyze-menu {
  position: relative;
}

.live-training-chat__analyze-chat-btn {
  list-style: none;
}

.live-training-chat__analyze-chat-btn::-webkit-details-marker {
  display: none;
}

.live-training-chat__analyze-chat-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  padding: 8px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.live-training-chat__analyze-chat-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--color-text-primary);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 13px;
}

.live-training-chat__analyze-chat-item:hover {
  background: var(--glass-button-hover-bg);
}

.live-training-chat__overflow-menu {
  position: relative;
}

.live-training-chat__overflow-trigger {
  min-width: 36px;
  min-height: 36px;
  border-radius: 12px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  list-style: none;
}

.live-training-chat__overflow-trigger::-webkit-details-marker {
  display: none;
}

.live-training-chat__overflow-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  padding: 8px;
  z-index: 30;
}

.live-training-chat__overflow-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--color-text-primary);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 13px;
}

.live-training-chat__overflow-item:hover {
  background: var(--glass-button-hover-bg);
}

.live-training-chat__overflow-divider {
  height: 1px;
  background: color-mix(in srgb, var(--color-border-glass-card) 72%, transparent);
  margin: 4px 0;
}

.live-training-chat__analysis-more {
  position: relative;
}

.live-training-chat__analysis-more-summary {
  list-style: none;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  padding: 0 8px;
}

.live-training-chat__analysis-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 230px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 30;
}

.live-training-chat__compact-stats {
  margin-top: var(--space-sm);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.live-training-chat__compact-stats .stat-card {
  display: block;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-training-chat__hint {
  margin-bottom: var(--space-md);
}

.live-training-chat__messages {
  position: relative;
  z-index: 1;
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: var(--space-md);
  padding-bottom: calc(
    var(--live-training-chat-composer-effective-height)
    + var(--space-md)
  );
  overscroll-behavior-y: contain;
}

.live-training-chat__messages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.live-training-chat__state {
  margin-bottom: 0;
}

.live-training-chat__state--error {
  margin-bottom: 10px;
}

.live-training-chat__composer .chat-input-send {
  align-self: flex-end;
}

.manager-chat-composer .chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  width: 100%;
}

.manager-chat-composer .chat-input-textarea {
  min-height: 44px;
  max-height: 132px;
  padding: 11px 14px;
  border-radius: 16px;
  border: 1px solid var(--glass-card-border, rgba(255, 255, 255, 0.15));
  background: var(--glass-card-bg, rgba(255, 255, 255, 0.08));
  backdrop-filter: blur(var(--blur-card));
  -webkit-backdrop-filter: blur(var(--blur-card));
  box-shadow: var(--shadow-glass);
}

.manager-chat-composer .chat-input-textarea:focus {
  border-color: rgba(118, 171, 255, 0.62);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 0 3px rgba(61, 127, 255, 0.16);
}

.manager-chat-composer .chat-input-send {
  margin-bottom: 0;
  flex-shrink: 0;
}

.chat-back-btn.chat-floating-back {
  position: absolute;
  bottom: var(--chat-floating-offset-bottom);
  left: var(--space-lg);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(14, 20, 35, 0.68);
  backdrop-filter: blur(var(--blur-button));
  border: 1px solid rgba(255, 255, 255, 0.52);
  box-shadow:
    0 10px 24px rgba(3, 9, 18, 0.48),
    0 2px 8px rgba(3, 9, 18, 0.38);
  color: rgba(240, 253, 255, 0.98);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  transition: all 180ms ease;
  z-index: 1101;
}

.chat-back-btn.chat-floating-back svg {
  width: 20px;
  height: 20px;
}

.chat-back-btn.chat-floating-back:hover {
  background: rgba(20, 32, 54, 0.84);
  border-color: rgba(167, 243, 255, 0.82);
  box-shadow:
    0 14px 30px rgba(3, 9, 18, 0.55),
    0 0 0 1px rgba(167, 243, 255, 0.32);
  transform: translateY(-1px) scale(1.06);
}

.chat-back-btn.chat-floating-back:active {
  background: rgba(9, 16, 30, 0.88);
  border-color: rgba(134, 239, 255, 0.9);
  box-shadow:
    0 8px 18px rgba(3, 9, 18, 0.5),
    inset 0 1px 3px rgba(0, 0, 0, 0.3);
  transform: translateY(0) scale(0.94);
}

.chat-back-btn.chat-floating-back.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px) scale(0.96);
}

.chat-back-btn.chat-floating-back.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.chat-back-btn.chat-floating-back:focus-visible {
  outline: none;
  border-color: rgba(125, 232, 255, 0.98);
  box-shadow:
    0 0 0 3px rgba(10, 20, 40, 0.82),
    0 0 0 5px rgba(125, 232, 255, 0.72),
    0 14px 30px rgba(3, 9, 18, 0.55);
}

@media (max-width: 480px) {
  .live-training-chat {
    --live-training-chat-scroll-button-clearance: var(--space-2xl);
  }

  .live-training-chat .chat-scroll-to-bottom {
    right: var(--space-md);
  }

  .chat-back-btn.chat-floating-back {
    left: var(--space-md);
    width: 40px;
    height: 40px;
  }

  .chat-back-btn.chat-floating-back svg {
    width: 18px;
    height: 18px;
  }

  .chat-dialog-view {
    --chat-bottom-controls-height: calc(var(--chat-input-height) + (var(--space-md) * 2) + 4px);
    --chat-floating-nav-clearance: 10px;
  }

  .chat-dialog-view:has(.ai-reply-panel:not(.is-hidden)) {
    --chat-bottom-controls-height: calc(var(--chat-input-height) + (var(--space-md) * 2) + 170px);
  }
}

/* ========================================
   Responsive Design
   ======================================== */

/* Tablet */
@media (min-width: 768px) {
  :root {
    --chat-bubble-max-width: 70%;
  }
  
  .chat-messages-container {
    padding: var(--space-2xl);
  }
  
  .chat-input-bar {
    padding: var(--space-lg) var(--space-2xl);
  }
}

/* Desktop */
@media (min-width: 1024px) {
  :root {
    --chat-bubble-max-width: 60%;
  }
  
  .chat-container {
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: var(--shadow-glass);
  }
  
  .chat-messages-container {
    padding: var(--space-2xl);
  }

  .live-training-chat__composer {
    padding-left: var(--layout-nav-width);
  }

  .live-training-composer-shell {
    max-width: none;
    padding-left: calc(var(--layout-nav-width) + var(--space-lg));
  }
}

/* ========================================
   AI Reply Panel - Operator Tooling Layer
   ======================================== */

/* 
 * STRICT SEPARATION: This panel is NOT part of the message stream.
 * It's an operator tool that sits BELOW messages and ABOVE navigation.
 * The AI reply is NOT a message until the operator sends it.
 */

.ai-reply-panel {
  position: relative;
  padding: var(--space-lg);
  background: var(--chat-header-bg);
  backdrop-filter: blur(var(--blur-panel));
  border-top: 2px solid var(--chat-header-border);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  z-index: 10;
  animation: panelSlideUp 300ms ease-out;
}

@keyframes panelSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-reply-panel.is-hidden {
  display: none;
}

/* Panel Header */
.ai-reply-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.ai-reply-panel__label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-accent-cyan);
}

.ai-reply-panel__label::before {
  content: '🤖';
  font-size: 18px;
}

.ai-reply-panel__menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--chat-text-secondary);
  cursor: pointer;
  transition: all 180ms ease;
  font-size: 18px;
}

.ai-reply-panel__menu-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--chat-text-primary);
}

/* Panel Content */
.ai-reply-panel__content {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* Textarea */
.ai-reply-panel__textarea {
  width: 100%;
  min-height: 80px;
  max-height: 200px;
  padding: 12px 16px;
  background: var(--chat-input-bg);
  border: 1px solid var(--chat-input-border);
  border-radius: 12px;
  color: var(--chat-text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.4;
  resize: vertical;
  overflow-y: auto;
  transition: border-color 180ms ease;
  -webkit-user-select: text;
  user-select: text;
}

.ai-reply-panel__textarea::placeholder {
  color: var(--chat-text-secondary);
}

.ai-reply-panel__textarea:focus {
  outline: none;
  border-color: var(--chat-input-focus-border);
}

.ai-reply-panel__textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.05);
}

/* Actions */
.ai-reply-panel__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
}

.ai-reply-panel__send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--color-accent-blue);
  border: none;
  border-radius: 24px;
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 180ms ease;
  flex-shrink: 0;
}

.ai-reply-panel__send-btn:hover {
  background: rgba(47, 107, 255, 0.9);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(47, 107, 255, 0.4);
}

.ai-reply-panel__send-btn:active {
  transform: translateY(0);
}

.ai-reply-panel__send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Secondary Menu */
.ai-reply-panel__menu {
  position: absolute;
  bottom: 100%;
  right: var(--space-lg);
  margin-bottom: 8px;
  min-width: 200px;
  padding: 8px;
  background: rgba(30, 35, 45, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  backdrop-filter: blur(20px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 100;
  animation: menuFadeIn 150ms ease-out;
}

.ai-reply-panel__menu.is-hidden {
  display: none;
}

.ai-reply-panel__menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--chat-text-primary);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease;
}

.ai-reply-panel__menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ai-reply-panel__menu-item:active {
  background: rgba(255, 255, 255, 0.15);
}

/* Loading state */
.ai-reply-panel__loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: var(--space-lg);
  color: var(--chat-text-secondary);
}

.ai-reply-panel__spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--color-accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ========================================
   Utility Classes
   ======================================== */
.chat-hidden {
  display: none !important;
}

.chat-visible {
  display: flex !important;
}

/* Typing indicator (optional) */
.chat-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
}

.chat-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chat-text-secondary);
  animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.6;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Empty state */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: var(--space-2xl);
  text-align: center;
  color: var(--chat-text-secondary);
}

.chat-empty-state-icon {
  font-size: 48px;
  margin-bottom: var(--space-lg);
  opacity: 0.5;
}

.chat-empty-state-text {
  font-size: 16px;
  line-height: 1.5;
}

/* Loading state */
.chat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
  color: var(--chat-text-secondary);
}

.chat-loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--color-accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
