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

:root {
    --bg: #f8fafc;
    --fg: #0f172a;
    --accent: #2563eb;
    --accent-light: #dbeafe;
    --muted: #64748b;
    --border: #e2e8f0;
    --surface: #ffffff;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --yellow: #ca8a04;
    --yellow-bg: #fef9c3;
    --red: #dc2626;
    --red-bg: #fee2e2;
}

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--fg); line-height: 1.6; }

/* -- Nav -- */
nav { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
nav .logo { font-weight: 700; font-size: 18px; color: var(--fg); text-decoration: none; }
nav .nav-links a { margin-left: 16px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; }
nav .nav-links a:hover { color: var(--accent); }

main { max-width: 1100px; margin: 24px auto; padding: 0 24px; }

/* -- Typography -- */
h2 { margin-bottom: 8px; font-size: 22px; }
h3 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }
.text-muted { color: var(--muted); font-size: 13px; }
.text-green { color: var(--green); font-weight: 600; }
.text-red { color: var(--red); font-weight: 600; }

/* -- Cards -- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 20px; }
.card h3 { margin-top: 0; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

/* -- Buttons -- */
.btn { display: inline-block; background: var(--accent); color: white; padding: 10px 24px; border-radius: 6px; text-decoration: none; font-weight: 600; border: none; cursor: pointer; font-size: 14px; }
.btn:hover { opacity: 0.9; }
.btn-sm { padding: 5px 14px; font-size: 12px; border-radius: 4px; }
.btn-active { background: var(--fg); }

/* -- Tables -- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { background: #f1f5f9; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
td a { color: var(--accent); text-decoration: none; font-weight: 500; }
td a:hover { text-decoration: underline; }
.table-wrap { overflow-x: auto; }
.rank-col { font-weight: 700; color: var(--muted); }

/* -- Score Badges -- */
.score-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-weight: 700; font-size: 13px; }
.score-high { background: var(--green-bg); color: var(--green); }
.score-mid { background: var(--yellow-bg); color: var(--yellow); }
.score-low { background: var(--red-bg); color: var(--red); }

/* -- Stat Cards -- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* -- Dashboard Grid -- */
.dash-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20px; }
.dash-date { color: var(--muted); font-size: 14px; }
.dash-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; }
@media (max-width: 768px) { .dash-grid { grid-template-columns: 1fr; } }

/* -- Company Detail -- */
.company-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 24px; flex-wrap: wrap; }
.company-desc { color: var(--muted); font-size: 14px; margin-top: 8px; max-width: 600px; }
.ticker-tag { background: var(--accent-light); color: var(--accent); padding: 2px 8px; border-radius: 4px; font-size: 14px; font-weight: 600; }

.score-hero { text-align: center; min-width: 120px; }
.score-hero-value { font-size: 48px; font-weight: 800; line-height: 1; }
.score-hero-label { font-size: 11px; color: var(--muted); text-transform: uppercase; margin-top: 4px; }
.score-hero-rank { font-size: 14px; font-weight: 600; margin-top: 2px; }

