/* =============================================================================
   LEKHANTRA - Premium AI Study Assistant Interface
   Design Tokens, Reset, Typography, Layout, Components, Animations
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. CSS Custom Properties (Design Tokens)
   ----------------------------------------------------------------------------- */
:root {
  /* Brand Colors - Burgundy/Wine Primary */
  --color-primary: #8B2252;
  --color-primary-hover: #A52A4A;
  --color-primary-active: #7A1E48;
  --color-primary-light: #C44D7A;
  --color-primary-bg: rgba(139, 34, 82, 0.08);
  --color-primary-border: rgba(139, 34, 82, 0.2);

  /* Gold Accent */
  --color-accent: #D4A853;
  --color-accent-hover: #E0B866;
  --color-accent-active: #C99942;
  --color-accent-light: #F0DCA0;
  --color-accent-bg: rgba(212, 168, 83, 0.1);
  --color-accent-border: rgba(212, 168, 83, 0.3);

  /* Cream/Neutral Backgrounds */
  --color-bg-primary: #FDFBF7;
  --color-bg-secondary: #F8F5EF;
  --color-bg-tertiary: #F2EDE4;
  --color-bg-card: #FFFFFF;
  --color-bg-overlay: rgba(15, 12, 8, 0.5);

  /* Text Colors */
  --color-text-primary: #1A1614;
  --color-text-secondary: #4A4540;
  --color-text-tertiary: #7A746D;
  --color-text-muted: #A09A91;
  --color-text-inverse: #FFFFFF;
  --color-text-link: var(--color-primary);

  /* Semantic Colors */
  --color-success: #2D8A5F;
  --color-success-bg: rgba(45, 138, 95, 0.1);
  --color-warning: #C98B2B;
  --color-warning-bg: rgba(201, 139, 43, 0.1);
  --color-error: #C93B3B;
  --color-error-bg: rgba(201, 59, 59, 0.1);
  --color-info: #3B7AC9;
  --color-info-bg: rgba(59, 122, 201, 0.1);

  /* Border Colors */
  --color-border: #E5E0D8;
  --color-border-light: #F0EDE6;
  --color-border-medium: #D8D3C9;
  --color-border-focus: var(--color-primary);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(26, 22, 20, 0.04);
  --shadow-sm: 0 2px 4px rgba(26, 22, 20, 0.06);
  --shadow-md: 0 4px 12px rgba(26, 22, 20, 0.08);
  --shadow-lg: 0 8px 24px rgba(26, 22, 20, 0.1);
  --shadow-xl: 0 16px 48px rgba(26, 22, 20, 0.12);
  --shadow-2xl: 0 24px 64px rgba(26, 22, 20, 0.16);
  --shadow-inner: inset 0 2px 4px rgba(26, 22, 20, 0.06);
  --shadow-focus: 0 0 0 3px var(--color-primary-border);

  /* Border Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Spacing Scale */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Monaco, monospace;

  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 30px;
  --text-4xl: 36px;

  --leading-none: 1;
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;
  --leading-loose: 2;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Layout */
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 64px;
  --header-height: 64px;
  --max-content-width: 800px;
  --input-height: 48px;

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
  --transition-slower: 400ms ease;

  /* Z-Index Scale */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-popover: 600;
  --z-tooltip: 700;
  --z-toast: 800;
}

/* -----------------------------------------------------------------------------
   2. Base Reset and Typography
   ----------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  min-height: 100vh;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  color: var(--color-text-primary);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p {
  margin-bottom: var(--space-4);
}

a {
  color: var(--color-text-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

strong, b {
  font-weight: var(--weight-semibold);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background-color: var(--color-bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background-color: var(--color-bg-tertiary);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
}

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-6) 0;
}

img, video {
  max-width: 100%;
  height: auto;
  display: block;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

textarea {
  resize: vertical;
}

ul, ol {
  list-style-position: inside;
}

::selection {
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: var(--color-border-medium);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-muted);
}

/* -----------------------------------------------------------------------------
   3. App Layout
   ----------------------------------------------------------------------------- */
.app {
  display: flex;
  min-height: 100vh;
  background-color: var(--color-bg-primary);
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background-color: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  z-index: var(--z-sticky);
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.app-header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-header-logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
}

.app-header-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-main {
  display: flex;
  flex: 1;
  padding-top: var(--header-height);
  min-height: 100vh;
}

