/* Body - No Fixed Height */
body {
    min-height: 100vh;
    height: auto;
}

/* Main Content - Not Full Width */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0;
    min-height: calc(100vh - 80px); /* Subtract header height */
}

.content-container {
    max-width: 100%;
    padding: 20px;
    padding-top: 100px;
}

/* Header Section - Match Content Width */
.header-section {
    margin: 0 auto 24px auto;
    max-width: 1200px;
    position: relative;
    z-index: 1;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 12px;
    padding: 20px 24px;
}

.header-text h1 {
    color: #ffffff;
    font-size: 1.7rem;
    font-weight: 600;
    margin: 0 0 6px 0;
    letter-spacing: -0.5px;
}

.header-text p {
    color: #cccccc;
    font-size: 0.95rem;
    margin: 0;
    line-height: 1.4;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.action-buttons .btn {
    padding: 8px 16px;
    font-size: 0.85rem;
    border-radius: 6px;
}

/* Statistics Section - Clean */
.stats-section {
    margin-bottom: 16px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
}

/* Auto-fit stat cards nicely for various counts */
@media (max-width: 1600px) {
    .stats-grid { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 1300px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 1000px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr; }
}

.stat-card {
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    transition: all 0.2s ease;
}

.stat-card:hover {
    border-color: #555;
    transform: translateY(-1px);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 6px;
    letter-spacing: -0.5px;
}

.stat-label {
    font-size: 0.85rem;
    color: #cccccc;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

/* Profit Chart - Ultra Compact */
.profit-chart-section {
    margin-bottom: 15px;
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 6px;
    padding: 12px;
}

.profit-chart-section h2 {
    color: #ffffff;
    font-size: 1rem;
    margin-bottom: 8px;
    font-weight: 600;
}

.chart-container {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 8px;
    height: 120px;
}

#profitChart {
    max-width: 100%;
    height: 100%;
}

/* Section Headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #404040;
}

.section-header h2 {
    color: #ffffff;
    font-size: 1.05rem;
    margin: 0;
    font-weight: 600;
}

.btn {
    padding: 9px 17px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
}

.btn-secondary {
    background: #404040;
    color: white;
    border: 1px solid #555;
}

.btn-secondary:hover {
    background: #4a4a4a;
}

.btn-icon {
    font-size: 0.9rem;
}

/* Investments List - Ultra Compact */
.investments-list {
    display: grid;
    gap: 8px;
}

.investment-card {
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 6px;
    padding: 10px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.investment-image {
    width: 44px;
    height: 44px;
    border-radius: 4px;
    object-fit: cover;
    background: #404040;
}

.investment-details {
    flex: 1;
}

.investment-details h4 {
    color: #ffffff;
    font-size: 0.95rem;
    margin-bottom: 2px;
    font-weight: 600;
    white-space: normal;
    overflow-wrap: anywhere;
}

.investment-details p {
    color: #cccccc;
    font-size: 0.75rem;
    margin-bottom: 4px;
}

.investment-value {
    color: #4CAF50;
    font-weight: 600;
    font-size: 0.95rem;
}

.investment-actions {
    display: flex;
    gap: 6px;
}

.btn-sell {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 5px 9px;
    border-radius: 3px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-sell:hover {
    background: #45a049;
}

.btn-edit {
    background: #f44336;
    color: white;
    border: none;
    padding: 5px 9px;
    border-radius: 3px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-edit:hover {
    background: #ffffff;
}

/* Sold Items - Ultra Compact */
.sold-items {
    margin-bottom: 15px;
}

.sold-items .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.sold-items .section-header h2 {
    margin: 0;
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 600;
}

.sold-items .section-header .btn {
    width: 100%;
    justify-content: space-between;
    padding: 8px 12px;
    background: #2d2d2d;
    border: 1px solid #404040;
    color: #ffffff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sold-items .section-header .btn:hover {
    background: #333333;
    border-color: #555;
}

.sold-items .section-header .btn .btn-icon {
    transition: transform 0.2s ease;
}

.sold-items .section-header .btn.expanded .btn-icon {
    transform: rotate(180deg);
}

.filter-buttons {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.filter-buttons .btn {
    padding: 3px 6px;
    font-size: 0.7rem;
}

.filter-buttons .btn.active {
    background: #ffffff;
    color: white;
}

.sold-items-list {
    display: grid;
    gap: 8px;
}

.sold-items-content {
    display: grid;
    gap: 8px;
}

.sold-item-card {
    background: linear-gradient(180deg, #191919 0%, #141414 100%);
    border: 1px solid #2e2e2e;
    border-radius: 12px;
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 60px 1fr auto;
    gap: 12px;
    align-items: start;
    transition: all 0.2s ease;
}

.sold-item-card:hover {
    background: #333333;
    border-color: #555;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.sold-item-toggle {
    margin-top: 4px;
    padding: 6px 8px;
    background: rgba(255,255,255,0.03);
    border: 1px solid #303030;
    border-radius: 6px;
    color: #cfcfcf;
    cursor: pointer;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.sold-item-toggle:hover { background: rgba(255,255,255,0.06); }
.sold-item-toggle .caret { transition: transform 0.2s ease; }
.sold-item-toggle.expanded .caret { transform: rotate(180deg); }

/* Compact details block under each card */
.sold-details {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    border-top: 1px dashed #3a3a3a;
    padding-top: 4px;
    margin-top: 4px;
    font-size: 0.82rem;
}
.sold-details .btn { padding: 6px 10px; font-size: 0.82rem; }
.sold-details .sold-item-stickers img { width: 18px; height: 18px; }
.sold-details .sold-item-meta { margin-top: 2px; }

.sold-item-image {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: contain;
    background: #242424;
    flex-shrink: 0;
    border: 1px solid #3a3a3a;
    padding: 2px;
}

.sold-item-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sold-item-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sold-item-name {
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    flex: 1;
    white-space: normal;
    overflow-wrap: anywhere;
}

.sold-item-main-content {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
}

.sold-item-prices {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 12px 16px;
    align-items: start;
}

.sold-item-price-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: flex-start;
}

.sold-item-price-label {
    color: #999999;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sold-item-sale-price { color: #ffffff; font-weight: 700; font-size: 1.05rem; line-height: 1.2; }

.sold-item-purchase-price { color: #cccccc; font-weight: 500; font-size: 0.95rem; line-height: 1.2; }

.sold-item-profit {
    color: #4CAF50;
    font-weight: 700;
    font-size: 1.1rem;
    text-align: center;
    padding: 7px 13px;
    background: rgba(76, 175, 80, 0.18);
    border-radius: 8px;
    border: 1px solid rgba(76, 175, 80, 0.45);
    min-width: 110px;
}

.sold-item-loss {
    color: #f44336;
    font-weight: 700;
    font-size: 1.1rem;
    text-align: center;
    padding: 7px 13px;
    background: rgba(244, 67, 54, 0.18);
    border-radius: 8px;
    border: 1px solid rgba(244, 67, 54, 0.45);
    min-width: 110px;
}

.sold-item-dates { display: flex; justify-content: space-between; margin-top: 8px; font-size: 0.7rem; color: #999999; border-top: 1px dashed #3a3a3a; padding-top: 6px; }

.sold-item-date {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sold-item-date-icon {
    width: 12px;
    height: 12px;
    opacity: 0.7;
}

.sold-item-card {
    background: linear-gradient(180deg, #191919 0%, #141414 100%);
    border: 1px solid #2e2e2e;
    border-radius: 12px;
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 60px 1fr auto;
    gap: 12px;
    align-items: center;
}

.sold-item-card.profit {
    border-left: 3px solid #4CAF50;
}

.sold-item-card.loss {
    border-left: 3px solid #f44336;
}

.sold-item-details {
    flex: 1;
}

.sold-item-details h4 {
    color: #ffffff;
    font-size: 0.9rem;
    margin-bottom: 2px;
    font-weight: 600;
}

.sold-item-details p {
    color: #cccccc;
    font-size: 0.7rem;
    margin-bottom: 4px;
}
.sold-item-sub { color: #999999; font-size: 0.75rem; margin-left: 6px; }

.sold-item-profit {
    font-weight: 600;
    font-size: 0.9rem;
}

.sold-item-profit.positive {
    color: #4CAF50;
}

.sold-item-profit.negative {
    color: #f44336;
}

/* Performance Metrics - Compact */
.performance-metrics {
    margin-bottom: 20px;
}

.performance-metrics h2 {
    color: #ffffff;
    font-size: 1.2rem;
    margin-bottom: 15px;
    font-weight: 600;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

.metric-card {
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.metric-title {
    color: #cccccc;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.metric-value {
    color: #ffffff;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.metric-description {
    color: #999999;
    font-size: 0.7rem;
}

/* Modals - Compact */
.modal {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: #2d2d2d;
    border-radius: 8px;
    padding: 0;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid #404040;
}

.modal-header {
    background: #404040;
    color: white;
    padding: 15px 20px;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.close-modal {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px;
}

/* Forms - Compact */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    color: #cccccc;
    font-size: 0.9rem;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 9px 13px;
    background: #404040;
    border: 1px solid #555;
    border-radius: 4px;
    color: #ffffff;
    font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Fee Calculator - Compact */
.fee-calculator {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 12px;
    margin: 15px 0;
}

.fee-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.fee-item.total {
    border-top: 1px solid #333;
    padding-top: 6px;
    margin-top: 6px;
    font-weight: 600;
}

.fee-item.profit {
    color: #4CAF50;
    font-weight: 700;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #999999;
}

.empty-state p {
    margin-bottom: 8px;
}

/* Item Actions */
.item-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* Responsive */
@media (max-width: 768px) {
    .quick-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .investment-card {
        flex-direction: column;
        text-align: center;
    }
    
    .investment-actions {
        justify-content: center;
    }
    
    .item-actions {
        margin-left: 0;
        justify-content: center;
    }
}

/* Responsive Design */
@media (max-width: 1400px) {
    .main-content {
        max-width: 1000px;
    }
    
    .header-section {
        max-width: 1000px;
    }
}

@media (max-width: 1200px) {
    .main-content {
        max-width: 900px;
    }
    
    .header-section {
        max-width: 900px;
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: 16px;
        min-height: calc(100vh - 60px);
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .section-actions {
        flex-direction: column;
        gap: 8px;
        align-items: flex-end;
    }
    
    .sold-item-main-content {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .sold-item-prices {
        flex-direction: column;
        gap: 8px;
        align-items: center;
        text-align: center;
    }
    
    .sold-item-dates {
        flex-direction: column;
        gap: 4px;
        align-items: center;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .section-actions {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
    }
}

/* Items Section - Clean */
.items-section { margin-bottom: 20px; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h2 {
    color: #ffffff;
    font-size: 1.3rem;
    margin: 0;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.items-count {
    color: #cccccc;
    font-size: 0.9rem;
    font-weight: 500;
}

.items-list { display: grid; gap: 12px; }

/* Global compact KPI row (opt-in via stats-compact) */
.stats-section.stats-compact { background: transparent; border: none; box-shadow: none; padding: 0; }
.stats-section.stats-compact .stats-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.stats-section.stats-compact .stat-card { padding: 10px; border-radius: 12px; min-width: 160px; }
.stats-section.stats-compact .stat-card .stat-value { font-size: 1.5rem; font-weight: 800; }
.stats-section.stats-compact .stat-card .stat-label { font-size: 0.72rem; }
.stats-section.stats-sticky { position: sticky; top: 16px; z-index: 5; }

/* Dashboard grid layout */
.dashboard-grid { display: grid; gap: 12px; align-items: start; grid-template-columns: 320px 1fr; }
.dash-row { display: block; }
@media (max-width: 1100px) { .dashboard-grid { grid-template-columns: 1fr; } }
.dash-row { display: block; }
.pies-grid, .lists-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
/* If only one child, let it span full width */
.pies-grid > :only-child, .lists-grid > :only-child { grid-column: 1 / -1; }
@media (max-width: 1100px) { .pies-grid, .lists-grid { grid-template-columns: 1fr; } }

/* Compact mini lists (recent items) to match portfolio style */
.mini-list { display: grid; gap: 8px; }
.mini-item {
    background: linear-gradient(180deg, #191919 0%, #141414 100%);
    border: 1px solid #2e2e2e;
    border-radius: 10px;
    padding: 8px 10px;
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 10px;
    align-items: center;
}
.mini-item img { width: 32px; height: 32px; object-fit: contain; background:#242424; border:1px solid #3a3a3a; border-radius:6px; padding:2px; }
.mini-title { color:#fff; font-size:0.92rem; font-weight:600; }
.mini-sub { color:#999; font-size:0.78rem; margin-top:2px; }
.mini-value { color:#ddd; font-weight:600; font-size:0.9rem; }

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #999999;
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 12px;
}

.empty-state p {
    margin: 0 0 8px 0;
    font-size: 1rem;
    font-weight: 500;
}

.empty-state p:last-child {
    margin: 0;
    font-size: 0.85rem;
    color: #666666;
}

/* Portfolio grid layout (stats panel left, list right) */
.portfolio-grid { display:grid; grid-template-columns: 1fr 220px; gap: 12px; align-items:start; }
@media (max-width: 1100px) { .portfolio-grid { grid-template-columns: 1fr; } }
/* Compact, sticky KPI sidebar (right) */
.portfolio-grid .stats-section.stats-sticky { position: sticky; top: 16px; align-self: start; }
/* Sidebar compact + modern */
.portfolio-grid .stats-section.stats-compact { width: 220px; background: transparent; border: none; box-shadow: none; padding: 0; }
.portfolio-grid .stats-section.stats-compact .stats-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.portfolio-grid .stats-section.stats-compact .stat-card { padding: 10px; border-radius: 12px; min-width: 0; background: #1c1c1c; border: none; box-shadow: 8px 8px 16px rgba(0,0,0,0.5), -8px -8px 16px rgba(255,255,255,0.04); }
.portfolio-grid .stats-section.stats-compact .stat-card .stat-value { font-size: 1.35rem; font-weight: 800; }
.portfolio-grid .stats-section.stats-compact .stat-card .stat-label { font-size: 0.7rem; }
.portfolio-grid .stats-section.stats-compact .stat-card::after { content: none; }
@media (max-width: 1100px) { .portfolio-grid { grid-template-columns: 1fr; } .portfolio-grid .stats-section.stats-compact { width: auto; } }