/* ====== SOFIA CHAT PAGE - REDESIGN ====== */
/* Modern full-width centered chat layout inspired by Claude.ai / ChatGPT */

/* ------------------------------------------------
   LAYOUT
   ------------------------------------------------ */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height));
  margin-top: var(--nav-height);
  position: relative;
  overflow: hidden;
}

.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--bg-primary);
  overflow: hidden;
}


/* ------------------------------------------------
   COMPACT AGENT HEADER (replaces sidebar on desktop)
   ------------------------------------------------ */
.chat-header {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
  background: rgba(18, 18, 26, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.chat-header-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-agent {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: visible;
  flex-shrink: 0;
}

.chat-header-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(108, 92, 231, 0.3);
}

.chat-header-status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #20e3b2;
  border: 2px solid var(--bg-secondary);
  z-index: 1;
}

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

.chat-header-name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.chat-header-role {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1.2;
}

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

/* Header new-chat button (icon only) */
.chat-new-btn-header {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  /* Override shared .chat-new-btn styles */
  padding: 0;
  font-size: 0;
  gap: 0;
}

.chat-new-btn-header svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.chat-new-btn-header:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
  transform: none;
  box-shadow: none;
}


/* ------------------------------------------------
   SIDEBAR (slide-over drawer from the right)
   ------------------------------------------------ */
.chat-sidebar {
  position: fixed;
  top: var(--nav-height);
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 85vw;
  z-index: 200;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform var(--transition-smooth);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}

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

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

.chat-sidebar-heading {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chat-sidebar-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.chat-sidebar-close svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.chat-sidebar-close:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.chat-sidebar-info {
  flex: 1;
  padding: 24px 20px;
  overflow-y: auto;
}

/* Agent card in sidebar */
.chat-agent-card {
  padding: 28px 20px;
  background: linear-gradient(135deg, rgba(108, 92, 231, 0.08) 0%, rgba(0, 210, 255, 0.05) 100%);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  text-align: center;
}

.chat-agent-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 16px;
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2), 0 8px 24px rgba(0, 0, 0, 0.3);
}

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

.chat-agent-name {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.chat-agent-role {
  font-size: 0.8125rem;
  color: var(--accent-2);
  font-weight: 600;
  margin-bottom: 12px;
}

.chat-agent-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.chat-agent-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  font-size: 0.75rem;
  color: #20e3b2;
  font-weight: 500;
}

.chat-agent-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #20e3b2;
  box-shadow: 0 0 8px rgba(32, 227, 178, 0.5);
  animation: statusPulse 2s ease-in-out infinite;
}

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

/* Sidebar actions */
.chat-sidebar-actions {
  margin-top: 24px;
}

.chat-new-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-new-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--accent-glow);
}

.chat-new-btn svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}

.chat-sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-align: center;
}

.chat-sidebar-footer a {
  color: var(--accent-2);
}

/* Sidebar overlay */
.chat-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.chat-sidebar.open ~ .chat-sidebar-overlay {
  display: block;
}


/* ------------------------------------------------
   SIDEBAR TOGGLE BUTTON
   ------------------------------------------------ */
.chat-sidebar-toggle {
  position: fixed;
  top: calc(var(--nav-height) + 12px);
  right: 16px;
  z-index: 101;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  /* Hidden by default on all sizes; the header replaces it */
  display: none;
}

.chat-sidebar-toggle svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.chat-sidebar-toggle:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}


/* ------------------------------------------------
   MESSAGES AREA
   ------------------------------------------------ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.12);
}


/* ------------------------------------------------
   MESSAGE ROWS
   ------------------------------------------------ */