.app-sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background-color: var(--color-bg-card);
  border-right: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sticky);
  transition: transform var(--transition-slow), width var(--transition-slow);
}

.app-sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.app-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-height));
  transition: margin-left var(--transition-slow);
}

.app-content.expanded {
  margin-left: var(--sidebar-collapsed-width);
}

.app-content-inner {
  flex: 1;
  max-width: var(--max-content-width);
  width: 100%;
  margin: 0 auto;
  padding: var(--space-8);
}

/* -----------------------------------------------------------------------------
   4. Premium Sidebar Components
   ----------------------------------------------------------------------------- */
.sidebar-header {
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
}

.sidebar-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-3);
}

.sidebar-actions {
  display: flex;
  gap: var(--space-2);
}

.sidebar-new-chat {
  flex: 1;
}

.sidebar-section {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
}

.sidebar-section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-3);
}

.sidebar-documents {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--color-border-light);
  background-color: var(--color-bg-secondary);
}

/* Document Upload Dropzone */
.dropzone {
  border: 2px dashed var(--color-border-medium);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  transition: all var(--transition-base);
  background-color: var(--color-bg-secondary);
  cursor: pointer;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--color-primary);
  background-color: var(--color-primary-bg);
}

.dropzone-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--color-text-muted);
  transition: color var(--transition-base);
}

.dropzone:hover .dropzone-icon,
.dropzone.dragover .dropzone-icon {
  color: var(--color-primary);
}

.dropzone-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.dropzone-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.dropzone.uploading {
  pointer-events: none;
  opacity: 0.7;
}

/* Document Cards */
.document-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  margin-bottom: var(--space-2);
  transition: all var(--transition-base);
  cursor: pointer;
}

.document-card:hover {
  border-color: var(--color-border-medium);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

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

.document-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background-color: var(--color-bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
}

.document-card.active .document-card-icon {
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
}

.document-card-info {
  flex: 1;
  min-width: 0;
}

.document-card-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-card-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.document-card-actions {
  display: flex;
  gap: var(--space-1);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.document-card:hover .document-card-actions {
  opacity: 1;
}

/* Chat History Items */
.chat-history-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
  cursor: pointer;
  color: var(--color-text-secondary);
}

.chat-history-item:hover {
  background-color: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.chat-history-item.active {
  background-color: var(--color-primary-bg);
  color: var(--color-primary);
}

.chat-history-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.chat-history-text {
  flex: 1;
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* -----------------------------------------------------------------------------
   5. Professional Chat Interface
   ----------------------------------------------------------------------------- */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.chat-welcome {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  max-width: 600px;
  margin: 0 auto;
}

.chat-welcome-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-6);
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.chat-welcome-title {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  margin-bottom: var(--space-4);
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chat-welcome-text {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
}

/* Message Bubbles */
.message {
  display: flex;
  gap: var(--space-4);
  max-width: var(--max-content-width);
  margin: 0 auto;
  width: 100%;
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
  color: white;
}

.message.user .message-avatar {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-bubble {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
}

.message.assistant .message-bubble {
  background-color: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-top-left-radius: var(--radius-xs);
}

.message.user .message-bubble {
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
  border-top-right-radius: var(--radius-xs);
}

.message-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
  padding-left: var(--space-5);
}

.message.user .message-time {
  text-align: right;
  padding-right: var(--space-5);
  padding-left: 0;
}

/* Markdown Rendering Styles */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin-top: var(--space-4);
  margin-bottom: var(--space-3);
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
  margin-top: 0;
}

.message-content p {
  margin-bottom: var(--space-3);
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ul,
.message-content ol {
  margin-bottom: var(--space-3);
  padding-left: var(--space-6);
}

.message-content li {
  margin-bottom: var(--space-2);
}

.message-content blockquote {
  border-left: 3px solid var(--color-primary);
  padding-left: var(--space-4);
  margin: var(--space-4) 0;
  color: var(--color-text-secondary);
  font-style: italic;
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-4) 0;
  font-size: var(--text-sm);
}

.message-content th,
.message-content td {
  border: 1px solid var(--color-border);
  padding: var(--space-3);
  text-align: left;
}

.message-content th {
  background-color: var(--color-bg-secondary);
  font-weight: var(--weight-semibold);
}

.message-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: var(--space-4) 0;
}

/* Code Blocks in Messages */
.message-content pre {
  margin: var(--space-4) 0;
  position: relative;
}

.message-content pre code {
  display: block;
  padding: var(--space-4);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  background-color: #1e1e2e;
  color: #cdd6f4;
  border-radius: var(--radius-md);
}

/* -----------------------------------------------------------------------------
   6. Modern Input Components
   ----------------------------------------------------------------------------- */
.input-wrapper {
  position: relative;
  width: 100%;
}

.input-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.input-field {
  width: 100%;
  height: var(--input-height);
  padding: 0 var(--space-4);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  background-color: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.input-field::placeholder {
  color: var(--color-text-muted);
}

.input-field:hover {
  border-color: var(--color-border-medium);
}

.input-field:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.input-field:disabled {
  background-color: var(--color-bg-secondary);
  cursor: not-allowed;
  opacity: 0.7;
}

.input-field.error {
  border-color: var(--color-error);
}

.input-field.error:focus {
  box-shadow: 0 0 0 3px var(--color-error-bg);
}

.input-error {
  font-size: var(--text-sm);
  color: var(--color-error);
  margin-top: var(--space-2);
}

.input-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}

/* Textarea */
.textarea-field {
  min-height: 120px;
  height: auto;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
}

/* Chat Input Area */
.chat-input-area {
  padding: var(--space-4) var(--space-8);
  background-color: var(--color-bg-card);
  border-top: 1px solid var(--color-border-light);
}

.chat-input-container {
  max-width: var(--max-content-width);
  margin: 0 auto;
  position: relative;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  background-color: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-3);
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.chat-input-wrapper:focus-within {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md), var(--shadow-focus);
}

