/* ── Custom properties ─────────────────────────────────── */
:root {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --card:     #1a2540;
  --border:   #2d3f5c;
  --text:     #e2e8f0;
  --muted:    #8096b4;
  --accent:   #38bdf8;
  --green:    #22c55e;
  --orange:   #f97316;
  --purple:   #a78bfa;
  --yellow:   #facc15;
  --red:      #ef4444;
  --blue:     #60a5fa;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
}

select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}

select {
  padding: 6px 10px;
  cursor: pointer;
}

select:focus {
  border-color: var(--accent);
}

/* ── Header ────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}

.logo-text {
  letter-spacing: -0.01em;
}

.mode-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.mode-badge.paper {
  background: rgba(250, 204, 21, 0.12);
  color: var(--yellow);
}

.mode-badge.live {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}

/* ── Tab navigation ────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
}

.tab {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition: color 0.15s, background 0.15s;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.tab.active {
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent);
}

/* ── Main layout ───────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

#main.chat-active {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.tab-padded {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
}

/* ── Section header ────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.card h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 16px;
}

/* ── Portfolio ─────────────────────────────────────────── */
.portfolio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 0;
}

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

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.positive { color: var(--green); }
.negative { color: var(--red); }

/* Bucket bars */
.bucket-row {
  margin-bottom: 18px;
}

.bucket-row:last-child {
  margin-bottom: 0;
}

.bucket-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  margin-bottom: 8px;
}

.bucket-name {
  font-weight: 600;
  color: var(--text);
}

.bucket-pcts {
  color: var(--muted);
}

.bucket-bar-bg {
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

.bucket-bar-target {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 3px;
  opacity: 0.25;
}

.bucket-bar-actual {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.bucket-core_compounders .bucket-bar-target,
.bucket-core_compounders .bucket-bar-actual { background: var(--accent); }

.bucket-special_situations .bucket-bar-target,
.bucket-special_situations .bucket-bar-actual { background: var(--orange); }

.bucket-concentrated_bets .bucket-bar-target,
.bucket-concentrated_bets .bucket-bar-actual { background: var(--purple); }

/* Tables */
.overflow-x {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(45, 63, 92, 0.5);
  vertical-align: middle;
}

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

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.loading {
  text-align: center;
  padding: 28px;
  color: var(--muted);
  font-size: 13px;
}

/* ── Filter bar ────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.ideas-count {
  font-size: 12px;
  color: var(--muted);
  margin-left: 4px;
}

/* ── Idea cards ────────────────────────────────────────── */
#ideas-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.idea-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.idea-card:hover {
  border-color: rgba(56, 189, 248, 0.25);
}

.idea-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
}

.idea-score {
  font-size: 22px;
  font-weight: 800;
  width: 52px;
  text-align: center;
  flex-shrink: 0;
  letter-spacing: -0.03em;
  line-height: 1;
}

.score-alert  { color: var(--orange); }
.score-shadow { color: var(--purple); }
.score-low    { color: var(--muted);  }

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

.idea-ticker {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.idea-company {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.idea-catalyst {
  font-size: 13px;
  color: var(--text);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.85;
}

.idea-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.idea-chevron {
  color: var(--muted);
  font-size: 18px;
  padding: 0 2px;
  flex-shrink: 0;
  transition: transform 0.2s;
  line-height: 1;
}

.idea-card.expanded .idea-chevron {
  transform: rotate(90deg);
}

/* Badges */
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.badge-alert       { background: rgba(249, 115, 22, 0.15); color: var(--orange); }
.badge-shadow      { background: rgba(167, 139, 250, 0.15); color: var(--purple); }
.badge-monitoring  { background: rgba(96, 165, 250, 0.15); color: var(--blue); }
.badge-recommended { background: rgba(34, 197, 94, 0.18); color: var(--green); }
.badge-active      { background: rgba(34, 197, 94, 0.28); color: var(--green); }
.badge-closed      { background: rgba(128, 150, 180, 0.12); color: var(--muted); }
.badge-source      { background: rgba(56, 189, 248, 0.1); color: var(--accent); }
.badge-vic         { background: rgba(250, 204, 21, 0.12); color: var(--yellow); }

/* Idea detail (expanded) */
.idea-detail {
  display: none;
  border-top: 1px solid var(--border);
  padding: 16px;
}

.idea-card.expanded .idea-detail {
  display: block;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.detail-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 3px;
}

.detail-value {
  font-size: 13px;
  font-weight: 500;
}

.detail-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(45, 63, 92, 0.6);
}

.detail-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.detail-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 8px;
}

