/* CPW Media Gallery */

#cpw-mg-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 100000 !important;
    background: rgba(0,0,0,0.88) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 24px !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}
#cpw-mg-frame {
    background: #1a1a1a !important;
    border: 1px solid #333 !important;
    border-radius: 10px;
    width: 100%;
    max-width: 1060px;
    height: 82vh;
    max-height: 740px;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 70px rgba(0,0,0,0.7);
    visibility: visible !important;
    opacity: 1 !important;
}

/* Title bar */
#cpw-mg-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 50px;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}
#cpw-mg-titlebar h2 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #fff;
    margin: 0;
}
#cpw-mg-close {
    background: none;
    border: none;
    color: #888;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
#cpw-mg-close:hover { color: #fff; }

/* Tabs */
#cpw-mg-tabs {
    display: flex;
    padding: 0 20px;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}
.cpw-mg-tab {
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: #888;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: inherit;
}
.cpw-mg-tab:hover { color: #ccc; }
.cpw-mg-tab.active { color: #E57200; border-bottom-color: #E57200; }

/* Content */
#cpw-mg-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* Upload panel */
#cpw-mg-upload {
    display: none;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    padding: 32px;
}
#cpw-mg-upload.visible { display: flex; }

#cpw-mg-dropzone {
    width: 100%;
    max-width: 480px;
    border: 2px dashed #444;
    border-radius: 10px;
    padding: 48px 32px;
    text-align: center;
    cursor: pointer;
}
#cpw-mg-dropzone:hover, #cpw-mg-dropzone.over {
    border-color: #E57200;
    background: rgba(229,114,0,0.04);
}

/* Library panel */
#cpw-mg-library {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: row;
}
#cpw-mg-library.visible { display: flex; }

#cpw-mg-lib-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Toolbar */
#cpw-mg-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    flex-wrap: wrap;
}
#cpw-mg-toolbar select,
#cpw-mg-toolbar input {
    padding: 5px 8px;
    background: #222;
    color: #fff;
    border: 1px solid #333;
    border-radius: 5px;
    font-size: 12px;
    font-family: inherit;
}
#cpw-mg-toolbar input {
    flex: 1;
    min-width: 120px;
}
#cpw-mg-count {
    font-size: 11px;
    color: #666;
    white-space: nowrap;
    margin-left: auto;
}

/* Grid */
#cpw-mg-grid-wrap {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
}
#cpw-mg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
    gap: 8px;
}
.cpw-mg-thumb {
    aspect-ratio: 1/1;
    border-radius: 5px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    border: 3px solid transparent;
    background: #222;
}
.cpw-mg-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.cpw-mg-thumb:hover { border-color: rgba(229,114,0,0.35); }
.cpw-mg-thumb.picked {
    border-color: #E57200;
    box-shadow: 0 0 0 1px #E57200, 0 0 10px rgba(229,114,0,0.3);
}
.cpw-mg-thumb.picked::after {
    content: '\2713';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: #E57200;
    color: #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}
.cpw-mg-audio {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: #666;
}

/* Sidebar */
#cpw-mg-sidebar {
    width: 280px;
    flex-shrink: 0;
    border-left: 1px solid #333;
    display: flex;
    flex-direction: column;
    background: #111;
    overflow-y: auto;
}

/* Bottom bar */
#cpw-mg-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 12px 20px;
    border-top: 1px solid #333;
    flex-shrink: 0;
    background: #111;
}
#cpw-mg-sel-thumb {
    width: 34px;
    height: 34px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid #333;
    display: none;
}
#cpw-mg-sel-name {
    flex: 1;
    font-size: 12px;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#cpw-mg-select-btn {
    padding: 8px 24px;
    background: #E57200;
    color: #000;
    border: none;
    border-radius: 6px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    opacity: 0.35;
    pointer-events: none;
}
#cpw-mg-select-btn.on {
    opacity: 1;
    pointer-events: auto;
}
#cpw-mg-select-btn.on:hover { filter: brightness(1.1); }

#cpw-mg-crop-btn {
    padding: 8px 18px;
    background: transparent;
    color: #aaa;
    border: 1px solid #444;
    border-radius: 6px;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    opacity: 0.35;
    pointer-events: none;
}
#cpw-mg-crop-btn.on {
    opacity: 1;
    pointer-events: auto;
    color: #fff;
    border-color: #666;
}
#cpw-mg-crop-btn.on:hover { border-color: #E57200; color: #E57200; }

/* Upload widget inline triggers */
.cpw-upload-zone {
    border: 2px dashed #444;
    border-radius: 8px;
    padding: 18px;
    text-align: center;
    cursor: pointer;
}
.cpw-upload-zone:hover {
    border-color: #E57200;
    background: rgba(229,114,0,0.03);
}
.cpw-upload-preview {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #333;
    cursor: pointer;
}
.cpw-upload-preview img {
    width: 100%;
    height: auto;
    display: block;
}
.cpw-upload-hover {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}
.cpw-upload-preview:hover .cpw-upload-hover { opacity: 1; }

/* Responsive */
@media (max-width: 768px) {
    #cpw-mg-overlay { padding: 0; }
    #cpw-mg-frame { border-radius: 0; height: 100vh; max-height: none; }
    #cpw-mg-sidebar { display: none; }
    #cpw-mg-grid { grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); }
}
