/**
 * CoreUpload v5.0
 * (c) RichScripts
 */

/* ── CSS Custom Properties ── */
:root {
    --cu-primary: #4f46e5;
    --cu-primary-hover: #4338ca;
    --cu-primary-light: #eef2ff;
    --cu-success: #16a34a;
    --cu-success-light: #f0fdf4;
    --cu-danger: #dc2626;
    --cu-danger-light: #fef2f2;
    --cu-warning: #d97706;
    --cu-gray-50: #f9fafb;
    --cu-gray-100: #f3f4f6;
    --cu-gray-200: #e5e7eb;
    --cu-gray-300: #d1d5db;
    --cu-gray-400: #9ca3af;
    --cu-gray-500: #6b7280;
    --cu-gray-600: #4b5563;
    --cu-gray-700: #374151;
    --cu-gray-800: #1f2937;
    --cu-gray-900: #111827;
    --cu-font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --cu-font-size: 0.875rem;
    --cu-border-radius: 0.5rem;
    --cu-border-radius-sm: 0.375rem;
    --cu-transition: 150ms ease;
    --cu-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --cu-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --cu-thumb-size: 64px;
}

/* ── Base ── */
.cu-uploader,
.cu-dropzone-standalone,
.cu-attachments {
    font-family: var(--cu-font-family);
    font-size: var(--cu-font-size);
    color: var(--cu-gray-800);
    line-height: 1.5;
}

/* ── Select Button ── */
.cu-button-area,
.cu-attachments-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.cu-select-btn,
.cu-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    background: var(--cu-primary);
    color: white;
    border: none;
    border-radius: var(--cu-border-radius-sm);
    font-size: var(--cu-font-size);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--cu-transition), box-shadow var(--cu-transition), transform var(--cu-transition);
    box-shadow: var(--cu-shadow);
}

.cu-upload-btn {
    background: var(--cu-success);
}

.cu-select-btn:hover,
.cu-upload-btn:hover {
    background: var(--cu-primary-hover);
    box-shadow: var(--cu-shadow-md);
    transform: translateY(-1px);
}

.cu-upload-btn:hover {
    background: #15803d;
}

.cu-select-btn:active,
.cu-upload-btn:active {
    transform: translateY(0);
}

/* ── Drop Zone ── */
.cu-dropzone,
.cu-dropzone-standalone .cu-dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 160px;
    padding: 2rem;
    margin-top: 1rem;
    border: 2px dashed var(--cu-gray-300);
    border-radius: var(--cu-border-radius);
    background: var(--cu-gray-50);
    color: var(--cu-gray-500);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--cu-transition), background var(--cu-transition), color var(--cu-transition), box-shadow var(--cu-transition);
}

.cu-dropzone:hover,
.cu-dropzone-standalone .cu-dropzone-content:hover {
    border-color: var(--cu-primary);
    background: var(--cu-primary-light);
    color: var(--cu-primary);
}

.cu-drag-over,
.cu-drag-over .cu-dropzone-content {
    border-color: var(--cu-primary) !important;
    background: var(--cu-primary-light) !important;
    color: var(--cu-primary) !important;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
}

.cu-dropzone-icon { opacity: 0.6; }
.cu-dropzone-text { font-size: 0.9375rem; font-weight: 500; }

/* ── Inline Image Thumbnails (paste/drop preview) ── */
.cu-preview-area {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding: 0;
}

.cu-thumb {
    position: relative;
    width: var(--cu-thumb-size);
    height: var(--cu-thumb-size);
    border-radius: var(--cu-border-radius-sm);
    overflow: hidden;
    border: 2px solid var(--cu-gray-200);
    background: var(--cu-gray-100);
    flex-shrink: 0;
    transition: border-color var(--cu-transition), box-shadow var(--cu-transition);
    animation: cu-thumb-appear 200ms ease;
}