.chat-textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text-primary);
  padding: var(--space-2) var(--space-3);
  max-height: 200px;
  min-height: 24px;
}

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

.chat-textarea:focus {
  outline: none;
}

.chat-input-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.chat-input-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--space-3);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--input-height);
  padding: 0 var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

.btn-primary {
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active:not(:disabled) {
  background-color: var(--color-primary-active);
  transform: translateY(0);
}

.btn-secondary {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--color-bg-secondary);
  border-color: var(--color-border-medium);
}

.btn-ghost {
  background-color: transparent;
  color: var(--color-text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background-color: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

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

.btn-accent:hover:not(:disabled) {
  background-color: var(--color-accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-danger {
  background-color: var(--color-error);
  color: var(--color-text-inverse);
}

.btn-danger:hover:not(:disabled) {
  background-color: #b53535;
}

.btn-sm {
  height: 36px;
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
}

.btn-lg {
  height: 56px;
  padding: 0 var(--space-8);
  font-size: var(--text-base);
}

.btn-icon {
  width: var(--input-height);
  padding: 0;
}

.btn-icon.btn-sm {
  width: 36px;
}

.btn-icon.btn-lg {
  width: 56px;
}

.btn-loading {
  position: relative;
  color: transparent !important;
}

.btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* -----------------------------------------------------------------------------
   7. Modal Dialogs
   ----------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: var(--color-bg-overlay);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  animation: fadeIn var(--transition-base);
}

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

.modal {
  background-color: var(--color-bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - var(--space-12));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalSlideIn var(--transition-slow);
}

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

.modal-lg {
  max-width: 640px;
}

.modal-xl {
  max-width: 800px;
}

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

.modal-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

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

.modal-close:hover {
  background-color: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border-light);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  background-color: var(--color-bg-secondary);
}

/* Auth Modal */
.auth-modal {
  text-align: center;
}

.auth-modal-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-6);
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: var(--text-3xl);
}

.auth-modal-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  margin-bottom: var(--space-2);
}

.auth-modal-subtitle {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-6);
}

.auth-form {
  text-align: left;
}

.auth-form .input-wrapper {
  margin-bottom: var(--space-4);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-6) 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: var(--color-border);
}

.auth-footer {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-6);
}

.auth-footer a {
  font-weight: var(--weight-medium);
}

/* Generator Modal */
.generator-modal .modal-body {
  padding: var(--space-8);
}

.generator-preview {
  background-color: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  min-height: 200px;
}

.generator-preview-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-3);
}

.generator-type-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.generator-type-btn {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-card);
  text-align: center;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.generator-type-btn:hover {
  border-color: var(--color-primary);
  background-color: var(--color-primary-bg);
}

.generator-type-btn.active {
  border-color: var(--color-primary);
  background-color: var(--color-primary-bg);
}

