:root {
  --core-black: #000000;
  --core-white: #FFFFFF;
  --core-accent: #B0C4DE; /* Platinum/Accent color */
  --core-accent-dark: #7B8A9E;
  --core-platinum: #E5E4E2;
  --core-card-bg: #1a1a1a;
  --core-accent-glow: rgba(176, 196, 222, 0.45); /* Refined glow */
  --core-line-subtle: rgba(176, 196, 222, 0.08);
  --core-line-active: rgba(176, 196, 222, 0.3);
  --chart-panel-bg: rgba(26, 26, 26, 0.85);
  --message-user-bg: rgba(176, 196, 222, 0.12);
  --message-user-color: #c3dcff;
  --message-assistant-bg: rgba(26, 26, 26, 0.9);
  --message-assistant-color: #f3f6ff;
  --input-bg: rgba(26, 32, 44, 0.85);
  --input-text: #f3f6ff;
  --input-border: rgba(176, 196, 222, 0.35);
  --input-placeholder: rgba(194, 210, 235, 0.7);
  --sidebar-offset: 0px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html[data-theme='light'] {
  --core-black: #f3f6ff;
  --core-white: #111827;
  --core-card-bg: #ffffff;
  --core-accent-glow: rgba(60, 80, 110, 0.4);
  --core-accent-dark: #4c5e7f;
  --core-line-subtle: rgba(60, 80, 110, 0.18);
  --core-line-active: rgba(60, 80, 110, 0.32);
  --chart-panel-bg: rgba(255, 255, 255, 0.98);
  --message-user-bg: #1f2937;
  --message-user-color: #f4f7ff;
  --message-assistant-bg: rgba(244, 248, 255, 0.95);
  --message-assistant-color: #17233e;
  --input-bg: rgba(247, 249, 255, 0.96);
  --input-text: #111827;
  --input-border: rgba(76, 94, 127, 0.35);
  --input-placeholder: rgba(76, 94, 127, 0.7);
}
html, body {
  font-family: Arial, sans-serif;
  margin: 0;
  background: var(--core-black);
  color: var(--core-white);
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  overflow-x: hidden;
}
#chat-wrapper {
  display: flex;
  flex-direction: column;
  height: calc(var(--vh, 1vh) * 100);
  background: var(--core-black);
  width: 100%;
  overflow-x: hidden;
}
#chat-wrapper.with-sidebar {
  flex-direction: row;
}
#conversation-sidebar {
  width: 280px;
  background: var(--core-card-bg);
  border-right: 1px solid var(--core-accent-dark);
  padding: 16px 12px;
  display: none;
  flex-direction: column;
  gap: 16px;
  box-shadow: inset -1px 0 0 rgba(176, 196, 222, 0.1);
  overflow-y: auto;
  position: fixed;
  left: 0;
  top: 0;
  height: 100%;
  z-index: 20;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}
html[data-theme='light'] #conversation-sidebar {
  background: rgba(255, 255, 255, 0.95);
  border-right: 1px solid rgba(76, 94, 127, 0.35);
  box-shadow: inset -1px 0 0 rgba(76, 94, 127, 0.15);
}
html[data-theme='light'] .conversation-item {
  background: rgba(76, 94, 127, 0.12);
  border-color: transparent;
}
html[data-theme='light'] .conversation-item:hover {
  border-color: rgba(76, 94, 127, 0.3);
  background: rgba(76, 94, 127, 0.18);
}
html[data-theme='light'] .conversation-item.active {
  border-color: var(--core-accent);
  background: rgba(76, 94, 127, 0.26);
  box-shadow: 0 0 14px rgba(76, 94, 127, 0.25);
}
html[data-theme='light'] .conversation-preview {
  color: rgba(60, 73, 98, 0.8);
}
html[data-theme='light'] .conversation-delete {
  color: rgba(58, 71, 94, 0.72);
}
html[data-theme='light'] .conversation-delete:hover {
  background: rgba(58, 71, 94, 0.22);
}
html[data-theme='light'] .chart-container {
  box-shadow: 0 0 24px rgba(58, 71, 94, 0.16);
}
body.history-panel-open #conversation-sidebar {
  display: flex;
  transform: translateX(0);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--core-accent);
}
#new-conversation-btn {
  background: transparent;
  border: 1px solid var(--core-accent);
  color: var(--core-accent);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