@keyframes cu-thumb-appear {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.cu-thumb:hover {
    border-color: var(--cu-primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.cu-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cu-thumb-close {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--cu-transition), background var(--cu-transition);
    z-index: 2;
}

.cu-thumb:hover .cu-thumb-close {
    opacity: 1;
}

.cu-thumb-close:hover {
    background: var(--cu-danger);
}

/* Thumbnail overlay states */
.cu-thumb-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.cu-thumb-overlay--uploading {
    background: rgba(0, 0, 0, 0.4);
}

.cu-thumb-overlay--done {
    background: rgba(22, 163, 74, 0.5);
    animation: cu-overlay-flash 600ms ease;
}

.cu-thumb-overlay--error {
    background: rgba(220, 38, 38, 0.5);
}

@keyframes cu-overlay-flash {
    0% { background: rgba(22, 163, 74, 0.8); }
    100% { background: rgba(22, 163, 74, 0.5); }
}

.cu-thumb-progress-ring {
    width: 28px;
    height: 28px;
}

.cu-thumb-progress-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.cu-thumb-progress-ring circle:last-child {
    transition: stroke-dasharray 200ms ease;
}

/* ── Progress Bar ── */
.cu-progress {
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--cu-gray-50);
    border-radius: var(--cu-border-radius-sm);
    border: 1px solid var(--cu-gray-200);
}

.cu-progress-bar {
    height: 0.5rem;
    background: var(--cu-gray-200);
    border-radius: 9999px;
    overflow: hidden;
}

.cu-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--cu-primary), #7c3aed);
    border-radius: 9999px;
    transition: width 200ms ease;
    width: 0;
}

.cu-progress-text {
    margin-top: 0.375rem;
    font-size: 0.8125rem;
    color: var(--cu-gray-500);
    font-variant-numeric: tabular-nums;
}

/* ── Queue ── */
.cu-queue {
    margin-top: 0.75rem;
}

.cu-queue-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: white;
    border: 1px solid var(--cu-gray-200);
    border-radius: var(--cu-border-radius-sm);
    margin-bottom: 0.375rem;
    transition: background var(--cu-transition), border-color var(--cu-transition);
    animation: cu-queue-slide-in 200ms ease;
}

@keyframes cu-queue-slide-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.cu-queue-item:hover {
    background: var(--cu-gray-50);
    border-color: var(--cu-gray-300);
}

.cu-queue-item--completed { border-left: 3px solid var(--cu-success); }
.cu-queue-item--failed { border-left: 3px solid var(--cu-danger); background: var(--cu-danger-light); }
.cu-queue-item--uploading { border-left: 3px solid var(--cu-primary); background: var(--cu-primary-light); }
.cu-queue-item--cancelled { opacity: 0.5; }

.cu-file-icon {
    flex-shrink: 0;
    font-size: 1rem;
}

.cu-status-icon {
    flex-shrink: 0;
    width: 1.25rem;
    text-align: center;
    font-weight: bold;
}

.cu-status-ok { color: var(--cu-success); }
.cu-status-error { color: var(--cu-danger); }
.cu-status-uploading { color: var(--cu-primary); animation: cu-spin 1s linear infinite; }
.cu-status-cancelled { color: var(--cu-gray-400); }
.cu-status-pending { color: var(--cu-gray-400); }

@keyframes cu-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.cu-queue-name {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cu-queue-size {
    flex-shrink: 0;
    color: var(--cu-gray-500);
    font-size: 0.8125rem;
}

.cu-queue-progress {
    flex: 0 0 100px;
    height: 0.375rem;
    background: rgba(79, 70, 229, 0.2);
    border-radius: 9999px;
    overflow: hidden;
}

.cu-queue-progress-fill {
    height: 100%;
    background: var(--cu-primary);
    border-radius: 9999px;
    transition: width 200ms ease;
}

.cu-queue-percent {
    flex-shrink: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--cu-primary);
    min-width: 2.5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.cu-queue-error {
    flex-shrink: 0;
    color: var(--cu-danger);
    font-size: 0.8125rem;
}

.cu-queue-cancel,
.cu-queue-remove {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 9999px;
    background: transparent;
    color: var(--cu-gray-400);
    font-size: 1rem;
    cursor: pointer;
    transition: background var(--cu-transition), color var(--cu-transition);
}

.cu-queue-cancel:hover { background: var(--cu-danger-light); color: var(--cu-danger); }
.cu-queue-remove:hover { background: var(--cu-gray-100); color: var(--cu-gray-600); }

/* ── Attachments ── */
.cu-attachments {
    border: 1px solid var(--cu-gray-200);
    border-radius: var(--cu-border-radius);
    overflow: hidden;
}

.cu-attachments-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--cu-gray-50);
    border-bottom: 1px solid var(--cu-gray-200);
}

.cu-attachments-count {
    color: var(--cu-gray-500);
    font-size: 0.8125rem;
}

