:root {
    --primary: #6366f1;
    --success: #10b981;
    --danger: #ef4444;
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem 1rem;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    margin-bottom: 2rem;
}

/* Header Layout */
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: nowrap;
    width: 100%;
}

.header-left {
    flex: 0 0 auto;
    min-width: 200px;
}

.header-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 200px;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Filter Section */
.filter-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.filter-label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.toggle-group {
    background: var(--bg-card);
    padding: 0.25rem;
    border-radius: 0.75rem;
    display: flex;
    gap: 0.25rem;
    border: 1px solid var(--border);
}

.toggle-btn {
    border: none;
    background: transparent;
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-size: 0.9rem;
}

.toggle-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.toggle-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* Market Indices Widget */
.market-indices {
    display: flex;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: rgba(30, 41, 59, 0.6);
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    align-items: center;
    flex: 0 1 auto;
    margin: 0 1rem;
    justify-content: center;
    white-space: nowrap;
}

.index-card {
    padding: 0.25rem 0.75rem;
    border-right: 1px solid rgba(148, 163, 184, 0.1);
    min-width: auto;
}

.index-card:last-child {
    border-right: none;
}

.index-symbol {
    font-size: 0.65rem;
    color: #64748b;
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.index-price {
    font-size: 0.95rem;
    font-weight: 700;
    color: #f1f5f9;
    margin-bottom: 0.1rem;
}

.index-change {
    font-size: 0.65rem;
    font-weight: 600;
}

.index-change.positive {
    color: #10b981;
}

.index-change.negative {
    color: #ef4444;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px var(--shadow);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.stat-change {
    font-size: 0.85rem;
    margin-top: 0.5rem;
    font-weight: 500;
}

.stat-change.positive {
    color: var(--success);
}

.stat-change.negative {
    color: var(--danger);
}

/* Chart */
.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px var(--shadow);
}

.chart-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

#performance-chart {
    max-height: 350px;
}

/* Table */
.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px var(--shadow);
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    background: var(--bg-main);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 1rem;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

tr:hover {
    background: var(--bg-hover);
}

tr.total-row {
    background: var(--bg-main);
    font-weight: 600;
    border-top: 2px solid var(--primary);
}

tr.total-row td {
    border-bottom: none;
}

.ticker-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ticker-logo {
    width: 32px;
    height: 32px;
    border-radius: 0.5rem;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--primary);
    border: 1px solid var(--border);
}

.ticker-logo img {
    width: 100%;
    height: 100%;
    border-radius: 0.5rem;
    object-fit: cover;
}

.ticker-name {
    font-weight: 600;
}

.positive {
    color: var(--success);
}

.negative {
    color: var(--danger);
}

.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none;
}

.error-message {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    padding: 1rem;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--danger);
}

@media (max-width: 768px) {
    h1 {
        font-size: 1.5rem;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-right {
        width: 100%;
        align-items: flex-start;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.stat-change {
    font-size: 0.85rem;
    margin-top: 0.5rem;
    font-weight: 500;
}

.stat-change.positive {
    color: var(--success);
}

.stat-change.negative {
    color: var(--danger);
}

/* Chart */
.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px var(--shadow);
}

.chart-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

#performance-chart {
    max-height: 350px;
}

/* Table */
.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px var(--shadow);
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    background: var(--bg-main);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 1rem;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

tr:hover {
    background: var(--bg-hover);
}

tr.total-row {
    background: var(--bg-main);
    font-weight: 600;
    border-top: 2px solid var(--primary);
}

tr.total-row td {
    border-bottom: none;
}

.ticker-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ticker-logo {
    width: 32px;
    height: 32px;
    border-radius: 0.5rem;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--primary);
    border: 1px solid var(--border);
}

.ticker-logo img {
    width: 100%;
    height: 100%;
    border-radius: 0.5rem;
    object-fit: cover;
}

.ticker-name {
    font-weight: 600;
}

.positive {
    color: var(--success);
}

.negative {
    color: var(--danger);
}

.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none;
}

.error-message {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    padding: 1rem;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--danger);
}

@media (max-width: 768px) {
    h1 {
        font-size: 1.5rem;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-right {
        width: 100%;
        align-items: flex-start;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    table {
        font-size: 0.8rem;
    }

    th,
    td {
        padding: 0.75rem 0.5rem;
    }
}

/* Login Page Styles */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.login-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.login-header p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.login-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-btn:hover {
    background: #4f46e5;
}

/* Buffett Quote Card for Closed Positions */
.buffett-quote-card {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, var(--bg-card) 0%, #2d3748 100%);
    border-radius: 1rem;
    padding: 2rem;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px var(--shadow);
}

.quote-content {
    display: flex;
    gap: 2rem;
    align-items: center;
    margin-bottom: 1.5rem;
}

.buffett-image {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.quote-text {
    flex: 1;
}

.quote-mark {
    font-size: 4rem;
    color: var(--primary);
    line-height: 0.5;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.quote {
    font-size: 1.5rem;
    font-style: italic;
    color: var(--text-primary);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.quote-author {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.closed-stats {
    display: flex;
    gap: 2rem;
    justify-content: center;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.closed-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.closed-stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.closed-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.closed-stat-value.positive {
    color: var(--success);
}

.closed-stat-value.negative {
    color: var(--danger);
}


/* Mobile Optimizations */
@media (max-width: 768px) {
    .chart-card {
        padding: 1rem;
    }
    
    .chart-title {
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    #performance-chart {
        min-height: 300px !important;
        max-height: 400px !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .header-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .buffett-quote-card {
        padding: 1.5rem;
    }
    
    .quote-content {
        flex-direction: column;
        text-align: center;
    }
    
    .buffett-image {
        width: 100px;
        height: 100px;
    }
    
    .quote {
        font-size: 1.25rem;
    }
    
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 800px;
    }
}