#new-conversation-btn:hover {
  background: var(--core-accent);
  color: var(--core-black);
}
#conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.conversation-item {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(176, 196, 222, 0.06);
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border 0.2s ease, background 0.2s ease;
}
.conversation-item:hover {
  border-color: rgba(176, 196, 222, 0.3);
  background: rgba(176, 196, 222, 0.12);
}
.conversation-item.active {
  border-color: var(--core-accent);
  background: rgba(176, 196, 222, 0.18);
  box-shadow: 0 0 12px rgba(176, 196, 222, 0.15);
}
.conversation-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--core-white);
}
.conversation-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.conversation-delete {
  margin-left: auto;
  background: transparent;
  border: none;
  color: rgba(176, 196, 222, 0.6);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.2s ease, background 0.2s ease;
}
.conversation-delete:hover {
  color: var(--core-accent);
  background: rgba(176, 196, 222, 0.15);
}
.conversation-preview {
  font-size: 0.8rem;
  color: rgba(176, 196, 222, 0.65);
  line-height: 1.4;
}
#main-region {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100%;
  width: 100%;
}
#chat-wrapper.with-sidebar #main-region {
  width: calc(100% - 280px);
}

#top-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  padding: 16px 20px 0 20px;
  width: 100%;
  max-width: 100%;
  z-index: 6;
  box-sizing: border-box;
}
#chat-wrapper.with-sidebar #top-controls {
  padding: 24px 32px 0 32px;
}
body.layout-welcome #top-controls {
  position: fixed;
  top: 12px;
  left: 0;
  right: 0;
  width: auto;
  padding: 0 18px;
  justify-content: space-between;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}
body.layout-welcome #top-controls button {
  pointer-events: auto;
}
 .chat-input-shell {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    justify-content: flex-start;
    flex-wrap: nowrap;
    position: relative;
  }
    .mode-switcher {
      position: relative;
      flex: 0 0 auto;
      z-index: 6;
      display: flex;
      align-items: center;
      margin-right: 12px;
      flex-shrink: 0;
    }
  #mode-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 999px;
    border: 1px solid var(--core-line-subtle);
    background: rgba(6, 10, 18, 0.55);
    color: var(--core-white);
    cursor: pointer;
    transition: border 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, transform 0.2s ease;
  }
  #mode-toggle:hover,
  .mode-switcher.open #mode-toggle {
    border-color: var(--core-line-active);
    box-shadow: 0 0 18px rgba(176, 196, 222, 0.22);
    background: rgba(8, 12, 20, 0.85);
    transform: translateY(-1px);
  }
  .mode-toggle-symbol {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--core-line-subtle);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    color: var(--core-accent);
    background: rgba(176, 196, 222, 0.08);
  }
    .mode-menu {
      position: absolute;
      top: calc(100% + 12px);
      left: 0;
      min-width: 200px;
      width: max-content;
      background: rgba(5, 8, 16, 0.92);
      border: 1px solid var(--core-line-subtle);
      border-radius: 14px;
      box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
      padding: 8px;
      display: flex;
      flex-direction: column;
      gap: 6px;
      opacity: 0;
      pointer-events: none;
      transform-origin: top left;
      transform: translateY(-6px) scale(0.96);
      transition: opacity 0.2s ease, transform 0.2s ease;
    }
  .mode-switcher.open .mode-menu {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }
.mode-switcher.dock-bottom .mode-menu {
  top: auto;
  bottom: calc(100% + 12px);
  transform-origin: bottom left;
  transform: translateY(6px) scale(0.96);
}
.mode-switcher.dock-bottom.open .mode-menu {
  transform: translateY(0) scale(1);
}
body.layout-welcome .mode-switcher {
  position: static;
  transform: none;
  width: 100%;
  max-width: 760px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  z-index: 9;
}
body.layout-welcome #mode-toggle {
  display: none;
}
body.layout-welcome .mode-menu {
  position: static;
  opacity: 1;
  pointer-events: auto;
  transform: none;
  display: flex;
  flex-direction: row;
  gap: 12px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  min-width: auto;
  width: 100%;
  max-width: 100%;
  justify-content: center;
}
body.layout-welcome .mode-menu button {
  flex: 0 1 auto;
  min-width: 160px;
  padding: 10px 16px;
  border: 1px solid var(--core-line-active);
  background: rgba(6, 10, 18, 0.65);
  border-radius: 12px;
  transition: all 0.2s ease;
}
body.layout-welcome .mode-menu button:hover {
  background: rgba(8, 12, 20, 0.85);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(176, 196, 222, 0.15);
}
body.layout-welcome .mode-menu button[aria-checked='true'] {
  border-color: var(--core-accent);
  background: rgba(176, 196, 222, 0.14);
  box-shadow: 0 0 18px rgba(176, 196, 222, 0.22);
}

