/* ============================================
   RAG ChatBot — Linear-Inspired Design System
   ============================================ */

/* --- Reset & Custom Properties --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Surfaces */
  --bg-deep: #08090a;
  --bg-panel: #0f1011;
  --bg-surface: #191a1b;
  --bg-elevated: #242529;
  --bg-hover: rgba(255,255,255,0.04);
  --bg-active: rgba(255,255,255,0.06);

  /* Text */
  --text-primary: #f0f2f5;
  --text-secondary: #b0b8c4;
  --text-tertiary: #7a808a;
  --text-quaternary: #555a63;
  --text-inverse: #0a0b0d;

  /* Brand */
  --brand-bg: #5e6ad2;
  --brand: #7170ff;
  --brand-hover: #828fff;
  --brand-muted: rgba(94,106,210,0.15);
  --brand-subtle: rgba(94,106,210,0.08);

  /* Status */
  --green: #10b981;
  --green-bg: rgba(16,185,129,0.12);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,0.12);
  --amber: #f59e0b;

  /* Borders */
  --border-subtle: rgba(255,255,255,0.04);
  --border-default: rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.10);
  --border-solid: #25262b;

  /* Shadows */
  --shadow-ring: 0 0 0 1px rgba(255,255,255,0.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-focus: 0 0 0 2px rgba(94,106,210,0.4);

  /* Radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-xl: 12px;
  --r-2xl: 16px;
  --r-pill: 9999px;

  /* Typography */
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Transitions */
  --t-fast: 120ms ease;
  --t-normal: 200ms ease;
  --t-slow: 350ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Sizes */
  --sidebar-w: 280px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv01', 'ss03';
}

/* --- Layout --- */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ======================== SIDEBAR ======================== */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: transform var(--t-slow);
}

/* --- Header --- */
.sidebar-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  transition: opacity var(--t-fast);
}

.logo:hover {
  opacity: 0.8;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--t-fast);
}

.logo:hover .logo-icon {
  transform: scale(1.1);
}

.logo-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.logo-accent {
  color: var(--brand);
  font-weight: 500;
}

/* --- Sections --- */
.sidebar-section {
  padding: 14px 16px;
  transition: background var(--t-fast);
}

.sidebar-section + .sidebar-section {
  border-top: 1px solid var(--border-subtle);
}

.sidebar-section:hover {
  background: var(--bg-hover);
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-quaternary);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 10px;
  transition: color var(--t-fast);
}

.sidebar-section:hover .section-label {
  color: var(--text-tertiary);
}

/* --- Drop Zone --- */
.drop-zone {
  border: 1px dashed var(--border-solid);
  border-radius: var(--r-lg);
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  transition: all var(--t-normal);
  background: var(--bg-hover);
  position: relative;
  overflow: hidden;
}

.drop-zone::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--brand-subtle) 0%, transparent 70%);
  opacity: 0;
  transition: opacity var(--t-normal);
}

.drop-zone:hover::before,
.drop-zone.drag-over::before {
  opacity: 1;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--brand);
  background: var(--brand-subtle);
}

.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.drop-icon {
  color: var(--text-tertiary);
  transition: all var(--t-fast);
}

.drop-zone:hover .drop-icon {
  color: var(--brand);
  transform: translateY(-2px);
}

.drop-text {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.drop-text strong {
  color: var(--text-secondary);
  font-weight: 510;
}

.drop-hint {
  font-size: 10px;
  color: var(--text-quaternary);
}

/* --- File List --- */
.file-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-tertiary);
  transition: all var(--t-fast);
  animation: slideIn 200ms ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.file-item:hover {
  background: var(--bg-hover);
}

.file-icon {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-status {
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
  padding: 1px 6px;
  border-radius: 3px;
  transition: all var(--t-fast);
}

.file-status.uploading {
  color: var(--text-quaternary);
}

.file-status.processing {
  color: var(--amber);
  background: rgba(245,158,11,0.1);
}

.file-status.ready {
  color: var(--green);
  background: var(--green-bg);
}

.file-status.error {
  color: var(--red);
  background: var(--red-bg);
}

.file-progress {
  width: 100%;
  height: 3px;
  background: var(--border-solid);
  border-radius: 2px;
  overflow: hidden;
  grid-column: 1 / -1;
  margin-top: 2px;
}

.file-progress-bar {
  height: 100%;
  background: var(--brand);
  border-radius: 2px;
  transition: width 500ms ease;
  animation: progressPulse 2s ease-in-out infinite;
}

@keyframes progressPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* --- Documents List --- */
.docs-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding: 0 4px;
}

.docs-count {
  font-size: 10px;
  color: var(--text-quaternary);
  font-weight: 500;
  background: var(--bg-hover);
  padding: 1px 8px;
  border-radius: var(--r-pill);
}

.doc-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background var(--t-fast);
  border: 1px solid transparent;
}

.doc-item:hover {
  background: var(--bg-hover);
}

