/* Modern ChatGPT-style theme variables */
:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #16213e;
  --bg-surface: #0f3460;
  --sidebar-bg: #202123;
  --sidebar-hover: #2a2b32;
  --text-primary: #ffffff;
  --text-secondary: #c5c5d2;
  --text-muted: #8e8ea0;
  --accent: #10a37f;
  --accent-hover: #0d8f6f;
  --border: #565869;
  --border-light: #40414f;
  --user-bg: #7c3aed;
  --assistant-bg: transparent;
  --shadow: 0 2px 8px rgba(0,0,0,0.15);
  --radius: 8px;
  --radius-lg: 12px;
}

/* Global reset */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
}

/* Global reset for WordPress themes */
.angela-app {
  display: flex;
  height: 100vh;
  min-height: 80vh;
  background: var(--bg-primary);
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  margin: 0;
  padding: 0;
}

/* Remove WordPress theme spacing */
.angela-app * {
  margin: 0;
  padding: 0;
}

/* Full viewport mode for chat pages */
.angela-full-viewport {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  height: 100vh;
}

/* When used in a page context, account for header/footer */
.angela-page-context {
  height: calc(100vh - var(--header-height, 0px) - var(--footer-height, 0px));
  min-height: 400px;
  position: relative;
}

/* Override any theme containers that might add spacing */
.angela-app .container,
.angela-app .wrapper,
.angela-app .content {
  margin: 0 !important;
  padding: 0 !important;
  max-width: none !important;
  width: 100% !important;
}

/* Ensure the chat page has no spacing */
.page .angela-app,
.post .angela-app {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Sidebar */
.angela-sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease;
}

/* Mobile sidebar overlay */
@media (max-width: 768px) {
  .angela-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 1000;
    transform: translateX(-100%);
    box-shadow: 0 0 20px rgba(0,0,0,0.3);
  }
  
  .angela-sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }
  
  .sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
  }
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.new-chat-btn {
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.new-chat-btn:hover {
  background: var(--sidebar-hover);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-item {
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.2s ease;
}

.chat-item:hover {
  background: var(--sidebar-hover);
}

.chat-item.active {
  background: var(--bg-surface);
}

.chat-item-content {
  flex: 1;
  min-width: 0;
}

.chat-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.chat-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-actions {
  opacity: 0;
  display: flex;
  gap: 4px;
  transition: opacity 0.2s ease;
}

.chat-item:hover .chat-actions {
  opacity: 1;
}

.chat-action-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.2s ease;
}

.chat-action-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

/* Main chat area */
.angela-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

/* Chat header */
.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
}

.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  font-size: 16px;
  transition: all 0.2s ease;
}

.sidebar-toggle:hover {
  background: var(--bg-tertiary);
}

@media (max-width: 768px) {
  .sidebar-toggle {
    display: flex;
  }
}

.agent-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: white;
}

.agent-details h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.agent-details p {
  margin: 2px 0 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.chat-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.control-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.control-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
}

.message-group {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 24px;
  margin-bottom: 32px;
}

.message {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.message.user .message-avatar {
  background: var(--user-bg);
  color: white;
}

.message.assistant .message-avatar {
  background: var(--accent);
  color: white;
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message.user .message-content {
  display: flex;
  justify-content: flex-end;
}

.message-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
}

.message.user .message-bubble {
  background: var(--user-bg);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--assistant-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message-group:hover .message-actions {
  opacity: 1;
}

.message-action {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.message-action:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

/* Empty state */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
}

.empty-title {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.empty-subtitle {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  max-width: 600px;
  width: 100%;
}

.suggestion-card {
  padding: 16px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  font-size: 14px;
  color: var(--text-secondary);
}

.suggestion-card:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent);
}

/* Input area */
.chat-input-area {
  padding: 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.input-wrapper {
  max-width: 768px;
  margin: 0 auto;
  position: relative;
}

.chat-input {
  width: 100%;
  min-height: 52px;
  max-height: 200px;
  padding: 12px 60px 12px 20px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: all 0.2s ease;
}

.chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.send-button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 16px;
}

.send-button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-button:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.stop-button {
  background: #dc2626;
}

.stop-button:hover {
  background: #b91c1c;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% { 
    transform: scale(0.8); 
    opacity: 0.5; 
  }
  40% { 
    transform: scale(1); 
    opacity: 1; 
  }
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar,
.chat-history::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-history::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-history::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-history::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Utility classes */
.hidden {
  display: none !important;
}

/* Responsive design */
/* WordPress theme override - remove all spacing around chat */
body.page .angela-app,
body.single .angela-app,
.entry-content .angela-app,
.site-content .angela-app,
.content-area .angela-app {
  margin: 0 !important;
  padding: 0 !important;
}

/* Remove spacing from parent containers */
body.page .entry-content,
body.single .entry-content {
  padding: 0 !important;
  margin: 0 !important;
}

/* Hide page title on chat page */
body.page .entry-title,
body.single .entry-title {
  display: none;
}

/* Make sure the chat takes full width */
body.page .site-content,
body.single .site-content,
body.page .content-area,
body.single .content-area {
  max-width: none !important;
  width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Remove any default WordPress content spacing */
body.page .site-main,
body.single .site-main {
  padding: 0 !important;
  margin: 0 !important;
}

@media (max-width: 1024px) {
  .angela-app {
    height: 100vh;
    min-height: 500px;
  }
}

@media (max-width: 768px) {
  .angela-app {
    height: 90vh;
    flex-direction: row;
    position: relative;
  }
  
  .angela-main {
    flex: 1;
    width: 100%;
  }
  
  .chat-header {
    padding: 12px 16px;
    gap: 8px;
  }
  
  .agent-info {
    gap: 8px;
  }
  
  .agent-details h2 {
    font-size: 14px;
  }
  
  .agent-details p {
    font-size: 11px;
  }
  
  .chat-controls {
    gap: 8px;
  }
  
  .agent-selector {
    display: none; /* Hide on mobile to save space */
  }
  
  .message-bubble {
    max-width: 85%;
  }
  
  .message-group {
    padding: 0 16px;
    margin-bottom: 24px;
  }
  
  .suggestions-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 16px;
  }
  
  .chat-input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 12px 50px 12px 16px;
  }
  
  .send-button {
    width: 32px;
    height: 32px;
    right: 6px;
  }
}

@media (max-width: 480px) {
  .angela-app {
    height: 95vh;
    border-radius: 0;
  }
  
  .chat-header {
    padding: 8px 12px;
    min-height: 56px;
  }
  
  .agent-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .message-group {
    padding: 0 12px;
    margin-bottom: 20px;
  }
  
  .message-bubble {
    padding: 10px 12px;
    max-width: 90%;
  }
  
  .chat-input-area {
    padding: 12px;
  }
  
  .empty-title {
    font-size: 24px;
  }
  
  .empty-subtitle {
    font-size: 14px;
  }
  
  .suggestion-card {
    padding: 12px 16px;
    font-size: 13px;
  }
}

/* Agent selector dropdown */
.agent-selector {
  position: relative;
  display: inline-block;
}

.agent-dropdown {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  outline: none;
}

.agent-dropdown:focus {
  border-color: var(--accent);
}

/* Tool indicators and web search */
.tool-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.source-link {
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  transition: all 0.2s ease;
}

.source-link:hover {
  background: var(--bg-surface);
  border-color: var(--accent);
  color: var(--accent);
}