/**
 * UFM Redesign — AutoDyna Upload Page
 * Overrides default plugin styles with a modern RTL design
 */

/* ── Reset & container ─────────────────────────────────────────────────── */
.ufm-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px 40px;
    font-family: 'Rubik', 'Assistant', 'Segoe UI', Arial, sans-serif;
    direction: rtl;
    color: #2d3748;
    background: transparent;
    border: none;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.ufm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid #e8edf3;
}

.ufm-title {
    margin: 0 !important;
    font-size: 22px !important;
    font-weight: 700 !important;
    color: #1a202c !important;
}

/* Quota bar */
.ufm-quota {
    flex: 1;
    max-width: 340px;
    min-width: 200px;
}

.ufm-quota-label {
    display: block;
    font-size: 12px;
    color: #718096;
    margin-bottom: 5px;
    text-align: left;
}

.ufm-quota-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 99px;
    overflow: hidden;
}

.ufm-quota-fill {
    height: 100%;
    background: #4a90d9;
    border-radius: 99px;
    transition: width 0.4s ease;
}

.ufm-quota-fill.warning { background: #f6ad55; }
.ufm-quota-fill.danger  { background: #fc8181; }

/* ── Dropzone ───────────────────────────────────────────────────────────── */
.ufm-upload-section {
    margin-bottom: 28px;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
}

.ufm-dropzone {
    position: relative;
    border: 2px dashed #b8c9e0;
    border-radius: 14px;
    background: #f7faff;
    padding: 36px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.ufm-dropzone:hover,
.ufm-dropzone--active {
    border-color: #4a90d9;
    background: #eef5ff;
}

.ufm-file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

.ufm-dropzone-inner {
    position: relative;
    z-index: 1;
    pointer-events: none;
}

.ufm-dropzone-icon {
    font-size: 40px;
    line-height: 1;
    margin-bottom: 10px;
}

.ufm-dropzone-main {
    font-size: 17px;
    font-weight: 600;
    color: #2d3748;
    margin: 0 0 4px;
}

.ufm-dropzone-sub {
    font-size: 13px;
    color: #a0aec0;
    margin: 0 0 12px;
}

.ufm-choose-btn {
    display: inline-block;
    background: #4a90d9;
    color: #fff !important;
    border: none;
    padding: 9px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    pointer-events: all;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none !important;
}

.ufm-choose-btn:hover {
    background: #357abd;
    transform: translateY(-1px);
}

.ufm-dropzone-hint {
    margin: 12px 0 0;
    font-size: 12px;
    color: #a0aec0;
}

/* Progress bar */
#ufm-upload-progress {
    margin-top: 14px;
}

.ufm-progress-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 6px;
}

.ufm-progress-fill {
    height: 100%;
    background: #4a90d9;
    border-radius: 99px;
    width: 0%;
    transition: width 0.3s ease;
}

.ufm-progress-status {
    font-size: 13px;
    color: #718096;
    text-align: center;
}

/* ── Files section ──────────────────────────────────────────────────────── */
.ufm-files-section {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
}

/* Toolbar */
.ufm-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
}

.ufm-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ufm-filter {
    background: #f0f4f8;
    border: 1.5px solid #e2e8f0;
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 13px;
    cursor: pointer;
    color: #4a5568;
    transition: all 0.15s;
    font-family: inherit;
}

.ufm-filter:hover  { border-color: #4a90d9; color: #4a90d9; }
.ufm-filter.active { background: #4a90d9; border-color: #4a90d9; color: #fff; font-weight: 600; }

/* ── Files grid ─────────────────────────────────────────────────────────── */
.ufm-files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}

/* ── File card ──────────────────────────────────────────────────────────── */
.ufm-file-item {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.15s;
    cursor: default;
}

.ufm-file-item:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

/* Preview area */
.ufm-preview-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #f0f4f8;
    overflow: hidden;
}

.ufm-preview,
.ufm-preview-image,
.ufm-preview-video,
.ufm-preview-audio {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ufm-preview img,
.ufm-preview-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Hide original edit buttons inside preview — they're now in the overlay */
.ufm-preview-image .ufm-edit-image-btn,
.ufm-preview-video .ufm-edit-video-btn,
.ufm-preview-audio .ufm-edit-audio-btn {
    display: none;
}

/* Prevent video/audio elements from swallowing mouse events (so overlay works) */
.ufm-preview-container video,
.ufm-preview-container audio {
    pointer-events: none;
}

.ufm-preview-audio audio,
.ufm-preview-video video {
    max-width: 90%;
    max-height: 90%;
}

/* Extension badge */
.ufm-ext-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    pointer-events: none;
}

/* Hover overlay */
.ufm-hover-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    opacity: 0;
    transition: opacity 0.2s;
}

.ufm-file-item:hover .ufm-hover-overlay { opacity: 1; }

