:root {
  --bg-primary: #0a0d14;
  --bg-secondary: #101520;
  --bg-card: #141b29;
  --bg-user-card: #182236;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(0, 229, 255, 0.4);
  
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #586069;
  
  --accent-cyan: #00e5ff;
  --accent-blue: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  font-size: 14.5px;
  min-height: 100vh;
  overflow-x: hidden;
}

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(16, 21, 32, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  gap: 16px;
}

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

.logo-orb {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00e5ff 0%, #3b82f6 50%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.4);
}

.orb-inner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--bg-primary);
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
}

.brand-title span {
  background: linear-gradient(90deg, var(--accent-cyan), #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-domain {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

/* Conversation Selector */
.header-center {
  flex: 1;
  max-width: 480px;
}

.conv-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px 12px;
}

.conv-selector-wrapper label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.conv-select {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  outline: none;
  cursor: pointer;
}

.conv-select option {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

/* Header Right Actions */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #6b7280;
}

.status-badge.connected .status-dot {
  background-color: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald);
  animation: pulse-dot 2s infinite ease-in-out;
}

.status-badge.connecting .status-dot {
  background-color: var(--accent-amber);
  box-shadow: 0 0 8px var(--accent-amber);
  animation: pulse-dot 1s infinite ease-in-out;
}

.status-badge.error .status-dot {
  background-color: var(--accent-rose);
  box-shadow: 0 0 8px var(--accent-rose);
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-icon.active {
  background: rgba(0, 229, 255, 0.12);
  border-color: rgba(0, 229, 255, 0.4);
  color: var(--accent-cyan);
}

/* ==========================================================================
   SUB HEADER METADATA
   ========================================================================== */
.sub-header {
  display: flex;
  align-items: center;
  padding: 8px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  color: var(--text-secondary);
  gap: 20px;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-label {
  color: var(--text-muted);
}

.meta-code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 11px;
}

.btn-copy-code {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.btn-copy-code:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

.meta-badge {
  background: rgba(0, 229, 255, 0.15);
  color: var(--accent-cyan);
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 11px;
}

.ml-auto {
  margin-left: auto;
}

/* ==========================================================================
   FEED & CARDS
   ========================================================================== */
.main-content {
  flex: 1;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.message-feed {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Empty / Loading State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(0, 229, 255, 0.15);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Message Card Base */
.msg-card {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  animation: slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
}

.msg-author {
  display: flex;
  align-items: center;
  gap: 10px;
}

.author-avatar {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.user-card .author-avatar {
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: #fff;
}

.assistant-card .author-avatar {
  background: linear-gradient(135deg, #10b981, #0284c7);
  color: #fff;
}

.author-name {
  font-weight: 600;
  color: #fff;
}

.step-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-secondary);
}

.msg-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* Specific Cards */
.user-card {
  background: var(--bg-user-card);
  border-left: 3px solid var(--accent-blue);
}

.assistant-card {
  background: var(--bg-card);
  border-left: 3px solid var(--accent-cyan);
}

/* Tool execution list */
.tools-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 18px;
  background: rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid var(--border-color);
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.tool-chip-name {
  color: var(--accent-cyan);
  font-weight: 600;
}

/* Message Body & Markdown */
.msg-body {
  padding: 20px;
  word-break: break-word;
}

.msg-body p {
  margin-bottom: 14px;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 {
  color: #fff;
  margin: 22px 0 10px;
  font-weight: 600;
}

.msg-body h1 { font-size: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 6px; }
.msg-body h2 { font-size: 17px; }
.msg-body h3 { font-size: 15px; }

.msg-body ul, .msg-body ol {
  margin: 10px 0 16px 24px;
}

.msg-body li {
  margin-bottom: 6px;
}

.msg-body blockquote {
  border-left: 3px solid var(--accent-cyan);
  padding: 8px 16px;
  margin: 14px 0;
  background: rgba(0, 229, 255, 0.04);
  color: #cbd5e1;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.msg-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13px;
}

.msg-body th, .msg-body td {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  text-align: left;
}

.msg-body th {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

/* Code Snippets */
.msg-body code:not(pre code) {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: #38bdf8;
  font-size: 12.5px;
}

.code-wrapper {
  position: relative;
  margin: 16px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #1e1e2e;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.35);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.btn-copy-codeblock {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
}

.btn-copy-codeblock:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.code-wrapper pre {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-wrap: wrap;
    padding: 10px 14px;
  }
  .header-center {
    order: 3;
    max-width: 100%;
    width: 100%;
  }
  .sub-header {
    padding: 8px 14px;
    gap: 10px;
  }
  .main-content {
    padding: 14px 10px 36px;
  }
  .msg-body {
    padding: 14px;
  }
}
