/* ======== MERCADO ONLINE ======== */

/* --- Botón flotante --- */
.mercado-toggle-btn {
    position: fixed;
    bottom: 25px;
    right: 220px;
    background: #1a120b;
    border: 2px solid #a335ee;
    padding: 8px;
    border-radius: 100px;
    width: 50px;
    height: 50px;
    cursor: pointer;
    font-size: 1.3rem;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.mercado-toggle-btn:hover {
    transform: scale(1.1);
    border-color: #c084fc;
    box-shadow: 0 0 12px rgba(163, 53, 238, 0.5);
}

/* --- Overlay modal --- */
.mercado-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2010;
    backdrop-filter: blur(4px);
}

/* --- Contenedor principal --- */
.mercado-modal-content {
    width: 92%;
    max-width: 980px;
    height: 82vh;
    max-height: 820px;
    background: #0a080f;
    border: 2px solid #7c3aed;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(124, 58, 237, 0.2), 0 0 100px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}

/* --- Cabecera --- */
.mercado-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    background: #13091e;
    border-bottom: 1px solid #3b1f6a;
    flex-shrink: 0;
}

.mercado-title {
    font-size: 0.85rem;
    font-weight: bold;
    letter-spacing: 0.15em;
    color: #c084fc;
    white-space: nowrap;
}

.mercado-tabs {
    display: flex;
    gap: 4px;
    flex: 1;
}

.mercado-tab {
    background: transparent;
    border: 1px solid #3b1f6a;
    color: #9ca3af;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.mercado-tab:hover {
    border-color: #7c3aed;
    color: #e2d4f8;
}

.mercado-tab.active {
    background: #7c3aed;
    border-color: #7c3aed;
    color: #fff;
    font-weight: bold;
}

