:root {
  --bg-color: #0b0f19;
  --sidebar-bg: rgba(17, 24, 39, 0.4);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --panel-bg: rgba(17, 24, 39, 0.6);
  --panel-border: rgba(255, 255, 255, 0.1);

  --user-bubble: linear-gradient(135deg, #6366f1, #a855f7);
  --bot-bubble: rgba(31, 41, 55, 0.6);
  --bot-border: rgba(255, 255, 255, 0.05);

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;

  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --danger: #ef4444;
  --success: #10b981;

  --font-heading: "Outfit", sans-serif;
  --font-body: "Inter", sans-serif;
}

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

html {
  height: 100%;
  overflow: hidden;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-body);
  height: 100vh;
  overflow: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* Background animated mesh */
.bg-mesh {
  position: fixed;
  inset: -50%;
  z-index: -1;
  background:
    radial-gradient(
      circle at 15% 50%,
      rgba(99, 102, 241, 0.15),
      transparent 25%
    ),
    radial-gradient(
      circle at 85% 30%,
      rgba(168, 85, 247, 0.15),
      transparent 25%
    );
  filter: blur(80px);
  animation: rotateMesh 20s linear infinite;
  pointer-events: none;
}

@keyframes rotateMesh {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Buttons */
.btn {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-primary {
  background: var(--user-bubble);
  border: none;
  color: #ffffff;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #7174ff, #b768ff);
}

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

/* Landing page */
.landing {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
  animation: fadeIn 0.8s ease-out;
}

.landing h1 {
  font-family: var(--font-heading);
  font-size: clamp(32px, 7vw, 48px);
  font-weight: 700;
  background: linear-gradient(135deg, #fff, #a5b4fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -1px;
}

.landing p {
  color: var(--text-muted);
  font-size: 17px;
  max-width: 500px;
  line-height: 1.6;
}

.landing .btn {
  margin-top: 12px;
  font-size: 15px;
  padding: 10px 24px;
  border-radius: 10px;
}

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

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  z-index: 2;
}

.sidebar h2 {
  font-family: var(--font-heading);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-left: 8px;
}

.collection-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.collection-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  word-break: break-all;
  border: 1px solid transparent;
  transition: all 0.2s;
  color: var(--text-muted);
}

.collection-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.collection-item.active {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.2);
  color: #fff;
}

.collection-item .chunk-count {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.collection-item.active .chunk-count {
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.2);
}

.collection-item .delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  flex-shrink: 0;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.2s;
}

.collection-item:hover .delete-btn {
  opacity: 1;
  transform: scale(1);
}

.collection-item .delete-btn:hover {
  color: var(--danger);
}

.add-docs-btn {
  margin-top: 12px;
  width: 100%;
}

/* Chat area */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
}

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

.message {
  max-width: 75%;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
  animation: slideUp 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  position: relative;
}

/* Plain-text bubbles keep author line breaks; rendered markdown handles its own spacing */
.message.user,
.message.bot.pending,
.message.bot.error {
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #ffffff;
  border-radius: 14px 14px 4px 14px;
}

.message.bot {
  align-self: flex-start;
  background: var(--bot-bubble);
  border: 1px solid var(--bot-border);
  border-radius: 14px 14px 14px 4px;
  color: var(--text-main);
}

.message.bot.pending {
  opacity: 0.7;
}

.message.bot.error {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.08);
  color: #fca5a5;
}

.message.bot.pending:after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 4px;
  margin-left: 8px;
  background: var(--text-muted);
  animation: pulse 1s infinite alternate;
  border-radius: 2px;
}

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

.message .sources {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-body);
}

