/* Market Overlay Containers */
.market-modal-container,
.market-add-listing-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    z-index: 1000000;
}

/* Premium Dark Panels */
.market-panel,
.market-add-listing-panel {
    background: #121212;
    border: 1px solid #333333;
    border-radius: 12px;
    width: min(800px, 95vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    color: #e0e0e0;
    font-family: 'Outfit', 'Inter', Arial, sans-serif;
    overflow: hidden;
    animation: marketFadeIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.market-add-listing-panel {
    width: min(600px, 92vw);
}

@keyframes marketFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Market Header */
.market-header,
.market-add-listing-header {
    background: linear-gradient(180deg, #222222 0%, #141414 100%);
    border-bottom: 1px solid #2a2a2a;
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.market-header h3,
.market-add-listing-header h3 {
    margin: 0;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* Close Button */
.market-close,
.market-add-listing-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.market-close:hover,
.market-add-listing-close:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(90deg);
}

/* Market Content Area */
.market-content,
.market-add-listing-content {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #0d0d0d;
}

/* Custom Scrollbars */
.market-content::-webkit-scrollbar,
.market-inventory-grid::-webkit-scrollbar,
.market-listings-grid::-webkit-scrollbar {
    width: 6px;
}
.market-content::-webkit-scrollbar-track,
.market-inventory-grid::-webkit-scrollbar-track,
.market-listings-grid::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}
.market-content::-webkit-scrollbar-thumb,
.market-inventory-grid::-webkit-scrollbar-thumb,
.market-listings-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}
.market-content::-webkit-scrollbar-thumb:hover,
.market-inventory-grid::-webkit-scrollbar-thumb:hover,
.market-listings-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Market Tabs */
.market-tabs {
    display: flex;
    gap: 10px;
    border-bottom: 1px solid #222;
    padding-bottom: 10px;
}

.market-tab {
    background: #181818;
    border: 1px solid #333;
    color: #aaaaaa;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.market-tab:hover {
    background: #242424;
    color: #ffffff;
    border-color: #444;
}

.market-tab.active {
    background: linear-gradient(135deg, #e67e22, #d35400);
    border-color: #e67e22;
    color: #ffffff;
    box-shadow: 0 2px 10px rgba(230, 126, 34, 0.3);
}

/* Tab Content Visibility */
.market-tab-content {
    display: none;
    flex-direction: column;
    gap: 16px;
    flex: 1;
    overflow: hidden;
}

.market-tab-content.active {
    display: flex;
}

/* Market Category Tabs */
.market-category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0 12px 0;
    border-bottom: 1px solid #222;
}

.category-tab {
    background: #181818;
    border: 1px solid #2c2c2c;
    color: #aaaaaa;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.category-tab:hover {
    background: #242424;
    color: #ffffff;
    border-color: #444;
}

.category-tab.active {
    background: linear-gradient(135deg, #e67e22, #d35400);
    border-color: #e67e22;
    color: #ffffff;
    box-shadow: 0 1px 6px rgba(230, 126, 34, 0.3);
}

/* Search and Filters */
.market-search-bar {
    display: flex;
    gap: 12px;
}

.market-search-bar input,
.market-search-bar select {
    background: #181818;
    border: 1px solid #2c2c2c;
    border-radius: 6px;
    color: #ffffff;
    padding: 10px 14px;
    font-size: 13px;
    outline: none;
    transition: all 0.2s ease;
}

.market-search-bar input {
    flex: 1;
}

.market-search-bar input:focus,
.market-search-bar select:focus {
    border-color: #e67e22;
    box-shadow: 0 0 5px rgba(230, 126, 34, 0.2);
}

/* Listings Grids */
.market-listings-grid,
.market-mylistings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    overflow-y: auto;
    padding-right: 4px;
    flex: 1;
}

/* Premium Listing Item Card */
.market-listing-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.market-listing-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(230, 126, 34, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* Item Image Overlay Effects */
.market-item-image-wrapper {
    position: relative;
    width: 60px;
    height: 60px;
    margin-bottom: 8px;
    background: rgba(0,0,0,0.4);
    border-radius: 8px;
    border: 1px solid #333;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.market-item-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Item Name & Details */
.market-item-name {
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
    color: #ffffff;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.3;
}

.market-item-quantity {
    font-size: 10px;
    color: #888888;
    margin-bottom: 8px;
}

.market-item-seller {
    font-size: 10px;
    color: #9b59b6;
    margin-bottom: 10px;
    font-style: italic;
}

/* Currency and Pricing */
.market-item-price-tag {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: 4px;
    width: 100%;
    margin-top: auto;
    margin-bottom: 8px;
}

.market-price-gold {
    background: none !important;
    border: 1px solid #111111;
    color: #f1c40f;
}

.market-price-ruby {
    background: none !important;
    border: 1px solid #111111;
    color: #e74c3c;
}

.market-item-price-tag img {
    width: 13px;
    height: 13px;
    object-fit: contain;
}

/* Action Buttons with button.webp background */
.market-btn-buy,
.market-btn-cancel {
    width: 100%;
    padding: 8px;
    background: url('../assets/icon/ui/button.webp') center/100% 100% no-repeat !important;
    border: none !important;
    color: #ffffff !important;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: transform 0.2s ease !important;
    text-shadow: 1px 1px 2px #000;
    box-shadow: none !important;
    border-radius: 0 !important;
}

.market-btn-buy:hover,
.market-btn-cancel:hover {
    transform: scale(1.05) !important;
}

.market-btn-buy:active,
.market-btn-cancel:active {
    transform: scale(0.95) !important;
}

/* Listings Count Info */
.market-mylistings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #222;
    padding-bottom: 10px;
}

.listings-count-info {
    font-size: 13px;
    font-weight: 600;
}

.listings-count-info span {
    color: #e67e22;
}

.market-btn-primary {
    background: url('../assets/icon/ui/button.webp') center/100% 100% no-repeat !important;
    border: none !important;
    color: #ffffff !important;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease !important;
    text-shadow: 1px 1px 2px #000;
    box-shadow: none !important;
    border-radius: 0 !important;
}

.market-btn-primary:hover {
    transform: scale(1.05) !important;
}

.market-btn-primary:active {
    transform: scale(0.95) !important;
}

/* Add Listing Dialog Details */
.market-inventory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
    background: #080808;
    border: 1px solid #222;
    border-radius: 8px;
    padding: 10px;
}

/* Inventory Item Slot */
.market-inv-slot {
    aspect-ratio: 1;
    background: rgba(255,255,255,0.02);
    border: 1px solid #2c2c2c;
    border-radius: 6px;
    padding: 4px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.market-inv-slot:hover {
    border-color: #e67e22;
    background: rgba(230, 126, 34, 0.05);
}

.market-inv-slot.selected {
    border-color: #e67e22;
    background: rgba(230, 126, 34, 0.12);
    box-shadow: 0 0 10px rgba(230, 126, 34, 0.3);
}

.market-inv-slot img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.market-inv-qty {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    text-shadow: 1px 1px 2px #000;
}

/* Details Section */
.listing-details-section {
    border-top: 1px solid #222;
    padding-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.selected-item-preview {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid #222;
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.preview-name {
    font-size: 13px;
    font-weight: 700;
}

.preview-type {
    font-size: 10px;
    color: #888888;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: #aaaaaa;
}

.form-group input[type="number"] {
    background: #181818;
    border: 1px solid #2c2c2c;
    border-radius: 6px;
    color: #ffffff;
    padding: 10px;
    font-size: 13px;
    outline: none;
}

.form-group input[type="number"]:focus {
    border-color: #e67e22;
}

.currency-selectors {
    display: flex;
    gap: 20px;
}

.currency-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    cursor: pointer;
}

.market-btn-submit {
    background: url('../assets/icon/ui/button.webp') center/100% 100% no-repeat !important;
    border: none !important;
    color: #ffffff !important;
    padding: 12px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: transform 0.2s ease !important;
    margin-top: 10px;
    text-shadow: 1px 1px 2px #000;
    box-shadow: none !important;
    border-radius: 0 !important;
}

.market-btn-submit:hover {
    transform: scale(1.03) !important;
}

.market-btn-submit:active {
    transform: scale(0.97) !important;
}

/* Enhancement & Rarity Indicator Styling */
.enhancement-level {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #f39c12;
    color: #ffffff;
    font-size: 9px;
    font-weight: bold;
    padding: 1px 5px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
    z-index: 5;
}

/* Rarity colors */
.rarity-common { color: #ffffff !important; }
.rarity-uncommon { color: #2ecc71 !important; }
.rarity-rare { color: #3498db !important; }
.rarity-epic { color: #9b59b6 !important; }
.rarity-legendary { color: #f1c40f !important; }
.rarity-mythic { color: #ff1493 !important; }
.rarity-divine { color: #ff00ff !important; }

/* Override global rarity backgrounds from inventory.css */
.market-item-name,
.preview-name {
    background: none !important;
    background-image: none !important;
}

/* Empty listings */
.market-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 10px;
    color: #888888;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.market-empty-icon {
    font-size: 32px;
    opacity: 0.4;
}

/* Mobile Styling */
@media (max-width: 768px) {
    .market-panel {
        width: 95%;
        max-height: 80vh;
    }
    
    .market-content {
        padding: 12px;
        gap: 12px;
    }
    
    .market-tab {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .market-search-bar {
        flex-direction: column;
        gap: 8px;
    }
    
    .market-search-bar input,
    .market-search-bar select {
        padding: 8px;
        font-size: 12px;
    }
    
    .market-listings-grid,
    .market-mylistings-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }
    
    .market-listing-item {
        padding: 8px;
    }
    
    .market-item-image-wrapper {
        width: 48px;
        height: 48px;
    }
    
    .market-item-name {
        font-size: 11px;
        min-height: 28px;
    }
    
    .market-btn-buy,
    .market-btn-cancel {
        padding: 6px;
        font-size: 10px;
    }
    
    .market-inventory-grid {
        max-height: 180px;
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    }
    
    .currency-selectors {
        flex-direction: column;
        gap: 8px;
    }
}

/* Red Dot Notification on Market Button */
.market-menu-btn.minimap-button {
    position: relative;
}

.market-menu-btn.minimap-button::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    background: #e74c3c;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 4px rgba(231, 76, 60, 1), 0 0 8px rgba(231, 76, 60, 0.6);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 100000;
}

.market-menu-btn.minimap-button.has-notification::after {
    opacity: 1;
    visibility: visible;
    animation: market-pulse-dot 1.5s ease-in-out infinite;
}

@keyframes market-pulse-dot {
    0% {
        transform: scale(0.9);
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7);
    }
    70% {
        transform: scale(1.1);
        box-shadow: 0 0 0 6px rgba(231, 76, 60, 0);
    }
    100% {
        transform: scale(0.9);
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
    }
}

/* Optimization for short vertical viewports (e.g. Mobile Landscape, Height <= 500px) */
@media (max-height: 500px) {
    .market-modal-container,
    .market-add-listing-container {
        padding: 5px !important;
        align-items: flex-start !important;
        padding-top: 1vh !important;
    }
    
    .market-panel,
    .market-add-listing-panel {
        max-height: 98vh !important;
        width: 98vw !important;
    }
    
    .market-content,
    .market-add-listing-content {
        padding: 8px !important;
        gap: 8px !important;
        background: #0d0d0d !important;
    }
    
    .market-header,
    .market-add-listing-header {
        padding: 8px 12px !important;
    }
    
    .market-tabs {
        padding-bottom: 6px !important;
        gap: 6px !important;
    }
    
    .market-tab {
        padding: 4px 10px !important;
        font-size: 11px !important;
    }
    
    .market-search-bar {
        gap: 6px !important;
    }
    
    .market-search-bar input,
    .market-search-bar select {
        padding: 6px 10px !important;
        font-size: 11px !important;
    }
    
    .market-listings-grid,
    .market-mylistings-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
        gap: 6px !important;
    }
    
    .market-listing-item {
        padding: 6px !important;
    }
    
    .market-item-image-wrapper {
        width: 38px !important;
        height: 38px !important;
        margin-bottom: 4px !important;
    }
    
    .market-item-name {
        font-size: 10px !important;
        min-height: 22px !important;
    }
    
    .market-item-price-tag {
        padding: 3px 6px !important;
        font-size: 10px !important;
        margin-bottom: 4px !important;
    }
    
    .market-btn-buy,
    .market-btn-cancel {
        padding: 5px !important;
        font-size: 9px !important;
    }
    
    .market-inventory-grid {
        max-height: 100px !important;
    }
    
    .listing-details-section {
        padding-top: 8px !important;
        gap: 6px !important;
    }
    
    .selected-item-preview {
        padding: 6px !important;
        gap: 8px !important;
    }
    
    .preview-image {
        width: 28px !important;
        height: 28px !important;
    }
    
    .form-group input[type="number"] {
        padding: 6px !important;
        font-size: 11px !important;
    }
}

/* Market History Tab Styles */
.market-history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    overflow-y: auto;
    padding-right: 4px;
    flex: 1;
}

.market-history-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.market-history-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.history-badge {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 8px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
    z-index: 5;
}

.badge-buy {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: #ffffff;
    border: 1px solid rgba(46, 204, 113, 0.3);
}

.badge-sell {
    background: linear-gradient(135deg, #e67e22, #d35400);
    color: #ffffff;
    border: 1px solid rgba(230, 126, 34, 0.3);
}

.market-history-party {
    font-size: 10px;
    color: #aaaaaa;
    margin-top: 4px;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.market-history-time {
    font-size: 9px;
    color: #777777;
    margin-top: 2px;
    margin-bottom: 8px;
}

/* Landscape short-height viewport support for History tab */
@media (max-height: 500px) {
    .market-history-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
        gap: 6px !important;
    }
    
    .market-history-item {
        padding: 6px !important;
    }
    
    .market-history-party {
        font-size: 9px !important;
        margin-top: 2px !important;
    }
    
    .market-history-time {
        font-size: 8px !important;
        margin-top: 1px !important;
        margin-bottom: 4px !important;
    }
    
    .history-badge {
        padding: 1px 4px !important;
        font-size: 7px !important;
    }
}