.mercado-close-btn {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.mercado-close-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

/* --- Cuerpo (tabs content) --- */
.mercado-body {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.mercado-tab-content {
    display: none;
    flex-direction: column;
    height: 100%;
    padding: 16px;
    overflow-y: auto;
}

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

/* --- Filtros (tab explorar) --- */
.mercado-filters {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.mercado-input {
    background: #1a0f2e;
    border: 1px solid #3b1f6a;
    color: #e2d4f8;
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s;
}

.mercado-input:focus {
    border-color: #7c3aed;
}

#mercadoSearch {
    flex: 1;
}

.mercado-select {
    background: #1a0f2e;
    border: 1px solid #3b1f6a;
    color: #e2d4f8;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 0.82rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.mercado-select:focus {
    border-color: #7c3aed;
}

/* --- Filtros de tipo (pills) --- */
.mercado-type-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.mercado-type-pill {
    background: rgba(26, 15, 46, 0.5);
    border: 1px solid rgba(124, 58, 237, 0.25);
    color: #6b7280;
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 0.74rem;
    font-weight: bold;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all 0.18s;
    white-space: nowrap;
}

.mercado-type-pill:hover {
    border-color: rgba(124, 58, 237, 0.55);
    color: #c4b5fd;
    background: rgba(124, 58, 237, 0.12);
}

.mercado-type-pill.active {
    background: #7c3aed;
    border-color: #7c3aed;
    color: #fff;
}

/* Ampliar el input de búsqueda cuando hay pills */
.mercado-search-input {
    flex: 1;
    min-width: 0;
}

/* --- Grid de cards --- */
.mercado-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    align-content: start;
}

/* --- Sprite de item (igual que .inv-item-img-wrap / .inv-sprite) --- */
.mercado-item-img-wrap {
    width: 52px;
    height: 52px;
    overflow: hidden;
    position: relative;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(65, 65, 65, 0.15);
    flex-shrink: 0;
}

.mercado-sprite {
    background-image: url('../../assets/img/game/items/items.webp');
    background-size: 900% 500%;
    position: absolute;
    width: 58px;
    height: 58px;
    top: -3px;
    left: -3px;
}

/* --- Cabecera de card (imagen + nombre/rareza) --- */
.mercado-card-header {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 4px;
}

.mercado-card-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

/* --- Cards --- */
.mercado-card {
    background: rgba(26, 15, 46, 0.7);
    border: 1px solid rgba(124, 58, 237, 0.25);
    border-radius: 8px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.mercado-card:hover {
    border-color: rgba(163, 53, 238, 0.6);
    background: rgba(36, 20, 60, 0.8);
    box-shadow: 0 0 10px rgba(124, 58, 237, 0.15);
}

.mercado-inv-card {
    cursor: pointer;
}

.mercado-inv-card.selected {
    border-color: #a335ee;
    background: rgba(124, 58, 237, 0.15);
    box-shadow: 0 0 14px rgba(163, 53, 238, 0.3);
}

.mercado-card-name {
    font-weight: bold;
    font-size: 0.9rem;
    line-height: 1.3;
}

.mercado-card-rarity {
    font-size: 0.72rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mercado-card-desc {
    font-size: 0.78rem;
    color: #9ca3af;
    flex: 1;
    max-height: 80px;
    overflow-y: scroll;
    text-align: left;
    line-height: 1.4;
    scrollbar-width: thin;
    scrollbar-color: #7c3aed #1a0f2e;
    background-color: #241143;
    color: #e3e3e3 !important;
    padding: 10px;
    border-radius: 8px;
}

.mercado-card-seller {
    font-size: 0.75rem;
    color: #6b7280;
}

.mercado-card-seller b {
    color: #a78bfa;
}

.mercado-card-price {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.88rem;
    font-weight: bold;
    color: #fbbf24;
}

.mercado-gold-icon {
    width: 14px;
    height: 14px;
    opacity: 0.9;
}

.mercado-card-qty {
    font-size: 0.75rem;
    color: #7c3aed;
}

.mercado-card-basevalue {
    font-size: 0.75rem;
    color: #6b7280;
}

/* --- Botones --- */
.mercado-btn {
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.8rem;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 0.04em;
    transition: all 0.2s ease;
    margin-top: auto;
}

.mercado-btn-primary {
    background: #7c3aed;
    color: #fff;
    border: 1px solid #9333ea;
}

.mercado-btn-primary:hover {
    background: #6d28d9;
    box-shadow: 0 0 10px rgba(124, 58, 237, 0.4);
}

.mercado-btn-secondary {
    background: transparent;
    color: #9ca3af;
    border: 1px solid #374151;
}

.mercado-btn-secondary:hover {
    color: #e2d4f8;
    border-color: #6b7280;
}

.mercado-btn-buy {
    background: #1f2d1a;
    color: #4ade80;
    border: 1px solid #166534;
}

.mercado-btn-buy:hover:not(:disabled) {
    background: #14532d;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.2);
}

.mercado-btn-buy.disabled,
.mercado-btn-buy:disabled {
    background: #1a1a1a;
    color: #4b5563;
    border-color: #374151;
    cursor: not-allowed;
    opacity: 0.7;
}

.mercado-btn-cancel {
    background: #2a1010;
    color: #f87171;
    border: 1px solid #7f1d1d;
}

.mercado-btn-cancel:hover {
    background: #450a0a;
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.2);
}

/* --- Estado vacío --- */
.mercado-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #4b5563;
    font-size: 0.85rem;
    padding: 40px 0;
}

/* --- Tab vender: layout --- */
.mercado-sell-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 16px;
    height: 100%;
}

.mercado-sell-inv-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}

.mercado-sell-hint {
    font-size: 0.78rem;
    color: #6b7280;
    margin: 0;
}

