/* MarcusChat - Core Styles (Dark Theme) */

:root {
  --bg-primary: #1a1a1a;
  --bg-secondary: #242424;
  --bg-tertiary: #2d2d2d;
  --bg-input: #2a2a2a;
  --text-primary: #e8e8e8;
  --text-secondary: #999;
  --text-muted: #666;
  --accent: #0066cc;
  --accent-hover: #0077ee;
  --user-bubble: #0066cc;
  --user-bubble-text: #fff;
  --assistant-bubble: #2d2d2d;
  --assistant-bubble-text: #e8e8e8;
  --border-color: #333;
  --error-color: #cc3333;
  --success-color: #33cc66;
  --warning-color: #ccaa33;
  --header-height: 60px;
  --input-area-min: 64px;
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* --- Header --- */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
}

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

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0066cc, #0044aa);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.header-info h1 {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--success-color);
  box-shadow: 0 0 4px var(--success-color);
}

.status-dot.connecting {
  background: var(--warning-color);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.disconnected {
  background: var(--error-color);
}

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

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

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

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

.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

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

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

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

.messages-container::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* --- Messages --- */

.message {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  max-width: 85%;
  animation: fadeIn 0.2s ease;
}

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

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

.message-assistant {
  margin-right: auto;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0066cc, #0044aa);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  position: relative;
  min-width: 40px;
}

.message-user .message-bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
  background: var(--assistant-bubble);
  color: var(--assistant-bubble-text);
  border-bottom-left-radius: 4px;
}

.message-content {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Markdown content inside assistant bubbles */
.message-assistant .message-content p {
  margin: 0 0 8px 0;
}

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

.message-assistant .message-content h1,
.message-assistant .message-content h2,
.message-assistant .message-content h3 {
  margin: 12px 0 6px;
  font-size: 1em;
  font-weight: 600;
}

.message-assistant .message-content h1 { font-size: 1.2em; }
.message-assistant .message-content h2 { font-size: 1.1em; }

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

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

.message-assistant .message-content a {
  color: #5eabff;
  text-decoration: none;
}

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

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

/* Inline code */
.message-content code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 5px;
  border-radius: 4px;
}

/* Code blocks */
.message-content pre {
  margin: 8px 0;
  border-radius: 8px;
  overflow-x: auto;
}

.message-content pre code {
  display: block;
  background: #0d1117;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
}

/* Code block wrapper with copy button */
.code-block-wrapper {
  position: relative;
  margin: 8px 0;
}

.code-block-wrapper pre {
  margin: 0;
}

.code-lang-label {
  position: absolute;
  top: 6px;
  left: 12px;
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  z-index: 1;
}

.copy-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #999;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 1;
}

.code-block-wrapper:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ddd;
}

.copy-btn.copied {
  color: var(--success-color);
}

/* Message meta (timestamp, copy) */
.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.message-bubble:hover .message-meta {
  opacity: 1;
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  cursor: default;
}

.message-user .message-time {
  color: rgba(255, 255, 255, 0.5);
}

.msg-copy-btn {
  display: flex;
  align-items: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  transition: color 0.15s;
}

.msg-copy-btn:hover {
  color: var(--text-primary);
}

.message-user .msg-copy-btn {
  color: rgba(255, 255, 255, 0.5);
}

.message-user .msg-copy-btn:hover {
  color: #fff;
}

/* Streaming cursor */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Aborted notice */
.message-aborted {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 6px;
}

/* Thinking dots */
.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

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

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

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

@keyframes thinking {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* Error message */
.message-error {
  justify-content: center;
  max-width: 100%;
}

.error-bubble {
  background: rgba(204, 51, 51, 0.15) !important;
  color: var(--error-color) !important;
  border: 1px solid rgba(204, 51, 51, 0.3);
  border-radius: 8px !important;
  font-size: 13px;
  text-align: center;
}

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

.input-area {
  padding: 8px 16px;
  padding-bottom: calc(8px + var(--safe-area-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.15s;
}

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

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 200px;
  padding: 4px 0;
}

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

#message-input:disabled {
  opacity: 0.5;
}

.send-btn,
.stop-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.send-btn {
  background: var(--accent);
  color: #fff;
}

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

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

.stop-btn {
  background: var(--error-color);
  color: #fff;
}

.stop-btn:hover {
  background: #dd4444;
}

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 4px;
}

/* --- Update Banner --- */

.update-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  z-index: 100;
}

.update-banner button {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.update-banner button:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* --- Selection --- */

::selection {
  background: rgba(0, 102, 204, 0.4);
}

/* --- Tables in markdown --- */
.message-content table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 14px;
  width: 100%;
}

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

.message-content th {
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
}