.chat-msg-row {
  display: flex;
  gap: 14px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  animation: chatMsgIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.chat-msg-row-user {
  justify-content: flex-end;
}

.chat-msg-row-assistant {
  justify-content: flex-start;
}

/* Assistant avatar next to messages */
.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

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

.chat-msg-row-user .chat-msg-avatar {
  display: none;
}

/* Message content bubbles */
.chat-msg-content {
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  line-height: 1.7;
  word-break: break-word;
  max-width: 700px;
}

/* User messages */
.chat-msg-row-user .chat-msg-content {
  background: var(--accent-1);
  background: linear-gradient(135deg, #6c5ce7 0%, #5a4bd1 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 12px rgba(108, 92, 231, 0.25);
}

/* Assistant messages */
.chat-msg-row-assistant .chat-msg-content {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 6px;
}


/* ------------------------------------------------
   MARKDOWN STYLES (assistant messages)
   ------------------------------------------------ */
.chat-msg-row-assistant .chat-msg-content p {
  margin: 0 0 12px;
}

.chat-msg-row-assistant .chat-msg-content p:last-child {
  margin-bottom: 0;
}

.chat-msg-row-assistant .chat-msg-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

.chat-msg-row-assistant .chat-msg-content a {
  color: var(--accent-2);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-msg-row-assistant .chat-msg-content a:hover {
  color: #33dcff;
}

.chat-msg-row-assistant .chat-msg-content .cb-code-block {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 12px 0;
  overflow-x: auto;
  font-size: 0.8125rem;
}

.chat-msg-row-assistant .chat-msg-content .cb-code-block code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.chat-msg-row-assistant .chat-msg-content .cb-inline-code {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.8125rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.chat-msg-row-assistant .chat-msg-content .cb-list {
  padding-left: 20px;
  margin: 8px 0;
}

.chat-msg-row-assistant .chat-msg-content ul.cb-list {
  list-style: disc;
}

.chat-msg-row-assistant .chat-msg-content ol.cb-list {
  list-style: decimal;
}


/* ------------------------------------------------
   TYPING INDICATOR
   ------------------------------------------------ */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  animation: chatMsgIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-typing-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 16px 22px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 6px;
}

.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: cbBounce 1.4s ease-in-out infinite;
}

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

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


/* ------------------------------------------------
   ERROR BANNER
   ------------------------------------------------ */
.chat-error {
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 18px;
  background: rgba(255, 71, 87, 0.08);
  border: 1px solid rgba(255, 71, 87, 0.15);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: #ff6b7a;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: chatMsgIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-error-dismiss {
  margin-left: auto;
  color: #ff6b7a;
  opacity: 0.5;
  font-size: 1.25rem;
  transition: opacity var(--transition-fast);
}

.chat-error-dismiss:hover {
  opacity: 1;
}


/* ------------------------------------------------
   INPUT AREA
   ------------------------------------------------ */
.chat-input-area {
  flex-shrink: 0;
  padding: 0 24px 24px;
  background: var(--bg-primary);
  position: relative;
}

/* Fade gradient above input */
.chat-input-area::before {
  content: '';
  position: absolute;
  top: -40px;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(to bottom, transparent, var(--bg-primary));
  pointer-events: none;
}

.chat-input-wrap {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 20px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-input-wrap:focus-within {
  border-color: rgba(108, 92, 231, 0.4);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.08);
}

.chat-textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text-primary);
  padding: 10px 0;
  font-family: var(--font-family);
  font-size: 0.9375rem;
  line-height: 1.5;
  max-height: 160px;
  min-height: 24px;
  outline: none;
}

.chat-textarea::placeholder {
  color: var(--text-muted);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

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

.chat-send-btn:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.35);
}

.chat-send-btn:not(:disabled):active {
  transform: scale(0.95);
}

.chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

.chat-input-footer {
  max-width: 780px;
  margin: 10px auto 0;
  text-align: center;
  font-size: 0.6875rem;
  color: var(--text-muted);
  line-height: 1.4;
}


/* ------------------------------------------------
   WELCOME STATE
   ------------------------------------------------ */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px 60px;
  text-align: center;
  animation: welcomeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.chat-welcome-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 24px;
  position: relative;
  box-shadow:
    0 0 0 3px rgba(108, 92, 231, 0.2),
    0 0 40px rgba(108, 92, 231, 0.2),
    0 0 80px rgba(0, 210, 255, 0.1);
}

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

.chat-welcome-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.chat-welcome-subtitle {
  font-size: 0.875rem;
  color: var(--accent-2);
  margin-bottom: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chat-welcome-text {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 480px;
  line-height: 1.7;
}


/* ------------------------------------------------
   RESPONSIVE: TABLET (max-width: 768px)
   ------------------------------------------------ */
@media (max-width: 768px) {

  .chat-header-inner {
    padding: 10px 16px;
  }

  .chat-messages {
    padding: 20px 16px 16px;
    gap: 18px;
  }

  .chat-input-area {
    padding: 0 12px 16px;
  }

  .chat-input-wrap {
    padding: 6px 6px 6px 16px;
    border-radius: var(--radius-md);
  }

  .chat-msg-content {
    font-size: 0.875rem;
    padding: 12px 16px;
    max-width: 85%;
  }

  .chat-msg-avatar {
    width: 28px;
    height: 28px;
  }

  .chat-msg-row {
    gap: 10px;
  }

  .chat-welcome {
    padding: 48px 20px 40px;
  }

  .chat-welcome-avatar {
    width: 80px;
    height: 80px;
  }

  .chat-welcome-title {
    font-size: 1.5rem;
  }

  .chat-welcome-text {
    font-size: 0.9375rem;
  }

  .chat-sidebar-toggle {
    display: flex;
  }

  .chat-send-btn {
    width: 40px;
    height: 40px;
  }

  .chat-send-btn svg {
    width: 16px;
    height: 16px;
  }
}


/* ------------------------------------------------
   RESPONSIVE: SMALL MOBILE (max-width: 480px)
   ------------------------------------------------ */
@media (max-width: 480px) {

  .chat-header-inner {
    padding: 8px 12px;
  }

  .chat-header-avatar {
    width: 34px;
    height: 34px;
  }

  .chat-header-avatar img {
    width: 34px;
    height: 34px;
  }

  .chat-header-name {
    font-size: 0.875rem;
  }

  .chat-messages {
    padding: 16px 12px 12px;
    gap: 14px;
  }

  .chat-input-area {
    padding: 0 8px 12px;
  }

  .chat-input-wrap {
    padding: 4px 4px 4px 14px;
  }

  .chat-textarea {
    font-size: 0.875rem;
  }

  .chat-input-footer {
    font-size: 0.625rem;
  }

  .chat-msg-content {
    padding: 10px 14px;
    font-size: 0.8125rem;
    max-width: 88%;
  }

  .chat-msg-row {
    gap: 8px;
  }

  .chat-msg-avatar {
    width: 26px;
    height: 26px;
  }
}