.mercado-sell-form {
    border-left: 1px solid #2d1d44;
    padding-left: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mercado-sell-preview {
    background: rgba(26, 15, 46, 0.5);
    border: 1px solid #3b1f6a;
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mercado-sell-price-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mercado-label {
    font-size: 0.78rem;
    color: #9ca3af;
}

.mercado-price-input {
    width: 100%;
    box-sizing: border-box;
    font-size: 1rem;
    font-weight: bold;
    color: #fbbf24;
}

.mercado-price-input::-webkit-inner-spin-button,
.mercado-price-input::-webkit-outer-spin-button {
    opacity: 0.5;
}

.mercado-min-hint {
    font-size: 0.72rem;
    color: #a78bfa;
    margin-top: 4px;
}

.mercado-sell-warning {
    font-size: 0.72rem;
    color: #b45309;
    background: rgba(180, 83, 9, 0.1);
    border: 1px solid rgba(180, 83, 9, 0.25);
    border-radius: 4px;
    padding: 6px 8px;
    line-height: 1.4;
}

/* --- Footer de estado --- */
.mercado-footer {
    padding: 8px 20px;
    border-top: 1px solid #1e0f38;
    font-size: 0.78rem;
    color: #a78bfa;
    flex-shrink: 0;
    min-height: 34px;
}

/* ---- Tab Precios ---- */

.mercado-prices-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.mercado-prices-item-select {
    flex: 1;
    min-width: 160px;
}

.mercado-range-btns {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.mercado-range-btn {
    background: rgba(26, 15, 46, 0.6);
    border: 1px solid rgba(124, 58, 237, 0.25);
    color: #6b7280;
    border-radius: 5px;
    padding: 5px 12px;
    font-size: 0.76rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.18s;
    letter-spacing: 0.05em;
}

.mercado-range-btn:hover {
    border-color: #7c3aed;
    color: #c4b5fd;
}

.mercado-range-btn.active {
    background: #7c3aed;
    border-color: #7c3aed;
    color: #fff;
}

/* Stats strip */
.mercado-prices-stats {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    background: rgba(26, 15, 46, 0.5);
    border: 1px solid rgba(124, 58, 237, 0.18);
    border-radius: 7px;
    margin-bottom: 10px;
    flex-shrink: 0;
    min-height: 46px;
}

.mercado-stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 70px;
}

.mercado-stat-label {
    font-size: 0.65rem;
    color: #4b5563;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.mercado-stat-value {
    font-size: 0.88rem;
    font-weight: bold;
    color: #e9d5ff;
}

.mercado-stat-up .mercado-stat-value {
    color: #4ade80;
}

.mercado-stat-down .mercado-stat-value {
    color: #f87171;
}

/* Chart */
.mercado-chart-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    background: rgba(10, 5, 20, 0.6);
    border: 1px solid rgba(124, 58, 237, 0.15);
    border-radius: 7px;
    overflow: hidden;
}

.mercado-chart-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.mercado-prices-nodata {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: #4b5563;
    pointer-events: none;
}

/* Transaction list */
.mercado-prices-txlist {
    flex-shrink: 0;
    max-height: 170px;
    overflow-y: auto;
    border: 1px solid rgba(124, 58, 237, 0.15);
    border-radius: 7px;
    font-size: 0.76rem;
    margin-top: 8px;
}

.mercado-tx-header,
.mercado-tx-row {
    display: grid;
    grid-template-columns: 90px 1fr 1fr 90px;
    gap: 8px;
    padding: 6px 12px;
    align-items: center;
}

.mercado-tx-header {
    background: rgba(26, 15, 46, 0.7);
    color: #4b5563;
    font-weight: bold;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 0.66rem;
    position: sticky;
    top: 0;
    z-index: 1;
}

.mercado-tx-row {
    border-top: 1px solid rgba(124, 58, 237, 0.07);
    transition: background 0.15s;
}

.mercado-tx-row:hover {
    background: rgba(124, 58, 237, 0.06);
}

.mercado-tx-date {
    color: #6b7280;
}

.mercado-tx-buyer {
    color: #a78bfa;
}

.mercado-tx-seller {
    color: #9ca3af;
}

.mercado-tx-price {
    color: #fbbf24;
    font-weight: bold;
    text-align: right;
}

/* Arreglar flex del tab precios para que el chart llene el espacio */
#mercadoTabPrices {
    flex-direction: column;
    gap: 0;
    overflow: hidden;
    padding-bottom: 8px;
}

/* --- Responsive --- */
@media (max-width: 700px) {
    .mercado-modal-content {
        width: 98%;
        height: 95vh;
        border-radius: 8px;
    }

    .mercado-sell-layout {
        grid-template-columns: 1fr;
    }

    .mercado-sell-form {
        border-left: none;
        border-top: 1px solid #2d1d44;
        padding-left: 0;
        padding-top: 12px;
    }

    .mercado-tabs {
        overflow-x: auto;
    }
}