/* ─── Chat Page ───────────────────────────────────────────────────── */
.chat-page {
  padding-top: var(--nav-height);
  height: 100vh;
  display: flex;
  background: var(--bg-primary);
}

.chat-container {
  display: flex;
  width: 100%;
  height: calc(100vh - var(--nav-height));
  max-width: 1400px;
  margin: 0 auto;
}

/* ─── Sidebar ─────────────────────────────────────────────────────── */
.chat-sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-base), min-width var(--transition-base), width var(--transition-base);
}

.chat-sidebar.collapsed {
  margin-left: -280px;
  min-width: 0;
  width: 0;
  overflow: hidden;
}

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

.sidebar-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.btn-new-chat {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  background: var(--accent-subtle);
  color: var(--accent-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.btn-new-chat:hover {
  background: var(--accent-glow);
}

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

.conversation-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 4px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  color: var(--text-primary);
  font-family: var(--font-body);
}

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

.conversation-item.active {
  background: var(--accent-subtle);
  border: 1px solid var(--border-default);
}

.conv-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.empty-state {
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
  padding: 24px 16px;
}

/* ─── Main Chat Area ──────────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

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

.agent-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.agent-avatar.large {
  width: 56px;
  height: 56px;
  font-size: 22px;
}

.agent-select {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  font-family: var(--font-body);
  padding: 0;
  margin: 0 0 1px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
  padding-right: 18px;
}

.agent-select option {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.agent-info p {
  font-size: 12px;
  color: var(--text-tertiary);
  margin: 0;
}

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

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-hover);
}

/* ─── Messages ────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.welcome-message {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.welcome-message h3 {
  font-size: 20px;
  color: var(--text-primary);
  margin: 16px 0 8px;
}

.welcome-message p {
  max-width: 420px;
  margin: 0 auto;
  font-size: 14px;
  line-height: 1.6;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 800px;
}

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

.message-user .message-avatar {
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
}

.message-body {
  max-width: 600px;
}

.message-user .message-body {
  background: var(--accent-subtle);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md) var(--radius-sm) var(--radius-md) var(--radius-md);
  padding: 10px 14px;
}

.message-assistant .message-body {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm) var(--radius-md) var(--radius-md) var(--radius-md);
  padding: 10px 14px;
}

.message-system .message-body {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: #ef4444;
  font-size: 13px;
  margin: 0 auto;
}

.message-text {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: break-word;
}

.message-text code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.message-text pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-text pre code {
  background: none;
  padding: 0;
}

.message-text strong {
  font-weight: 600;
}

/* ─── Typing Indicator ────────────────────────────────────────────── */
.typing-indicator .dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator .dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typing 1.4s infinite;
}

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

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ─── Input Area ──────────────────────────────────────────────────── */
.chat-input-area {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  transition: border-color var(--transition-fast);
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#chatInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 150px;
}

#chatInput::placeholder {
  color: var(--text-tertiary);
}

.btn-send {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--accent-primary);
  color: #000;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--transition-fast);
}

.btn-send:hover {
  opacity: 0.85;
}

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

.input-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  margin: 6px 0 0 4px;
}

/* ─── Chat Size Modes ────────────────────────────────────────────── */
.chat-container.size-half {
  max-width: 720px;
}

.chat-container.size-three-quarter {
  max-width: 1060px;
}

.chat-container.size-full {
  max-width: 100%;
}

/* ─── Mobile ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chat-sidebar {
    position: fixed;
    left: 0;
    top: var(--nav-height);
    height: calc(100vh - var(--nav-height));
    z-index: 50;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
    transform: translateX(0);
    transition: transform var(--transition-base);
  }

  .chat-sidebar.collapsed {
    transform: translateX(-100%);
    margin-left: 0;
    width: 280px;
    min-width: 280px;
  }

  .message-body {
    max-width: calc(100vw - 80px);
  }
}
