/**
 * Portfolio Optimizer Styles
 */

.optimizer-container {
    max-width: 1400px;
    padding-bottom: 3rem;
}

.viz-subtitle {
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-size: 1rem;
}

/* Info Grid */
.optimizer-info {
    margin-bottom: 2rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.info-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-color);
    border-radius: 8px;
    padding: 1rem 1.25rem;
}

.info-item h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.info-item p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.info-item ul {
    margin: 0;
    padding-left: 1.2rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.info-item li {
    margin-bottom: 0.25rem;
}

/* Portfolio Builder */
.optimizer-builder {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.optimizer-builder h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
}

.portfolio-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .portfolio-selector {
        grid-template-columns: 1fr;
    }
}

.portfolio-column h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.portfolio-select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.portfolio-select optgroup {
    font-weight: 600;
    background: var(--card-bg);
    color: var(--text-primary);
}

.portfolio-select option {
    padding: 0.5rem;
    background: var(--card-bg);
    color: var(--text-primary);
}

/* Dark theme specific fixes for dropdowns */
[data-theme="dark"] .portfolio-select,
[data-theme="dark"] .portfolio-select option,
[data-theme="dark"] .portfolio-select optgroup {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

[data-theme="dark"] .portfolio-select optgroup {
    color: #fff;
}

/* Dark theme fixes for parameter dropdowns (rebalancing, etc.) */
[data-theme="dark"] .param-group select,
[data-theme="dark"] .param-group select option {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

[data-theme="dark"] .param-group input {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

.btn-primary {
    display: block;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* Optimizer Form */
.optimizer-form {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.optimizer-form h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    padding-top: 1rem;
}

.optimizer-form h3:first-child {
    padding-top: 0;
}

.ticker-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .ticker-grid {
        grid-template-columns: 1fr;
    }
}

.ticker-column label,
.weight-column label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.label-hint {
    color: var(--text-secondary);
    font-weight: normal;
    font-size: 0.8rem;
}

.ticker-column textarea,
.weight-column textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.85rem;
    resize: vertical;
}

/* Parameters Grid */
.params-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.param-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.param-group input,
.param-group select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

/* Optimize Button */
.optimize-action {
    text-align: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.btn-optimize {
    padding: 1rem 3rem;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn-optimize:hover:not(:disabled) {
    background: #c0392b;
    transform: translateY(-2px);
}

.btn-optimize:disabled {
    background: #999;
    cursor: not-allowed;
}

.btn-optimize i {
    margin-right: 0.5rem;
}

.rate-limit-info {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Results Section */
.optimizer-results {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.optimizer-results h3 {
    margin: 0 0 1.5rem 0;
    font-size: 1.2rem;
}

.optimizer-results h4 {
    margin: 1.5rem 0 1rem 0;
    font-size: 1rem;
}

/* Loading State */
.results-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.results-loading i {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--accent-color);
}

.results-loading #loading-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.progress-container {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), #3498db);
    border-radius: 4px;
    width: 0%;
    transition: width 0.5s ease;
}

.progress-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
}

.chart-error {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

/* Error State */
.results-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    border-radius: 8px;
}

.results-error i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
}

.metric-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Chart */
.results-chart {
    margin-bottom: 1.5rem;
}

.results-chart img {
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* Chart Header - title and legend inline */
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.chart-header h4 {
    margin: 0;
}

/* Chart Legend */
.chart-legend {
    display: flex;
    gap: 1.5rem;
    font-size: 0.9rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-color {
    display: inline-block;
    width: 20px;
    height: 3px;
    border-radius: 1px;
}

/* Light theme colors (default) */
.legend-color.portfolio {
    background: #ff0000;
}

.legend-color.benchmark {
    background: #0000ff;
}

/* Dark theme colors */
[data-theme="dark"] .legend-color.portfolio {
    background: #ff5252;
}

[data-theme="dark"] .legend-color.benchmark {
    background: #ff9800;
}

/* Allocations Table */
.allocations-section {
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.allocations-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.allocations-table th,
.allocations-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.allocations-table th {
    background: var(--bg-primary);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.allocations-table tbody tr:hover {
    background: var(--bg-primary);
}

.allocations-table .positive {
    color: #27ae60;
}

.allocations-table .negative {
    color: #e74c3c;
}

.allocations-table a {
    color: var(--accent-color);
    text-decoration: none;
}

.allocations-table a:hover {
    text-decoration: underline;
}

/* Invalid Tickers Warning */
.invalid-warning {
    background: rgba(243, 156, 18, 0.1);
    border: 1px solid #f39c12;
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}

.invalid-warning h4 {
    margin: 0 0 0.5rem 0;
    color: #f39c12;
    font-size: 0.95rem;
}

.invalid-warning p {
    margin: 0 0 0.5rem 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.invalid-warning ul {
    margin: 0;
    padding-left: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* Download Links */
.download-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.btn-download:hover {
    background: var(--border-color);
}

/* Educational Content */
.optimizer-education {
    margin-bottom: 2rem;
}

.edu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.edu-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem;
}

.edu-item h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
}

.edu-item p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Disclaimer */
.optimizer-disclaimer {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem 1.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.optimizer-disclaimer strong {
    color: var(--text-primary);
}

/* Returns Tables */
.returns-section {
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.returns-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.returns-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 600px;
}

.returns-table th,
.returns-table td {
    padding: 0.5rem 0.75rem;
    text-align: right;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

.returns-table th {
    background: var(--bg-primary);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.returns-table th:first-child,
.returns-table td:first-child {
    text-align: left;
    font-weight: 600;
    position: sticky;
    left: 0;
    background: var(--card-bg);
    z-index: 1;
}

.returns-table tbody tr:hover {
    background: var(--bg-primary);
}

.returns-table .positive {
    color: #27ae60;
}

.returns-table .negative {
    color: #e74c3c;
}

/* Monthly Returns Calendar Grid */
.monthly-table {
    min-width: 800px;
}

.monthly-table th {
    text-align: center;
}

.monthly-table td {
    text-align: center;
    min-width: 55px;
}

.monthly-table td:first-child {
    min-width: 70px;
    text-align: center;
}

.monthly-table .year-total {
    font-weight: 600;
    background: var(--bg-primary);
}

/* Allocations History */
.allocations-history-wrapper {
    margin-top: 0.5rem;
}

.allocations-history-wrapper .portfolio-select {
    margin-bottom: 1rem;
}
