/* Enhanced Portfolio Dashboard Styles */
#portfolio-dashboard-container {
    font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
}

/* Tab Navigation */
.portfolio-tabs {
    margin-bottom: 30px;
}

.tab-nav {
    display: flex;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-bottom: 0;
}

.tab-button {
    flex: 1;
    padding: 15px 20px;
    background: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #666;
    transition: all 0.3s ease;
    position: relative;
}

.tab-button:hover {
    background: #f8f9fa;
    color: #333;
}

.tab-button.active {
    background: #3498db;
    color: white;
}

.tab-button:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 25%;
    height: 50%;
    width: 1px;
    background: #e0e0e0;
}

.tab-button.active::after {
    display: none;
}

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

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

/* Summary Cards */
.portfolio-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}

.metric-card:hover {
    transform: translateY(-2px);
}

.metric-card h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    opacity: 0.9;
}

.metric-value {
    font-size: 24px;
    font-weight: bold;
    display: block;
}

/* Charts */
.portfolio-charts, .chart-container {
    margin-bottom: 30px;
}

.chart-container, .performance-chart-container, .historical-chart-container {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    height: 400px;
}

/* Order Book Styles */
.orderbook-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.orderbook-filters {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.orderbook-filters select,
.orderbook-filters input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.orderbook-filters button {
    padding: 8px 16px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.orderbook-filters button:hover {
    background: #2980b9;
}

/* Performance Styles */
.performance-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.performance-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.time-range-buttons {
    display: flex;
    gap: 5px;
}

.time-btn, .hist-time-btn {
    padding: 8px 15px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    transition: all 0.2s ease;
}

.time-btn:hover, .hist-time-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.time-btn.active, .hist-time-btn.active {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

.performance-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.performance-metric {
    display: flex;
    flex-direction: column;
    text-align: center;
}

.metric-label {
    font-size: 12px;
    color: #666;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.performance-metric .metric-value {
    font-size: 18px;
    font-weight: bold;
    color: #333;
}

/* Historical Data Styles */
.historical-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.historical-controls {
    margin-bottom: 20px;
}

.control-row {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 15px;
}

#stock-selector {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    min-width: 150px;
}

.chart-type-toggle {
    display: flex;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.chart-type-btn {
    padding: 8px 15px;
    background: white;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    transition: all 0.2s ease;
}

.chart-type-btn:hover {
    background: #f8f9fa;
}

.chart-type-btn.active {
    background: #3498db;
    color: white;
}

.chart-type-btn:not(:last-child) {
    border-right: 1px solid #ddd;
}

.trade-markers-legend {
    display: flex;
    gap: 20px;
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.buy-marker, .sell-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.buy-marker {
    background: #27ae60;
    border: 2px solid #1e8449;
}

.sell-marker {
    background: #e74c3c;
    border: 2px solid #c0392b;
}

/* Table Styling */
.portfolio-table {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.portfolio-table h3 {
    margin: 0 0 20px 0;
    color: #2c3e50;
}

.table-responsive {
    overflow-x: auto;
}

#holdings-table, #orders-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
}

#holdings-table th, #holdings-table td,
#orders-table th, #orders-table td {
    padding: 12px 8px;
    text-align: center;
    border-bottom: 1px solid #ddd;
    font-size: 14px;
}

#holdings-table th, #orders-table th {
    background: #3498db;
    color: white;
    font-weight: bold;
    position: sticky;
    top: 0;
}

#holdings-table tbody tr:hover,
#orders-table tbody tr:hover {
    background-color: #f5f5f5;
}

/* Order Status Colors */
.order-buy {
    color: #27ae60 !important;
    font-weight: bold;
}

.order-sell {
    color: #e74c3c !important;
    font-weight: bold;
}

.order-deposit {
    color: #3498db !important;
    font-weight: bold;
}

.order-withdraw {
    color: #f39c12 !important;
    font-weight: bold;
}

/* P&L Styling */
.positive {
    color: #27ae60 !important;
    font-weight: bold;
}

.negative {
    color: #e74c3c !important;
    font-weight: bold;
}

/* Footer */
.portfolio-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-top: 1px solid #eee;
    margin-top: 20px;
}

.last-updated {
    font-size: 12px;
    color: #666;
    margin: 0;
}

#refresh-btn {
    background: #0073aa;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

#refresh-btn:hover {
    background: #005a87;
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .tab-nav {
        flex-direction: column;
    }
    
    .tab-button:not(:last-child)::after {
        display: none;
    }
    
    .portfolio-summary {
        grid-template-columns: 1fr;
    }
    
    .metric-card {
        margin: 5px 0;
    }
    
    .performance-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .chart-container, .performance-chart-container, .historical-chart-container {
        padding: 10px;
        height: 300px;
    }
    
    .orderbook-filters {
        flex-direction: column;
        align-items: stretch;
    }
    
    .performance-metrics {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .time-range-buttons {
        justify-content: center;
    }
    
    .portfolio-footer {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
}

@media (max-width: 480px) {
    #portfolio-dashboard-container {
        padding: 10px;
    }
    
    .metric-card {
        padding: 15px;
    }
    
    .metric-value {
        font-size: 20px;
    }
    
    .chart-container, .performance-chart-container, .historical-chart-container {
        height: 250px;
    }
    
    .performance-metrics {
        grid-template-columns: 1fr;
    }
}

/* WordPress Integration */
.wp-block-shortcode #portfolio-dashboard-container {
    margin: 0;
}