.generator-type-icon {
  width: 32px;
  height: 32px;
  margin: 0 auto var(--space-2);
  color: var(--color-text-muted);
}

.generator-type-btn.active .generator-type-icon {
  color: var(--color-primary);
}

.generator-type-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
}

/* -----------------------------------------------------------------------------
   8. Toast Notifications
   ----------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  background-color: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 320px;
  max-width: 480px;
  pointer-events: auto;
  animation: toastSlideIn var(--transition-slow);
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.hiding {
  animation: toastSlideOut var(--transition-slow) forwards;
}

@keyframes toastSlideOut {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
}

.toast.success .toast-icon { color: var(--color-success); }
.toast.error .toast-icon { color: var(--color-error); }
.toast.warning .toast-icon { color: var(--color-warning); }
.toast.info .toast-icon { color: var(--color-info); }

.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
  margin-bottom: var(--space-1);
}

.toast-message {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: var(--leading-snug);
}

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

.toast-close:hover {
  background-color: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

/* Toast Progress Bar */
.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background-color: var(--color-border-light);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow: hidden;
}

.toast-progress-bar {
  height: 100%;
  background-color: var(--color-primary);
  animation: toastProgress linear forwards;
}

.toast.success .toast-progress-bar { background-color: var(--color-success); }
.toast.error .toast-progress-bar { background-color: var(--color-error); }
.toast.warning .toast-progress-bar { background-color: var(--color-warning); }
.toast.info .toast-progress-bar { background-color: var(--color-info); }

@keyframes toastProgress {
  from { width: 100%; }
  to { width: 0%; }
}

/* -----------------------------------------------------------------------------
   9. Typing Indicators and Loading Animations
   ----------------------------------------------------------------------------- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background-color: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  width: fit-content;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background-color: var(--color-text-muted);
  border-radius: var(--radius-full);
  animation: typingBounce 1.4s ease-in-out infinite;
}

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

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

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Loading Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.spinner-white {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: white;
}

/* Loading Skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-tertiary) 0%,
    var(--color-bg-secondary) 50%,
    var(--color-bg-tertiary) 100%
  );
  background-size: 200% 100%;
  animation: skeleton 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 16px;
  margin-bottom: var(--space-2);
}

.skeleton-text:last-child {
  width: 70%;
}

.skeleton-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.skeleton-bubble {
  height: 80px;
  border-radius: var(--radius-lg);
}

/* Pulse Animation */
.pulse {
  animation: pulse 2s ease-in-out infinite;
}

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

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background-color: var(--color-bg-overlay);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.loading-content {
  text-align: center;
}

.loading-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--color-primary);
}

.loading-text {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
}

/* Upload Progress */
.upload-progress {
  margin-top: var(--space-4);
}

.upload-progress-bar {
  height: 4px;
  background-color: var(--color-bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-accent) 100%);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
}

.upload-progress-text {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
  text-align: center;
}

/* Document Processing */
.document-processing {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-8);
  text-align: center;
}

.document-processing-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-4);
  color: var(--color-primary);
  animation: spin 2s linear infinite;
}

.document-processing-text {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-4);
}

.document-processing-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
  max-width: 300px;
}

