.investment-section {
    margin: 20px 0;
    padding: 20px;
    border: 1px solid var(--bg-card-border);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9em; /* Added to make overall text smaller */
}

.investment-section h2 {
    margin-top: 0;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 1.1em; /* Reduced from default */
}

.source-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--bg-card-border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.add-row {
    border: 2px dashed var(--accent-blue);
    background: rgba(88, 166, 255, 0.1);
}

.source-name {
    flex: 1;
    font-weight: 500;
    margin-right: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
    font-size: 0.85em; /* Added to make smaller */
}

.rate-display {
    margin-right: 10px;
    font-weight: bold;
    color: var(--accent-green);
    min-width: 60px;
    text-align: right;
    font-size: 0.9em; /* Added to make smaller */
}

.source-input {
    margin-right: 10px;
    padding: 8px;
    border: 1px solid var(--bg-card-border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 120px;
}

.source-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

.source-select {
    margin-right: 10px;
    padding: 8px;
    border: 1px solid var(--bg-card-border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    flex: 1;
    min-width: 200px;
}

.source-select:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

.delete-btn {
    background: var(--status-error-text);
    color: var(--text-primary);
    border: none;
    padding: 6px 8px; /* Reduced padding */
    border-radius: 6px;
    cursor: pointer;
    margin-left: auto;
    font-size: 1.2em; /* Larger for × */
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    transition: background 0.2s ease;
}

.delete-btn:hover {
    background: #ff5a52;
}

.confirm-btn {
    background: var(--accent-green);
    color: var(--text-primary);
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-right: 5px;
    font-size: 0.85em;
    transition: background 0.2s ease;
}

.confirm-btn:hover {
    background: #2ea043;
}

.cancel-btn {
    background: var(--text-muted);
    color: var(--text-primary);
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: background 0.2s ease;
}

.cancel-btn:hover {
    background: #6e7681;
}

.totals {
    margin: 15px 0;
    padding: 12px;
    background: rgba(88, 166, 255, 0.1);
    border: 1px solid rgba(88, 166, 255, 0.3);
    border-radius: 8px;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.total-row, .projections-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid rgba(88, 166, 255, 0.2);
}

.projections-row {
    border-bottom: none;
}

.label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.8em; /* Reduced */
}

.value {
    font-weight: 600;
    color: var(--accent-blue);
    font-size: 0.9em; /* Reduced */
    text-align: right;
}

.projections-row .value {
    color: var(--accent-green);
}

#overall-avg-yield {
    color: var(--accent-green);
    font-weight: 600;
}

/* Portfolio styles */
.portfolio {
    margin: 20px 0; /* Top and bottom margin for spacing */
    border: 1px solid var(--bg-card-border);
    border-radius: 8px;
    background: var(--bg-card);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.portfolio-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--bg-card-border);
    border-radius: 8px 8px 0 0;
    flex-wrap: wrap;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.portfolio-header:hover {
    background: rgba(88, 166, 255, 0.05);
}

.portfolio-name-container {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0; /* Allow flex shrink */
    cursor: pointer;
}

.portfolio-name {
    font-weight: 500;
    color: var(--text-primary);
    cursor: text;
    margin-right: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px; /* Slightly reduced */
    font-size: 0.9em; /* Added to make smaller */
}