/* Error States */
.portfolio-error {
    background: #ffe6e6;
    border: 1px solid #ff9999;
    color: #cc0000;
    padding: 15px;
    border-radius: 5px;
    text-align: center;
    margin: 20px 0;
}

/* Success Messages */
.portfolio-success {
    background: #e6ffe6;
    border: 1px solid #99ff99;
    color: #006600;
    padding: 15px;
    border-radius: 5px;
    text-align: center;
    margin: 20px 0;
}

/* Enhanced Performance Tab Styles */

/* Chart Controls */
.chart-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
}

.chart-toggle-buttons {
    display: flex;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chart-view-btn {
    padding: 10px 20px;
    background: white;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #666;
    transition: all 0.3s ease;
    position: relative;
}

.chart-view-btn:hover {
    background: #f8f9fa;
    color: #333;
}

.chart-view-btn.active {
    background: #3498db;
    color: white;
}

.chart-view-btn:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 25%;
    height: 50%;
    width: 1px;
    background: #e0e0e0;
}

.chart-view-btn.active::after {
    display: none;
}

/* Multi-Chart Container */
.multi-chart-container {
    position: relative;
    margin-bottom: 30px;
}

.performance-chart-container {
    display: none;
}

.performance-chart-container.active-chart {
    display: block;
}

/* Stock Selector Row */
.stock-selector-row {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.stock-selector-row label {
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

#performance-stock-selector {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    min-height: 80px;
    max-width: 400px;
}

#performance-stock-selector option {
    padding: 5px;
}

/* Enhanced Performance Metrics Grid */
.performance-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    margin-top: 30px;
}

.metrics-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-left: 4px solid #3498db;
}

.metrics-section h4 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #ecf0f1;
    padding-bottom: 8px;
}

.metrics-section .performance-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 15px;
}

.metrics-section .performance-metric {
    display: flex;
    flex-direction: column;
    text-align: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    transition: transform 0.2s ease;
}

.metrics-section .performance-metric:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Stock Performance Summary */
.stock-summary-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-top: 25px;
    border-left: 4px solid #e74c3c;
}

.stock-summary-section h4 {
    margin: 0 0 20px 0;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 700;
}

#stock-performance-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 13px;
}

#stock-performance-table th,
#stock-performance-table td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid #ddd;
}

#stock-performance-table th {
    background: #34495e;
    color: white;
    font-weight: bold;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
}

#stock-performance-table tbody tr:hover {
    background-color: #f8f9fa;
}

#stock-performance-table tbody tr:nth-child(even) {
    background-color: #fcfcfc;
}

/* Enhanced Positive/Negative Colors */
.positive {
    color: #27ae60 !important;
    font-weight: 600;
}

.negative {
    color: #e74c3c !important;
    font-weight: 600;
}

/* Cash Flow Chart Specific Styling */
#cashflow-chart-container {
    border-left: 4px solid #2ecc71;
}

/* Stock Performance Chart Specific Styling */
#stock-performance-chart-container {
    border-left: 4px solid #9b59b6;
}

/* Responsive Design for Performance Tab */
@media (max-width: 1200px) {
    .chart-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .chart-toggle-buttons {
        order: 2;
    }
    
    .time-range-buttons {
        order: 1;
        justify-content: center;
    }
    
    .performance-metrics-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
}

@media (max-width: 768px) {
    .chart-toggle-buttons {
        flex-direction: column;
    }
    
    .chart-view-btn:not(:last-child)::after {
        display: none;
    }
    
    .stock-selector-row {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    #performance-stock-selector {
        max-width: none;
    }
    
    .performance-metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .metrics-section .performance-metrics {
        grid-template-columns: repeat(2, 1fr);
    }
    
    #stock-performance-table {
        font-size: 11px;
    }
    
    #stock-performance-table th,
    #stock-performance-table td {
        padding: 6px 4px;
    }
}

@media (max-width: 480px) {
    .chart-view-btn {
        padding: 8px 12px;
        font-size: 11px;
    }
    
    .metrics-section {
        padding: 15px;
    }
    
    .metrics-section .performance-metrics {
        grid-template-columns: 1fr;
    }
    
    .performance-metric {
        padding: 8px !important;
    }
    
    .performance-metric .metric-value {
        font-size: 16px !important;
    }
    
    .stock-summary-section {
        padding: 15px;
    }
}

/* Loading states for performance charts */
.multi-chart-container.loading {
    opacity: 0.6;
    pointer-events: none;
}

.multi-chart-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1000;
}

/* Metric cards color coding */
.metrics-section:nth-child(1) {
    border-left-color: #3498db; /* Portfolio Performance - Blue */
}

.metrics-section:nth-child(2) {
    border-left-color: #2ecc71; /* Cash Flow - Green */
}

.metrics-section:nth-child(3) {
    border-left-color: #f39c12; /* Returns - Orange */
}

/* Enhanced tooltip styling for complex metrics */
.performance-metric[title]:hover {
    position: relative;
}

.performance-metric[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    white-space: nowrap;
    font-size: 11px;
    z-index: 1000;
}

/* Animation for metric updates */
.metric-value {
    transition: all 0.3s ease;
}

.metric-value.updating {
    opacity: 0.5;
    transform: scale(0.95);
}

.metric-value.updated {
    animation: metricUpdate 0.5s ease;
}

@keyframes metricUpdate {
    0% { 
        opacity: 0.5; 
        transform: scale(0.95); 
    }
    50% { 
        opacity: 1; 
        transform: scale(1.05); 
    }
    100% { 
        opacity: 1; 
        transform: scale(1); 
    }
}