:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #242736;
    --border: #2e3140;
    --text: #e4e4e7;
    --text-muted: #8b8d98;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 8px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.nav-brand a {
    color: var(--primary);
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.nav-links { display: flex; gap: 1rem; align-items: center; }
.nav-links a { color: var(--text-muted); text-decoration: none; font-size: 0.875rem; }
.nav-links a:hover { color: var(--text); }

.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }

.hero {
    text-align: center;
    padding: 6rem 2rem;
}

.hero h1 {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.125rem;
    margin-bottom: 2rem;
}

.btn {
    display: inline-block;
    padding: 0.625rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-full { width: 100%; text-align: center; }

.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.auth-card h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    text-align: center;
}

.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color 0.15s ease;
}

.form-group input:focus { border-color: var(--primary); }

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: var(--success);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--primary);
}

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.search-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.search-wrapper {
    flex: 1;
    position: relative;
}
.search-bar input {
    width: 100%;
    padding: 0.625rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9375rem;
    outline: none;
}
.search-bar input:focus { border-color: var(--primary); }

.lookup-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 320px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.lookup-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    cursor: pointer;
    transition: background 0.1s;
}
.lookup-item:hover { background: var(--surface-hover); }
.lookup-item .lookup-ticker {
    font-weight: 700;
    color: var(--primary);
    min-width: 60px;
    font-size: 0.875rem;
}
.lookup-item .lookup-name {
    flex: 1;
    color: var(--text);
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lookup-item .lookup-exchange {
    color: var(--text-muted);
    font-size: 0.75rem;
}
.lookup-item .lookup-db {
    font-size: 0.625rem;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-weight: 600;
}
.lookup-item .in-db { background: rgba(34,197,94,0.15); color: var(--success); }
.lookup-item .not-in-db { background: rgba(139,141,152,0.15); color: var(--text-muted); }
.lookup-hint {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

.security-header { margin-bottom: 1.5rem; }
.security-header h2 { display: inline; margin-right: 0.75rem; color: var(--primary); }
.security-meta { margin-top: 0.5rem; display: flex; gap: 0.5rem; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.text-muted { color: var(--text-muted); }

.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}
.tab {
    padding: 0.625rem 1.25rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.chart-controls, .financial-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.period-btn {
    padding: 0.375rem 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8125rem;
}
.period-btn.active, .period-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.financial-controls select {
    padding: 0.375rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.8125rem;
}

.table-container { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.data-table th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    background: var(--surface);
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table tr:hover { background: var(--surface-hover); }
.data-table .clickable { cursor: pointer; }
.data-table .clickable:hover { background: rgba(59, 130, 246, 0.1); }

.scores-grid { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }
.score-item { display: flex; align-items: center; gap: 0.75rem; }
.score-label { width: 80px; font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; }
.score-bar { flex: 1; height: 8px; background: var(--surface-hover); border-radius: 4px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 4px; transition: width 0.3s ease; }
.score-value { width: 40px; text-align: right; font-size: 0.8125rem; font-weight: 600; }
.score-details { margin-top: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }

.analysis-actions { margin-bottom: 1rem; display: flex; gap: 0.75rem; }

.portfolio-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
}
.portfolio-header { display: flex; justify-content: space-between; margin-bottom: 0.5rem; }
.portfolio-stats { display: flex; gap: 1.5rem; font-size: 0.8125rem; color: var(--text-muted); }

/* Discovery Page */
.discovery { max-width: 100%; }
.discovery-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}
.discovery-header h1 { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.discovery-actions { display: flex; gap: 0.5rem; }
.btn-sm { padding: 0.375rem 0.875rem; font-size: 0.8125rem; }

.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    text-align: center;
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.05em; }

.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.section-header h2 { font-size: 1.125rem; font-weight: 600; }

.factor-tabs { display: flex; gap: 0; }
.factor-tab {
    padding: 0.375rem 0.875rem;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.15s;
}
.factor-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.factor-tab:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.factor-tab:not(:first-child) { border-left: none; }
.factor-tab.active, .factor-tab:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.sector-filter { margin-bottom: 0.75rem; }
.sector-filter select, .filter-select {
    padding: 0.375rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.8125rem;
}

.pipeline-banner {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    margin-bottom: 1rem;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--primary);
}

.anomaly-grid { display: flex; flex-direction: column; gap: 0.75rem; }
.anomaly-card {
    padding: 0.875rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}
.anomaly-card.severity-high { border-left: 3px solid var(--danger); }
.anomaly-card.severity-medium { border-left: 3px solid var(--warning); }
.anomaly-card.severity-low { border-left: 3px solid var(--text-muted); }
.anomaly-type-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 3px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}
.anomaly-type-badge.score_mover { background: rgba(59,130,246,0.15); color: var(--primary); }
.anomaly-type-badge.volume_spike { background: rgba(245,158,11,0.15); color: var(--warning); }
.anomaly-type-badge.insider_cluster { background: rgba(34,197,94,0.15); color: var(--success); }
.anomaly-type-badge.multi_factor_alignment { background: rgba(168,85,247,0.15); color: #a855f7; }
.anomaly-type-badge.piotroski_shift { background: rgba(34,197,94,0.15); color: var(--success); }
.anomaly-type-badge.altman_z_shift { background: rgba(34,197,94,0.15); color: var(--success); }
.anomaly-title { font-weight: 600; font-size: 0.875rem; }
.anomaly-desc { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }

.rec-grid { display: flex; flex-direction: column; gap: 1rem; }
.rec-card {
    padding: 1.25rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.rec-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.rec-ticker { font-size: 1.125rem; font-weight: 700; color: var(--primary); }
.rec-name { font-size: 0.8125rem; color: var(--text-muted); margin-left: 0.5rem; }
.rec-sector { font-size: 0.75rem; color: var(--text-muted); }
.rating-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}
.rating-STRONG_BUY { background: rgba(34,197,94,0.2); color: var(--success); }
.rating-BUY { background: rgba(34,197,94,0.12); color: #4ade80; }
.rating-HOLD { background: rgba(245,158,11,0.15); color: var(--warning); }
.rating-SELL { background: rgba(239,68,68,0.12); color: #f87171; }
.rating-STRONG_SELL { background: rgba(239,68,68,0.2); color: var(--danger); }
.rec-thesis { font-size: 0.875rem; line-height: 1.5; margin-bottom: 0.75rem; }
.rec-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.rec-list h4 { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.rec-list ul { list-style: none; font-size: 0.8125rem; }
.rec-list li { padding: 0.25rem 0; padding-left: 1rem; position: relative; }
.rec-list.catalysts li::before { content: "+"; position: absolute; left: 0; color: var(--success); font-weight: 700; }
.rec-list.risks li::before { content: "!"; position: absolute; left: 0.1rem; color: var(--danger); font-weight: 700; }
.rec-why { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 0.875rem; }
