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

:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #3730a3;
  --bg: #f8f9fc;
  --bg-secondary: #ffffff;
  --surface: #f1f3f9;
  --text: #1e1e2e;
  --text-secondary: #6b7280;
  --border: #e2e5ef;
  --user-bubble: #4f46e5;
  --bot-bubble: #ffffff;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Inter", sans-serif;
}

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

/* ===== App Container ===== */
#chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

/* ===== Header ===== */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  z-index: 10;
}

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

.logo-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.25);
}

.header-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  animation: pulse 2s infinite;
}

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

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

.btn-header {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
}

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

.file-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
}

/* ===== Files Panel ===== */
.files-panel {
  display: none;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  animation: slideDown 0.2s ease;
  max-height: 200px;
  overflow-y: auto;
}

.files-panel.open {
  display: block;
}

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

.files-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.files-panel-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.files-hint {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.files-hint code {
  background: rgba(79, 70, 229, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--primary);
}

.files-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: 8px;
  font-size: 0.82rem;
}

.file-item .file-icon {
  font-size: 1rem;
}

.file-item .file-name {
  flex: 1;
}

.file-item .file-status {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
}

.file-item .file-status.processing {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.no-files {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  padding: 12px;
}

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

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

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

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

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  gap: 12px;
  animation: fadeIn 0.5s ease;
}

.welcome-icon {
  margin-bottom: 8px;
}

.welcome-screen h2 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-screen p {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 420px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
}

.quick-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 24px;
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.quick-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

/* ===== Message Bubbles ===== */
.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: slideUp 0.3s ease;
}

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

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 4px;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
}

.message.assistant .message-avatar {
  background: var(--surface);
  border: 1px solid var(--border);
}

.message-content {
  padding: 14px 18px;
  border-radius: var(--radius);
  line-height: 1.7;
  font-size: 0.95rem;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user .message-content {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.2);
}

.message.assistant .message-content {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 6px 4px;
}

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

.typing-indicator span:nth-child(2) { animation-delay: 0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

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

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

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

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  resize: none;
  max-height: 120px;
  line-height: 1.6;
  padding: 8px 0;
}

#user-input::placeholder {
  color: var(--text-secondary);
}

.btn-send {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.35);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.footer-note {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 8px;
  opacity: 0.6;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .chat-header {
    padding: 12px 16px;
  }

  .chat-messages {
    padding: 16px;
  }

  .chat-input-area {
    padding: 12px 16px 8px;
  }

  .message {
    max-width: 92%;
  }

  .quick-actions {
    flex-direction: column;
    align-items: center;
  }
}

/* ===== Code blocks inside messages ===== */
.message-content code {
  background: rgba(79, 70, 229, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: "Fira Code", "Courier New", monospace;
  color: var(--primary-dark);
}

.message-content pre {
  background: #1e1e2e;
  color: #e8e8f0;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-content pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