.cu-attachments-list { padding: 0; }

.cu-attachment-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--cu-gray-100);
    transition: background var(--cu-transition);
}

.cu-attachment-item:last-child { border-bottom: none; }
.cu-attachment-item:hover { background: var(--cu-gray-50); }

.cu-attachment-icon { flex-shrink: 0; font-size: 1rem; }

.cu-attachment-thumb {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid var(--cu-gray-200);
}

.cu-attachment-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cu-attachment-size {
    flex-shrink: 0;
    color: var(--cu-gray-500);
    font-size: 0.8125rem;
}

.cu-attachment-progress {
    flex-shrink: 0;
    color: var(--cu-primary);
    font-weight: 600;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.cu-attachment-remove {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 9999px;
    background: transparent;
    color: var(--cu-gray-400);
    cursor: pointer;
    transition: background var(--cu-transition), color var(--cu-transition);
}

.cu-attachment-remove:hover {
    background: var(--cu-danger-light);
    color: var(--cu-danger);
}

/* ── Paused / Processing / Disabled States ── */
.cu-queue-item--paused { border-left: 3px solid var(--cu-warning); background: rgba(217, 119, 6, 0.05); }
.cu-queue-item--processing { border-left: 3px solid var(--cu-primary); background: var(--cu-primary-light); }
.cu-status-paused { color: var(--cu-warning); }
.cu-status-processing { color: var(--cu-primary); animation: cu-pulse 1.5s ease infinite; }

@keyframes cu-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.cu-disabled {
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
}

.cu-queue-retry,
.cu-queue-pause,
.cu-queue-resume {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 9999px;
    background: transparent;
    color: var(--cu-gray-400);
    font-size: 1rem;
    cursor: pointer;
    transition: background var(--cu-transition), color var(--cu-transition);
}

.cu-queue-retry:hover { background: var(--cu-primary-light); color: var(--cu-primary); }
.cu-queue-pause:hover { background: rgba(217, 119, 6, 0.1); color: var(--cu-warning); }
.cu-queue-resume:hover { background: var(--cu-success-light); color: var(--cu-success); }

/* ── Thumbnail paused overlay ── */
.cu-thumb-overlay--paused {
    background: rgba(217, 119, 6, 0.5);
}

/* ── Toast Notifications ── */
.cu-toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    max-width: 360px;
}

.cu-toast {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    border-radius: var(--cu-border-radius);
    background: white;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12), 0 4px 10px rgba(0, 0, 0, 0.08);
    font-family: var(--cu-font-family);
    font-size: var(--cu-font-size);
    color: var(--cu-gray-800);
    pointer-events: auto;
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 300ms ease, transform 300ms ease;
    border-left: 4px solid var(--cu-gray-300);
}

.cu-toast--visible {
    opacity: 1;
    transform: translateX(0);
}

.cu-toast--leaving {
    opacity: 0;
    transform: translateX(100%);
}

.cu-toast--success { border-left-color: var(--cu-success); }
.cu-toast--error { border-left-color: var(--cu-danger); }
.cu-toast--warning { border-left-color: var(--cu-warning); }
.cu-toast--info { border-left-color: var(--cu-primary); }

.cu-toast-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}

.cu-toast--success .cu-toast-icon { color: var(--cu-success); }
.cu-toast--error .cu-toast-icon { color: var(--cu-danger); }
.cu-toast--warning .cu-toast-icon { color: var(--cu-warning); }
.cu-toast--info .cu-toast-icon { color: var(--cu-primary); }

.cu-toast-message {
    flex: 1;
    line-height: 1.4;
}

.cu-toast-close {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--cu-gray-400);
    font-size: 1rem;
    cursor: pointer;
    border-radius: 9999px;
    transition: background var(--cu-transition), color var(--cu-transition);
}

.cu-toast-close:hover {
    background: var(--cu-gray-100);
    color: var(--cu-gray-600);
}

/* ── Lightbox ── */
.cu-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100001;
    align-items: center;
    justify-content: center;
}

.cu-lightbox--visible {
    display: flex;
}

.cu-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    animation: cu-fade-in 200ms ease;
}

@keyframes cu-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cu-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: cu-lightbox-zoom 200ms ease;
}