.processing-step {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.processing-step.completed {
  color: var(--color-success);
}

.processing-step.active {
  color: var(--color-primary);
  font-weight: var(--weight-medium);
}

.processing-step-icon {
  width: 16px;
  height: 16px;
}

/* -----------------------------------------------------------------------------
   10. Responsive Breakpoints
   ----------------------------------------------------------------------------- */

/* Tablet - 768px and below */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 260px;
    --space-6: 20px;
    --space-8: 24px;
  }

  .app-sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }

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

  .app-content {
    margin-left: 0;
  }

  .chat-messages {
    padding: var(--space-4);
  }

  .chat-input-area {
    padding: var(--space-4);
  }

  .message {
    gap: var(--space-3);
  }

  .message-avatar {
    width: 32px;
    height: 32px;
  }

  .message-bubble {
    padding: var(--space-3) var(--space-4);
  }

  .modal {
    max-width: calc(100vw - var(--space-8));
    margin: var(--space-4);
  }

  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
    bottom: var(--space-4);
  }

  .toast {
    min-width: auto;
    width: 100%;
  }

  .generator-type-selector {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile - 480px and below */
@media (max-width: 480px) {
  :root {
    --header-height: 56px;
    --space-4: 12px;
    --space-6: 16px;
    --space-8: 20px;
    --text-base: 14px;
  }

  .app-header {
    padding: 0 var(--space-4);
  }

  .app-header-title {
    font-size: var(--text-base);
  }

  .chat-welcome {
    padding: var(--space-8) var(--space-4);
  }

  .chat-welcome-title {
    font-size: var(--text-2xl);
  }

  .chat-welcome-text {
    font-size: var(--text-base);
  }

  .message {
    flex-direction: column;
    gap: var(--space-2);
  }

  .message.user {
    flex-direction: column;
    align-items: flex-end;
  }

  .message-avatar {
    display: none;
  }

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

  .chat-input-wrapper {
    border-radius: var(--radius-lg);
    padding: var(--space-2);
  }

  .chat-input-actions .btn-icon {
    width: 40px;
    height: 40px;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-4);
  }

  .modal-footer {
    flex-direction: column;
  }

  .modal-footer .btn {
    width: 100%;
  }

  .auth-modal-icon {
    width: 48px;
    height: 48px;
    font-size: var(--text-2xl);
  }

  .generator-type-selector {
    grid-template-columns: 1fr;
  }

  .toast-container {
    bottom: auto;
    top: calc(var(--header-height) + var(--space-4));
    left: var(--space-4);
    right: var(--space-4);
  }
}

/* Large Desktop - 1400px and above */
@media (min-width: 1400px) {
  :root {
    --max-content-width: 900px;
    --sidebar-width: 320px;
  }

  .chat-messages {
    padding: var(--space-8) var(--space-12);
  }

  .message-bubble {
    padding: var(--space-5) var(--space-6);
    font-size: var(--text-lg);
  }
}
/* Print Styles */
@media print {
  .app-sidebar,
  .chat-input-area,
  .app-header {
    display: none !important;
  }

  .app-content {
    margin-left: 0;
    padding: 0;
  }

  .message {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .message-bubble {
    border: 1px solid #ddd;
    background: white !important;
    color: black !important;
  }
}

/* -----------------------------------------------------------------------------
   Utility Classes
   ----------------------------------------------------------------------------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.hidden { display: none !important; }
.block { display: block; }
.inline-block { display: inline-block; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }

.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }

.cursor-pointer { cursor: pointer; }
.cursor-grab { cursor: grab; }

.transition { transition: all var(--transition-base); }
.transition-fast { transition: all var(--transition-fast); }
.transition-slow { transition: all var(--transition-slow); }

/* Focus Visible for Accessibility */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* -----------------------------------------------------------------------------
   HTML Structure Overrides
   Match HTML class names to CSS
   ----------------------------------------------------------------------------- */

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  background-color: var(--color-bg-primary);
}

/* Main Content Area */
.main-content {
  display: flex;
  flex: 1;
  padding-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  z-index: 200;
}

.header-left,
.header-center,
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-left {
  flex: 0 0 auto;
}

.header-center {
  flex: 1;
  justify-content: center;
}

.header-right {
  flex: 0 0 auto;
}

.current-doc-name {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Brand */
.brand-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--color-text-primary);
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.brand-name {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -0.02em;
}

/* Sidebar Toggle */
.sidebar-toggle {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}

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

/* New Chat Button */
.new-chat-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.new-chat-btn:hover {
  background: var(--color-primary-hover);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--color-bg-card);
  border-right: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition-slow);
  overflow: hidden;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.sidebar-header h2 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.sidebar-action:hover {
  background: var(--color-bg-secondary);
  color: var(--color-error);
}

/* Upload Section */
.upload-section {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
}

.upload-dropzone {
  border: 2px dashed var(--color-border-medium);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  transition: all var(--transition-base);
  background: var(--color-bg-secondary);
  cursor: pointer;
  margin-bottom: var(--space-3);
}

.upload-dropzone:hover,
.upload-dropzone.drag-over {
  border-color: var(--color-primary);
  background: var(--color-primary-bg);
}

.upload-dropzone input {
  display: none;
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.upload-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
}

.upload-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.upload-link {
  color: var(--color-primary);
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  font-size: inherit;
  padding: 0;
  font-family: inherit;
}

.upload-link:hover {
  color: var(--color-primary-hover);
  text-decoration: none;
}

.upload-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.upload-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.upload-btn:hover {
  background: var(--color-primary-hover);
}