/* Light mode: unselected should be light, selected should be dark */
html[data-theme='light'] body.layout-welcome .mode-menu button {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(76, 94, 127, 0.3);
  color: #111827;
}

html[data-theme='light'] body.layout-welcome .mode-menu button[aria-checked='true'] {
  background: rgba(31, 42, 60, 0.95);
  border-color: var(--core-accent);
  color: #f3f6ff;
  box-shadow: 0 0 18px rgba(76, 94, 127, 0.35);
}
  .mode-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    color: var(--core-white);
    border-radius: 10px;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 0.88rem;
    text-align: left;
    transition: border 0.2s ease, background 0.2s ease;
  }
  .mode-menu button:hover {
    border-color: var(--core-line-active);
    background: rgba(176, 196, 222, 0.08);
  }
  .mode-menu button[aria-checked='true'] {
    border-color: var(--core-accent);
    background: rgba(176, 196, 222, 0.14);
  }
  .mode-menu-symbol {
    font-size: 0.9rem;
    color: var(--core-accent);
    border: 1px solid var(--core-line-active);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(176, 196, 222, 0.06);
  }
  .mode-menu-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .mode-menu-name {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.04em;
  }
  .mode-menu-tagline {
    font-size: 0.68rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--core-accent);
  }
  .mode-symbol-core {
    color: var(--core-accent);
  }
  .mode-symbol-pulse {
    color: var(--core-platinum);
    text-shadow: 0 0 10px rgba(229, 228, 226, 0.45);
  }
  .mode-symbol-ultra {
    color: #d7b4ff;
    text-shadow: 0 0 10px rgba(215, 180, 255, 0.45);
  }
  html[data-theme='light'] #mode-toggle {
      background: rgba(255, 255, 255, 0.95);
    color: #111827;
    border-color: rgba(76, 94, 127, 0.25);
  }
  html[data-theme='light'] .mode-toggle-symbol {
    border-color: rgba(76, 94, 127, 0.3);
    background: rgba(76, 94, 127, 0.12);
    color: rgba(76, 94, 127, 0.95);
  }
  html[data-theme='light'] .mode-toggle-tagline {
    color: rgba(76, 94, 127, 0.9);
  }
  html[data-theme='light'] .mode-menu {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(76, 94, 127, 0.2);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.12);
  }
  html[data-theme='light'] .mode-menu button {
    color: #111827;
  }
    html[data-theme='light'] #chat-form-container {
      background: linear-gradient(180deg, rgba(248, 250, 255, 0.94) 0%, rgba(235, 240, 255, 0.96) 75%);
      border-top: 1px solid rgba(76, 94, 127, 0.2);
      box-shadow: 0 -12px 30px rgba(76, 94, 127, 0.18);
    }
    html[data-theme='light'] #chat-form-container.welcome-state {
      background: transparent;
      box-shadow: none;
    }
#theme-toggle {
  background: var(--core-card-bg);
  border: 1px solid var(--core-accent-dark);
  color: var(--core-white);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border 0.2s ease, box-shadow 0.2s ease;
}
#theme-toggle:hover {
  background: var(--core-accent);
  color: var(--core-black);
  border-color: var(--core-accent);
  box-shadow: 0 0 12px var(--core-accent-glow);
}
#history-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--core-card-bg);
  border: 1px solid var(--core-accent-dark);
  color: var(--core-white);
  border-radius: 18px;
  padding: 6px 14px;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border 0.2s ease, box-shadow 0.2s ease;
}

