/* ==========================================================================
   RAG Document Assistant — Modern Dark Glassmorphism Design System
   ========================================================================== */

:root {
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Color Palette */
  --bg-dark: #090d16;
  --bg-card: rgba(18, 24, 38, 0.65);
  --bg-card-hover: rgba(28, 36, 56, 0.8);
  --bg-glass: rgba(255, 255, 255, 0.03);

  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(99, 102, 241, 0.3);

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
  --accent-glow: radial-gradient(circle, rgba(99, 102, 241, 0.25) 0%, transparent 70%);

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow-main: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
  --backdrop-blur: blur(16px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  overflow: hidden;
  background-image: 
    radial-gradient(at 10% 10%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
    radial-gradient(at 90% 90%, rgba(168, 85, 247, 0.12) 0px, transparent 50%);
}

/* App Container */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
}

/* Header */
.top-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(9, 13, 22, 0.8);
  backdrop-filter: var(--backdrop-blur);
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 50;
}

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

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: white;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.4);
}

.brand-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.toggle-container {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Switch Toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .3s;
  border-radius: 24px;
  border: 1px solid var(--border-glass);
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background: var(--accent-primary);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* Main Layout */
.app-layout {
  display: flex;
  width: 100%;
  height: calc(100vh - 64px);
  margin-top: 64px;
}

/* Sidebar */
.sidebar {
  width: 320px;
  background: var(--bg-card);
  backdrop-filter: var(--backdrop-blur);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 20px;
}

.section-header {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 8px;
}

.upload-dropzone {
  border: 2px dashed var(--border-glass);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  background: var(--bg-glass);
  cursor: pointer;
  transition: all 0.2s ease;
}

.upload-dropzone:hover, .upload-dropzone.drag-over {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.08);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.15);
}

.upload-icon {
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--accent-primary);
}

.upload-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  flex: 1;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.doc-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-glow);
}

.doc-info {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.doc-icon {
  color: var(--accent-primary);
  font-size: 1.1rem;
}

.doc-name {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.doc-chunks {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.delete-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.delete-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}

/* Chat Main Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: transparent;
  position: relative;
}

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

/* Message Item */
.message {
  display: flex;
  gap: 16px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

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

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.user .avatar {
  background: var(--accent-gradient);
  color: white;
}

.bot .avatar {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--accent-primary);
}

.message-content {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  backdrop-filter: var(--backdrop-blur);
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.6;
}

.user .message-content {
  background: var(--accent-primary);
  border-color: transparent;
  color: white;
  border-bottom-right-radius: 4px;
}

.bot .message-content {
  border-bottom-left-radius: 4px;
}

.sources-container {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-glass);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-tag {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.source-tag:hover {
  background: rgba(99, 102, 241, 0.25);
}

/* Chat Input Bar */
.chat-input-bar {
  padding: 16px 32px 24px;
  background: rgba(9, 13, 22, 0.9);
  backdrop-filter: var(--backdrop-blur);
  border-top: 1px solid var(--border-glass);
}

.input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 8px 16px;
  gap: 12px;
  box-shadow: var(--shadow-main);
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.2);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: var(--font-body);
  outline: none;
  resize: none;
  max-height: 120px;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-gradient);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: transform 0.2s, opacity 0.2s;
}

.send-btn:hover {
  transform: scale(1.05);
}

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

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: var(--backdrop-blur);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: #111827;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  width: 550px;
  max-width: 90vw;
  max-height: 80vh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-main);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.modal-body {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  background: rgba(255, 255, 255, 0.03);
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
  white-space: pre-wrap;
  overflow-y: auto;
}
