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

:root {
  --bg-100: #09090b;
  --bg-200: #18181b;
  --bg-300: #27272a;
  --bg-400: #3f3f46;
  --text-100: #fafafa;
  --text-200: #a1a1aa;
  --text-300: #71717a;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-bg: rgba(139, 92, 246, 0.15);
  --success: #22c55e;
  --error: #ef4444;
  --border: rgba(255, 255, 255, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --header-h: 60px;
  --input-h: 140px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-100);
  color: var(--text-100);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ========== App Layout ========== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* ========== Header ========== */
.header {
  height: var(--header-h);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-200);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.logo-text {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-100);
}

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

.header-btn:hover {
  background: var(--bg-400);
  color: var(--text-100);
}

.header-btn svg {
  width: 20px;
  height: 20px;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--accent);
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge:empty, .badge[data-count="0"] {
  display: none;
}

/* ========== Select ========== */
.select {
  height: 40px;
  padding: 0 12px;
  background: var(--bg-300);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-100);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.select:hover {
  border-color: var(--text-300);
}

.select:focus {
  border-color: var(--accent);
}

.select.full {
  width: 100%;
}

/* ========== Chat Container ========== */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

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

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

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

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

/* Welcome Screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  min-height: 100%;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg);
  border-radius: 50%;
  margin-bottom: 24px;
}

.welcome-icon svg {
  width: 40px;
  height: 40px;
  color: var(--accent);
}

.welcome h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.welcome p {
  color: var(--text-200);
  max-width: 400px;
  margin-bottom: 32px;
}

.capabilities {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.cap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-200);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  color: var(--text-200);
}

.cap-icon {
  font-size: 16px;
}

/* Message Styles */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  animation: fadeIn 0.3s ease;
}

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

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-300);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

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

.message-body {
  flex: 1;
  min-width: 0;
}

.message-content {
  padding: 12px 16px;
  background: var(--bg-200);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--accent-bg);
  border-color: rgba(139, 92, 246, 0.3);
}

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

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

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

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

.message-content code {
  padding: 2px 6px;
  background: var(--bg-300);
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9em;
}

.message-content pre {
  margin: 12px 0;
  padding: 12px;
  background: var(--bg-300);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

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

/* Tool Calls */
.tool-calls {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-call {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-300);
  border-radius: 16px;
  font-size: 13px;
}

.tool-call-icon {
  font-size: 14px;
}

.tool-call-name {
  color: var(--accent);
  font-weight: 500;
}

/* Thinking Indicator */
.thinking {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-200);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

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

.thinking-text {
  color: var(--text-200);
  font-size: 14px;
}

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

.suggestions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.suggestions::-webkit-scrollbar {
  height: 0;
}

.suggestion {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--bg-200);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-200);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.suggestion:hover {
  background: var(--bg-300);
  color: var(--text-100);
  border-color: var(--text-300);
}

.suggestions.hidden {
  display: none;
}

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 12px;
  background: var(--bg-200);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

#user-input {
  flex: 1;
  min-height: 24px;
  max-height: 120px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text-100);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
}

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

.send-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

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

.send-btn:disabled {
  background: var(--bg-400);
  color: var(--text-300);
  cursor: not-allowed;
}

.send-btn svg {
  width: 20px;
  height: 20px;
}

/* ========== Sidebar ========== */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 400px;
  height: 100%;
  background: var(--bg-200);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 200;
  display: flex;
  flex-direction: column;
}

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

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  z-index: 199;
}

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

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.sidebar-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

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

#doc-count {
  font-size: 14px;
  color: var(--text-200);
}

/* ========== Tabs ========== */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-300);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-200);
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.tab:hover {
  background: var(--bg-400);
  color: var(--text-100);
}

.tab.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ========== Form Elements ========== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-200);
}

.input,
.tab-panel textarea,
.tab-panel input {
  width: 100%;
  padding: 12px;
  background: var(--bg-300);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-100);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.tab-panel textarea {
  min-height: 120px;
  resize: vertical;
  margin-bottom: 12px;
}

.tab-panel input {
  margin-bottom: 12px;
}

.input:focus,
.tab-panel textarea:focus,
.tab-panel input:focus {
  border-color: var(--accent);
}

.input::placeholder,
.tab-panel textarea::placeholder,
.tab-panel input::placeholder {
  color: var(--text-300);
}

.input.full {
  width: 100%;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 20px;
  background: var(--bg-300);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-100);
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.full {
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  padding: 8px;
  color: var(--text-200);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.2s;
}

.btn-link:hover {
  color: var(--text-100);
}

.btn-link.danger:hover {
  color: var(--error);
}

.close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-200);
  cursor: pointer;
  transition: all 0.2s;
}

.close-btn:hover {
  background: var(--bg-300);
  color: var(--text-100);
}

.close-btn svg {
  width: 20px;
  height: 20px;
}

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
  z-index: 300;
  padding: 20px;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  width: 100%;
  max-width: 400px;
  background: var(--bg-200);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: scale(0.95);
  transition: transform 0.2s;
}

.modal-overlay.open .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
}

/* ========== Toast Notifications ========== */
.toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 400;
  pointer-events: none;
}

.toast {
  padding: 14px 20px;
  background: var(--bg-200);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: toastIn 0.3s ease;
  pointer-events: auto;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--error);
}

.toast.info {
  border-left: 3px solid var(--accent);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ========== Responsive ========== */
@media (max-width: 640px) {
  .header {
    padding: 0 8px;
  }

  .header-right {
    gap: 6px;
  }

  .header-btn {
    width: 34px;
    height: 34px;
  }

  .header-btn svg {
    width: 16px;
    height: 16px;
  }

  .select {
    max-width: 100px;
    font-size: 12px;
    height: 34px;
    padding: 0 8px;
  }

  .logo-icon {
    width: 22px;
    height: 22px;
  }

  .logo-text {
    font-size: 0.95rem;
  }

  .messages {
    padding: 16px 12px;
  }

  .welcome h1 {
    font-size: 1.5rem;
  }

  .capabilities {
    gap: 8px;
  }

  .cap {
    padding: 6px 12px;
    font-size: 13px;
  }

  .input-wrapper {
    padding: 12px 12px 20px;
  }

  .suggestion {
    padding: 6px 12px;
    font-size: 12px;
  }

  .toasts {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    width: 100%;
  }
}
