/* Custom Scrollbar Styling - Higher Visibility */
::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
  background-clip: content-box;
}

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg-dark: #0f172a;
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
}

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

body {
  font-family: "Outfit", sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.6;
}

.hero-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(rgba(15, 23, 42, 0.6), rgba(15, 23, 42, 0.6)),
    url("./hero.png") no-repeat center center;
  background-size: cover;
  opacity: 1;
  z-index: -1;
  filter: blur(0px);
}

.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem;
}

.chart-container {
  height: 300px;
  margin-bottom: 1.5rem;
  position: relative;
}

.glass-header {
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  padding: 0.8rem 1.5rem;
}

.header-content {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 2.2rem;
  font-weight: 800;
}

.gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: 0;
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 15px 35px -12px rgba(0, 0, 0, 0.5);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 350px 1fr 300px;
  gap: 1.5rem;
  height: calc(100vh - 120px);
  margin-top: 5rem; /* Account for fixed header */
  align-items: stretch;
  animation: fadeInUp 0.8s ease-out 0.2s backwards;
}

.config-server-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.45;
  margin: -0.25rem 0 0.85rem;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.config-panel,
.results-panel,
.history-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#results-panel {
  height: 100%;
  max-height: 100%;
  display: flex !important;
  flex-direction: column;
  overflow: hidden !important;
}

#results-content {
  flex: 1;
  display: none; /* Toggled to flex by JS */
  flex-direction: column;
  min-height: 0;
  max-height: calc(100% - 40px); /* Account for H3 header */
  overflow: hidden;
}

.config-form {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.config-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.8rem 1rem 0; /* Add top/bottom padding for "lift" room */
  margin-bottom: 1rem;
}

.glass h3 {
  margin-bottom: 1.5rem;
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

h2 {
  font-size: 2rem;
  margin-bottom: 2rem;
  font-weight: 600;
}

.input-group {
  margin-bottom: 2.5rem;
  margin-bottom: 1.2rem;
}

#portfolio-form .input-group:first-child {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

#portfolio-form .input-group:first-child label {
  margin-bottom: 0;
  white-space: nowrap;
}

label {
  display: block;
  margin-bottom: 0.8rem;
  font-weight: 500;
  color: var(--text-main);
}

input[type="number"] {
  width: 120px;
  padding: 0.6rem;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: var(--text-main);
  font-size: 1rem;
  transition: all 0.3s ease;
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

.hint {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 0.4rem;
}

.strategies-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem; /* Increased gap for scale room */
  margin-top: 1rem;
}

.strategy-card {
  cursor: pointer;
  position: relative;
}

.strategy-card input {
  position: absolute;
  opacity: 0;
}

.card-content {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.8rem;
  text-align: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.card-content:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-3px);
}

.strategy-icon {
  font-size: 1.2rem;
  display: block;
  margin-bottom: 0.5rem;
}

.strategy-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.strategy-card input:checked + .card-content {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary);
  transform: translateY(-4px) scale(1.02); /* Reduced translate slightly */
  box-shadow: 0 8px 20px -5px rgba(139, 92, 246, 0.4);
  z-index: 10;
}

.primary-btn {
  width: 100%;
  background: var(--accent-gradient);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 1.2rem;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.4);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 25px -5px rgba(99, 102, 241, 0.5);
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 2rem;
  margin-top: 2rem;
}

.total-value {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 0.5rem 0 1rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.results-panel {
  flex: 1;
}

#results-content {
  flex: 1;
  display: none; /* Toggled to flex by JS */
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.stocks-container {
  flex: 1;
  min-height: 0;
  overflow-y: scroll !important;
  padding: 0 1rem 1.5rem 0;
  margin-top: 0.5rem;
}

.results-panel h3 {
  margin-bottom: 0.5rem; /* Compressed */
}

#total-value {
  font-size: 2.8rem;
  margin-bottom: 0.5rem; /* Compressed */
}

.portfolio-warnings {
  font-size: 0.78rem;
  color: #fcd34d;
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.28);
  line-height: 1.45;
}

.portfolio-warnings p {
  margin: 0 0 0.35rem;
}

.portfolio-warnings p:last-child {
  margin-bottom: 0;
}

.rationale-origin-banner {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 0 0 0.85rem;
  line-height: 1.45;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.22);
}

.rationale-pill {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.18rem 0.5rem;
  border-radius: 6px;
  vertical-align: middle;
}

.rationale-pill-llm {
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
}

.rationale-pill-fallback {
  background: rgba(148, 163, 184, 0.12);
  color: #94a3b8;
}

.stock-rationale-heading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
}

/* Ensure chart doesn't crowd out the stock list */
.chart-container {
  width: 100% !important;
  max-width: 100%;
  height: 35% !important; /* Dynamic height */
  min-height: 200px;
  margin-bottom: 1rem;
  position: relative;
}

.stock-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  transition: transform 0.3s ease;
}

.stock-main {
  flex: 1;
  min-width: 0;
}

.stock-rationale {
  margin: 0.65rem 0 0 0;
  padding-left: 0.75rem;
  border-left: 2px solid rgba(99, 102, 241, 0.35);
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-dim);
}

