:root {
    --primary-color: #3a8dff;
    --danger-color: #ff4757;
    --bg-primary: #1a1a1a;
    --bg-secondary: #252525;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-color: #333333;
    --glass: rgba(255,255,255,0.1);
}

/* =========================================
   LAYOUT PRINCIPAL (CORRIGIDO PARA FULL WIDTH)
   ========================================= */
.market-layout {
    display: block; /* Remove o Grid lateral */
    width: 100%;
    position: relative;
}

/* Sidebar agora funciona como Menu/Drawer (Gaveta) em todas as telas */
.market-sidebar {
    position: fixed;
    top: 0;
    left: -100%; /* Escondido na esquerda */
    width: 300px;
    height: 100vh;
    z-index: 10000;
    background: var(--bg-secondary);
    padding: 20px;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 5px 0 15px rgba(0,0,0,0.5);
}

    .market-sidebar.active {
        left: 0; /* Aparece ao ativar */
    }

    .market-sidebar::-webkit-scrollbar {
        width: 6px;
    }

    .market-sidebar::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 3px;
    }

/* Cabeçalho da Sidebar (Botão fechar) sempre visível dentro dela */
.mobile-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.close-sidebar-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

/* Botão de abrir filtros visível sempre */
.mobile-only-btn {
    display: inline-flex !important;
}

/* =========================================
   CONTEÚDO PRINCIPAL (CENTRALIZADO)
   ========================================= */
.market-main {
    width: 95%; /* Ocupa quase toda a largura */
    max-width: 1400px; /* Limite para monitores ultrawide */
    margin: 0 auto; /* Centraliza na tela */
    padding: 20px 0;
    display: flex;
    flex-direction: column;
}

/* Overlay Escuro (Fundo quando sidebar abre) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 9998;
    backdrop-filter: blur(3px);
}

    .sidebar-overlay.active {
        display: block;
    }

/* =========================================
   FILTROS INTERNOS
   ========================================= */
.filter-group h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.filter-section {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

    .filter-section h4 {
        margin: 0 0 10px 0;
        font-size: 0.95rem;
        color: var(--text-primary);
    }

.sidebar-input {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    margin-bottom: 10px;
    box-sizing: border-box;
}

.category-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.cat-group summary {
    cursor: pointer;
    padding: 8px;
    font-weight: 600;
    color: var(--text-primary);
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 6px;
    transition: 0.2s;
    user-select: none;
}

    .cat-group summary:hover {
        background: var(--bg-primary);
    }

    .cat-group summary::-webkit-details-marker {
        display: none;
    }

    .cat-group summary::after {
        content: '+';
        font-weight: normal;
        opacity: 0.7;
    }

.cat-group[open] summary::after {
    content: '-';
}

.sub-list {
    padding-left: 15px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 5px;
    border-left: 2px solid var(--border-color);
    margin-left: 12px;
}

.sub-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 3px 0;
    transition: 0.2s;
}

    .sub-label:hover {
        color: var(--primary-color);
    }

    .sub-label.parent-selector {
        font-style: italic;
        opacity: 0.8;
        margin-bottom: 5px;
    }

.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

    .checkbox-list label {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 0.9rem;
        color: var(--text-secondary);
        cursor: pointer;
    }

.price-range-inputs {
    display: flex;
    gap: 5px;
    align-items: center;
    color: var(--text-secondary);
}

    .price-range-inputs input {
        width: 100%;
        padding: 8px;
        border-radius: 6px;
        border: 1px solid var(--border-color);
        background: var(--bg-primary);
        color: var(--text-primary);
    }

/* ESTILOS DE BOTÕES */
.action-btn-primary, .action-btn-secondary {
    border: none;
    padding: 7px 20px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    text-decoration: none;
}

.action-btn-primary {
    background-color: var(--primary-color);
    color: white;
}

    .action-btn-primary:hover {
        filter: brightness(1.1);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(58, 141, 255, 0.3);
    }

    .action-btn-primary:disabled {
        background-color: #555;
        cursor: not-allowed;
    }

.action-btn-secondary {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

    .action-btn-secondary:hover {
        background-color: var(--border-color);
        color: var(--text-primary);
    }

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
}

    .icon-btn:hover {
        color: var(--text-primary);
    }

.small-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* MODAL PADRÃO */
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.7);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #242526;
    margin: auto;
    padding: 0;
    border: 1px solid #3e4042;
    width: 90%;
    text-align: center;
    max-width: 500px;
    border-radius: 8px;
    color: #e4e6eb;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #3e4042;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255,255,255,0.02);
    border-radius: 8px 8px 0 0;
}

    .modal-header h3 {
        margin: 0;
        font-size: 1.2rem;
        font-weight: 700;
    }

.close-modal-btn {
    color: #b0b3b8;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

    .close-modal-btn:hover {
        color: #fff;
        text-decoration: none;
        cursor: pointer;
    }

.modal-actions {
    padding: 15px 20px;
    border-top: 1px solid #3e4042;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: rgba(255,255,255,0.02);
    border-radius: 0 0 8px 8px;
}

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-size: 0.9rem;
    transition: background 0.2s;
    color: white;
    background: var(--primary-color);
}

    .btn:hover {
        filter: brightness(1.1);
    }

    .btn.ghost {
        background: transparent;
        color: #b0b3b8;
    }

        .btn.ghost:hover {
            background: rgba(255,255,255,0.1);
            color: white;
        }

    .btn.delete {
        background: var(--danger-color);
        color: white;
    }

        .btn.delete:hover {
            background: #ff6b81;
        }

