/* ---------------------------------------------------------------------------
   Jarvis Chat - Dark Theme
   --------------------------------------------------------------------------- */

:root {
  --bg-app: #0f0f13;
  --bg-header: #16161d;
  --bg-input: #1a1a24;
  --bg-user-msg: #2563eb;
  --bg-assistant-msg: #1e1e2a;
  --bg-code: #13131d;
  --text-primary: #e4e4ed;
  --text-secondary: #8b8b9e;
  --text-muted: #5e5e72;
  --border: #2a2a3a;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --danger: #ef4444;
  --success: #22c55e;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

/* ---------------------------------------------------------------------------
   Header
   --------------------------------------------------------------------------- */

#header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  flex-shrink: 0;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 860px;
  margin: 0 auto;
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.brand h1 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}

.subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Status indicator */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

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

.status-dot.connecting {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
  animation: pulse 1.5s infinite;
}

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

/* ---------------------------------------------------------------------------
   Chat Container
   --------------------------------------------------------------------------- */

#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

#chat-container::-webkit-scrollbar {
  width: 6px;
}

#chat-container::-webkit-scrollbar-track {
  background: transparent;
}

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

#chat-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: min-content;
}

/* ---------------------------------------------------------------------------
   Messages
   --------------------------------------------------------------------------- */

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

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

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

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

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

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

.message-timestamp {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* ---------------------------------------------------------------------------
   Markdown rendering
   --------------------------------------------------------------------------- */

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

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

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

.message-content li {
  margin: 2px 0;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin: 12px 0 6px;
  line-height: 1.3;
}

.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 15px; }

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

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

.message-content pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 13px;
  line-height: 1.5;
}

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

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

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

.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}

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

.message-content th {
  background: var(--bg-code);
  font-weight: 600;
}

.message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.message-content img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------------------
   Typing Indicator
   --------------------------------------------------------------------------- */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  align-self: flex-start;
  background: var(--bg-assistant-msg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  animation: fadeIn 0.3s ease;
}

.typing-indicator.hidden {
  display: none;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

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

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

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

.typing-text {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---------------------------------------------------------------------------
   Input Area
   --------------------------------------------------------------------------- */

#input-area {
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  flex-shrink: 0;
}

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

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

#message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  padding: 8px 12px;
  resize: none;
  max-height: 120px;
  min-height: 24px;
}

#message-input::placeholder {
  color: var(--text-muted);
}

#message-input::-webkit-scrollbar {
  width: 4px;
}

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

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

#send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

/* ---------------------------------------------------------------------------
   Error banner
   --------------------------------------------------------------------------- */

.error-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: center;
  margin-bottom: 8px;
  animation: fadeIn 0.3s ease;
}

/* ---------------------------------------------------------------------------
   Empty state
   --------------------------------------------------------------------------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 500;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 14px;
  max-width: 300px;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */

@media (max-width: 600px) {
  #header {
    padding: 10px 16px;
  }

  #chat-container {
    padding: 12px;
  }

  #input-area {
    padding: 8px 12px;
  }

  .message {
    max-width: 92%;
  }

  .brand h1 {
    font-size: 16px;
  }

  .subtitle {
    display: none;
  }
}