.upload-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Upload Progress */
.upload-progress {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.progress-filename {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-primary);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-percent {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
}

.progress-bar {
  height: 4px;
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: var(--space-2);
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
  width: 0%;
}

.progress-status {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Current Document */
.current-document {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
}

.section-header {
  margin-bottom: var(--space-3);
}

.section-header h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}

.document-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

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

.document-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-bg);
  color: var(--color-primary);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.document-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.document-name {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.document-meta {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.3;
}

.document-status {
  flex-shrink: 0;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
}

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

.status-indicator.error {
  background: var(--color-error);
}

/* Recent Documents */
.recent-documents {
  overflow-y: auto;
  padding: var(--space-4);
  max-height: 200px;
}

.documents-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  color: var(--color-text-muted);
  text-align: center;
}

.empty-state svg {
  margin-bottom: var(--space-2);
  opacity: 0.5;
}

.empty-state p {
  font-size: var(--text-sm);
  margin: 0;
}

/* Chat History Section */
.chat-history {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 120px;
  max-height: 300px;
  flex-shrink: 0;
  padding: var(--space-4);
}

.chat-history .section-header {
  margin-bottom: var(--space-4);
}

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

.conversation-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  margin-bottom: var(--space-2);
}

.conversation-item:last-child {
  margin-bottom: 0;
}

.conversation-item:hover {
  background: var(--color-bg-secondary);
  border-color: var(--color-border-medium);
}

.conversation-item.active {
  background: var(--color-primary-bg);
  border-color: var(--color-primary-border);
  padding-left: calc(var(--space-3) - 3px);
  border-left: 3px solid var(--color-primary);
}

.conversation-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.conversation-item.active .conversation-icon {
  background: var(--color-primary-border);
  color: var(--color-primary);
}

.conversation-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.conversation-date {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.3;
}

.conversation-delete {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  opacity: 0;
  transition: all var(--transition-fast);
  background: transparent;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}

.conversation-item:hover .conversation-delete {
  opacity: 1;
}

.conversation-delete:hover {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.empty-conversations {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  color: var(--color-text-muted);
  text-align: center;
  background: var(--color-bg-card);
  border: 1px dashed var(--color-border-medium);
  border-radius: var(--radius-md);
}

.empty-conversations svg {
  margin-bottom: var(--space-2);
  opacity: 0.5;
}

.empty-conversations p {
  font-size: var(--text-sm);
  margin: 0;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg-secondary);
  flex-shrink: 0;
}

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.action-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}

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

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sidebar-settings {
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border-light);
}

.questions-count {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.questions-count input {
  width: 60px;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: var(--text-sm);
}

/* Chat Area */
.chat-area {
  flex: 1;
  margin-left: 280px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-height));
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
  padding-bottom: 140px;
}

/* Welcome State */
.welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  min-height: 60vh;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-6);
}

.welcome-icon img {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.welcome-state h1 {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.welcome-state p {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-8);
}

.suggested-prompts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  max-width: 600px;
  width: 100%;
}

.prompt-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-align: left;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}

.prompt-card:hover {
  background: var(--color-primary-bg);
  border-color: var(--color-primary-border);
  color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.prompt-card svg {
  flex-shrink: 0;
  opacity: 0.7;
}

/* Messages Container */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  max-width: 800px;
  margin: 0 auto;
}

/* Message Bubbles */
.message {
  display: flex;
  gap: var(--space-3);
  animation: fadeIn 0.3s ease;
}

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

.message-ai {
  align-items: flex-start;
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--color-primary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

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

.message-avatar svg {
  color: var(--color-primary);
}

.message-user .message-avatar {
  background: var(--color-bg-tertiary);
}

.message-content {
  max-width: 75%;
  min-width: 100px;
}

.message-text {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
}

.message-ai .message-text {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  color: var(--color-text-primary);
}

.message-user .message-text {
  background: var(--color-primary);
  color: white;
}

.message-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
  padding: 0 var(--space-2);
}

.message-user .message-time {
  text-align: right;
}

.message-actions {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-2);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.message:hover .message-actions {
  opacity: 1;
}

.message-actions .action-btn {
  padding: var(--space-1);
  background: var(--color-bg-secondary);
  border: none;
}

.message-actions .action-btn:hover {
  background: var(--color-bg-tertiary);
}

/* Typing Indicator */
.message.typing .message-content {
  padding: var(--space-4);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
}

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

