/* Design System and Variables */
:root {
  /* Common Brand Colors */
  --primary: #ff6a00;
  --primary-rgb: 255, 106, 0;
  --primary-hover: #e05300;
  --primary-glow: rgba(255, 106, 0, 0.15);
  --success: #10b981;
  --error: #ef4444;

  /* Hitesh Avatar Gradient */
  --avatar-hitesh-grad: linear-gradient(135deg, #ff8c00, #e52d27);
  /* Piyush Avatar Gradient - containing pink since he loves pink! */
  --avatar-piyush-grad: linear-gradient(135deg, #ff416c, #ff4b2b);

  /* Fonts */
  --font-display: 'Outfit', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
  --transition-speed: 0.3s;
}

/* Light Theme Variables */
html[data-theme="light"] {
  --bg-app: #ffffff;
  --bg-sidebar: #f8f9fa;
  --bg-chat-header: #ffffff;
  --bg-card-active: #fff0e6;
  --bg-card-hover: #f1f3f5;
  --text-main: #1a1a1a;
  --text-muted: #5e6e78;
  --border-color: #e9ecef;
  --chat-bubble-user: #ff6a00;
  --chat-bubble-user-text: #ffffff;
  --chat-bubble-ai: #f1f3f5;
  --chat-bubble-ai-text: #1a1a1a;
  --bg-input: #f8f9fa;
  --bg-input-focus: #ffffff;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
  --card-border-active: #ffe0cc;
  --step-bg: #f8f9fa;
  --step-border: #e9ecef;
}

/* Dark Theme Variables */
html[data-theme="dark"] {
  --bg-app: #000000;
  --bg-sidebar: #090909;
  --bg-chat-header: #000000;
  --bg-card-active: #1f140d;
  --bg-card-hover: #141414;
  --text-main: #f5f5f5;
  --text-muted: #9aa0a6;
  --border-color: #1e1e1e;
  --chat-bubble-user: #ff6a00;
  --chat-bubble-user-text: #ffffff;
  --chat-bubble-ai: #0d0d0d;
  --chat-bubble-ai-text: #f5f5f5;
  --bg-input: #0c0c0c;
  --bg-input-focus: #000000;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.8);
  --card-border-active: #ff6a004d;
  --step-bg: #090909;
  --step-border: #1e1e1e;
}

/* Basic Resets & Document Setup */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body, 
.sidebar, 
.chat-header, 
.chat-container,
.character-card, 
.chat-input-container, 
.chat-form, 
.chat-form textarea,
.message-bubble, 
.pipeline-container, 
.pipeline-header, 
.pipeline-body, 
.step-text, 
.typing-indicator-bubble {
  transition: background-color var(--transition-speed) ease, 
              border-color var(--transition-speed) ease, 
              color var(--transition-speed) ease, 
              box-shadow var(--transition-speed) ease;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* Scrollbar styles */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
  position: relative;
}

/* Sidebar Styles */
.sidebar {
  width: 320px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 100;
  transition: transform var(--transition-speed) ease, background-color var(--transition-speed), border-color var(--transition-speed);
}

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

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(var(--primary-rgb), 0.3);
  border: 1px solid var(--border-color);
}

.logo-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--transition-speed) ease;
}

/* Theme toggle based logo visibility */
html[data-theme="light"] .logo-light {
  opacity: 1;
}
html[data-theme="light"] .logo-dark {
  opacity: 0;
}
html[data-theme="dark"] .logo-light {
  opacity: 0;
}
html[data-theme="dark"] .logo-dark {
  opacity: 1;
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.5px;
}

.accent-text {
  color: var(--primary);
}

.sidebar-close-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
}

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

.new-chat-container {
  padding: 20px 16px 8px 16px;
}

.new-chat-btn {
  width: 100%;
  height: 48px;
  background-color: transparent;
  border: 1.5px dashed var(--primary);
  border-radius: 12px;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.new-chat-btn:hover {
  background-color: var(--primary);
  color: white;
  border-style: solid;
  box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.25);
  transform: translateY(-1px);
}

.new-chat-btn:active {
  transform: translateY(0);
}

.new-chat-btn i {
  width: 18px;
  height: 18px;
}

