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

:root {
  --bg: #0f1117;
  --bg-card: #181a20;
  --bg-hover: #1e2028;
  --border: #2a2d37;
  --text: #e1e3e8;
  --text-dim: #8b8f9a;
  --text-muted: #5c5f6a;
  --accent: #4f8ff7;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --orange: #f97316;
  --buy: #166534;
  --sell: #7f1d1d;
  --keep: #854d0e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: baseline; gap: 12px; }
.header h1 { font-size: 1.25rem; font-weight: 600; }
.stock-count { color: var(--text-dim); font-size: .85rem; }

/* === Buttons === */
.btn {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
  transition: background .15s;
}
.btn:hover { background: var(--border); }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-back { padding: 6px 16px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* === Tags === */
.tag, .tag-sm {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.tag { font-size: .8rem; padding: 3px 12px; }
.tag-market { background: #1e3a5f; color: #7cb9f7; }
.tag-score { background: #2a2d37; color: var(--text); }
.tag-buy, .class-BUY { background: var(--buy); color: #86efac; }
.tag-strongbuy, .class-STRONG-BUY { background: #14532d; color: #4ade80; }
.tag-sell, .class-SELL { background: var(--sell); color: #fca5a5; }
.tag-strongsell, .class-STRONG-SELL { background: #450a0a; color: #f87171; }
.tag-keep, .class-KEEP { background: var(--keep); color: #fde68a; }

.certainty-strong { background: #14532d; color: #4ade80; }
.certainty-standard { background: var(--keep); color: #fde68a; }
.certainty-weak { background: #451a03; color: #fdba74; }

/* === Filters === */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  align-items: end;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: .75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.filter-group select, .filter-group input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: .85rem;
  min-width: 100px;
}
.filter-group select { min-width: 140px; }
.filter-group input[type="text"] { min-width: 180px; }
.filter-group input[type="number"] { width: 70px; }
.filter-checkbox { justify-content: flex-end; padding-bottom: 6px; }
.filter-checkbox label { display: flex; align-items: center; gap: 4px; font-size: .85rem; color: var(--text); text-transform: none; cursor: pointer; white-space: nowrap; }
.filter-checkbox input[type="checkbox"] { min-width: auto; width: 16px; }

/* === Table === */
.table-wrap { overflow-x: auto; padding: 0 8px; }

.stock-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.stock-table th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-dim);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.stock-table th:hover { color: var(--text); }
.stock-table th.sort-asc::after { content: ' \25b2'; font-size: .65rem; }
.stock-table th.sort-desc::after { content: ' \25bc'; font-size: .65rem; }

.stock-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.stock-table tbody tr { cursor: pointer; transition: background .1s; }
.stock-table tbody tr:hover { background: var(--bg-hover); }

.col-symbol { font-weight: 600; color: var(--accent); }
.col-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }
.col-num { text-align: right; font-variant-numeric: tabular-nums; }
.col-center { text-align: center; }


.score-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: .8rem;
  font-weight: 600;
}
.score-high { background: #166534; color: #86efac; }
.score-mid { background: #854d0e; color: #fde68a; }
.score-low { background: #7f1d1d; color: #fca5a5; }

.held-dot { color: var(--accent); font-size: 1rem; }

/* === Detail View === */
.detail-view { padding: 0 24px 40px; max-width: 1200px; margin: 0 auto; }

.detail-header {
  padding: 20px 0;
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.detail-title h2 { font-size: 1.4rem; display: flex; align-items: center; gap: 10px; }
.symbol-badge {
  background: var(--accent);
  color: #fff;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 1rem;
}
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

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

.card h3 { font-size: 1rem; margin-bottom: 12px; color: var(--text); }

/* === Description === */
.card-description { background: var(--bg-card); }
.description-row { display: flex; gap: 16px; align-items: flex-start; }
.company-logo { width: 56px; height: 56px; border-radius: 8px; object-fit: contain; background: #fff; padding: 4px; flex-shrink: 0; }
.description-text p { font-size: .9rem; color: var(--text-dim); line-height: 1.6; margin-bottom: 8px; }
.description-meta { display: flex; flex-wrap: wrap; gap: 16px; font-size: .8rem; color: var(--text-muted); }
.description-meta a { color: var(--accent); text-decoration: none; }
.description-meta a:hover { text-decoration: underline; }

/* === Verdict === */
.card-verdict { border-left: 4px solid var(--border); }
.card-verdict h3 { display: flex; align-items: center; }
.card-verdict p { font-size: .9rem; color: var(--text-dim); line-height: 1.6; }
.verdict-buy { border-left-color: var(--green); }
.verdict-strong-buy { border-left-color: var(--green); }
.verdict-sell { border-left-color: var(--red); }
.verdict-strong-sell { border-left-color: var(--red); }
.verdict-keep { border-left-color: var(--yellow); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-header h3 { margin-bottom: 0; }

.card-holdings { border-color: var(--accent); border-width: 2px; }

/* === Metrics Row === */
.metrics-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  flex: 1;
  min-width: 140px;
}
.metric-label { font-size: .75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 1.2rem; font-weight: 600; margin-top: 4px; }

/* === Holdings === */
.holdings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.holding-item { display: flex; flex-direction: column; }
.holding-label { font-size: .75rem; color: var(--text-dim); text-transform: uppercase; }
.holding-value { font-size: 1.1rem; font-weight: 600; }
.holding-total .holding-value { font-size: 1.2rem; }
.holdings-history { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); cursor: pointer; }
.holdings-history h4 { font-size: .85rem; color: var(--text-dim); margin-bottom: 8px; }
.toggle-arrow { font-size: .7rem; margin-left: 4px; }
.recommendation { margin-top: 12px; color: var(--text-dim); font-style: italic; font-size: .9rem; line-height: 1.5; }

/* === Scoring === */
.scoring-grid { display: flex; flex-direction: column; gap: 12px; }
.scoring-item {
  padding: 12px;
  background: var(--bg);
  border-radius: 6px;
  border-left: 4px solid var(--border);
}
.scoring-item:has(.rating-pass) { border-left-color: var(--green); }
.scoring-item:has(.rating-marginal) { border-left-color: var(--yellow); }
.scoring-item:has(.rating-fail) { border-left-color: var(--red); }

.scoring-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.scoring-name { font-weight: 600; font-size: .9rem; }
.scoring-badge {
  padding: 2px 10px;
  border-radius: 10px;
  font-size: .75rem;
  font-weight: 700;
}
.rating-pass { background: #166534; color: #86efac; }
.rating-marginal { background: #854d0e; color: #fde68a; }
.rating-fail { background: #7f1d1d; color: #fca5a5; }
.scoring-detail { font-size: .85rem; color: var(--text-dim); line-height: 1.5; }

.yearly-breakdown { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; font-size: .8rem; color: var(--text-muted); }
.yearly-item { display: flex; gap: 12px; padding: 4px 8px; background: var(--bg-card); border-radius: 4px; }

/* === Financial Grid === */
.financial-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.fin-item { display: flex; flex-direction: column; }
.fin-label { font-size: .75rem; color: var(--text-dim); text-transform: uppercase; }
.fin-value { font-size: 1.05rem; font-weight: 600; }

/* === Analyst === */
.analyst-bar { display: flex; height: 32px; border-radius: 6px; overflow: hidden; font-size: .8rem; font-weight: 600; }
.analyst-buy { background: var(--green); color: #fff; display: flex; align-items: center; justify-content: center; }
.analyst-hold { background: var(--yellow); color: #000; display: flex; align-items: center; justify-content: center; }
.analyst-sell { background: var(--red); color: #fff; display: flex; align-items: center; justify-content: center; }
.price-target { margin-top: 8px; color: var(--text-dim); font-size: .9rem; }

/* === Risks/Catalysts === */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .two-col { grid-template-columns: 1fr; } }

.risk-list, .catalyst-list { list-style: none; }
.risk-list li, .catalyst-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.risk-list li:last-child, .catalyst-list li:last-child { border-bottom: none; }
.risk-list li::before { content: '\26A0'; margin-right: 8px; color: var(--red); }
.catalyst-list li::before { content: '\2713'; margin-right: 8px; color: var(--green); }

/* === Charts Section === */
.charts-section { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.charts-section .card:first-child { grid-column: 1 / -1; }
@media (max-width: 900px) { .charts-section { grid-template-columns: 1fr; } }

/* === Chart === */
.chart-container { position: relative; height: 300px; }
.chart-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: .9rem;
  background: rgba(15, 17, 23, 0.7);
}
.chart-periods { display: flex; gap: 4px; }

/* === P/L colors === */
.pl-positive { color: var(--green); }
.pl-negative { color: var(--red); }

/* === Loading === */
.loading {
  padding: 60px;
  text-align: center;
  color: var(--text-dim);
  font-size: 1rem;
}

/* === Responsive === */
@media (max-width: 1024px) {
  .metrics-row { gap: 8px; }
  .metric-card { min-width: 120px; padding: 10px 14px; }
}