.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

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

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Chat Input */
.chat-input-container {
  position: fixed;
  bottom: 0;
  left: 280px;
  right: 0;
  padding: var(--space-4) var(--space-6);
  background: linear-gradient(to top, var(--color-bg-primary) 80%, transparent);
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  max-width: 800px;
  margin: 0 auto;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-3);
  box-shadow: var(--shadow-lg);
}

.chat-input-wrapper textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: var(--text-base);
  color: var(--color-text-primary);
  outline: none;
  min-height: 24px;
  max-height: 150px;
  padding: var(--space-2) 0;
}

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

.input-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding-bottom: var(--space-1);
}

.input-action-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}

.input-action-btn:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.send-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.send-btn:hover {
  background: var(--color-primary-hover);
  transform: scale(1.05);
}

.input-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--space-2);
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  z-index: 400;
}

.modal-overlay:not(.hidden) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--color-bg-card);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  width: 100%;
  max-width: 420px;
  margin: var(--space-4);
  padding: var(--space-6);
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.modal-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
  background: transparent;
  border: none;
}

.modal-close:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.modal-close svg {
  width: 20px;
  height: 20px;
}

.modal-header {
  text-align: center;
  margin-bottom: var(--space-5);
  width: 100%;
  padding: 0;
  border: none;
  display: block;
  flex: none;
  align-items: unset;
  justify-content: unset;
}

.auth-logo {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  margin: 0 auto var(--space-4);
  object-fit: cover;
  display: block;
}

.auth-eyebrow {
  font-size: var(--text-xs);
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  margin: 0 0 var(--space-2) 0;
  display: block;
}

.modal-header h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0 0 var(--space-2) 0;
}

.auth-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin: 0;
}

.modal {
  background: var(--color-bg-card);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  max-width: 440px;
  width: calc(100% - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding: var(--space-6);
  position: relative;
  margin: auto;
}

.modal-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.modal-header {
  text-align: center;
  margin-bottom: var(--space-6);
}

.auth-logo {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  margin: 0 auto var(--space-4);
  object-fit: cover;
}

.auth-eyebrow {
  font-size: var(--text-xs);
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.modal-header h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.auth-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* Auth Form */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
}

.form-group {
  width: 100%;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  transition: all var(--transition-fast);
  background: var(--color-bg-card);
  color: var(--color-text-primary);
  box-sizing: border-box;
  display: block;
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-border);
}

.form-group input::placeholder {
  color: var(--color-text-muted);
}

.btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 500;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  cursor: pointer;
  box-sizing: border-box;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  border: none;
}

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

.btn-secondary {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg-tertiary);
}

.btn-google {
  background: white;
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}

.btn-google:hover {
  background: var(--color-bg-secondary);
}

.google-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin: var(--space-2) 0;
}

.auth-divider span {
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.auth-message {
  font-size: var(--text-sm);
  color: var(--color-error);
  text-align: center;
  margin-top: var(--space-3);
  min-height: 20px;
  padding: var(--space-2);
  background: var(--color-error-bg);
  border-radius: var(--radius-md);
  display: none;
}

.auth-message:empty {
  display: none;
}

.auth-message:not(:empty) {
  display: block;
}

/* User Menu */
.user-profile {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.user-greeting {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
}

.profile-trigger {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-primary-bg);
  border: 2px solid var(--color-primary-border);
}

.profile-trigger img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  min-width: 240px;
  z-index: 100;
}

.dropdown-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
}

.dropdown-header img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.dropdown-user-info {
  display: flex;
  flex-direction: column;
}

.dropdown-user-info span:first-child {
  font-weight: 600;
  color: var(--color-text-primary);
}

.dropdown-user-info span:last-child {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.dropdown-divider {
  height: 1px;
  background: var(--color-border-light);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  text-align: left;
  transition: all var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.dropdown-item.danger:hover {
  background: var(--color-error-bg);
  color: var(--color-error);
}

/* Sign In Button */
.signup-btn {
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.signup-btn:hover {
  background: var(--color-primary-hover);
}

/* User Menu */
.user-menu {
  display: none;
  align-items: center;
  gap: var(--space-2);
  position: relative;
}

.user-menu:not(.hidden) {
  display: flex;
}

/* Generator Modal */
.generator-modal {
  max-width: 600px;
  text-align: center;
}

.generator-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-2);
}

.generator-content {
  margin: var(--space-6) 0;
}

.typing-indicator {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: var(--space-6);
}

.generator-result {
  text-align: left;
  padding: var(--space-4);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  white-space: pre-wrap;
}

.generator-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
}

