:root {
  /* Color tokens */
  --bg-base: #0A0E14;
  --bg-chat: #0D1219;
  --bg-panel: #10151F;
  --bg-card: #1A2130;
  --bg-card-hover: #202942;
  --bubble-assistant: #1A2130;
  --bubble-user-start: #3D63C9;
  --bubble-user-end: #5B8DEF;

  --text-primary: #E8EAED;
  --text-muted: #8B93A7;
  --text-faint: #5A6274;

  --accent: #5B8DEF;
  --accent-soft: rgba(91, 141, 239, 0.15);
  --positive: #4ADE80;
  --negative: #F87171;

  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-medium: rgba(255, 255, 255, 0.12);

  --font-sans: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

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

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow: hidden;
}

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ------------------------------------------------------------------ */
/* App layout                                                          */
/* ------------------------------------------------------------------ */

.app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ------------------------------------------------------------------ */
/* Chat panel (left)                                                   */
/* ------------------------------------------------------------------ */

.chat-panel {
  width: 38%;
  min-width: 360px;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  border-right: 1px solid var(--border-subtle);
}

.chat-header {
  height: 73px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-thread::-webkit-scrollbar {
  width: 6px;
}
.chat-thread::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 3px;
}
.chat-thread:hover::-webkit-scrollbar-thumb {
  background: var(--border-medium);
}
.chat-thread {
  scrollbar-color: transparent transparent;
}
.chat-thread:hover {
  scrollbar-color: var(--border-medium) transparent;
}

.msg {
  display: flex;
  max-width: 88%;
  animation: msg-in 0.28s ease-out;
}

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

.msg-user {
  align-self: flex-end;
}

.msg-assistant {
  align-self: flex-start;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  line-height: 1.55;
}

.msg-user .msg-bubble {
  background: linear-gradient(135deg, var(--bubble-user-start), var(--bubble-user-end));
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-assistant .msg-bubble {
  background: var(--bubble-assistant);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-subtle);
}

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { color: var(--text-primary); font-weight: 600; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin-bottom: 8px; }

/* Assistant markdown tables: keep them clean, not raw pipes */
.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.msg-bubble th, .msg-bubble td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}
.msg-bubble th {
  color: var(--text-muted);
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Orb thinking indicator — 3x3 lattice, one bright head with a short
   fading tail chases clockwise around the ring perimeter. Deliberately
   NOT combined with any position animation — that murkied the effect
   into an unclear blur. Pure opacity/glow staggering reads much more
   clearly as "one dot moving." */

.orb-thinking {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  width: fit-content;
}

.orb {
  position: relative;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.orb-cell {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  animation: orb-chase 1700ms linear infinite;
}

.orb-cell[data-still] {
  display: none; /* interior cell plays no role in the chase — omit entirely */
}

@keyframes orb-chase {
  0%   { opacity: 0; }
  2%   { opacity: 1; box-shadow: 0 0 7px 1px var(--accent); }
  14%  { opacity: 0.45; box-shadow: none; }
  28%  { opacity: 0.15; }
  40%  { opacity: 0; }
  100% { opacity: 0; }
}

.orb-thinking-text {
  font-size: 13px;
  color: var(--text-muted);
  background: linear-gradient(
    90deg,
    var(--text-muted) 0%,
    var(--text-muted) 42%,
    #ffffff 50%,
    var(--text-muted) 58%,
    var(--text-muted) 100%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: text-shimmer 2.4s ease-in-out infinite;
}

@keyframes text-shimmer {
  0%   { background-position: 160% 0; }
  100% { background-position: -60% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .orb-cell { animation: none !important; opacity: 0 !important; }
  .orb-thinking-text {
    animation: none !important;
    background: none !important;
    -webkit-background-clip: initial !important;
    background-clip: initial !important;
    color: var(--text-muted) !important;
  }
}

.chat-input-row {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border-subtle);
}

.chat-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--radius-md);
}

.chat-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 48px 12px 16px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color 0.15s ease;
}

.chat-input:focus {
  border-color: var(--accent);
  outline: none;
}

.chat-input::placeholder {
  color: var(--text-faint);
}

.send-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--bubble-user-end);
  transform: translateY(-50%) scale(1.06);
}

.send-btn:active {
  transform: translateY(-50%) scale(0.94);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: translateY(-50%);
}

/* ------------------------------------------------------------------ */
/* Workspace panel (right)                                             */
/* ------------------------------------------------------------------ */

.workspace-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
}

.workspace-header {
  height: 73px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}

.workspace-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.workspace-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

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

.workspace-empty-icon {
  width: 480px;
  height: 480px;
  max-width: 70%;
  color: var(--text-faint);
  opacity: 0.35;
}

.workspace-empty p {
  font-size: 14px;
  max-width: 260px;
}

/* Workspace content, populated dynamically by JS */

.ws-section {
  animation: ws-in 0.35s ease-out;
}

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

.ws-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.ws-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
  font-family: var(--font-mono);
}

/* Big single-stat card */
.stat-card-large {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: left;
  margin-bottom: 16px;
}

.stat-card-large .stat-value {
  font-family: var(--font-mono);
  font-size: 42px;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 6px;
}

.stat-card-large .stat-label {
  font-size: 14px;
  color: var(--text-muted);
}

/* Row of smaller stat cards */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card-small {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
}

.stat-card-small .stat-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.stat-card-small .stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-positive { color: var(--positive); }
.stat-negative { color: var(--negative); }
.stat-neutral { color: var(--text-primary); }

/* Chart container */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  height: 340px;
}

/* Data table */
.data-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255,255,255,0.02);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* ------------------------------------------------------------------ */
/* Mobile                                                               */
/* ------------------------------------------------------------------ */

.mobile-toggle {
  display: none;
}

@media (max-width: 860px) {
  .app {
    flex-direction: column;
    /* dvh follows the real visible viewport on phones — 100vh extends
       behind the browser's bottom bar, which pushed the input row
       underneath it. */
    height: 100dvh;
  }

  .chat-panel, .workspace-panel {
    width: 100%;
    min-width: 0;
    flex: 1;
  }

  .chat-panel {
    border-right: none;
  }

  .app.view-chat .workspace-panel { display: none; }
  .app.view-workspace .chat-panel { display: none; }

  .mobile-toggle {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-subtle);
    z-index: 10;
  }

  .mobile-toggle-btn {
    flex: 1;
    padding: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
  }

  .mobile-toggle-btn.active {
    color: var(--accent);
  }

  /* Chat-only on mobile: the workspace panel and its toggle are disabled. */
  .workspace-panel,
  .mobile-toggle {
    display: none !important;
  }

  .app.view-workspace .chat-panel {
    display: flex !important;
  }

  .chat-input-row {
    padding-bottom: calc(20px + env(safe-area-inset-bottom)); /* clears phone home-indicator area */
  }
}