@keyframes cu-lightbox-zoom {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.cu-lightbox-img {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--cu-border-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.cu-lightbox-caption {
    margin-top: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    font-family: var(--cu-font-family);
    font-size: var(--cu-font-size);
    text-align: center;
}

.cu-lightbox-close {
    position: absolute;
    top: -2rem;
    right: -1rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 1.25rem;
    border-radius: 9999px;
    cursor: pointer;
    transition: background var(--cu-transition);
}

.cu-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ── Confirm Dialog ── */
.cu-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 100002;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    animation: cu-fade-in 150ms ease;
}

.cu-confirm-dialog {
    background: white;
    border-radius: var(--cu-border-radius);
    padding: 1.5rem;
    min-width: 300px;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    font-family: var(--cu-font-family);
    animation: cu-lightbox-zoom 150ms ease;
}

.cu-confirm-message {
    margin: 0 0 1.25rem 0;
    font-size: 0.9375rem;
    color: var(--cu-gray-800);
    line-height: 1.5;
}

.cu-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.cu-confirm-btn {
    padding: 0.4rem 1rem;
    border: 1px solid var(--cu-gray-300);
    border-radius: var(--cu-border-radius-sm);
    font-size: var(--cu-font-size);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--cu-transition), border-color var(--cu-transition);
}

.cu-confirm-btn--cancel {
    background: white;
    color: var(--cu-gray-600);
}

.cu-confirm-btn--cancel:hover {
    background: var(--cu-gray-50);
    border-color: var(--cu-gray-400);
}

.cu-confirm-btn--ok {
    background: var(--cu-primary);
    color: white;
    border-color: var(--cu-primary);
}

.cu-confirm-btn--ok:hover {
    background: var(--cu-primary-hover);
    border-color: var(--cu-primary-hover);
}

/* ── Full Page Drop Overlay ── */
.cu-fullpage-drop-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(79, 70, 229, 0.08);
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
}

.cu-fullpage-drop-overlay--visible {
    display: flex;
}

.cu-fullpage-drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 3rem 4rem;
    background: white;
    border: 3px dashed var(--cu-primary);
    border-radius: 1rem;
    color: var(--cu-primary);
    font-family: var(--cu-font-family);
    font-size: 1.125rem;
    font-weight: 600;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    animation: cu-lightbox-zoom 200ms ease;
}

/* ── Attachment uploading state ── */
.cu-attachment-item--uploading {
    background: var(--cu-primary-light);
}

/* ── Dark Mode ── */
.cu-dark,
.cu-uploader.cu-dark,
.cu-dropzone-standalone.cu-dark,
.cu-attachments.cu-dark {
    --cu-gray-50: #1a1a2e;
    --cu-gray-100: #16213e;
    --cu-gray-200: #2a2a4a;
    --cu-gray-300: #3a3a5a;
    --cu-gray-400: #6a6a8a;
    --cu-gray-500: #9a9aba;
    --cu-gray-600: #c0c0d0;
    --cu-gray-700: #d0d0e0;
    --cu-gray-800: #e8e8f0;
    --cu-gray-900: #f5f5ff;
    --cu-primary-light: rgba(79, 70, 229, 0.15);
    --cu-success-light: rgba(22, 163, 74, 0.15);
    --cu-danger-light: rgba(220, 38, 38, 0.15);
}

.cu-dark .cu-queue-item,
.cu-dark .cu-thumb {
    background: var(--cu-gray-100);
}

.cu-dark .cu-toast {
    background: var(--cu-gray-100);
    color: var(--cu-gray-800);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.cu-dark .cu-confirm-dialog {
    background: var(--cu-gray-100);
    color: var(--cu-gray-800);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.cu-dark .cu-confirm-btn--cancel {
    background: var(--cu-gray-50);
    color: var(--cu-gray-600);
    border-color: var(--cu-gray-300);
}

.cu-dark .cu-fullpage-drop-content {
    background: var(--cu-gray-100);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* ── Responsive ── */
@media (max-width: 480px) {
    .cu-queue-progress { display: none; }
    .cu-queue-item { flex-wrap: wrap; }
    .cu-thumb { --cu-thumb-size: 48px; }
}

/* ── Reduced motion (a11y) ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .cu-uploader *,
    .cu-lightbox,
    .cu-confirm-overlay,
    .cu-fullpage-drop-overlay {
        animation: none !important;
        transition: none !important;
    }
    .cu-thumb-progress-ring circle { transition: none !important; }
}