.doc-item.active {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.doc-icon {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.doc-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 400;
}

.doc-status {
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
  padding: 1px 6px;
  border-radius: 3px;
}

.doc-status.ready {
  color: var(--green);
  background: var(--green-bg);
}

.doc-status.processing {
  color: var(--amber);
  background: rgba(245,158,11,0.1);
}

.doc-status.error {
  color: var(--red);
  background: var(--red-bg);
}

.doc-delete {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-quaternary);
  border-radius: var(--r-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--t-fast), background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
  padding: 0;
}

.doc-item:hover .doc-delete,
.doc-item.active .doc-delete {
  opacity: 1;
}

.doc-delete:hover {
  background: var(--red-bg);
  color: var(--red);
}

.doc-list-empty {
  font-size: 11px;
  color: var(--text-quaternary);
  padding: 4px 8px;
}

@media (max-width: 768px) {
  .doc-delete {
    opacity: 0.6;
  }

  .doc-item:hover .doc-delete,
  .doc-item.active .doc-delete {
    opacity: 1;
  }
}

/* --- History --- */
.sidebar-section-history {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.sidebar-section-history::-webkit-scrollbar {
  width: 4px;
}

.sidebar-section-history::-webkit-scrollbar-thumb {
  background: var(--border-solid);
  border-radius: 2px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-quaternary);
  padding: 20px 0;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background var(--t-fast);
  border: 1px solid transparent;
}

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

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

/* --- Footer --- */
.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-quaternary);
  transition: all var(--t-normal);
}

.status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px rgba(16,185,129,0.4);
}

.status-dot.disconnected {
  background: var(--red);
  box-shadow: 0 0 6px rgba(239,68,68,0.4);
}

.status-label {
  font-size: 11px;
  color: var(--text-quaternary);
  transition: color var(--t-fast);
}

.status-dot.connected + .status-label {
  color: var(--text-tertiary);
}

.status-dot.disconnected + .status-label {
  color: var(--red);
}

.sidebar-actions {
  display: flex;
  gap: 4px;
}

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-quaternary);
  cursor: pointer;
  transition: all var(--t-fast);
}

.icon-button:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.icon-button:active {
  transform: scale(0.95);
}

/* ======================== MAIN ======================== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* --- Chat Header --- */
#chatHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-deep);
  z-index: 10;
}

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

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-solid);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--t-fast);
}

.mobile-menu-btn:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.mobile-menu-btn:active {
  transform: scale(0.95);
}

.header-title {
  font-size: 14px;
  font-weight: 510;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-quaternary);
  margin-top: 1px;
}

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

.ghost-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-solid);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-quaternary);
  cursor: pointer;
  transition: all var(--t-fast);
}

.ghost-button:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-color: rgba(255,255,255,0.10);
}

.ghost-button:active {
  transform: scale(0.95);
}

/* --- Messages --- */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border-solid);
  border-radius: 3px;
}

/* --- Welcome Screen --- */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: 40px 24px;
  animation: fadeIn 400ms ease;
}

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

.welcome-graphic {
  margin-bottom: 16px;
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.welcome-title {
  font-size: 20px;
  font-weight: 510;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  margin-bottom: 8px;
}

.welcome-desc {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-bottom: 32px;
  max-width: 420px;
  line-height: 1.6;
}

.welcome-tips {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}

.tip-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  text-align: left;
  transition: all var(--t-normal);
  cursor: default;
}

.tip-card:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: translateX(4px);
}

.tip-icon {
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-subtle);
  border-radius: var(--r-md);
  flex-shrink: 0;
}

.tip-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* --- Messages --- */
.message {
  display: flex;
  flex-direction: column;
  padding: 0 24px;
  max-width: 780px;
  width: 100%;
  animation: messageSlide 250ms var(--t-slow);
}

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

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

.message.assistant {
  align-self: flex-start;
}

.message.error {
  align-self: center;
  max-width: 500px;
  width: 100%;
}

.message-role {
  font-size: 11px;
  font-weight: 510;
  color: var(--text-quaternary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 0 16px;
  margin-bottom: 4px;
}

.message-content {
  padding: 12px 16px;
  border-radius: var(--r-xl);
  font-size: 14px;
  line-height: 1.65;
  word-wrap: break-word;
}

.message-content p {
  margin: 0 0 8px 0;
}

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

.message-content ol {
  margin: 6px 0 10px 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  list-style-type: decimal;
}

.message-content ul {
  margin: 6px 0 10px 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  list-style-type: disc;
}

.message-content li {
  line-height: 1.5;
}

.message-content blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  background: var(--bg-hover);
  border-left: 3px solid var(--brand);
  border-radius: 4px;
  color: var(--text-secondary);
}

.message.user .message-content {
  background: var(--brand-bg);
  color: white;
  border-bottom-right-radius: var(--r-sm);
}

.message.user .message-content p {
  color: rgba(255,255,255,0.95);
}

.message.user .message-content code {
  background: rgba(255,255,255,0.15);
  color: white;
}

.message.user .message-content blockquote {
  border-left-color: rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.85);
}

.message.user .message-content a {
  color: rgba(255,255,255,0.9);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message.assistant .message-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  border-bottom-left-radius: var(--r-sm);
}

