@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap');

:root {
    --bg-dark: #0a0e1a;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary: #4f46e5;
    --accent: #8b5cf6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 20% 20%, rgba(79, 70, 229, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    padding-top: 6rem; /* Space for sticky navbar */
}

/* Navbar & Logo */
.navbar {
    position: fixed;
    top: 1rem;
    left: 2rem;
    right: 2rem;
    height: 70px;
    z-index: 2000;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    border-radius: 20px;
}

.nav-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    cursor: pointer;
}

.logo-img {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    object-fit: cover;
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo-dot {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.nav-links {
    display: flex;
    gap: 2rem;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    position: relative;
}

.nav-link:hover, .nav-link.active {
    color: white;
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary);
    transition: width 0.3s ease;
    border-radius: 2px;
}

.nav-link:hover::after, .nav-link.active::after {
    width: 100%;
}

/* Glassmorphism Common */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Header & Search */
header {
    text-align: center;
    margin-bottom: 4rem;
    padding-top: 2rem;
}

h1 {
    font-size: 3.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
}

subtitle {
    display: block;
    font-size: 1.2rem;
    color: var(--text-muted);
    font-weight: 300;
}

.search-section {
    position: sticky;
    top: 6.5rem;
    z-index: 1000;
    margin: 0 auto 5rem auto;
    max-width: 600px;
    transition: all 0.3s ease;
}

.search-container {
    padding: 0.5rem;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
    background: rgba(10, 14, 26, 0.8); /* Darkened for stickiness visibility */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.search-container:focus-within {
    transform: scale(1.02);
    box-shadow: 0 0 20px rgba(79, 70, 229, 0.3);
}

#search-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    outline: none;
}

.search-icon {
    margin-left: 1.5rem;
    color: var(--text-muted);
}

#search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 1rem;
    padding: 0.5rem;
    display: none;
}

.result-item {
    padding: 1rem 1.5rem;
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.2s ease;
}

.result-item:hover {
    background: rgba(255,255,255,0.05);
}

.result-item .symbol {
    font-weight: 700;
    color: var(--primary);
    margin-right: 0.5rem;
}

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

/* Keyboard-selected result */
.result-item.active {
    background: rgba(79, 70, 229, 0.15);
    outline: 1px solid rgba(79, 70, 229, 0.4);
}

/* Match highlighting */
.highlight {
    background: rgba(79, 70, 229, 0.35);
    color: #e0e7ff;
    padding: 0 2px;
    border-radius: 3px;
}

/* Inline search spinner */
.search-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: rotation 0.6s linear infinite;
    margin-right: 1rem;
    flex-shrink: 0;
}

/* Empty state */
.search-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Scrollable dropdown for many results */
#search-results {
    max-height: 360px;
    overflow-y: auto;
}

/* Results Content */
#analysis-content {
    display: none;
    animation: fadeInUp 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

.company-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 3rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 2rem;
}

.company-title h2 {
    font-size: 2.5rem;
    margin-bottom: 0.2rem;
}

.scores-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 2rem;
    margin-bottom: 4rem;
}

.score-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.score-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1rem;
}

.score-value {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.score-progress {
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-bar {
    height: 100%;
    transition: width 1s ease-out;
}

.score-reason {
    font-size: 0.95rem;
    color: #cbd5e1;
    font-weight: 300;
}

/* Color Levels */
.good { color: var(--success); }
.neutral { color: var(--warning); }
.bad { color: var(--danger); }

.bg-good { background: var(--success); }
.bg-neutral { background: var(--warning); }
.bg-bad { background: var(--danger); }

/* Ranking Section */
.tabs-container {
    display: flex;
    gap: 0.5rem;
}

.tab-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 0.6rem 1.2rem;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(79, 70, 229, 0.4);
}

.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.ranking-row {
    display: flex;
    align-items: center;
    padding: 1.5rem 2.5rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
    cursor: pointer;
    animation: fadeInSlide 0.4s ease forwards;
    opacity: 0;
}

@keyframes fadeInSlide {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.ranking-row:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(5px);
    border-color: var(--glass-border);
}

/* Section Header for Ranking Group */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    gap: 1.5rem;
}

.ranking-section {
    padding: 4rem;
    margin-bottom: 5rem;
}

.analysis-section, .backtest-section {
    margin-top: 3rem;
    padding: 4rem;
}