#history-toggle:hover:not([disabled]) {
  background: var(--core-accent);
  color: var(--core-black);
  border-color: var(--core-accent);
  box-shadow: 0 0 12px var(--core-accent-glow);
}
#history-toggle[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
body.layout-welcome #history-toggle {
  opacity: 1;
  pointer-events: auto;
}
#history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 18;
}
body.history-panel-open {
  overflow: hidden;
}
body.history-panel-open #history-overlay {
  opacity: 1;
  pointer-events: auto;
}
.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-close {
  display: none;
  background: transparent;
  border: 1px solid var(--core-line-subtle);
  color: var(--core-accent);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.mode-menu-desc {
  font-size: 0.72rem;
  color: var(--core-line-active);
}
#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 32px clamp(28px, 5vw, 80px) 32px clamp(48px, 10vw, 160px);
  transition: padding 0.3s ease;
}
body.layout-welcome #main-content {
  flex: 0;
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(24px, 4vw, 48px);
  gap: 28px;
}
body.layout-welcome #main-content::-webkit-scrollbar {
  display: none;
}
#welcome-screen {
  display: flex;
  flex-direction: column; 
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: min(440px, calc(var(--vh, 1vh) * 100 - 300px));
  padding: 0 24px;
  gap: 24px;
  width: min(820px, 100%);
  margin: 0 auto;
}
body.layout-welcome #welcome-screen {
  min-height: auto;
  padding-bottom: 0;
  gap: 28px;
}
#welcome-screen h1 {
  font-size: clamp(2rem, 6vw, 2.8rem); /* Slightly larger to pop */
  color: var(--core-accent); 
  margin: 20px 0 5px 0;
  font-weight: 700;
  text-shadow: 0 0 10px var(--core-accent-glow); /* Glow for pop */
  letter-spacing: 1px; /* Spacing for modernity */
  animation: titleFadeIn 1.5s ease-out forwards; /* Gentle fade-in */
}
#welcome-screen p {
  font-size: clamp(1rem, 3vw, 1.1rem);
  color: var(--core-white); 
  margin: 0 0 20px 0;
  font-weight: 300;
  text-shadow: 0 0 5px var(--core-accent-glow); /* Subtle glow */
  animation: titleFadeIn 1.5s ease-out forwards 0.5s; /* Delayed fade-in */
}
.welcome-animation-container {
  position: relative;
  width: clamp(240px, 50vw, 320px);
  height: clamp(240px, 50vw, 320px);
  perspective: 1500px;
  overflow: hidden;
  transform: scale(0.9); 
}
html[data-theme='light'] .welcome-animation-container {
  filter: brightness(0.85);
}
html[data-theme='light'] #welcome-screen h1,
html[data-theme='light'] #welcome-screen p {
  color: #1f2a3c;
  text-shadow: none;
}
html[data-theme='light'] .veridian-core-grid-line {
  background: rgba(76, 94, 127, 0.25);
}
html[data-theme='light'] .veridian-core-outer {
  border: 3px solid rgba(76, 94, 127, 0.55);
  box-shadow: 0 0 55px rgba(76, 94, 127, 0.35), inset 0 0 30px rgba(76, 94, 127, 0.25);
}
html[data-theme='light'] .veridian-core-orbiter, 
html[data-theme='light'] .veridian-core-innermost {
  background: rgba(76, 94, 127, 0.85);
  box-shadow: 0 0 18px rgba(31, 42, 60, 0.45);
}
#chat-container {
  display: none; 
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 980px; 
  margin: 0 auto; 
  padding: 0 clamp(64px, 12vw, 220px) 32px clamp(28px, 6vw, 80px);
  box-sizing: border-box;
}
#chat-wrapper.with-sidebar #main-content {
  padding: 32px clamp(32px, 4vw, 60px) 24px clamp(32px, 4vw, 60px);
}
#chat-wrapper.with-sidebar #chat-container {
  margin: 0;
  max-width: none;
  align-self: stretch;
  padding: 0 clamp(32px, 4vw, 72px) 32px clamp(32px, 4vw, 72px);
}
@media (max-width: 1024px) {
  #chat-container {
    padding: 0 clamp(24px, 6vw, 72px) 28px clamp(24px, 6vw, 72px);
  }
}
#loading-animation {
  position: fixed;
  bottom: 140px; /* Adjusted higher to be above input bar */
  left: calc(var(--sidebar-offset, 0px) + 20px);
  z-index: 10;
  display: none; 
  width: 200px; 
  height: 200px;
  transform: scale(0.25); 
  transform-origin: bottom left;
  perspective: 1500px;
  overflow: hidden;
}
#chat-wrapper.with-sidebar #loading-animation {
  left: calc(var(--sidebar-offset, 0px) + 20px);
}
/* --- Refined Animation Sub-Elements --- */
.veridian-core-outer{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:220px;height:220px;background:var(--core-card-bg);border:3px solid var(--core-accent);box-shadow:0 0 50px var(--core-accent-glow),inset 0 0 30px var(--core-accent-glow);animation:core-pulseGlow 2s ease-in-out infinite alternate,core-rotate3D 12s linear infinite;clip-path:polygon(50% 0,90% 20%,90% 80%,50% 100%,10% 80%,10% 20%)}
.veridian-core-inner{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:70%;height:70%;background:transparent;border:1px dashed rgba(176,196,222,.4);animation:core-rotateInner 6s linear infinite reverse;clip-path:polygon(50% 0,90% 20%,90% 80%,50% 100%,10% 80%,10% 20%)}
.veridian-core-innermost{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:15px;height:15px;background:var(--core-accent);border-radius:50%;box-shadow:0 0 20px var(--core-white),0 0 30px var(--core-accent);animation:core-pulseCoreDot 1.2s ease-in-out infinite alternate}
.veridian-core-orbiter-path{position:absolute;top:50%;left:50%;width:300px;height:300px;transform:translate(-50%,-50%) rotateX(70deg) rotateY(20deg);border:1px dashed rgba(176,196,222,.1);border-radius:50%;animation:core-rotate3D 18s linear infinite}
.veridian-core-orbiter{position:absolute;width:6px;height:6px;background:var(--core-accent);border-radius:50%;box-shadow:0 0 10px var(--core-white);top:50%;left:50%;margin:-3px;animation:core-orbit 3.5s linear infinite}
.veridian-core-orbiter:nth-child(2){animation-delay:-1s}
.veridian-core-orbiter:nth-child(3){animation-delay:-2s}
.veridian-core-orbiter:nth-child(4){animation-delay:-3s}
.veridian-core-flow-line{position:absolute;top:50%;left:50%;width:120px;height:2px;background:linear-gradient(to right,transparent,var(--core-line-active),transparent);transform-origin:left center;animation:core-radialFlow 3.5s ease-in-out infinite;opacity:0}
.veridian-core-grid-line{position:absolute;background:var(--core-line-subtle);height:1px;opacity:0;animation:core-gridFadeAndMove 10s ease-in-out infinite;z-index:0;width:150%}
@keyframes core-pulseGlow{from{box-shadow:0 0 20px var(--core-accent-glow),inset 0 0 10px var(--core-accent-glow)}to{box-shadow:0 0 60px var(--core-accent),inset 0 0 40px var(--core-accent)}}
@keyframes core-rotate3D{from{transform:translate(-50%,-50%) rotateY(0deg) rotateX(10deg)}to{transform:translate(-50%,-50%) rotateY(360deg) rotateX(10deg)}}
@keyframes core-rotateInner{from{transform:translate(-50%,-50%) rotate(0deg)}to{transform:translate(-50%,-50%) rotate(-360deg)}}
@keyframes core-pulseCoreDot{from{opacity:.7;transform:translate(-50%,-50%) scale(.8)}to{opacity:1;transform:translate(-50%,-50%) scale(1.2)}}
@keyframes core-orbit{from{transform:rotate(0deg) translateX(150px) rotate(0deg)}to{transform:rotate(360deg) translateX(150px) rotate(-360deg)}}
@keyframes core-radialFlow{0%{transform:scaleX(.1) rotate(var(--rotation-deg,0deg));opacity:0}20%{transform:scaleX(1.5) rotate(var(--rotation-deg,0deg));opacity:1}80%{transform:scaleX(.2) rotate(var(--rotation-deg,0deg));opacity:.5}100%{transform:scaleX(.1) rotate(var(--rotation-deg,0deg));opacity:0}}
@keyframes core-gridFadeAndMove{0%{transform:translateX(-100%) rotate(var(--line-rotate,0deg));opacity:0}25%{opacity:.2}50%{transform:translateX(100%) rotate(var(--line-rotate,0deg));opacity:.1}75%{opacity:.2}100%{transform:translateX(-100%) rotate(var(--line-rotate,0deg));opacity:0}}
/* --- Message Bubbles --- */
.message {
  margin: 5px 0;
  padding: 12px;
  border-radius: 8px;
  line-height: 1.5;
  word-wrap: break-word;
  width: fit-content;
  max-width: min(100%, 760px);
  align-self: flex-start;
  display: inline-block;
}
.user {
  text-align: left;
  color: var(--message-user-color);
  background: var(--message-user-bg);
  align-self: flex-end;
  max-width: min(75%, 520px);
  width: fit-content;
  border-bottom-right-radius: 2px;
}
.assistant { 
  text-align: left;
  color: var(--message-assistant-color);
  background: var(--message-assistant-bg); 
  align-self: stretch;
  width: 100%;
  max-width: 100%;
}
/* --- UPDATED Input Form Styling --- */
#chat-form-container {
    left: var(--sidebar-offset, 0px);
    right: 0;
    width: auto;
  padding: 14px clamp(16px, 3vw, 32px) calc(18px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(6, 10, 18, 0.72) 0%, rgba(0, 0, 0, 0.94) 72%);
  border-top: 1px solid var(--core-accent-dark);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.55);
  box-sizing: border-box;
  flex-shrink: 0;
  position: fixed;
  bottom: env(safe-area-inset-bottom, 0px);
  z-index: 5;
  backdrop-filter: blur(14px);
  transition: position 0.3s ease, opacity 0.3s ease, padding 0.3s ease, background 0.3s ease;
}
#chat-form-container.welcome-state {
  position: static;
  left: unset;
  width: 100%;
  max-width: none;
  margin: 0 auto 32px;
  padding: 0 clamp(20px, 4vw, 48px);
  background: transparent;
  border-top: none;
  box-shadow: none;
  backdrop-filter: none;
}
body.layout-welcome #chat-form-container.welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
#chat-form-container.welcome-state .chat-input-shell {
  justify-content: center;
  max-width: 760px;
  width: 100%;
  flex-wrap: wrap;
}
#chat-form-container.welcome-state #chat-form {
  max-width: 760px;
  width: 100%;
}
#chat-form {
      flex: 1 1 280px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 14px;
    padding: 8px 12px;
      min-height: 60px;
    box-shadow: 0 0 15px var(--core-accent-glow); /* Subtle glow for interactivity */
    transition: box-shadow 0.3s ease; /* Smooth transition */
  }
