/* ============================================
   PDF Tools - Shared UI Components
   ============================================ */

/* ============ DROPZONE ============ */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--border-radius-lg);
    padding: var(--space-12) var(--space-6);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(135deg, rgba(248,249,250,0.8), rgba(255,255,255,0.9));
    position: relative;
    box-shadow: var(--shadow-sm);
}

.dropzone:hover {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(229, 57, 53, 0.02), rgba(229, 57, 53, 0.05));
    box-shadow: var(--shadow);
}

.dropzone.dragover {
    border-color: var(--primary);
    background: rgba(229, 57, 53, 0.06);
    transform: scale(1.01);
    box-shadow: 0 0 0 4px rgba(229, 57, 53, 0.1);
}

.dropzone-icon {
    font-size: 3.5rem;
    margin-bottom: var(--space-4);
    display: block;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.dropzone-text {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-2);
}

.dropzone-hint {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-5);
}

.dropzone-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-8);
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 2px 8px rgba(229, 57, 53, 0.3);
}

.dropzone-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(229, 57, 53, 0.4);
}

.dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.dropzone.has-files {
    padding: var(--space-6);
    border-style: solid;
    border-color: var(--border);
}

/* ============ FILE LIST ============ */
.file-list {
    margin-top: var(--space-4);
}

/* Standard file item (single file tools) */
.file-item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    margin-bottom: var(--space-3);
    transition: background var(--transition), box-shadow var(--transition);
}

.file-item:hover { background: var(--bg-hover); box-shadow: var(--shadow-sm); }