.detail-section-text {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  opacity: 0.9;
}

.detail-link {
  margin-top: 14px;
  font-size: 12px;
}

/* ── Chat ──────────────────────────────────────────────── */
#tab-chat {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#tab-chat.active {
  display: flex;
}

.chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  padding: 0 24px;
}

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

.chat-message {
  display: flex;
}

.chat-message.user {
  justify-content: flex-end;
}

.chat-message.assistant {
  justify-content: flex-start;
}

.message-content {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
}

.chat-message.user .message-content {
  background: rgba(56, 189, 248, 0.13);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 14px 14px 3px 14px;
}

.chat-message.assistant .message-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 3px;
}

.message-content p {
  margin-bottom: 8px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content strong {
  font-weight: 700;
  color: var(--text);
}

.message-content code {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  font-family: "SF Mono", "Fira Code", monospace;
}

.message-content pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-size: 12px;
  font-family: "SF Mono", "Fira Code", monospace;
  margin: 8px 0;
  line-height: 1.5;
}

.message-content ul, .message-content ol {
  padding-left: 20px;
  margin: 6px 0;
}

.message-content li {
  margin-bottom: 3px;
}

/* VIC result card */
.vic-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-top: 10px;
  font-size: 13px;
}

.vic-result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.vic-ticker {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.vic-company {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.vic-rating {
  font-size: 22px;
  font-weight: 800;
  text-align: right;
}

.vic-rating-label {
  font-size: 10px;
  color: var(--muted);
  text-align: right;
  margin-top: 2px;
}

.vic-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.vic-field-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 3px;
}

.vic-field-value {
  font-size: 13px;
}

.vic-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(45, 63, 92, 0.6);
}

.vic-section-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  opacity: 0.9;
}

.vic-saved {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
}

.vic-not-saved {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

.thinking {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

/* Chat input area */
.chat-input-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 0 20px;
  flex-shrink: 0;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.vic-mode-btn {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--muted);
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.vic-mode-btn:hover {
  border-color: var(--yellow);
  color: var(--yellow);
}

.vic-mode-btn.active {
  background: rgba(250, 204, 21, 0.12);
  border-color: var(--yellow);
  color: var(--yellow);
}

.vic-mode-label {
  font-size: 12px;
  color: var(--yellow);
  font-weight: 500;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

textarea#chat-input {
  flex: 1;
  resize: none;
  padding: 10px 14px;
  border-radius: 10px;
  min-height: 54px;
  max-height: 180px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

textarea#chat-input:focus {
  border-color: var(--accent);
}

.send-btn {
  background: var(--accent);
  color: #0c1a2e;
  font-weight: 700;
  font-size: 14px;
  padding: 0 24px;
  border-radius: 10px;
  height: 54px;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.send-btn:hover:not(:disabled) {
  opacity: 0.88;
}

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

.chat-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  opacity: 0.7;
}

/* VIC result status variants */
.vic-shadow {
  color: var(--yellow);
}

.vic-dedup {
  margin-top: 12px;
  font-size: 12px;
  color: var(--yellow);
}

.vic-dedup code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
}

/* Context banner (Fix 6) */
.context-banner {
  font-size: 11px;
  color: var(--accent);
  opacity: 0.8;
  margin-bottom: 10px;
  padding: 4px 8px;
  border-left: 2px solid var(--accent);
  border-radius: 0 4px 4px 0;
}

/* Chat toolbar right group (Fix 4) */
.chat-toolbar-right {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.new-chat-btn,
.history-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--muted);
  transition: all 0.15s;
}

.new-chat-btn:hover,
.history-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* History panel */
.history-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  max-height: 260px;
  display: flex;
  flex-direction: column;
}

.history-panel[hidden] {
  display: none;
}

.history-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-panel-header button {
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  padding: 0 4px;
}

.history-panel-header button:hover {
  color: var(--text);
}

.history-list {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  gap: 10px;
  transition: background 0.1s;
}

.history-item:hover {
  background: rgba(255,255,255,0.04);
}

.history-item-info {
  flex: 1;
  min-width: 0;
}

.history-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.history-delete-btn {
  font-size: 16px;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  opacity: 0.6;
}

.history-delete-btn:hover {
  color: #ef4444;
  opacity: 1;
}

.history-empty {
  padding: 20px 16px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.history-item-summary {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Fix 7: Fetch progress display */
.fetch-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.fetch-item {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}

.fetch-item em {
  font-style: italic;
  opacity: 0.7;
}