#chat-form:focus-within, #chat-form:hover {
  box-shadow: 0 0 25px var(--core-accent-glow); /* Pulsing glow on interaction */
  animation: chatGlowPulse 1.5s ease-in-out infinite alternate; /* Faint pulse */
}
textarea#user-input {
  flex: 1;
  background: transparent;
  color: var(--input-text);
  border: none;
    font-size: 0.98rem;
  font-family: Arial, sans-serif;
    line-height: 1.4;
  resize: none;
  overflow-y: hidden; 
  max-height: 200px; 
    padding: 6px 4px;
    min-height: 42px;
}
textarea#user-input:focus {
  outline: none;
}
textarea#user-input::placeholder {
  color: var(--input-placeholder);
}
button[type="submit"] {
  background: var(--core-accent);
  color: var(--core-black);
  border: 1px solid var(--core-accent);
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: bold;
  padding: 0 20px;
    height: 42px; 
    min-width: 90px;
}
button[type="submit"]:hover {
  background: var(--core-white);
  border-color: var(--core-white);
}
/* --- MARKDOWN AND CODE STYLES --- */
.code-block-wrapper {
  position: relative;
  background: #0D0D0D; 
  border-radius: 8px;
  margin: 10px 0;
}
.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #333;
  color: var(--core-white);
  border: 1px solid var(--core-accent-dark);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0.7;
  z-index: 1;
}
.code-block-wrapper:hover .copy-code-btn {
  opacity: 1;
}
.message.assistant pre {
  padding: 16px;
  padding-top: 40px; 
  overflow-x: auto;
  color: #f8f8f2; 
  background: transparent;
  border-radius: 8px;
  margin: 0;
}
.message.assistant code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9rem;
  background: none;
  padding: 0;
}
/* --- THIS SECTION IS UPDATED --- */
.message.assistant code:not([class*="language-"]) {
  background: none; /* No more ugly highlight */
  padding: 0;
  font-family: Arial, sans-serif; /* Use same font */
  font-size: 1em; /* Use same font size */
  color: var(--core-accent-dark); /* Muted color */
}
.message.assistant p,
.message.assistant li {
  margin: 16px 0 0 0;
  line-height: 1.6;
  font-weight: bold; /* Make all body text bold */
}
.message.assistant p:first-child,
.message.assistant li:first-child {
  margin-top: 0;
}
/* --- END UPDATED SECTION --- */
.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
  color: var(--core-accent);
  margin: 24px 0 10px 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--core-accent-dark);
}
.message.assistant h1 { font-size: 1.8rem; }
.message.assistant h2 { font-size: 1.5rem; }
.message.assistant h3 { font-size: 1.2rem; }
.message.assistant ul {
  margin: 16px 0;
  padding-left: 25px;
}
.message.assistant li {
  margin-bottom: 8px;
}
/* --- STYLE FOR LINKS --- */
.message.assistant a {
  color: var(--core-accent); /* Use your platinum color */
  text-decoration: underline;
  font-weight: normal; /* Make links NOT bold to stand out */
}
.message.assistant a:hover {
  color: var(--core-white); /* Brighter on hover */
}
/* --- END NEW STYLE --- */
@keyframes titleFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes chatGlowPulse {
  from { box-shadow: 0 0 15px var(--core-accent-glow); }
  to { box-shadow: 0 0 25px var(--core-accent-glow); }
}
.chart-container {
  margin-top: 16px;
  padding: 16px;
  width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--chart-panel-bg);
  border: 1px solid var(--core-accent-dark);
  border-radius: 12px;
  box-shadow: 0 0 25px rgba(176, 196, 222, 0.12);
}
.chart-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 12px;
}
.chart-header-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--core-white);
}
.chart-header-subline {
  font-size: 0.85rem;
  color: var(--core-accent);
  letter-spacing: 0.04em;
}
.chart-panel {
  width: 100%;
  height: 280px;
}
.chart-panel + .chart-panel {
  margin-top: 18px;
}
.chart-panel.indicator {
  height: 170px;
}
.chart-caption {
  margin-top: 12px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--core-accent);
  font-weight: 500;
}
.chart-summary {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--core-white);
  opacity: 0.85;
}
.chart-summary span strong {
  color: var(--core-accent);
}
.chart-footnote {
  margin-top: 12px;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: var(--core-accent);
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chart-panel.tv-panel {
  height: 320px;
  position: relative;
  overflow: hidden;
}
.chart-panel.tv-panel > div {
  width: 100%;
  height: 100%;
}
.chart-error {
  margin-top: 12px;
  text-align: center;
  color: #ff6b6b;
  font-size: 0.9rem;
}

.pie-chart-title {
  text-align: center;
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 12px;
  color: var(--core-accent);
}

.pie-chart-wrapper {
  width: 200px;
  height: 200px;
  margin: 0 auto 16px auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pie-chart {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.35);
}

.pie-legend {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  font-size: 0.9rem;
  color: var(--core-white);
}

.pie-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pie-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.25);
}