.sidebar-section-title {
  padding: 24px 24px 8px 24px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.character-list {
  flex: 1;
  padding: 0 16px;
  overflow-y: auto;
}

/* Character Card */
.character-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  margin-bottom: 8px;
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  background-color: transparent;
}

.character-card:hover {
  background-color: var(--bg-card-hover);
}

.character-card.active {
  background-color: var(--bg-card-active);
  border-color: var(--card-border-active);
}

.avatar-container {
  position: relative;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.hitesh-avatar {
  background: var(--avatar-hitesh-grad);
}

.piyush-avatar {
  background: var(--avatar-piyush-grad);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  position: absolute;
  bottom: -2px;
  right: -2px;
  border: 2px solid var(--bg-sidebar);
}

.status-indicator.online {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.char-info {
  flex: 1;
  overflow: hidden;
}

.char-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 2px;
}

.char-tagline {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.char-preview {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.8;
}

.sidebar-footer {
  padding: 20px 24px;
  border-top: 1px solid var(--border-color);
}

/* Theme Toggle Button */
.theme-toggle-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.theme-label {
  font-size: 14px;
  font-weight: 500;
}

.theme-toggle-btn {
  background-color: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  width: 64px;
  height: 32px;
  border-radius: 16px;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  color: var(--text-muted);
}

.theme-toggle-btn i {
  width: 14px;
  height: 14px;
  z-index: 2;
  transition: color var(--transition-speed);
}

.toggle-slider {
  position: absolute;
  width: 24px;
  height: 24px;
  background-color: var(--primary);
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.4);
  z-index: 1;
}

/* Toggle transformations */
html[data-theme="light"] .toggle-slider {
  transform: translateX(0);
}

html[data-theme="dark"] .toggle-slider {
  transform: translateX(32px);
}

html[data-theme="light"] .sun-icon {
  color: white;
}

html[data-theme="dark"] .moon-icon {
  color: white;
}

.creator-badge {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  opacity: 0.6;
}

/* Main Chat Container */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* Chat Header */
.chat-header {
  height: 80px;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-chat-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  z-index: 10;
  transition: all var(--transition-speed);
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  margin-right: 12px;
}

.menu-btn:hover {
  background-color: var(--bg-card-hover);
}

.active-char-profile {
  display: flex;
  align-items: center;
  gap: 16px;
}

.active-header-avatar {
  width: 44px;
  height: 44px;
  font-size: 16px;
  border-radius: 10px;
}

.active-char-meta h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
}

.active-char-status {
  font-size: 12px;
  color: var(--success);
  font-weight: 500;
}

.header-status-link {
  color: var(--success);
  text-decoration: none;
  transition: opacity 0.25s ease;
}

.header-status-link:hover {
  text-decoration: underline;
  opacity: 0.8;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.action-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.action-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background-color: var(--primary-glow);
}

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

/* Message Styles */
.message-row {
  display: flex;
  width: 100%;
  animation: messageFadeIn 0.3s ease forwards;
}

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

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

.message-row.ai {
  justify-content: flex-start;
  flex-direction: column;
  gap: 8px;
}

.message-bubble {
  max-width: 70%;
  padding: 16px 20px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.6;
  position: relative;
  word-wrap: break-word;
}

