/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #1a1a1a;
    --bg-card: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent-green: #00c853;
    --accent-red: #ff1744;
    --border-color: #333;
}

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

/* Header */
header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 16px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

header .subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Navigation */
.category-nav {
    display: flex;
    overflow-x: auto;
    background: var(--bg-secondary);
    padding: 8px;
    gap: 8px;
    position: sticky;
    top: 68px;
    z-index: 99;
    border-bottom: 1px solid var(--border-color);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.category-nav::-webkit-scrollbar {
    display: none;
}

.nav-item {
    flex-shrink: 0;
    padding: 8px 16px;
    background: var(--bg-card);
    border-radius: 20px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.nav-item:hover,
.nav-item.active {
    background: #2a2a4a;
    color: var(--text-primary);
    border-color: #4a4a8a;
}

/* Main content */
main {
    padding: 8px;
    max-width: 1400px;
    margin: 0 auto;
}

/* Section styles */
.category-section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    padding: 12px 8px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 8px;
}

/* Stock grid - 2 columns on mobile */
.stock-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
}

/* Stock card */
.stock-card {
    background: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    min-height: 180px;
}

/* TradingView widget container */
.tradingview-widget-container {
    width: 100%;
    height: 180px;
}

.tradingview-widget-container iframe {
    width: 100%;
    height: 100%;
}

/* Custom card styles for non-widget display */
.stock-card-custom {
    padding: 8px;
    display: flex;
    flex-direction: column;
    height: 180px;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.card-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-secondary);
}

.card-name {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-symbol {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-left: auto;
}

.card-price {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 4px 0;
}

.card-change {
    font-size: 1rem;
    font-weight: 700;
}

.card-change.positive {
    color: var(--accent-green);
}

.card-change.negative {
    color: var(--accent-red);
}

.card-chart {
    flex: 1;
    margin-top: 8px;
    background: linear-gradient(to top, rgba(0, 200, 83, 0.1), transparent);
    border-radius: 4px;
    position: relative;
}

/* Loading state */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 180px;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Placeholder for lazy loading */
.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 180px;
    padding: 16px;
    text-align: center;
    background: linear-gradient(135deg, var(--bg-card) 0%, #252525 100%);
}

.placeholder-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.placeholder-symbol {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: #4dabf7;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}

footer p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

footer a {
    color: #4dabf7;
    text-decoration: none;
}

footer .disclaimer {
    font-size: 0.65rem;
    color: #666;
}

/* Tablet - 3 columns */
@media (min-width: 600px) {
    .stock-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    main {
        padding: 16px;
    }

    .stock-card,
    .tradingview-widget-container,
    .placeholder {
        min-height: 200px;
        height: 200px;
    }
}

/* Desktop - 4 columns */
@media (min-width: 900px) {
    .stock-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
    }

    header h1 {
        font-size: 2rem;
    }

    .category-nav {
        justify-content: center;
    }

    .stock-card,
    .tradingview-widget-container,
    .placeholder {
        min-height: 220px;
        height: 220px;
    }
}

/* Large desktop - 6 columns */
@media (min-width: 1200px) {
    .stock-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Dark mode adjustments for TradingView widgets */
.tradingview-widget-container {
    background: var(--bg-card);
}

/* Smooth scroll */
html {
    scroll-behavior: smooth;
}

/* Hide scrollbar but keep functionality */
body {
    scrollbar-width: thin;
    scrollbar-color: #333 #1a1a1a;
}

body::-webkit-scrollbar {
    width: 8px;
}

body::-webkit-scrollbar-track {
    background: #1a1a1a;
}

body::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

body::-webkit-scrollbar-thumb:hover {
    background: #444;
}