#disp-company-meta {
    color: var(--text-muted);
    font-size: 1.2rem;
}


.rank-num {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-muted);
    width: 30px;
}

.rank-symbol {
    font-weight: 700;
    color: white;
    width: 160px;
}

.rank-name {
    flex: 1;
    color: var(--text-muted);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rank-score {
    font-weight: 700;
    font-size: 1.1rem;
    margin-left: 1rem;
}

/* Loading State */
.loading {
    display: none;
    text-align: center;
    padding: 4rem;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #FFF;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Business Summary */
.business-summary-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 2.5rem;
    margin-bottom: 3rem;
    line-height: 1.7;
    animation: fadeIn 0.6s ease forwards;
}

.business-summary-box h4 {
    margin-bottom: 1rem;
    color: var(--primary-light);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 800;
}

#disp-business-summary {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Backtest Dashboard */
.backtest-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 3.5rem;
    margin-top: 4rem;
    animation: fadeIn 0.8s ease forwards;
}

.backtest-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 24px;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.backtest-card:hover {
    transform: translateY(-8px);
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--glass-border);
}

.bt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bt-company-info {
    display: flex;
    flex-direction: column;
}

.bt-symbol {
    font-size: 1.6rem;
    font-weight: 800;
    color: white;
}

.bt-year {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.bt-accuracy-badge {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 30px;
    background: rgba(79, 70, 229, 0.15);
    color: var(--primary-light);
    border: 1px solid rgba(79, 70, 229, 0.3);
}

.bt-metrics-container {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.bt-metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.8rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.bt-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.bt-values {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.bt-score-pill {
    font-size: 1.1rem;
    font-weight: 800;
    color: white;
}

.bt-arrow {
    color: var(--text-muted);
    opacity: 0.5;
}

.bt-return-pill {
    font-size: 1.2rem;
    font-weight: 800;
    min-width: 80px;
    text-align: right;
}

.bt-return-pill.positive { color: var(--success); }
.bt-return-pill.negative { color: var(--danger); }

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

/* --- Mobile Responsive Updates --- */

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header {
        margin-bottom: 2.5rem;
    }

    h1 {
        font-size: 2.2rem;
    }

    subtitle {
        font-size: 1rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .tabs-container {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 0.5rem;
        -ms-overflow-style: none;  /* Hide scrollbar IE/Edge */
        scrollbar-width: none;  /* Hide scrollbar Firefox */
    }

    .tabs-container::-webkit-scrollbar {
        display: none; /* Hide scrollbar Chrome/Safari */
    }

    .tab-btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }

    .ranking-section, .analysis-section {
        padding: 1.2rem;
    }

    .rank-symbol {
        width: 90px;
        font-size: 0.9rem;
    }

    .rank-name {
        display: none; /* Hide company name on small mobile rows */
    }

    .company-title h2 {
        font-size: 1.8rem;
    }

    #disp-company-meta {
        font-size: 0.9rem;
    }

    .company-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .score-value {
        font-size: 2.2rem;
    }

    .score-card {
        padding: 1.2rem;
    }

    .navbar {
        top: 0;
        left: 0;
        right: 0;
        border-radius: 0;
        height: 60px;
        padding: 0 1rem;
    }

    .nav-links {
        display: none; /* Hide links on mobile, or could use a burger menu */
    }

    .logo-text {
        font-size: 1.2rem;
    }

    .container {
        padding-top: 5rem;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.8rem;
    }

    .ranking-row {
        padding: 0.8rem 1rem;
    }
    
    .rank-symbol {
        flex: 1;
    }

    .rank-score {
        font-size: 1rem;
    }
}

/* Footer */
.footer {
    margin-top: 6rem;
    padding: 4rem 2rem 2rem 2rem;
    background: rgba(10, 14, 26, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1.5fr 1fr 2fr;
    gap: 3rem;
    margin-bottom: 3rem;
}

.footer-col h4 {
    color: white;
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.footer-col a {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 0.8rem;
    transition: color 0.2s ease;
}

.footer-col a:hover {
    color: var(--accent);
}

.footer-disclaimer {
    font-size: 0.85rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.4);
}

.footer-bottom {
    max-width: 1200px;
    margin: 0 auto;
    padding-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .footer-content {
        grid-template-columns: 1fr;
    }
    .footer-bottom {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
}
