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

:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #1a1a24;
  --bg-tertiary: #24243a;
  --bg-hover: #2a2a44;
  --bg-active: #32325a;
  --text-primary: #e8e8f0;
  --text-secondary: #9898b8;
  --text-muted: #6868a0;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-dim: #4834d4;
  --success: #00cec9;
  --warning: #fdcb6e;
  --danger: #ff6b6b;
  --border: #2a2a44;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-width: 300px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

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

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 16px;
}

.logo i {
  font-size: 1.5rem;
}

.new-chat-btn {
  width: 100%;
  padding: 10px 16px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, transform 0.1s;
}

.new-chat-btn:hover {
  background: var(--accent-dim);
  transform: translateY(-1px);
}

.new-chat-btn:active {
  transform: translateY(0);
}

/* Thread list */
.sidebar-threads {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

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

.sidebar-threads::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.thread-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

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

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

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

.thread-item .thread-title {
  flex: 1;
  font-size: 0.87rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}

.thread-item.active .thread-title {
  color: var(--text-primary);
}

.thread-item .thread-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 4px;
  font-size: 0.8rem;
  transition: opacity 0.15s;
}

.thread-item:hover .thread-delete {
  opacity: 0.7;
}

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

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.stats {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stats i {
  margin-right: 4px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

.status-dot.ready {
  background: var(--success);
  animation: none;
}

.status-dot.initializing {
  background: var(--warning);
}

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

/* ── Chat Area ────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
}

.chat-title {
  flex: 1;
}

.chat-title h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--danger);
}

/* Messages container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

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

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

.messages {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Welcome screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.welcome-icon {
  font-size: 3.5rem;
  color: var(--accent);
  margin-bottom: 20px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.welcome-screen h1 {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}

.welcome-screen p {
  color: var(--text-secondary);
  margin-bottom: 30px;
  font-size: 1rem;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 600px;
}

.suggestion-chip {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 10px 18px;
  border-radius: 24px;
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.suggestion-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.suggestion-chip i {
  color: var(--accent-light);
  font-size: 0.8rem;
}

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: fadeIn 0.3s ease;
}

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

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

.message-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 2px;
}

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

.message.assistant .message-avatar {
  background: var(--bg-tertiary);
  color: var(--accent-light);
  border: 1px solid var(--border);
}

.message-content {
  max-width: 75%;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 0.93rem;
  line-height: 1.65;
  word-break: break-word;
}

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

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

/* Markdown-like formatting in assistant messages */
.message.assistant .message-content strong {
  color: var(--accent-light);
  font-weight: 600;
}

.message.assistant .message-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--success);
}

.message.assistant .message-content pre {
  background: var(--bg-tertiary);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.85em;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
  padding-left: 20px;
  margin: 6px 0;
}

.message.assistant .message-content li {
  margin-bottom: 4px;
}

.message.assistant .message-content a {
  color: var(--accent-light);
  text-decoration: none;
}

.message.assistant .message-content a:hover {
  text-decoration: underline;
}

.message.assistant .message-content h3,
.message.assistant .message-content h4 {
  margin: 10px 0 6px;
  color: var(--accent-light);
}

.message.assistant .message-content table {
  border-collapse: collapse;
  margin: 10px 0;
  width: 100%;
  font-size: 0.88em;
}

.message.assistant .message-content th,
.message.assistant .message-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.message.assistant .message-content th {
  background: var(--bg-tertiary);
  color: var(--accent-light);
  font-weight: 600;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.message.assistant .message-time {
  text-align: left;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  max-width: 860px;
  margin: 0 auto;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.4s infinite;
}

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

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
}

/* ── Input Area ───────────────────────────────────────────────────── */
.input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 860px;
  margin: 0 auto;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
}

.input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.93rem;
  resize: none;
  min-height: 24px;
  max-height: 150px;
  line-height: 1.5;
  outline: none;
  padding: 4px 0;
}

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

.send-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}

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

.send-btn:not(:disabled):hover {
  background: var(--accent-dim);
  transform: scale(1.05);
}

.input-hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Error message ────────────────────────────────────────────────── */
.error-toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  z-index: 1000;
  animation: slideUp 0.3s ease;
  box-shadow: var(--shadow);
}

@keyframes slideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }

  .menu-toggle {
    display: block;
  }

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

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    display: none;
  }

  .sidebar-overlay.active {
    display: block;
  }
}

@media (max-width: 480px) {
  .message-content {
    max-width: 90%;
  }

  .suggestions {
    flex-direction: column;
    align-items: stretch;
  }

  .suggestion-chip {
    justify-content: center;
  }
}

/* ── File Cards ───────────────────────────────────────────────────── */
.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 6px 0;
  transition: border-color 0.2s, background 0.2s;
}

.file-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.file-card-icon {
  font-size: 1.5rem;
  min-width: 36px;
  text-align: center;
}

.file-card-icon .fa-file-pdf { color: #e74c3c; }
.file-card-icon .fa-file-excel { color: #27ae60; }
.file-card-icon .fa-file-csv { color: #27ae60; }
.file-card-icon .fa-file-word { color: #2980b9; }
.file-card-icon .fa-file-image { color: #e67e22; }
.file-card-icon .fa-file-code { color: #f39c12; }
.file-card-icon .fa-file-zipper { color: #9b59b6; }
.file-card-icon .fa-file { color: var(--text-muted); }

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

.file-card-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-card-path {
  font-size: 0.73rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  font-family: "Consolas", "Courier New", monospace;
}

.file-card-type {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

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

.file-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.file-btn:hover {
  transform: translateY(-1px);
}

.file-btn:active {
  transform: translateY(0);
}

.file-btn-open {
  background: var(--accent);
  color: white;
}

.file-btn-open:hover {
  background: var(--accent-dim);
}

.file-btn-download {
  background: var(--bg-primary);
  color: var(--success);
  border: 1px solid var(--border);
}

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

.file-btn-folder {
  background: var(--bg-primary);
  color: var(--warning);
  border: 1px solid var(--border);
}

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

/* Responsive file cards */
@media (max-width: 600px) {
  .file-card {
    flex-wrap: wrap;
    gap: 8px;
  }

  .file-card-info {
    flex-basis: calc(100% - 50px);
  }

  .file-card-type {
    display: none;
  }

  .file-card-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