.file-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.file-icon.pdf { background: #FFEBEE; color: #C62828; }
.file-icon.image { background: #E8F5E9; color: #2E7D32; }
.file-icon.word { background: #E3F2FD; color: #1565C0; }
.file-icon.excel { background: #E8F5E9; color: #388E3C; }
.file-icon.ppt { background: #FBE9E7; color: #D84315; }
.file-icon.generic { background: var(--bg); color: var(--text-secondary); }

.file-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    direction: ltr;
    text-align: right;
}

.file-size {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: 400;
}

.file-remove {
    width: 36px;
    height: 36px;
    border: 1px solid transparent;
    background: none;
    color: var(--text-muted);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
    font-size: 18px;
}

.file-remove:hover {
    background: #FFEBEE;
    color: var(--danger);
    border-color: #FFCDD2;
}

/* ============ FILE LIST ITEMS (multi-file tools like Merge) ============ */
.file-list-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    margin-bottom: var(--space-2);
    transition: background var(--transition), box-shadow var(--transition), border-color var(--transition);
    cursor: grab;
}

.file-list-item:hover {
    background: var(--bg-hover);
    box-shadow: var(--shadow-sm);
    border-color: var(--primary-light);
}

.file-list-item:active { cursor: grabbing; }

.file-list-item.drag-over {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(229, 57, 53, 0.15);
}

.file-list-order {
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: 700;
    flex-shrink: 0;
}

.file-list-handle {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    cursor: grab;
    padding: var(--space-1);
}

.file-list-handle:active { cursor: grabbing; }

.file-list-icon {
    width: 40px;
    height: 40px;
    background: #FFEBEE;
    color: #C62828;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-list-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.file-list-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: ltr;
    text-align: right;
}

.file-list-size {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: 400;
}

.file-list-remove {
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    background: none;
    color: var(--text-muted);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
    font-size: 18px;
    line-height: 1;
}

.file-list-remove:hover {
    background: #FFEBEE;
    color: var(--danger);
    border-color: #FFCDD2;
}

/* ============ IMAGE PREVIEW GRID ============ */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    border: 2px solid var(--border);
    cursor: grab;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item .preview-remove {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition);
}

.preview-item:hover .preview-remove { opacity: 1; }

.preview-item .preview-order {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: var(--primary);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============ PDF PAGE PREVIEW ============ */
.pdf-pages {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.pdf-page {
    position: relative;
    background: white;
    border: 2px solid var(--border);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.pdf-page:hover { border-color: var(--primary-light); box-shadow: var(--shadow); }

.pdf-page.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.2); }

.pdf-page canvas {
    width: 100%;
    display: block;
}

.pdf-page-number {
    text-align: center;
    padding: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    background: var(--bg);
    font-weight: 500;
}

.pdf-page-check {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 24px;
    height: 24px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.pdf-page.selected .pdf-page-check { display: flex; }

/* ============ ACTION BUTTONS ============ */
.action-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-6);
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    border: none;
    border-radius: var(--border-radius-sm);
    font-family: var(--font);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(229, 57, 53, 0.25);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(229, 57, 53, 0.35);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(67, 160, 71, 0.3);
}

.btn-success:hover:not(:disabled) {
    background: #388E3C;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(67, 160, 71, 0.4);
}

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: var(--font-size-lg);
    border-radius: var(--border-radius);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ============ PROGRESS BAR ============ */
.progress-container {
    margin-top: var(--space-4);
    display: none;
}

.progress-container.active { display: block; }

.progress-bar-wrapper {
    width: 100%;
    height: 10px;
    background: var(--border-light);
    border-radius: 5px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.08);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 5px;
    width: 0;
    transition: width 0.3s ease;
    box-shadow: 0 1px 4px rgba(229, 57, 53, 0.3);
}

.progress-text {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

/* ============ RESULT/DOWNLOAD AREA ============ */
.result-area {
    margin-top: var(--space-6);
    padding: var(--space-8);
    background: linear-gradient(135deg, #E8F5E9, #C8E6C9);
    border: 2px solid #A5D6A7;
    border-radius: var(--border-radius-lg);
    text-align: center;
    display: none;
    box-shadow: 0 4px 16px rgba(67, 160, 71, 0.15);
}

.result-area.active { display: block; }

.result-icon {
    font-size: 3.5rem;
    margin-bottom: var(--space-3);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.result-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: #2E7D32;
    margin-bottom: var(--space-2);
}

.result-info {
    font-size: var(--font-size-sm);
    color: #4E6E50;
    margin-bottom: var(--space-5);
    line-height: 1.6;
}

/* ============ OPTIONS PANEL ============ */
.options-panel {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--border-radius-lg);
    padding: var(--space-6);
    margin-top: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.options-title {
    font-size: var(--font-size-base);
    font-weight: 600;
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.option-group {
    margin-bottom: var(--space-4);
}

.option-group:last-child { margin-bottom: 0; }

.option-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    margin-bottom: var(--space-2);
    color: var(--text);
}

.option-select,
.option-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1.5px solid var(--border);
    border-radius: var(--border-radius-sm);
    font-family: var(--font);
    font-size: var(--font-size-sm);
    background: var(--bg-white);
    color: var(--text);
    direction: rtl;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.option-select:focus,
.option-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.1);
}

.option-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239aa0a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left var(--space-3) center;
    padding-left: var(--space-8);
    cursor: pointer;
}

.option-range {
    width: 100%;
    margin-top: var(--space-2);
}

.option-range-value {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-align: center;
    margin-top: var(--space-1);
}

/* ============ ADD MORE FILES ============ */
.add-more-area {
    margin-top: var(--space-3);
    text-align: center;
}

.add-more-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    background: var(--bg-white);
    border: 2px dashed var(--border);
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
}

.add-more-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(229, 57, 53, 0.02);
}

.add-more-btn input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* ============ LOADING SPINNER ============ */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.processing-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.9);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-3);
    border-radius: var(--border-radius-lg);
    z-index: 10;
}

.processing-overlay.active { display: flex; }

.processing-text {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============ RESPONSIVE TOOLS ============ */
@media (max-width: 768px) {
    .dropzone { padding: var(--space-8) var(--space-4); }
    .dropzone-icon { font-size: 2rem; }
    .dropzone-text { font-size: var(--font-size-base); }

    .preview-grid { grid-template-columns: repeat(3, 1fr); }
    .pdf-pages { grid-template-columns: repeat(2, 1fr); }

    .action-bar { flex-direction: column; }
    .action-bar .btn { width: 100%; justify-content: center; }
}