/* MODAL DE PRODUTO */
.product-modal-content {
    max-width: 800px;
    width: 95%;
    background: #1e1e1e;
}

.product-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    padding: 20px;
}

.detail-image-col {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    max-height: 450px;
    border: 1px solid var(--border-color);
}

.main-detail-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    max-height: 450px;
}

.detail-info-col {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.seller-info-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

    .seller-info-row img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        object-fit: cover;
    }

#md-product-title {
    margin: 0;
    font-size: 1.5rem;
    color: #fff;
    line-height: 1.2;
}

.detail-price {
    font-size: 1.8rem;
    color: var(--primary-color);
    font-weight: bold;
}

.tags-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.detail-tag {
    background: #333;
    color: #ccc;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.detail-description-box {
    background: #252525;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    flex-grow: 1;
    overflow-y: auto;
    max-height: 200px;
}

    .detail-description-box h4 {
        margin: 0 0 8px 0;
        color: #fff;
        font-size: 1rem;
        border-bottom: 1px solid #444;
        padding-bottom: 5px;
    }

    .detail-description-box p {
        font-size: 0.95rem;
        color: #bbb;
        white-space: pre-wrap;
        margin: 0;
        line-height: 1.5;
    }

.contact-area {
    margin-top: auto;
    padding-top: 15px;
}

/* Form e Inputs */
#product-form-container {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

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

.select-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#product-form input[type="text"], #product-form input[type="number"], #product-form select, #product-form textarea {
    width: 100%;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

#product-form textarea {
    resize: vertical;
    min-height: 80px;
}

    #product-form input:focus, #product-form select:focus, #product-form textarea:focus {
        border-color: none;
        outline: none;
    }

#product-form select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Galeria de Upload */
.upload-gallery-container {
    display: flex;
    flex-wrap: wrap;
    padding-top: 8px;
    gap: 10px;
    align-items: flex-start;
}

.gallery-item {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #000;
    flex-shrink: 0;
}

    .gallery-item img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

.gallery-remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: 0.2s;
    backdrop-filter: blur(2px);
}

    .gallery-remove-btn:hover {
        background: var(--danger-color);
    }

.gallery-add-btn {
    width: 100px;
    height: 100px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.5rem;
    transition: 0.2s;
    background: var(--bg-primary);
    flex-shrink: 0;
}

    .gallery-add-btn:hover {
        border-color: var(--primary-color);
        color: var(--primary-color);
    }

    .gallery-add-btn input {
        display: none;
    }

/* Cards & Grid */
.market-topbar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    padding: 10px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    gap: 15px;
    flex-wrap: wrap;
    box-sizing: border-box;
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    padding: 8px 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    flex-grow: 1;
    max-width: 32%;
}

    .search-box input {
        border: none;
        background: transparent;
        color: var(--text-primary);
        margin-left: 10px;
        width: 100%;
        outline: none;
    }

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

#sort-select {
    padding: 10px;
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    outline: none;
}

.products-grid {
    width: 100%;
    display: grid;
    /* Colunas ajustáveis automaticamente */
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    min-height: 200px;
}

.market-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    position: relative;
}

    .market-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    }

.card-image {
    height: 180px;
    background-size: cover;
    background-position: center;
    position: relative;
    background-color: #000;
}

.card-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.1);
}

.delete-item-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(255, 71, 87, 0.9);
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: 0.2s;
    z-index: 2;
}

    .delete-item-btn:hover {
        transform: scale(1.1);
        background: red;
    }

.card-body {
    padding: 15px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 1rem;
    margin: 0 0 5px 0;
    color: var(--text-primary);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.card-price {
    color: var(--primary-color);
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.card-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.card-actions {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
}

.no-results {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    text-align: center;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
}

    .no-results i {
        margin-bottom: 15px;
        opacity: 0.5;
        color: var(--primary-color);
    }

    .no-results p {
        font-size: 1.2rem;
        margin: 5px 0;
    }

.hidden {
    display: none !important;
}

/* =========================================
   MEDIA QUERIES (AJUSTES FINAIS PARA CELULAR)
   ========================================= */
@media (max-width: 768px) {
    /* Em mobile, a sidebar já é configurada globalmente como gaveta,
       apenas ajustamos o layout interno da página */

    .market-sidebar {
        width: 80%; /* Gaveta ocupa mais espaço no mobile */
    }

    .products-grid {
        grid-template-columns: 1fr 1fr; /* Força 2 colunas */
        gap: 10px;
    }

    .market-card {
        border-radius: 8px;
    }

    .card-image {
        height: 140px;
    }

    .card-body {
        padding: 10px;
    }

    .card-title {
        font-size: 0.9rem;
    }

    .card-price {
        font-size: 1rem;
        margin-bottom: 5px;
    }

    .card-meta {
        display: none;
    }

    .market-topbar {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .search-box {
        width: 100%;
        max-width: none;
    }

    .topbar-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    #sort-select {
        width: 100%;
    }

    /* Botão Flutuante (FAB) para criar anúncio */
    #toggle-create-product-form {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 9990;
        border-radius: 50px;
        width: auto;
        padding: 12px 20px;
        box-shadow: 0 4px 15px rgba(58, 141, 255, 0.4);
        display: flex !important;
    }

    .desktop-only {
        display: none;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    /* Modal Mobile Fullscreen */
    .product-modal-content {
        width: 100%;
        height: 100%;
        max-width: none;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .product-detail-grid {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        padding-bottom: 60px;
        height: 100%;
    }

    .detail-image-col {
        max-height: 250px;
        border: none;
        background: transparent;
        flex-shrink: 0;
    }
}
