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

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

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

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

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

.au-select-btn:active {
    transform: translateY(0);
}

/* ── Drop Zone ── */
.au-dropzone,
.au-dropzone-standalone .au-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(--au-gray-300);
    border-radius: var(--au-border-radius);
    background: var(--au-gray-50);
    color: var(--au-gray-500);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--au-transition), background var(--au-transition), color var(--au-transition), box-shadow var(--au-transition);
}

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

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

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

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

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

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

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

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

.au-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(--au-transition), background var(--au-transition);
    z-index: 2;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.au-queue-cancel,
.au-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(--au-gray-400);
    font-size: 1rem;
    cursor: pointer;
    transition: background var(--au-transition), color var(--au-transition);
}

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

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

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

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

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

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

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

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

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

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

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

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

.au-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(--au-gray-400);
    cursor: pointer;
    transition: background var(--au-transition), color var(--au-transition);
}

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

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

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

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

.au-queue-retry,
.au-queue-pause,
.au-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(--au-gray-400);
    font-size: 1rem;
    cursor: pointer;
    transition: background var(--au-transition), color var(--au-transition);
}

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

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

/* ── Toast Notifications ── */
.au-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;
}

.au-toast {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    border-radius: var(--au-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(--au-font-family);
    font-size: var(--au-font-size);
    color: var(--au-gray-800);
    pointer-events: auto;
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 300ms ease, transform 300ms ease;
    border-left: 4px solid var(--au-gray-300);
}

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

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

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

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

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

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

.au-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(--au-gray-400);
    font-size: 1rem;
    cursor: pointer;
    border-radius: 9999px;
    transition: background var(--au-transition), color var(--au-transition);
}

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

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

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

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

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

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

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

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

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

.au-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(--au-transition);
}

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

/* ── Confirm Dialog ── */
.au-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: au-fade-in 150ms ease;
}

.au-confirm-dialog {
    background: white;
    border-radius: var(--au-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(--au-font-family);
    animation: au-lightbox-zoom 150ms ease;
}

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

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

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

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

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

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

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

/* ── Full Page Drop Overlay ── */
.au-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;
}

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

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

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

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

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

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

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

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

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

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