/* ========================================
   TechBrain Chat UI — Design System
   ======================================== */

/* ----- Reset & Base ----- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Color Palette */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a26;
  --bg-elevated: #222232;
  --bg-hover: #2a2a3c;

  --surface-1: rgba(255, 255, 255, 0.03);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-3: rgba(255, 255, 255, 0.09);

  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b8;
  --text-tertiary: #6b6b80;
  --text-muted: #4a4a5c;

  --accent-primary: #6366f1;
  --accent-hover: #7c7ff7;
  --accent-subtle: rgba(99, 102, 241, 0.12);
  --accent-glow: rgba(99, 102, 241, 0.25);

  --violet: #8b5cf6;
  --violet-subtle: rgba(139, 92, 246, 0.12);

  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;

  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Sidebar */
  --sidebar-width: 280px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.hidden {
  display: none !important;
}

/* ----- Scrollbar ----- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================
   ONBOARDING SCREEN
   ============================ */
.onboarding-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

.onboarding-card {
  position: relative;
  z-index: 2;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow:
    0 0 0 1px var(--border),
    0 24px 48px -12px rgba(0, 0, 0, 0.5);
  animation: cardEntry 0.6s var(--transition-slow) both;
}

@keyframes cardEntry {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.onboarding-logo {
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
}

.onboarding-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(
    135deg,
    var(--text-primary),
    var(--accent-primary)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.onboarding-subtitle {
  color: var(--text-secondary);
  font-size: 0.925rem;
  margin-bottom: 32px;
  line-height: 1.5;
}

.onboarding-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.input-group {
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: var(--transition-fast);
  outline: none;
}

.input-group input::placeholder {
  color: var(--text-muted);
}

.input-group input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* ----- Background Orbs ----- */
.onboarding-bg-orbs {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.35;
  animation: orbFloat 8s ease-in-out infinite alternate;
}

.orb-1 {
  width: 400px;
  height: 400px;
  background: var(--accent-primary);
  top: -10%;
  left: -5%;
}

.orb-2 {
  width: 350px;
  height: 350px;
  background: var(--violet);
  bottom: -10%;
  right: -5%;
  animation-delay: 2s;
}

.orb-3 {
  width: 250px;
  height: 250px;
  background: #ec4899;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: 4s;
}

@keyframes orbFloat {
  0% {
    transform: translate(0, 0) scale(1);
  }
  100% {
    transform: translate(30px, -20px) scale(1.08);
  }
}

/* ============================
   BUTTONS
   ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-weight: 500;
  transition: var(--transition-fast);
  outline: none;
  text-decoration: none;
}

.btn-primary {
  padding: 12px 24px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), var(--violet));
  color: #fff;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

/* ============================
   CHAT APP LAYOUT
   ============================ */
.chat-app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ----- Sidebar ----- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  transition: var(--transition-base);
  overflow: hidden;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
  padding: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-text {
  font-weight: 700;
  font-size: 1.05rem;
  background: linear-gradient(
    135deg,
    var(--text-primary),
    var(--accent-primary)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 32px);
  margin: 0 16px 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
  color: var(--accent-hover);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px dashed rgba(99, 102, 241, 0.3);
}

.btn-new-chat:hover {
  background: rgba(99, 102, 241, 0.18);
  border-color: var(--accent-primary);
}

.sidebar-sessions-label {
  padding: 4px 20px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-sessions {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-fast);
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 2px;
  position: relative;
}

.session-item:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.session-item.active {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}

.session-item .session-icon {
  flex-shrink: 0;
  opacity: 0.6;
}

.session-item .session-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item .session-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.session-item .session-delete-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.session-item:hover .session-delete-btn {
  display: flex;
}

.session-item .session-delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

/* Sidebar footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-primary), var(--violet));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  flex-shrink: 0;
}

.sidebar-username {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 130px;
}

.btn-logout {
  color: var(--text-muted);
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.12);
  color: var(--error);
}

/* ============================
   CHAT MAIN AREA
   ============================ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  background: var(--bg-primary);
}

/* -- Header -- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(10, 10, 15, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-info h2 {
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-session-id {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.sidebar-toggle-mobile {
  display: none;
}

/* -- Messages -- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  animation: fadeIn 0.5s ease;
}

.empty-state-icon {
  margin-bottom: 20px;
  opacity: 0.3;
}

.empty-state h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9rem;
  max-width: 360px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Message Bubble */
.message {
  display: flex;
  gap: 12px;
  padding: 8px 24px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  animation: messageIn 0.35s ease;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 4px;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--accent-primary), var(--violet));
  color: #fff;
}