@media (max-width: 900px) {
  #chat-wrapper.with-sidebar {
    flex-direction: column;
  }
  #conversation-sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 320px;
    border-right: none;
    padding: 24px 20px 32px 20px;
    z-index: 20;
    background: var(--core-card-bg);
    transform: translateX(-100%);
  }
  body.history-panel-open #conversation-sidebar {
    display: flex !important;
    transform: translateX(0);
  }
  #chat-wrapper.with-sidebar #conversation-list {
    max-height: 180px;
    overflow-y: auto;
  }
  #chat-container {
    padding: 0 20px 28px 20px;
  }
  #chat-wrapper.with-sidebar #main-content {
    padding: 20px 18px 16px 18px;
  }
  #chat-wrapper.with-sidebar #chat-container {
    margin: 12px 12px 20px 12px;
    padding: 0 20px 24px 20px;
    max-width: 100%;
  }
  #top-controls {
    padding: 16px 16px 0 16px;
  }
  #theme-toggle {
    display: inline-flex;
  }
  .history-close {
    display: inline-flex;
  }
  
  /* Mobile: hide top controls on welcome screen until first message */
  body.layout-welcome #top-controls {
    opacity: 0;
    pointer-events: none;
  }
  
  /* Show controls after first message */
  body.layout-chat #top-controls {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 768px) {
  html, body {
    overflow-y: auto;
    overflow-x: hidden;
  }
  #chat-wrapper {
    min-height: calc(var(--vh, 1vh) * 100);
    height: auto;
  }
  #main-content {
    padding: 14px 12px 140px 12px;
  }
  #chat-wrapper.with-sidebar #main-content {
    padding: 14px 12px 140px 12px;
  }
  #chat-container {
    max-width: 100%;
    margin: 0;
    padding: 0 14px 96px 14px;
  }
  .chat-input-shell {
    max-width: 100%;
    gap: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .mode-switcher {
    width: auto;
  }
  #mode-toggle {
    min-width: 0;
  }
  #chat-wrapper.with-sidebar #chat-container {
    margin: 10px;
    padding: 0 14px 96px 14px;
  }
  #chat-form-container {
    padding: 10px clamp(12px, 4vw, 24px) calc(18px + env(safe-area-inset-bottom, 0px));
  }
  #chat-form-container.welcome-state {
    margin: 16px auto 24px;
    padding: 0 clamp(14px, 5vw, 32px);
  }
  #chat-form {
    max-width: 100%;
    width: 100%;
    margin: 0;
  }
  #loading-animation {
    bottom: 120px; /* Adjusted for mobile input height */
    left: calc(var(--sidebar-offset, 0px) + 5px);
  }
  .welcome-animation-container {
    transform: scale(0.7);
  }
}

