/* CSS Variables - Compatible with Twenty Twenty-Five */
:root {
    --mohgom-dg-gap: 1.5rem;
    --mohgom-dg-columns: 3;
    --mohgom-dg-primary: var(--wp--preset--color--primary, #8B4513);
    --mohgom-dg-secondary: var(--wp--preset--color--secondary, #2E8B57);
    --mohgom-dg-border: var(--wp--preset--color--tertiary, #e0e0e0);
    --mohgom-dg-bg: var(--wp--preset--color--background, #ffffff);
    --mohgom-dg-text: var(--wp--preset--color--foreground, #1a1a1a);
    --mohgom-dg-shadow: 0 2px 8px rgba(0,0,0,0.08);
    --mohgom-dg-radius: 8px;
    --mohgom-dg-transition: all 0.3s ease;
}

.mohgom-document-gallery {
    max-width: 1400px;
    margin: 2rem auto;
    font-family: inherit;
}

/* Toolbar */
/* ========================================
   TOOLBAR - CORREÇÃO COMPLETA
   ======================================== */

.mohgom-dg-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.25rem;
    background: #ffffff;
    border: 1px solid #F5F5DC;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    align-items: center;
    justify-content: space-between;
}

/* Search box */
.mohgom-dg-search {
    flex: 1;
    min-width: 250px;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.mohgom-dg-search-input {
    flex: 1;
    padding: 0.875rem 1.25rem;
    border: 2px solid #F5F5DC;
    border-radius: 8px;
    background: #fdf5e6;
    color: #1a1a1a;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.mohgom-dg-search-input:focus {
    outline: none;
    border-color: #DAA520;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(218, 165, 32, 0.15);
}

/* Botão de busca - AGORA COM TEXTO VISÍVEL */
.mohgom-dg-search-btn {
    padding: 0.875rem 1.5rem;
    background: #8B4513;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.mohgom-dg-search-btn:hover {
    background: #A0522D;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 69, 19, 0.25);
}

.mohgom-dg-search-btn::before {
    content: "\f179"; /* Dashicon search */
    font-family: 'dashicons';
    font-size: 1.1rem;
}

/* Controls container */
.mohgom-dg-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Selects dropdowns */
.mohgom-dg-filter select,
.mohgom-dg-sort select {
    padding: 0.875rem 2.5rem 0.875rem 1.25rem;
    border: 2px solid #F5F5DC;
    border-radius: 8px;
    background: #ffffff;
    color: #1a1a1a;
    font-size: 0.95rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238B4513' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    min-width: 160px;
    transition: all 0.3s ease;
}

.mohgom-dg-filter select:hover,
.mohgom-dg-sort select:hover {
    border-color: #DAA520;
}

/* Layout switcher */
.mohgom-dg-layout-switch {
    display: flex;
    gap: 0.25rem;
    background: #f5f5f5;
    padding: 0.25rem;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.mohgom-dg-layout-btn {
    background: transparent;
    border: none;
    padding: 0.75rem;
    cursor: pointer;
    border-radius: 6px;
    color: #666;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}

.mohgom-dg-layout-btn:hover {
    background: rgba(139, 69, 19, 0.1);
    color: #8B4513;
}

.mohgom-dg-layout-btn.active {
    background: #8B4513;
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(139, 69, 19, 0.3);
}

/* Ícones dashicons nos botões de layout */
.mohgom-dg-layout-btn .dashicons {
    font-size: 1.25rem;
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Responsivo */
@media (max-width: 768px) {
    .mohgom-dg-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .mohgom-dg-search {
        width: 100%;
    }
    
    .mohgom-dg-controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .mohgom-dg-filter,
    .mohgom-dg-sort {
        flex: 1;
    }
    
    .mohgom-dg-filter select,
    .mohgom-dg-sort select {
        width: 100%;
    }
}

/* Grid Layout */
.mohgom-dg-grid {
    display: grid;
    grid-template-columns: repeat(var(--mohgom-dg-columns), 1fr);
    gap: var(--mohgom-dg-gap);
}

/* Mobile: Sempre 1 coluna em telas pequenas */
@media (max-width: 640px) {
    .mohgom-dg-grid {
        grid-template-columns: 1fr !important; /* Força 1 coluna */
        gap: 1.5rem;
    }
    
    .mohgom-dg-item {
        max-width: 100%;
        margin: 0 auto;
    }
}

/* Tablet: 2 colunas */
@media (min-width: 641px) and (max-width: 1024px) {
    .mohgom-dg-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Desktop: respeita o valor definido nas variáveis */
@media (min-width: 1025px) {
    .mohgom-dg-grid {
        grid-template-columns: repeat(var(--mohgom-dg-columns), 1fr);
    }
}

.mohgom-dg-item {
    background: var(--mohgom-dg-bg);
    border: 1px solid var(--mohgom-dg-border);
    border-radius: var(--mohgom-dg-radius);
    overflow: hidden;
    transition: var(--mohgom-dg-transition);
    box-shadow: var(--mohgom-dg-shadow);
}

.mohgom-dg-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.mohgom-dg-item-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.mohgom-dg-icon {
    position: relative;
    height: 160px;
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.mohgom-dg-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mohgom-dg-file-icon {
    font-size: 3rem;
    font-weight: 800;
    color: var(--mohgom-dg-primary);
    text-transform: uppercase;
}

.mohgom-dg-file-ext {
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    background: var(--mohgom-dg-primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
}

.mohgom-dg-content {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.mohgom-dg-title {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--mohgom-dg-text);
    line-height: 1.3;
}

.mohgom-dg-categories {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.mohgom-dg-category {
    font-size: 0.75rem;
    color: var(--mohgom-dg-secondary);
    background: rgba(46, 139, 87, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

.mohgom-dg-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.75rem;
}

.mohgom-dg-excerpt {
    font-size: 0.9rem;
    color: #555;
    line-height: 1.5;
    margin-bottom: 1.5rem;
    flex: 1;
}

.mohgom-dg-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: auto;
}

.mohgom-dg-download-btn,
.mohgom-dg-preview-btn {
    flex: 1;
    text-align: center;
    padding: 0.75rem 1rem;
    border-radius: var(--mohgom-dg-radius);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--mohgom-dg-transition);
    border: none;
    cursor: pointer;
}

.mohgom-dg-download-btn {
    background: var(--mohgom-dg-primary);
    color: white;
}

.mohgom-dg-download-btn:hover {
    background: var(--mohgom-dg-secondary);
    color: white;
    transform: translateY(-2px);
}

.mohgom-dg-preview-btn {
    background: transparent;
    color: var(--mohgom-dg-primary);
    border: 2px solid var(--mohgom-dg-primary);
}

.mohgom-dg-preview-btn:hover {
    background: var(--mohgom-dg-primary);
    color: white;
}

/* List Layout */
.mohgom-dg-list-view .mohgom-dg-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mohgom-dg-list-item {
    display: grid;
    grid-template-columns: 60px 1fr auto auto;
    gap: 1.5rem;
    align-items: center;
    padding: 1rem;
}

.mohgom-dg-list-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    border-radius: var(--mohgom-dg-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: var(--mohgom-dg-primary);
}

.mohgom-dg-list-content {
    min-width: 0;
}

.mohgom-dg-list-title {
    margin: 0 0 0.25rem 0;
    font-size: 1.1rem;
}

.mohgom-dg-list-desc {
    margin: 0;
    color: #666;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mohgom-dg-list-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: #666;
    text-align: right;
}

.mohgom-dg-list-actions .mohgom-dg-download-btn {
    white-space: nowrap;
}

/* Pagination */
.mohgom-dg-pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 3rem;
    flex-wrap: wrap; /* Quebra linha se necessário */
    padding: 0 1rem; /* Respiro nas laterais */
}

.mohgom-dg-page {
    padding: 0.75rem 1rem;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.3s ease;
    min-width: 44px; /* Área de toque mínima */
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile: Paginação otimizada para toque */
@media (max-width: 640px) {
    .mohgom-dg-pagination {
        gap: 0.5rem;
        margin-top: 2rem;
    }
    
    .mohgom-dg-page {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
        min-width: 40px;
        min-height: 40px;
    }
    
    /* Se houver muitas páginas, limita largura */
    .mohgom-dg-pagination button:nth-child(n+6) {
        display: none; /* Mostra apenas primeiras 5 páginas no mobile */
    }
    
    .mohgom-dg-pagination::after {
        content: "...";
        display: flex;
        align-items: center;
        padding: 0 0.5rem;
        color: #666;
    }
}

.mohgom-dg-page {
    padding: 0.5rem 1rem;
    border: 1px solid var(--mohgom-dg-border);
    background: white;
    cursor: pointer;
    border-radius: var(--mohgom-dg-radius);
    font-weight: 600;
    transition: var(--mohgom-dg-transition);
}

.mohgom-dg-page.active,
.mohgom-dg-page:hover {
    background: var(--mohgom-dg-primary);
    color: white;
    border-color: var(--mohgom-dg-primary);
}

/* Loading State */
.mohgom-dg-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.mohgom-dg-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid var(--mohgom-dg-border);
    border-top-color: var(--mohgom-dg-primary);
    border-radius: 50%;
    animation: mohgom-spin 0.8s linear infinite;
}

@keyframes mohgom-spin {
    to { transform: rotate(360deg); }
}

/* No Results */
.mohgom-dg-no-results {
    text-align: center;
    padding: 4rem 2rem;
    color: #666;
    font-size: 1.1rem;
    grid-column: 1 / -1;
}

/* Responsive */
@media (max-width: 1024px) {
    :root {
        --mohgom-dg-columns: 2;
    }
}

@media (max-width: 768px) {
    :root {
        --mohgom-dg-columns: 1;
    }
    
    .mohgom-dg-toolbar {
        flex-direction: column;
    }
    
    .mohgom-dg-controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .mohgom-dg-list-item {
        grid-template-columns: 50px 1fr;
        grid-template-rows: auto auto;
    }
    
    .mohgom-dg-list-meta,
    .mohgom-dg-list-actions {
        grid-column: 2;
        text-align: left;
    }
    
    .mohgom-dg-list-actions .mohgom-dg-download-btn {
        display: block;
        width: 100%;
    }
}

/* Icon Colors by Extension */
.mohgom-dg-icon.pdf { background: linear-gradient(135deg, #fee 0%, #fcc 100%); }
.mohgom-dg-icon.pdf .mohgom-dg-file-icon { color: #e74c3c; }
.mohgom-dg-icon.docx,
.mohgom-dg-icon.doc { background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); }
.mohgom-dg-icon.docx .mohgom-dg-file-icon { color: #1976d2; }
.mohgom-dg-icon.xlsx,
.mohgom-dg-icon.xls,
.mohgom-dg-icon.csv { background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); }
.mohgom-dg-icon.xlsx .mohgom-dg-file-icon { color: #388e3c; }
.mohgom-dg-icon.png,
.mohgom-dg-icon.jpg,
.mohgom-dg-icon.jpeg { background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%); }
.mohgom-dg-icon.png .mohgom-dg-file-icon { color: #8e24aa; }

/* ========================================
   RESPONSIVIDADE MOBILE - CORREÇÕES
   ======================================== */

@media (max-width: 768px) {
    /* Container principal com respiro */
    .mohgom-document-gallery {
        padding: 0 1rem; /* Respiro nas laterais */
        margin: 1rem auto;
    }
    
    /* Toolbar em coluna no mobile */
    .mohgom-dg-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 1rem;
    }
    
    .mohgom-dg-search {
        width: 100%;
        order: 1; /* Search primeiro */
    }
    
    .mohgom-dg-controls {
        width: 100%;
        justify-content: space-between;
        order: 2;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* Filtros ocupam largura total */
    .mohgom-dg-filter,
    .mohgom-dg-sort {
        flex: 1;
        min-width: 48%;
    }
    
    .mohgom-dg-filter select,
    .mohgom-dg-sort select {
        width: 100%;
        font-size: 16px; /* Previne zoom no iOS */
    }
    
    /* Botões de layout menores */
    .mohgom-dg-layout-switch {
        order: 3;
        width: 100%;
        justify-content: center;
        margin-top: 0.5rem;
    }
    
    /* Cards com respiro interno adequado */
    .mohgom-dg-item-inner {
        margin: 0 0.5rem; /* Margem lateral nos cards */
    }
    
    .mohgom-dg-content {
        padding: 1rem; /* Padding menor no mobile */
    }
    
    /* Botões em coluna no mobile para não ficarem espremidos */
    .mohgom-dg-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .mohgom-dg-download-btn,
    .mohgom-dg-preview-btn {
        width: 100%;
        text-align: center;
    }
}

/* ========================================
   CORREÇÃO: LARGURA IGUAL DOS CARDS
   ======================================== */

/* Garante que todos os cards tenham a mesma largura */
.mohgom-dg-item {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.mohgom-dg-item-inner {
    width: 100%;
    height: 100%; /* Altura igual também se desejado */
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* Mobile: Força largura máxima igual para todos */
@media (max-width: 640px) {
    .mohgom-dg-item {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    .mohgom-dg-item-inner {
        max-width: 100%;
        margin: 0; /* Remove margens que causam desalinhamento */
    }
    
    /* Garante que o grid cell ocupe toda a largura */
    .mohgom-dg-grid > * {
        min-width: 0; /* Previne overflow de grid items */
        width: 100%;
    }
}

/* Força quebra de texto longo não estique o card */
.mohgom-dg-title,
.mohgom-dg-excerpt,
.mohgom-dg-list-title,
.mohgom-dg-list-desc {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
}

/* Garante que a toolbar não cause scroll horizontal */
.mohgom-document-gallery {
    width: 100%;
    max-width: 90%;
    overflow-x: hidden;
}

/* ========================================
   PAGINAÇÃO - CORREÇÃO DE CONTRASTE
   ======================================== */

.mohgom-dg-page {
    padding: 0.75rem 1rem;
    border: 1px solid #ddd;
    background: #ffffff;
    color: #333333 !important; /* TEXTO ESCURO no estado normal */
    cursor: pointer;
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.3s ease;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Estado hover */
.mohgom-dg-page:hover {
    background: #f5f5f5;
    color: #8B4513 !important; /* Cor terra no hover */
    border-color: #8B4513;
}

/* Estado ativo (página atual) */
.mohgom-dg-page.active {
    background: #8B4513 !important;
    color: #ffffff !important; /* TEXTO BRANCO no ativo */
    border-color: #8B4513 !important;
}

/* Mobile */
@media (max-width: 640px) {
    .mohgom-dg-page {
        padding: 0.5rem 0.875rem;
        font-size: 0.9rem;
        min-width: 40px;
        min-height: 40px;
    }
}