.stock-rationale-label {
  font-weight: 600;
  color: rgba(226, 232, 240, 0.92);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stock-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stock-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: white;
  padding: 4px;
  object-fit: contain;
}

.stock-info h4 {
  font-size: 1.1rem;
  font-weight: 700;
}

.stock-info p {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.stock-stats {
  text-align: right;
}

.stock-price {
  font-weight: 700;
  color: #10b981;
}

.stock-shares {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.loader {
  width: 60px;
  height: 60px;
  border: 5px solid rgba(99, 102, 241, 0.1);
  border-top: 5px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1.5rem;
}

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

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.history-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 1rem;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.history-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(5px);
  border-color: var(--primary);
}

.placeholder-text {
  color: var(--text-dim);
  text-align: center;
  margin-top: 5rem;
}

.history-item:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: var(--primary);
  transform: translateY(-3px);
}

.history-date {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 0.3rem;
}

.history-summary {
  font-weight: 600;
  font-size: 1rem;
}

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

/* Floating chat */
.chat-dock {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.65rem;
  max-width: calc(100vw - 2.5rem);
}

.chat-toggle-btn {
  font-family: Outfit, system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.75rem 1.15rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(99, 102, 241, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-toggle-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(99, 102, 241, 0.45);
}

.chat-panel {
  display: none;
  flex-direction: column;
  width: min(400px, calc(100vw - 2.5rem));
  max-height: min(520px, 70vh);
  padding: 1rem 1rem 0.85rem;
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.chat-panel.is-open {
  display: flex;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.chat-panel-title {
  font-weight: 700;
  font-size: 1rem;
}

.chat-close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.45rem;
  line-height: 1;
  border-radius: 8px;
}

.chat-close-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

.chat-panel-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin: 0 0 0.65rem;
  line-height: 1.35;
}

.chat-panel-hint-sub {
  font-size: 0.68rem;
  color: var(--text-dim);
  opacity: 0.9;
  margin: -0.45rem 0 0.55rem;
  line-height: 1.35;
}

.chat-messages {
  flex: 1;
  min-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding-right: 0.25rem;
  margin-bottom: 0.65rem;
}

.chat-bubble {
  max-width: 92%;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-bubble-user {
  align-self: flex-end;
  background: rgba(99, 102, 241, 0.22);
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.chat-bubble-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
}

.chat-bubble-warn {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.08);
}

/* Markdown inside assistant bubbles (marked + DOMPurify) */
.chat-bubble-md {
  line-height: 1.5;
}

.chat-bubble-md > :first-child {
  margin-top: 0;
}

.chat-bubble-md > :last-child {
  margin-bottom: 0;
}

.chat-bubble-md p {
  margin: 0 0 0.5rem;
}

.chat-bubble-md h1,
.chat-bubble-md h2,
.chat-bubble-md h3,
.chat-bubble-md h4 {
  margin: 0.65rem 0 0.35rem;
  font-weight: 700;
  line-height: 1.25;
  color: rgba(248, 250, 252, 0.98);
}

.chat-bubble-md h1 {
  font-size: 1rem;
}

.chat-bubble-md h2 {
  font-size: 0.95rem;
}

.chat-bubble-md h3,
.chat-bubble-md h4 {
  font-size: 0.88rem;
}

.chat-bubble-md ul,
.chat-bubble-md ol {
  margin: 0.35rem 0 0.55rem;
  padding-left: 1.15rem;
}

.chat-bubble-md li {
  margin-bottom: 0.25rem;
}

.chat-bubble-md strong {
  font-weight: 700;
  color: rgba(248, 250, 252, 0.98);
}

.chat-bubble-md em {
  font-style: italic;
  opacity: 0.95;
}

.chat-bubble-md a {
  color: #a5b4fc;
  text-decoration: underline;
}

.chat-bubble-md code {
  font-family: ui-monospace, monospace;
  font-size: 0.82em;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.12rem 0.35rem;
  border-radius: 5px;
}

.chat-bubble-md pre {
  margin: 0.45rem 0;
  padding: 0.5rem 0.65rem;
  overflow-x: auto;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--glass-border);
}

.chat-bubble-md pre code {
  padding: 0;
  background: transparent;
  font-size: 0.78rem;
}

.chat-bubble-md blockquote {
  margin: 0.45rem 0;
  padding-left: 0.65rem;
  border-left: 3px solid rgba(99, 102, 241, 0.45);
  color: var(--text-dim);
}

.chat-bubble-md hr {
  border: none;
  border-top: 1px solid var(--glass-border);
  margin: 0.55rem 0;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--glass-border);
}

.chat-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 44px;
  max-height: 120px;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.25);
  color: #e2e8f0;
  font-family: Outfit, system-ui, sans-serif;
  font-size: 0.85rem;
}

.chat-form textarea:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.55);
}

.chat-send-btn {
  align-self: flex-end;
  padding: 0.45rem 1.1rem;
  font-size: 0.85rem;
}

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

/* Toast Notifications */
.notification-container {
  position: fixed;
  top: 5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.toast {
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  color: white;
  min-width: 300px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 1rem;
  animation: slideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  transition: all 0.3s ease;
}

.toast.error {
  border-left: 4px solid #ef4444;
}

.toast.success {
  border-left: 4px solid #22c55e;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100px);
  }
}