@media (max-width: 600px) {
  #chat-wrapper {
    min-height: 100vh;
    height: auto;
  }
  #main-content,
  #chat-wrapper.with-sidebar #main-content {
    padding: 12px 10px 180px 10px;
  }
  #chat-container {
    padding: 0 12px 150px 12px;
    gap: 8px;
  }
  /* Mobile: Keep chat form horizontal but reduce height */
  #chat-form {
    flex-direction: row;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    min-height: 48px;
  }
  #chat-form button[type="submit"] {
    width: auto;
    margin: 0;
    height: 40px;
    min-width: 70px;
    padding: 0 16px;
  }
  textarea#user-input {
    font-size: 0.95rem;
    min-height: 36px;
    max-height: 120px;
  }
  body.layout-welcome #main-content {
    padding: 24px 16px;
    gap: 20px;
  }
  body.layout-welcome #chat-form-container.welcome-state {
    max-width: 100%;
    margin: 8px auto 24px;
  }
  #welcome-screen {
    padding: 0;
    gap: 14px;
    align-items: center;
    text-align: center;
    justify-content: center;
    width: 100%;
  }
  #welcome-screen h1 {
    font-size: clamp(1.6rem, 7vw, 2.2rem);
    margin: 8px 0 4px 0;
    padding: 0 20px;
  }
  #welcome-screen p {
    font-size: 0.95rem;
    margin: 0;
    padding: 0 20px;
  }
  .welcome-animation-container {
    transform: scale(0.75);
    width: clamp(200px, 60vw, 260px);
    height: clamp(200px, 60vw, 260px);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Mobile: Mode toggle positioning after first message */
  body.layout-chat .mode-switcher {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    width: auto;
    background: transparent;
  }
  
  body.layout-chat .mode-switcher.dock-bottom {
    bottom: 90px;
  }
  
  body.layout-chat .mode-menu {
    left: 50%;
    right: auto;
    bottom: calc(100% + 8px);
    transform: translateX(-50%) translateY(6px) scale(0.96);
    transform-origin: bottom center;
    min-width: 280px;
  }
  
  body.layout-chat .mode-switcher.open .mode-menu {
    transform: translateX(-50%) translateY(0) scale(1);
  }
  
  .mode-details {
    display: none;
  }
  #top-controls {
    justify-content: space-between;
    padding: 16px 10px 0 10px;
  }
  .message {
    max-width: 100%;
    font-size: 0.95rem;
  }
  .chart-container {
    padding: 12px;
  }
  .chart-panel {
    height: 220px;
  }
  .chart-panel.indicator {
    height: 150px;
  }
  
  /* Mobile specific: horizontal mode selector on welcome - centered */
  body.layout-welcome .mode-switcher {
    position: static;
    transform: none;
    left: auto;
    bottom: auto;
    width: 100%;
    max-width: 100%;
    padding: 0 20px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  body.layout-welcome .mode-menu {
    flex-direction: column;
    gap: 10px;
    max-width: 90%;
    width: 100%;
    align-items: stretch;
    position: static;
    left: auto;
    transform: none;
  }
  body.layout-welcome .mode-menu button {
    min-width: 100%;
    width: 100%;
  }
}

@media (max-width: 420px) {
  #main-content,
  #chat-wrapper.with-sidebar #main-content {
    padding: 10px 8px 140px 8px;
  }
  #chat-container {
    padding: 0 8px 90px 8px;
  }
  #chat-form button[type="submit"] {
    height: 44px;
  }
  .chart-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