.ufm-overlay-btn {
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    text-decoration: none !important;
    transition: background 0.15s, transform 0.1s;
    cursor: pointer;
}

.ufm-overlay-btn:hover { background: #fff; transform: scale(1.1); }

/* File info */
.ufm-file-info {
    padding: 8px 10px;
}

.ufm-filename {
    font-size: 12px;
    font-weight: 500;
    color: #2d3748;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.ufm-filesize {
    font-size: 11px;
    color: #a0aec0;
}

/* Hide old action links (replaced by overlay) */
.ufm-file-actions { display: none !important; }

/* ── Empty state ────────────────────────────────────────────────────────── */
.ufm-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #a0aec0;
}

.ufm-empty-icon { font-size: 54px; margin-bottom: 16px; }

.ufm-empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: #4a5568;
    margin: 0 0 8px;
}

.ufm-empty-state p {
    font-size: 14px;
    color: #a0aec0;
    margin: 0 0 20px;
}

/* ── Delete all ─────────────────────────────────────────────────────────── */
.ufm-delete-all-section {
    margin-top: 32px;
    text-align: center;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
}

#ufm-delete-all-btn {
    background: transparent;
    border: 1.5px solid #fc8181;
    color: #c53030;
    padding: 7px 18px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

#ufm-delete-all-btn:hover {
    background: #fff5f5;
    border-color: #c53030;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .ufm-header { flex-direction: column; align-items: flex-start; }
    .ufm-quota  { max-width: 100%; width: 100%; }

    .ufm-files-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    /* On mobile: always show overlay actions */
    .ufm-hover-overlay { opacity: 1; background: rgba(0,0,0,0.3); }

    .ufm-dropzone { padding: 28px 16px; }
}

@media (min-width: 601px) and (max-width: 900px) {
    .ufm-files-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── UFM Image Editor Modal ─────────────────────────────────────────────── */
#ufm-img-editor-modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 28, 0.82);
    backdrop-filter: blur(4px);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .25s ease;
}
#ufm-img-editor-modal.open { opacity: 1; }

.uie-shell {
    background: #1a1e35;
    border-radius: 18px;
    width:  min(96vw, 980px);
    height: min(94vh, 760px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 32px 80px rgba(0,0,0,.6);
    transform: translateY(16px);
    transition: transform .25s ease;
}
#ufm-img-editor-modal.open .uie-shell { transform: translateY(0); }

/* Header */
.uie-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: #141729;
    border-bottom: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}

.uie-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    color: #e2e8f0;
    white-space: nowrap;
}
.uie-title svg { color: #a78bfa; flex-shrink: 0; }

.uie-fname {
    font-size: 13px;
    color: #64748b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    direction: ltr;
    text-align: left;
}

.uie-close {
    background: none;
    border: none;
    color: #64748b;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    margin-right: auto;
    transition: color .15s, background .15s;
    flex-shrink: 0;
}
.uie-close:hover { color: #e2e8f0; background: rgba(255,255,255,.08); }

/* Body — TUI fills this */
.uie-body {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#uie-tui-wrap {
    width: 100%;
    height: 100%;
}

/* Force TUI to fill container */
#uie-tui-wrap .tui-image-editor-wrap,
#uie-tui-wrap .tui-image-editor-main,
#uie-tui-wrap .tui-image-editor {
    width:  100% !important;
    height: 100% !important;
}

/* Footer */
.uie-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px;
    background: #141729;
    border-top: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
    direction: rtl;
}

.uie-footer-btns {
    display: flex;
    gap: 8px;
}

.uie-btn {
    border: none;
    border-radius: 8px;
    padding: 9px 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s, opacity .15s, transform .1s;
}
.uie-btn:disabled { opacity: .45; cursor: not-allowed; }
.uie-btn:not(:disabled):active { transform: scale(.97); }

.uie-btn-primary {
    background: #7c3aed;
    color: #fff;
}
.uie-btn-primary:not(:disabled):hover { background: #6d28d9; }

.uie-btn-ghost {
    background: transparent;
    color: #94a3b8;
    border: 1px solid rgba(255,255,255,.12);
}
.uie-btn-ghost:not(:disabled):hover {
    background: rgba(255,255,255,.06);
    color: #e2e8f0;
}

.uie-msg {
    font-size: 13px;
    color: #94a3b8;
    flex: 1;
}
.uie-msg.uie-msg-error   { color: #f87171; }
.uie-msg.uie-msg-success { color: #4ade80; }

@media (max-width: 600px) {
    .uie-shell {
        width:  100vw;
        height: 100dvh;
        border-radius: 0;
    }
    .uie-header { padding: 10px 14px; }
    .uie-footer { padding: 10px 14px; }
    .uie-btn    { padding: 8px 16px; font-size: 13px; }
}