.portfolio-subtotals-compact {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85em;
    color: var(--text-secondary);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.portfolio-subtotals-compact span {
    background: rgba(88, 166, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid rgba(88, 166, 255, 0.2);
}

.subtotal-item {
    background: rgba(88, 166, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid rgba(88, 166, 255, 0.2);
    white-space: nowrap;
    font-weight: 500;
}

.subtotal-item.total-inv {
    color: var(--text-primary);
    border-color: var(--accent-blue);
}

.subtotal-item.daily-proj,
.subtotal-item.avg-yield {
    color: var(--accent-green);
    border-color: var(--accent-green);
}

.subtotal-item.avg-yield::after {
    content: '%';
    margin-left: 2px;
}

.delete-portfolio-btn {
    background: var(--status-error-text);
    color: var(--text-primary);
    border: none;
    padding: 6px 10px; /* Reduced padding for icon */
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2em; /* Larger font for × icon */
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.delete-portfolio-btn:hover {
    background: #ff5a52;
}

/* Make portfolio sources collapsible - instant toggle */
.portfolio-sources {
    max-height: 0;
    overflow: hidden;
    padding: 0; /* No padding when collapsed */
}

.portfolio-sources.expanded {
    max-height: 1000px; /* Adjust as needed */
    padding: 12px 12px 12px 12px; /* Full padding when expanded */
}

/* Portfolio chevron styles - instant rotation */
.portfolio-chevron {
    margin-left: 8px;
    font-size: 0.8em;
    color: var(--text-muted);
    flex-shrink: 0;
}

.portfolio-chevron.rotated {
    transform: rotate(180deg);
}

/* Adjust name container for chevron */
.portfolio-name-container {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.name-input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--bg-card-border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin-right: 8px;
    max-width: 150px;
    font-size: 1em;
    font-weight: 500;
    min-width: 100px; /* Ensure minimum width for usability */
}

.name-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

/* Ensure the name container accommodates the input during editing */
.portfolio-name-container {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    gap: 5px; /* Small gap for better spacing */
}

.empty-portfolios {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 1em;
    border: 2px dashed var(--bg-card-border);
    border-radius: 8px;
    background: var(--bg-card);
    margin: 20px 0;
}

/* Button styles - ensure preserved */
.btn {
    background: var(--accent-blue);
    color: var(--text-primary);
    border: none;
    padding: 10px 15px;
    margin-right: 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s ease;
}

.btn:hover {
    background: #388bfd;
}

#reset-all {
    background: var(--status-error-text);
}

#reset-all:hover {
    background: #ff5a52;
}

.add-source-btn-local {
    background: var(--accent-blue);
    color: var(--text-primary);
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s ease;
    width: 100%;
    margin-top: 10px;
}

.add-source-btn-local:hover {
    background: #388bfd;
}

/* Investment section toggle styles - instant toggle with visible rotation */
.toggle-header {
    cursor: pointer;
    user-select: none;
    padding: 10px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-header:hover {
    background: rgba(88, 166, 255, 0.05);
}

.toggle-header h2 {
    margin: 0;
    display: inline;
    color: var(--accent-blue);
    flex: 1;
}

.chevron {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-left: auto;
    display: inline-block; /* Ensure transform applies correctly */
}

.chevron.rotated {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
}

.collapsible-content.expanded {
    max-height: 2000px;
    border-top: 1px solid rgba(88, 166, 255, 0.3);
}

/* Styles for unavailable sources */
.source-row.unavailable-source {
    background: rgba(255, 90, 82, 0.1);
    border: 1px solid var(--status-error-text);
    opacity: 0.7;
}

.source-row.unavailable-source .source-name,
.source-row.unavailable-source .rate-display {
    color: var(--status-error-text);
    font-style: italic;
}

.source-row.unavailable-source .rate-display {
    font-weight: normal;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .portfolio-subtotals-compact {
        flex-direction: column;
        gap: 6px;
        align-items: flex-start;
    }
    
    .subtotal-item {
        width: 100%;
        text-align: center;
    }
    
    .totals {
        gap: 8px;
    }
    
    .total-row, .projections-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        text-align: left;
    }
    
    .value {
        text-align: left;
    }
    
    .projections-row .value {
        flex-direction: row;
        justify-content: flex-start;
        gap: 8px;
        width: 100%;
    }
}

/* Protocol Allocation Styles */
.protocol-allocation {
    margin: 15px 0;
    padding: 12px;
    background: rgba(46, 160, 67, 0.1);
    border: 1px solid rgba(46, 160, 67, 0.3);
    border-radius: 8px;
    color: var(--text-primary);
}

.allocation-header {
    font-weight: 600;
    color: var(--accent-green);
    margin-bottom: 10px;
    font-size: 0.9em;
}

.allocation-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.allocation-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.allocation-label {
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 80px;
    font-size: 0.85em;
    text-transform: capitalize;
}

.allocation-bar-container {
    flex: 1;
    height: 16px;
    background: var(--bg-primary);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--bg-card-border);
}

.allocation-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), #4ade80);
    border-radius: 8px;
    transition: width 0.3s ease;
}

.allocation-value {
    font-weight: 600;
    color: var(--accent-green);
    min-width: 100px;
    text-align: right;
    font-size: 0.85em;
}

.allocation-empty {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.85em;
    text-align: center;
    padding: 10px;
}