/* Delete Confirmation Modal */
.modal.delete-modal {
  max-width: 400px;
  text-align: center;
  padding: var(--space-8);
}

.modal-icon.delete-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  background: var(--color-error-bg);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-icon.delete-icon svg {
  color: var(--color-error);
}

.modal.delete-modal .modal-header h2 {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
  margin: 0 0 var(--space-2);
}

.delete-modal-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
  margin: 0 0 var(--space-6);
}

.delete-modal-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
}

.delete-modal-actions .btn {
  flex: 1;
  padding: var(--space-3) var(--space-6);
}

.btn-danger {
  background: var(--color-error);
  color: var(--color-text-inverse);
  border: none;
  font-weight: var(--font-medium);
}

.btn-danger:hover {
  background: #B03333;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 20px;
  background: var(--color-text-primary);
  color: white;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  z-index: 800;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-xl);
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: var(--color-success);
}

.toast.error {
  background: var(--color-error);
}

.toast.warning {
  background: var(--color-warning);
}

.toast.info {
  background: var(--color-info);
}

/* Markdown Styles in Messages */
.message-text h2,
.message-text h3,
.message-text h4 {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
}

.message-text h2:first-child,
.message-text h3:first-child,
.message-text h4:first-child {
  margin-top: 0;
}

.message-text ul,
.message-text ol {
  margin: var(--space-3) 0;
  padding-left: var(--space-6);
}

.message-text li {
  margin-bottom: var(--space-2);
}

.message-text pre {
  margin: var(--space-4) 0;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
}

.message-text pre code {
  background: none;
  padding: 0;
  font-size: var(--text-sm);
}

.message-text .inline-code {
  background: var(--color-bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  font-size: 0.9em;
}

.message-text blockquote {
  margin: var(--space-4) 0;
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-primary);
  color: var(--color-text-secondary);
  font-style: italic;
}

.message-text a {
  color: var(--color-primary);
  text-decoration: underline;
}

.message-text hr {
  margin: var(--space-6) 0;
}

/* Responsive */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .chat-area,
  .chat-input-container {
    margin-left: 0;
  }

  .chat-input-container {
    left: 0;
  }
}

@media (max-width: 768px) {
  .header-center {
    display: none;
  }

  .suggested-prompts {
    grid-template-columns: 1fr;
  }

  .chat-messages {
    padding: var(--space-4);
    padding-bottom: 160px;
  }

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

  .chat-input-container {
    padding: var(--space-3);
  }

  .modal {
    padding: var(--space-6);
    margin: var(--space-4);
  }
}

@media (max-width: 480px) {
  .brand-name {
    display: none;
  }

  .new-chat-btn span {
    display: none;
  }

  .welcome-state h1 {
    font-size: var(--text-2xl);
  }

  /* Modal mobile fixes */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 85vh;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    padding: var(--space-5);
    margin: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateY(0);
    overflow-y: auto;
  }

  .modal-overlay:not(.hidden) .modal {
    animation: slideUp 0.3s ease;
  }

  @keyframes slideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  .modal-close {
    top: var(--space-3);
    right: var(--space-3);
  }

  .auth-logo {
    width: 56px;
    height: 56px;
  }

  .modal-header h2 {
    font-size: var(--text-xl);
  }
}

/* ============================================
   Auth Modal Specific Overrides
   ============================================ */

/* Override generic .modal styles for auth-modal */
.modal.auth-modal {
  background-color: var(--color-bg-card);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  width: 100%;
  max-width: 420px;
  margin: var(--space-4);
  padding: var(--space-6);
  position: relative;
  box-sizing: border-box;
  overflow: visible;
  max-height: none;
  animation: none;
}

/* Override generic .modal-header for auth modal */
.modal.auth-modal .modal-header {
  text-align: center;
  margin-bottom: var(--space-5);
  padding: 0;
  border: none;
  display: block;
  flex-direction: unset;
  align-items: unset;
  justify-content: unset;
  width: 100%;
}

/* Ensure auth form text is properly aligned */
.modal.auth-modal .auth-form {
  text-align: left;
  width: 100%;
}

.modal.auth-modal .auth-form .form-group {
  width: 100%;
}

.modal.auth-modal .auth-form input {
  width: 100%;
  display: block;
}