.message.assistant .message-avatar {
  background: var(--bg-elevated);
  color: var(--accent-primary);
  border: 1px solid var(--border);
}

.message.assistant .message-avatar svg {
  width: 18px;
  height: 18px;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-sender {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.message.user .message-sender {
  color: var(--accent-hover);
}

.message.assistant .message-sender {
  color: var(--violet);
}

.message-content {
  font-size: 0.925rem;
  line-height: 1.7;
  color: var(--text-primary);
  word-break: break-word;
}

/* Markdown inside messages */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  margin: 16px 0 8px;
  font-weight: 600;
  line-height: 1.3;
}

.message-content h1 {
  font-size: 1.4rem;
}
.message-content h2 {
  font-size: 1.2rem;
}
.message-content h3 {
  font-size: 1.05rem;
}

.message-content p {
  margin-bottom: 10px;
}

.message-content ul,
.message-content ol {
  margin: 8px 0 12px 20px;
}

.message-content li {
  margin-bottom: 4px;
}

.message-content a {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-content blockquote {
  border-left: 3px solid var(--accent-primary);
  padding: 8px 16px;
  margin: 12px 0;
  background: var(--surface-1);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.875rem;
}

.message-content th,
.message-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.message-content th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-secondary);
}

.message-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent-hover);
}

.message-content pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 12px 0;
  overflow-x: auto;
  position: relative;
}

.message-content pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
  font-size: 0.85rem;
  line-height: 1.6;
}

/* JSON formatted display */
.json-block {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.json-block .json-key {
  color: #93c5fd;
}
.json-block .json-string {
  color: #86efac;
}
.json-block .json-number {
  color: #fde68a;
}
.json-block .json-boolean {
  color: #c4b5fd;
}
.json-block .json-null {
  color: var(--text-muted);
}

/* Copy button on code blocks */
.code-block-wrapper {
  position: relative;
}

.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  font-family: var(--font-sans);
}

.copy-code-btn:hover {
  background: var(--surface-3);
  color: var(--text-primary);
}

/* Loading indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: typingBounce 1.4s infinite;
}

.typing-indicator .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* -- Input Area -- */
.chat-input-container {
  padding: 0 24px 16px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 18px;
  transition: var(--transition-fast);
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

#chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  resize: none;
  max-height: 160px;
  line-height: 1.5;
  padding: 6px 0;
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), var(--violet));
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-send:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.chat-input-footer {
  text-align: center;
  padding: 8px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ============================
   TOAST NOTIFICATIONS
   ============================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.875rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.3s ease;
  max-width: 380px;
}

.toast.toast-error {
  border-color: rgba(239, 68, 68, 0.3);
}

.toast.toast-success {
  border-color: rgba(34, 197, 94, 0.3);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(30px);
  }
}

/* ============================
   SESSION LOADING SKELETON
   ============================ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-1) 25%,
    var(--surface-2) 50%,
    var(--surface-1) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

.skeleton-session {
  height: 40px;
  margin: 4px 8px;
  border-radius: var(--radius-sm);
}

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  .sidebar-toggle-mobile {
    display: flex;
  }

  .chat-input-container {
    padding: 0 12px 12px;
  }

  .message {
    padding: 8px 12px;
  }

  .onboarding-card {
    margin: 16px;
    padding: 32px 24px;
  }
}

/* Mobile backdrop */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

/* ============================
   USAGE / META INFO
   ============================ */
.usage-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 6px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.usage-badge svg {
  width: 12px;
  height: 12px;
  opacity: 0.5;
}
