/**
 * Media Selector — Estilos
 * Layout grid+sidebar inspirado no WordPress/NR Foto
 */

/* === Modal Principal === */
#mediaSelectorModal .modal-body {
    padding: 0;
    height: 70vh;
    overflow: hidden;
}

#mediaSelectorModal .ms-layout {
    display: flex;
    height: 100%;
}

/* === Área Esquerda: Toolbar + Grid === */
.ms-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-right: 1px solid var(--border, #1f2937);
}

.ms-toolbar {
    display: flex;
    gap: .5rem;
    align-items: center;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border, #1f2937);
    background: var(--panel, #111827);
    flex-shrink: 0;
}

.ms-toolbar .form-control {
    max-width: 280px;
}

.ms-grid-wrap {
    flex: 1;
    overflow-y: auto;
    padding: .5rem;
    background: var(--bg, #0f172a);
}

/* === Reset do .card Bootstrap nos grids de mídia === */
#mediaGrid .media-card,
#mediaSelectorGrid .media-card {
    border-radius: 0 !important;
    background: transparent !important;
    padding: 0 !important;
    border: 2px solid var(--border, #1f2937) !important;
    overflow: hidden;
    height: auto !important;
}

#mediaGrid .media-card .ratio,
#mediaSelectorGrid .media-card .ratio {
    background: transparent;
}

#mediaGrid .media-card img,
#mediaSelectorGrid .media-card img {
    border-radius: 0 !important;
}

#mediaGrid [class*="col-"],
#mediaSelectorGrid [class*="col-"] {
    padding: 3px !important;
}

/* === Card de Mídia (interações) === */
#mediaSelectorGrid .media-card {
    position: relative;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}

#mediaSelectorGrid .media-card img {
    object-fit: cover;
    transition: transform .2s;
}

#mediaSelectorGrid .media-card:hover {
    border-color: rgba(var(--bs-primary-rgb, 13, 110, 253), .5) !important;
    box-shadow: 0 0 0 1px rgba(var(--bs-primary-rgb, 13, 110, 253), .3);
}

#mediaSelectorGrid .media-card:hover img {
    opacity: .9;
}

/* Ativo (clicado para ver detalhes) */
#mediaSelectorGrid .media-card.active {
    border-color: var(--bs-primary, #0d6efd) !important;
    box-shadow: 0 0 0 2px rgba(var(--bs-primary-rgb, 13, 110, 253), .4);
}

/* Selecionado (multi-seleção) */
#mediaSelectorGrid .media-card.selected {
    border-color: var(--bs-success, #198754) !important;
}

#mediaSelectorGrid .media-card .ms-check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bs-success, #198754);
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    z-index: 2;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}

#mediaSelectorGrid .media-card.selected .ms-check {
    display: flex;
}

/* === Sidebar de Detalhes === */
.ms-sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel, #111827);
    overflow-y: auto;
    transition: opacity .2s;
}

.ms-sidebar-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--muted, #9ca3af);
}

.ms-sidebar-empty i {
    font-size: 3rem;
    opacity: .3;
    margin-bottom: 1rem;
}

.ms-sidebar-content {
    display: none;
    flex-direction: column;
    height: 100%;
}

.ms-sidebar-content.active {
    display: flex;
}

/* Preview */
.ms-preview {
    position: relative;
    background: #1a1a2e;
    min-height: 200px;
    max-height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ms-preview img {
    max-width: 100%;
    max-height: 250px;
    object-fit: contain;
}

.ms-preview .ms-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, .5);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .2s;
    z-index: 2;
}

.ms-preview:hover .ms-nav-btn {
    opacity: 1;
}

.ms-preview .ms-nav-prev {
    left: 8px;
}

.ms-preview .ms-nav-next {
    right: 8px;
}

/* Info e Ações da Sidebar */
.ms-info {
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
}

.ms-info-table {
    width: 100%;
    font-size: .8rem;
    margin-bottom: .75rem;
}

.ms-info-table td {
    padding: 3px 0;
    vertical-align: top;
}

.ms-info-table td:first-child {
    color: var(--muted, #9ca3af);
    white-space: nowrap;
    padding-right: .75rem;
    width: 80px;
}

.ms-info-table td:last-child {
    word-break: break-all;
}

.ms-sidebar-actions {
    padding: .75rem 1rem;
    border-top: 1px solid var(--border, #1f2937);
    flex-shrink: 0;
}

/* === Footer do Modal === */
.ms-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    border-top: 1px solid var(--border, #1f2937);
    background: var(--panel, #111827);
}

/* === Upload Inline === */
.ms-upload-area {
    padding: 1rem;
    border-bottom: 1px solid var(--border, #1f2937);
    background: var(--panel, #111827);
    display: none;
    /* Toggledo via JS */
    flex-shrink: 0;
}

.ms-upload-area.active {
    display: block;
}

.ms-dropzone {
    border: 2px dashed var(--border, #1f2937);
    border-radius: .5rem;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
}

.ms-dropzone:hover,
.ms-dropzone.dragover {
    border-color: var(--primary, #22c55e);
    background: rgba(34, 197, 94, .05);
}

.ms-dropzone i {
    font-size: 2rem;
    color: var(--primary, #22c55e);
    display: block;
    margin-bottom: .5rem;
}

/* === Paginação === */
.ms-pagination {
    padding: .5rem 1rem;
    border-top: 1px solid var(--border, #1f2937);
    flex-shrink: 0;
}

/* === Responsivo === */
@media (max-width: 768px) {
    #mediaSelectorModal .modal-body {
        height: 85vh;
    }

    #mediaSelectorModal .ms-layout {
        flex-direction: column;
    }

    .ms-sidebar {
        width: 100%;
        max-height: 40%;
        border-right: none;
        border-top: 1px solid var(--border, #1f2937);
    }
}

/* === Light theme overrides === */
.theme-light .ms-grid-wrap {
    background: var(--bg);
}

.theme-light .ms-toolbar,
.theme-light .ms-footer,
.theme-light .ms-upload-area {
    background: var(--panel);
}

.theme-light .ms-sidebar {
    background: var(--panel);
}

.theme-light #mediaGrid .media-card,
.theme-light #mediaSelectorGrid .media-card {
    border-color: var(--border) !important;
}