.message-row.user .message-bubble {
  background-color: var(--chat-bubble-user);
  color: var(--chat-bubble-user-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(var(--primary-rgb), 0.2);
}

.message-row.ai .message-bubble {
  background-color: var(--chat-bubble-ai);
  color: var(--chat-bubble-ai-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  max-width: 80%;
}

.message-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  align-self: flex-end;
  opacity: 0.6;
}

.message-row.user .message-time {
  margin-right: 4px;
}

.message-row.ai .message-time {
  margin-left: 56px; /* Offset to align with content */
}

/* System Welcome Message styling */
.system-message {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 24px;
  border-radius: 16px;
  background-color: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  max-width: 600px;
  margin: 20px auto;
  animation: messageFadeIn 0.5s ease forwards;
}

.system-avatar {
  background-color: var(--primary-glow);
  color: var(--primary);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.system-content h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.system-content p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Orange Glow animation for branding */
.orange-glow {
  filter: drop-shadow(0 0 4px var(--primary));
}

/* Collapsible Pipeline Accordion */
.pipeline-container {
  margin-bottom: 8px;
  border: 1px solid var(--step-border);
  border-radius: 12px;
  overflow: hidden;
  background-color: var(--step-bg);
  max-width: 80%;
  animation: messageFadeIn 0.3s ease forwards;
}

.pipeline-header {
  padding: 12px 16px;
  background-color: var(--bg-card-hover);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background-color 0.2s;
}

.pipeline-header:hover {
  background-color: var(--border-color);
}

.pipeline-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pipeline-title i {
  color: var(--primary);
  width: 16px;
  height: 16px;
}

.pipeline-chevron {
  transition: transform 0.2s ease;
}

.pipeline-container.open .pipeline-chevron {
  transform: rotate(180deg);
}

.pipeline-body {
  display: none;
  padding: 16px;
  flex-direction: column;
  gap: 16px;
  border-top: 1px solid var(--step-border);
}

.pipeline-container.open .pipeline-body {
  display: flex;
}

/* Individual pipeline step styling */
.pipeline-step {
  display: flex;
  gap: 12px;
  position: relative;
}

.pipeline-step:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 10px;
  top: 24px;
  bottom: -20px;
  width: 2px;
  background-color: var(--border-color);
}

.step-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: var(--border-color);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  z-index: 2;
  flex-shrink: 0;
  border: 1px solid var(--step-border);
}

.pipeline-step.initial .step-marker {
  background-color: #2b78e4;
  color: white;
}

.pipeline-step.think .step-marker {
  background-color: #a855f7;
  color: white;
}

.pipeline-step.analyse .step-marker {
  background-color: #f59e0b;
  color: white;
}

.pipeline-step.rejected .step-marker {
  background-color: var(--error);
  color: white;
}

.step-details {
  flex: 1;
}

.step-name {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  text-transform: uppercase;
}

.pipeline-step.initial .step-name { color: #2b78e4; }
.pipeline-step.think .step-name { color: #a855f7; }
.pipeline-step.analyse .step-name { color: #f59e0b; }
.pipeline-step.rejected .step-name { color: var(--error); }

.step-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-main);
  opacity: 0.9;
  background-color: var(--bg-card-hover);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

/* Typing Indicator Styling */
.typing-indicator-container {
  padding: 8px 32px;
  display: flex;
  align-items: center;
  animation: fadeIn 0.2s ease forwards;
}

.typing-indicator-bubble {
  background-color: var(--chat-bubble-ai);
  border: 1px solid var(--border-color);
  padding: 12px 18px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.typing-status-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.dots-container {
  display: flex;
  gap: 4px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--primary);
  animation: dotFlashing 1s infinite alternate;
}

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

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

@keyframes dotFlashing {
  0% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1.2);
  }
}

.hidden {
  display: none !important;
}

/* Chat Input Footer container */
.chat-input-container {
  padding: 24px 32px 32px 32px;
  background-color: var(--bg-app);
  border-top: 1px solid var(--border-color);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s;
}

.chat-form:focus-within {
  border-color: var(--primary);
  background-color: var(--bg-input-focus);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.chat-form textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text-main);
  padding: 8px 0;
  resize: none;
  max-height: 120px;
  min-height: 24px;
}

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

.send-btn {
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(var(--primary-rgb), 0.3);
}

.send-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.send-btn:active {
  transform: translateY(0);
}

/* Overlay for Mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 90;
  animation: fadeIn 0.2s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Responsive Media Queries */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }

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

  .sidebar.open + .sidebar-overlay {
    display: block;
  }

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

  .menu-btn {
    display: block;
  }

  .chat-header {
    padding: 0 16px;
  }

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

  .chat-input-container {
    padding: 16px;
  }

  .message-bubble {
    max-width: 85%;
  }
}

/* Link and Bubble States */
.chat-link {
  color: #ff8c00;
  text-decoration: underline;
  font-weight: 500;
  transition: color 0.2s;
}

.chat-link:hover {
  color: var(--primary-hover);
}

.error-bubble {
  background-color: rgba(239, 68, 68, 0.15) !important;
  color: var(--error) !important;
  border: 1px solid rgba(239, 68, 68, 0.3) !important;
}

.rejected-bubble {
  background-color: rgba(239, 68, 68, 0.1) !important;
  color: var(--error) !important;
  border-left: 4px solid var(--error) !important;
}