.message .sources span {
  display: block;
  margin-bottom: 6px;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.message .sources a {
  color: var(--accent);
  text-decoration: none;
  display: inline-block;
  word-break: break-all;
  background: rgba(139, 92, 246, 0.1);
  padding: 4px 8px;
  border-radius: 6px;
  margin-top: 4px;
  transition: background 0.2s;
}

.message .sources a:hover {
  background: rgba(139, 92, 246, 0.2);
}

/* Input bar */
.input-bar {
  margin: 0 auto 16px auto;
  width: calc(100% - 48px);
  max-width: 800px;
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 6px;
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  z-index: 10;
  transition: border-color 0.3s;
}

.input-bar:focus-within {
  border-color: rgba(139, 92, 246, 0.5);
}

.input-bar input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 12px;
  color: var(--text-main);
  font-size: 15px;
  font-family: var(--font-body);
  min-width: 0;
}

.input-bar input:focus {
  outline: none;
}

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

.input-bar button {
  border-radius: 8px;
  padding: 8px 18px;
  font-weight: 600;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

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

.modal {
  background: #111827;
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  margin: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: modalIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.modal h2 {
  font-family: var(--font-heading);
  font-size: 20px;
  margin-bottom: 16px;
  color: #fff;
}

.modal input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-main);
  font-size: 15px;
  transition: all 0.2s;
}

.modal input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .btn {
  flex: 1;
  padding: 9px;
}

.ingest-status {
  margin-top: 12px;
  font-size: 14px;
  color: var(--text-muted);
  min-height: 20px;
  text-align: center;
}

.ingest-status.error {
  color: var(--danger);
}

.ingest-status.success {
  color: var(--success);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  padding: 24px;
  color: var(--text-muted);
  animation: fadeIn 0.4s ease;
}

.empty-state h3 {
  font-family: var(--font-heading);
  font-size: 22px;
  color: var(--text-main);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 15px;
  max-width: 400px;
  line-height: 1.5;
}

/* Markdown Styling in Messages */
.markdown-body {
  font-family: var(--font-body);
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote {
  margin-bottom: 10px;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-family: var(--font-heading);
  margin: 14px 0 8px;
  line-height: 1.3;
}

.markdown-body h1 { font-size: 20px; }
.markdown-body h2 { font-size: 18px; }
.markdown-body h3 { font-size: 16px; }
.markdown-body h4 { font-size: 15px; }

.markdown-body ul,
.markdown-body ol {
  padding-left: 24px;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body li > p {
  margin-bottom: 4px;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-muted);
}

.markdown-body a {
  color: var(--accent);
}

.markdown-body pre {
  margin: 12px 0;
  padding: 12px;
  border-radius: 8px;
  background-color: #282c34; /* Atom One Dark base bg */
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.markdown-body pre code {
  display: block;
  background: transparent;
  padding: 0;
  line-height: 1.5;
}

.markdown-body code {
  font-family:
    ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}

/* Inline code */
.markdown-body :not(pre) > code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar {
    width: 220px;
  }

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

@media (max-width: 640px) {
  .app {
    flex-direction: column;
  }

  /* Sidebar collapses into a top bar with a horizontal collection list */
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
  }

  .sidebar h2 {
    margin-bottom: 0;
    padding-left: 0;
    flex-shrink: 0;
  }

  .collection-list {
    flex-direction: row;
    gap: 6px;
    overflow-y: hidden;
    overflow-x: auto;
    min-width: 0;
  }

  .collection-item {
    flex-shrink: 0;
    padding: 6px 10px;
    word-break: normal;
    white-space: nowrap;
  }

  .collection-item .delete-btn {
    opacity: 1;
    transform: scale(1);
  }

  .add-docs-btn {
    margin-top: 0;
    width: auto;
    flex-shrink: 0;
    white-space: nowrap;
    padding: 6px 12px;
  }

  .messages {
    padding: 16px 12px;
    gap: 12px;
  }

  .message {
    max-width: 92%;
  }

  .input-bar {
    width: calc(100% - 24px);
    margin-bottom: 12px;
  }

  .input-bar input {
    padding: 8px 10px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .input-bar button {
    padding: 8px 14px;
  }
}
