:root {
  --bg-main: #0c1017;
  --bg-surface: #121824;
  --bg-card: #171f2e;
  --bg-input: #1a2335;
  --border-subtle: #242f44;
  --border-active: #3b82f6;
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;
  --accent-amber: #f59e0b;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg-main);
  overflow: hidden;
}

/* Header */
.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px 16px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 10;
}

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

.header-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.header-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.model-select {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  max-width: 150px;
}

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

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

.icon-btn:hover, .icon-btn:active {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

/* Tab Bar */
.tab-bar {
  flex-shrink: 0;
  display: flex;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 4px 16px;
  gap: 8px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

/* Tab Content Container */
.tab-content {
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.tab-pane {
  display: none;
  height: 100%;
  width: 100%;
  flex: 1 1 0%;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.tab-pane.active {
  display: flex;
}

/* Chat View */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
}

.chat-stream {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Message Bubbles */
.message-bubble {
  display: flex;
  flex-direction: column;
  max-width: 92%;
  animation: fadeIn 0.2s ease;
}

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

.message-bubble.user {
  align-self: flex-end;
  background-color: var(--accent-primary);
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  font-size: 14.5px;
}

.message-bubble.assistant {
  align-self: flex-start;
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 16px 16px 16px 4px;
  padding: 14px 16px;
  width: 100%;
  max-width: 100%;
}

/* Timestamp & Market Badge */
.market-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  color: #93c5fd;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  margin-bottom: 10px;
}

.market-badge.closed {
  background-color: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.25);
  color: #fcd34d;
}

.market-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-green);
}

.market-badge.closed .dot {
  background-color: var(--accent-amber);
}

/* Markdown Formatting */
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  color: #f8fafc;
  margin-top: 12px;
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 700;
}

.markdown-body p {
  margin-bottom: 8px;
}

.markdown-body ul, .markdown-body ol {
  margin-left: 18px;
  margin-bottom: 8px;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body strong {
  color: #ffffff;
  font-weight: 600;
}

.markdown-body code {
  background-color: rgba(0, 0, 0, 0.3);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: #93c5fd;
}

.markdown-body pre {
  background-color: #0b0e14;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: #e2e8f0;
}

.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background-color: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  cursor: pointer;
}

/* Chart Cards in Chat */
.chart-card {
  margin: 12px 0 6px 0;
  background-color: #090d14;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.chart-card:hover, .chart-card:active {
  border-color: var(--accent-primary);
  transform: scale(1.005);
}

.chart-img {
  width: 100%;
  height: auto;
  display: block;
  min-height: 180px;
  background-color: #0b0e14;
}

.chart-hint {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-subtle);
}

/* Tool Status Pill */
.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.tool-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent-primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Quick Chips & Prompt Bar */
#promptContainer {
  flex-shrink: 0;
  z-index: 10;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}

.quick-chips-bar {
  display: flex;
  overflow-x: auto;
  padding: 8px 16px 4px 16px;
  gap: 8px;
  scrollbar-width: none;
}

.quick-chips-bar::-webkit-scrollbar {
  display: none;
}

.chip-btn {
  background-color: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-btn:hover, .chip-btn:active {
  background-color: var(--bg-input);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.prompt-bar-container {
  padding: 6px 16px calc(12px + var(--safe-bottom)) 16px;
  background-color: var(--bg-surface);
}

.prompt-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 6px 8px 6px 14px;
  transition: border-color 0.15s ease;
}

.prompt-form:focus-within {
  border-color: var(--border-active);
}

.prompt-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  outline: none;
  padding: 4px 0;
}

.prompt-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background-color: var(--accent-primary);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.prompt-send-btn:disabled {
  background-color: var(--bg-card);
  color: var(--text-muted);
  cursor: not-allowed;
}

.prompt-stop-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background-color: var(--accent-red);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Settings Drawer Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modalPop 0.2s ease;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input {
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.form-input:focus {
  border-color: var(--border-active);
}

.primary-btn {
  background-color: var(--accent-primary);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* Lightbox Modal */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: none;
  flex-direction: column;
  z-index: 200;
}

.lightbox-overlay.open {
  display: flex;
}

.lightbox-header {
  display: flex;
  justify-content: flex-end;
  padding: calc(12px + var(--safe-top)) 16px 12px 16px;
}

.lightbox-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
  touch-action: pinch-zoom;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  transition: transform 0.1s ease-out;
}