/* -- Component Bars -- */
.component-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .component-grid { grid-template-columns: 1fr; } }
.component-card { background: var(--bg); border-radius: 6px; padding: 12px; }
.component-name { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-bottom: 6px; }
.component-bar-wrap { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.component-bar { height: 100%; border-radius: 4px; transition: width 0.3s; }
.bar-high { background: var(--green); }
.bar-mid { background: var(--yellow); }
.bar-low { background: var(--red); }
.component-vals { display: flex; justify-content: space-between; margin-top: 4px; }
.component-score { font-weight: 700; font-size: 14px; }

.mini-bar-wrap { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; width: 100px; }
.mini-bar { height: 100%; border-radius: 3px; }

/* -- Sort Controls -- */
.sort-controls { display: flex; align-items: center; gap: 6px; }

/* -- Weight Legend -- */
.weight-legend { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; margin-top: 20px; }
.weight-bars { display: flex; flex-direction: column; gap: 6px; }
.weight-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.weight-bar { display: inline-block; height: 8px; background: var(--accent); border-radius: 4px; min-width: 4px; }

/* -- News Feed -- */
.news-feed { display: flex; flex-direction: column; gap: 12px; }
.news-item { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.news-item:last-child { border-bottom: none; padding-bottom: 0; }
.news-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.news-ticker { font-weight: 700; font-size: 12px; color: var(--accent); }
.news-title { font-size: 13px; color: var(--fg); text-decoration: none; font-weight: 500; line-height: 1.4; }
.news-title:hover { color: var(--accent); }
.news-summary { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

/* -- Sentiment -- */
.sentiment-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.sentiment-positive, .sentiment-dot.sentiment-positive { background: var(--green); }
.sentiment-negative, .sentiment-dot.sentiment-negative { background: var(--red); }
.sentiment-neutral, .sentiment-dot.sentiment-neutral { background: var(--muted); }
.sentiment-label { font-size: 11px; font-weight: 600; text-transform: uppercase; }
.sentiment-label.sentiment-positive { color: var(--green); }
.sentiment-label.sentiment-negative { color: var(--red); }
.sentiment-label.sentiment-neutral { color: var(--muted); }

/* -- Rating Badges -- */
.rating-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.rating-strong-buy { background: var(--green-bg); color: var(--green); }
.rating-buy { background: #dcfce7; color: #15803d; }
.rating-hold { background: var(--yellow-bg); color: var(--yellow); }
.rating-sell { background: #fee2e2; color: #b91c1c; }
.rating-strong-sell { background: var(--red-bg); color: var(--red); }

/* -- Events -- */
.events-page .card-header { margin-bottom: 20px; }
.event-type-badge { display: inline-block; padding: 2px 8px; background: var(--accent-light); color: var(--accent); border-radius: 4px; font-size: 11px; font-weight: 600; }
.status-confirmed { color: var(--green); font-size: 12px; font-weight: 600; }
.status-tentative { color: var(--yellow); font-size: 12px; font-weight: 600; }
.past-event { opacity: 0.6; }

/* -- Rankings -- */
.rankings-table td { white-space: nowrap; }
.company-link { display: flex; align-items: baseline; gap: 6px; }
.company-link span { font-weight: 400; }

/* -- Landing Page -- */
.hero { text-align: center; padding: 80px 0; }
.hero h1 { font-size: 36px; margin-bottom: 12px; }
.hero p { font-size: 18px; color: var(--muted); max-width: 560px; margin: 0 auto 24px; }

/* -- Auth Forms -- */
.auth-form { max-width: 400px; margin: 60px auto; background: var(--surface); padding: 32px; border-radius: 8px; border: 1px solid var(--border); }
.auth-form h2 { margin-bottom: 20px; }
.auth-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
.auth-form input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 4px; margin-bottom: 16px; font-size: 14px; }
.auth-form .btn { width: 100%; text-align: center; }
.auth-form p { margin-top: 16px; font-size: 13px; text-align: center; }
.error { color: var(--red); font-size: 13px; margin-bottom: 12px; }

/* -- Empty States -- */
.empty-state { color: var(--muted); font-size: 14px; text-align: center; padding: 32px 16px; }

/* -- Upgrade / Pricing -- */
.btn-upgrade { background: var(--accent); color: #fff; padding: 4px 14px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.btn-upgrade:hover { opacity: 0.85; }
.btn-disabled { opacity: 0.5; cursor: default; pointer-events: none; }
.upgrade-page { max-width: 960px; margin: 0 auto; padding: 40px 20px; }
.upgrade-page .alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 24px; font-size: 14px; }
.alert-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.pricing-header { text-align: center; margin-bottom: 40px; }
.pricing-header h1 { font-size: 32px; margin-bottom: 8px; }
.pricing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-bottom: 16px; }
.pricing-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 28px 24px; position: relative; }
.pricing-card-pro { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
.plan-badge { position: absolute; top: -12px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 3px 12px; border-radius: 20px; white-space: nowrap; }
.plan-badge-save { background: var(--green); }
.plan-name { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.plan-price { font-size: 32px; font-weight: 800; margin-bottom: 4px; }
.plan-period { font-size: 14px; font-weight: 400; color: var(--muted); }
.plan-subprice { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.plan-features { list-style: none; padding: 0; margin: 16px 0 20px; }
.plan-features li { font-size: 14px; padding: 5px 0; padding-left: 20px; position: relative; color: var(--text); }
.plan-features li::before { content: "✓"; position: absolute; left: 0; color: var(--green); font-weight: 700; }
.pricing-note { text-align: center; color: var(--muted); font-size: 13px; }
.locked-row td { padding: 0; }
.upgrade-gate { display: flex; align-items: center; gap: 12px; padding: 16px 20px; background: #f8faff; border-top: 1px dashed var(--border); flex-wrap: wrap; }
.lock-icon { font-size: 18px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin: 40px 0; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px 20px; }
.feature-icon { font-size: 28px; margin-bottom: 12px; }
.feature-card h3 { font-size: 16px; margin-bottom: 8px; }
.feature-card p { font-size: 14px; color: var(--muted); line-height: 1.5; }
.pricing { text-align: center; margin: 40px 0; }
.pricing h2 { font-size: 28px; margin-bottom: 32px; }
.success-page { text-align: center; max-width: 480px; margin: 80px auto; }
.success-icon { font-size: 56px; color: var(--green); margin-bottom: 16px; }
.success-page h1 { font-size: 28px; margin-bottom: 12px; }
.success-page p { color: var(--muted); margin-bottom: 24px; }
.success-page .btn { margin: 0 8px; }

/* -- Meta / Footer -- */
.meta { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
footer { text-align: center; padding: 32px; font-size: 12px; color: var(--muted); }

/* -- Account Page -- */
.account-page h1 { font-size: 24px; margin-bottom: 20px; }
.account-page h2 { font-size: 16px; margin-bottom: 16px; }
.account-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 20px; }
.account-details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin-bottom: 16px; font-size: 14px; }
.account-details dt { color: var(--muted); font-weight: 600; }
.account-details dd { color: var(--fg); }
.account-card form { display: flex; flex-direction: column; gap: 6px; max-width: 360px; }
.account-card form label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 8px; }
.account-card form input { padding: 8px 12px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; }
.account-card form .btn { width: max-content; margin-top: 12px; }
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; }
.alert-success { background: var(--green-bg); color: #15803d; border: 1px solid #bbf7d0; }
.alert-error { background: var(--red-bg); color: #b91c1c; border: 1px solid #fecaca; }

/* Older templates reference `.btn-primary`; .btn already provides the
 * primary blue styling, so alias the two to keep rendering identical
 * regardless of which class name a template uses. */
.btn-primary { /* identical to .btn */ }

/* -- Mobile (≤600px) -- */
@media (max-width: 600px) {
    nav { padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
    nav .logo { font-size: 16px; }
    nav .nav-links { display: flex; flex-wrap: wrap; gap: 8px; }
    nav .nav-links a { margin-left: 0; font-size: 13px; }

    main { margin: 16px auto; padding: 0 16px; }

    h2 { font-size: 20px; }

    .card { padding: 16px; margin-bottom: 16px; }
    .card-header { flex-wrap: wrap; gap: 12px; }
    .dash-header { flex-direction: column; align-items: flex-start; gap: 4px; }

    .company-header { flex-direction: column; align-items: stretch; gap: 12px; }
    .score-hero { text-align: left; min-width: auto; }
    .score-hero-value { font-size: 36px; }

    .stat-cards { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .stat-card { padding: 12px 14px; }
    .stat-value { font-size: 22px; }

    th, td { padding: 6px 8px; font-size: 12px; }

    .sort-controls { flex-wrap: wrap; }

    .auth-form { margin: 24px 16px; padding: 24px; }

    .hero { padding: 48px 0; }
    .hero h1 { font-size: 28px; }
    .hero p { font-size: 16px; }

    .pricing-grid { grid-template-columns: 1fr; }

    .account-details { grid-template-columns: 1fr; gap: 2px 0; }
    .account-details dt { margin-top: 8px; }
}