.message.error .message-content {
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,0.2);
  color: var(--red);
  text-align: center;
  font-size: 13px;
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.message.error .message-content::before {
  content: "⚠️";
  font-size: 14px;
}

/* --- Streaming Cursor --- */
.stream-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--brand);
  animation: blink 900ms step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
  border-radius: 1px;
}

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

/* --- Sources --- */
.sources-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--brand-muted);
  border: 1px solid rgba(94,106,210,0.25);
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 500;
  color: var(--brand-hover);
  cursor: pointer;
  transition: all var(--t-fast);
}

.source-chip:hover {
  background: rgba(94,106,210,0.25);
  border-color: rgba(94,106,210,0.5);
  transform: translateY(-1px);
}

.source-chip:active {
  transform: translateY(0);
}

.source-chip .source-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand-bg);
  color: white;
  font-size: 9px;
  font-weight: 600;
}

/* --- Typing Indicator --- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  margin: 0 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  border-bottom-left-radius: var(--r-sm);
  align-self: flex-start;
  width: fit-content;
  max-width: 100px;
}

.typing-dot {
  width: 5px;
  height: 5px;
  background: var(--text-quaternary);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

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

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ======================== INPUT AREA ======================== */
#inputArea {
  padding: 12px 24px 16px;
  background: linear-gradient(180deg, transparent 0%, var(--bg-deep) 30%);
  position: relative;
}

.input-container {
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  padding: 6px 6px 6px 16px;
  transition: border-color var(--t-normal), box-shadow var(--t-normal);
}

.input-wrapper:focus-within {
  border-color: var(--brand);
  box-shadow: var(--shadow-focus);
}

#chatInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  min-height: 22px;
  padding: 4px 0;
  overflow-y: auto;
}

#chatInput::placeholder {
  color: var(--text-quaternary);
}

#chatInput::-webkit-scrollbar {
  width: 4px;
}

#chatInput::-webkit-scrollbar-thumb {
  background: var(--border-solid);
  border-radius: 2px;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-quaternary);
  cursor: pointer;
  transition: all var(--t-fast);
}

.attach-btn:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
  transform: rotate(15deg);
}

.attach-btn:active {
  transform: rotate(0deg) scale(0.95);
}

.send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--r-md);
  background: var(--brand-bg);
  color: white;
  cursor: pointer;
  transition: all var(--t-fast);
}

.send-button:hover:not(:disabled) {
  background: var(--brand-hover);
  transform: scale(1.05);
}

.send-button:active:not(:disabled) {
  transform: scale(0.95);
}

.send-button:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-quaternary);
  margin-top: 8px;
  padding: 0 4px;
}

.input-footer kbd {
  display: inline-block;
  padding: 0 4px;
  font-family: var(--font);
  font-size: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border-solid);
  border-radius: 3px;
  color: var(--text-tertiary);
}

.model-badge {
  padding: 2px 8px;
  background: var(--brand-subtle);
  border-radius: var(--r-pill);
  font-size: 10px;
  font-weight: 500;
  color: var(--brand);
  border: 1px solid rgba(94,106,210,0.15);
  transition: all var(--t-fast);
}

.model-badge:hover {
  background: rgba(94,106,210,0.12);
  border-color: rgba(94,106,210,0.3);
}

/* ======================== TOAST ======================== */
.toast-container {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  padding: 10px 18px;
  border-radius: var(--r-lg);
  font-size: 12.5px;
  font-weight: 500;
  color: white;
  opacity: 0;
  transition: all var(--t-slow);
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  animation: toastIn 300ms ease forwards;
  text-align: center;
  width: fit-content;
  max-width: 100%;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast.out {
  animation: toastOut 200ms ease forwards;
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-4px) scale(0.95); }
}

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

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

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

/* ======================== OVERLAY ======================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 20;
  opacity: 0;
  transition: opacity var(--t-normal);
  backdrop-filter: blur(2px);
}

.sidebar-overlay.visible {
  opacity: 1;
}

/* ======================== RESPONSIVE ======================== */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 30;
    box-shadow: var(--shadow-lg);
    width: 85%;
    max-width: 300px;
  }

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

  .mobile-menu-btn {
    display: flex;
  }

  .sidebar-overlay {
    display: block;
  }

  #chatHeader {
    padding: 12px 16px;
  }

  .messages-container {
    padding: 16px 0;
    gap: 12px;
  }

  .message {
    padding: 0 16px;
    max-width: 100%;
  }

  .message-content {
    padding: 10px 14px;
    font-size: 13px;
  }

  #inputArea {
    padding: 10px 12px 12px;
  }

  .welcome-tips {
    max-width: 100%;
  }

  .welcome-title {
    font-size: 18px;
  }

  .input-footer span:first-child {
    display: none;
  }

  .doc-delete {
    opacity: 0.7;
  }

  .doc-item:hover .doc-delete,
  .doc-item.active .doc-delete {
    opacity: 1;
  }
}

/* --- Global Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-solid);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* --- Selection --- */
::selection {
  background: var(--brand-muted);
  color: inherit;
}
